Added config option to enable currentcontrol module, and added enable
authorArthur Wolf <wolf.arthur@gmail.com>
Sun, 22 Apr 2012 07:25:28 +0000 (09:25 +0200)
committerArthur Wolf <wolf.arthur@gmail.com>
Sun, 22 Apr 2012 07:25:28 +0000 (09:25 +0200)
pins in Stepper

src/libs/Pin.h
src/modules/robot/Stepper.cpp
src/modules/robot/Stepper.h
src/modules/utils/currentcontrol/CurrentControl.cpp
src/modules/utils/pausebutton/PauseButton.cpp

index 203dda0..1a0eb2a 100644 (file)
@@ -13,7 +13,8 @@ class Pin{
 
         Pin* from_string(std::string value){
             LPC_GPIO_TypeDef* gpios[5] ={LPC_GPIO0,LPC_GPIO1,LPC_GPIO2,LPC_GPIO3,LPC_GPIO4};
-            this->port = gpios[ atoi(value.substr(0,1).c_str()) ]; 
+            this->port_number =  atoi(value.substr(0,1).c_str());  
+            this->port = gpios[this->port_number]; 
             this->inverting = ( value.find_first_of("!")!=string::npos ? true : false );
             this->pin  = atoi( value.substr(2, value.size()-2-(this->inverting?1:0)).c_str() );
             return this;
@@ -29,6 +30,15 @@ class Pin{
             return this;
         }  
 
+        inline Pin* as_open_drain(){
+            if( this->port_number == 0 ){ LPC_PINCON->PINMODE_OD0 |= (1<<this->pin); }
+            if( this->port_number == 1 ){ LPC_PINCON->PINMODE_OD1 |= (1<<this->pin); }
+            if( this->port_number == 2 ){ LPC_PINCON->PINMODE_OD2 |= (1<<this->pin); }
+            if( this->port_number == 3 ){ LPC_PINCON->PINMODE_OD3 |= (1<<this->pin); }
+            if( this->port_number == 4 ){ LPC_PINCON->PINMODE_OD4 |= (1<<this->pin); }
+            return this;
+        }
+
         inline bool get(){
             if( this->inverting ){
                return ~(( this->port->FIOPIN >> this->pin ) & 1);
@@ -49,6 +59,7 @@ class Pin{
 
         bool inverting; 
         LPC_GPIO_TypeDef* port;
+        char port_number;
         char pin; 
 };
 
index 1004de7..3f3d2a0 100644 (file)
@@ -57,6 +57,16 @@ void Stepper::on_config_reload(void* argument){
     this->alpha_dir_pin                 =  this->kernel->config->value(alpha_dir_pin_checksum                )->by_default("1.18"     )->as_pin()->as_output();
     this->beta_dir_pin                  =  this->kernel->config->value(beta_dir_pin_checksum                 )->by_default("1.20"     )->as_pin()->as_output();
     this->gamma_dir_pin                 =  this->kernel->config->value(gamma_dir_pin_checksum                )->by_default("1.19"     )->as_pin()->as_output();
+    this->alpha_en_pin                  =  this->kernel->config->value(alpha_en_pin_checksum                 )->by_default("0.4"      )->as_pin()->as_output()->as_open_drain();
+    this->beta_en_pin                   =  this->kernel->config->value(beta_en_pin_checksum                  )->by_default("0.10"     )->as_pin()->as_output()->as_open_drain();
+    this->gamma_en_pin                  =  this->kernel->config->value(gamma_en_pin_checksum                 )->by_default("0.19"     )->as_pin()->as_output()->as_open_drain();
+
+
+    // TODO : This is supposed to be done by gcodes
+    this->alpha_en_pin->set(0);
+    this->beta_en_pin->set(0);
+    this->gamma_en_pin->set(0);
+
 
     // Set the Timer interval for Match Register 1, 
     this->kernel->step_ticker->set_reset_delay( this->microseconds_per_step_pulse / 1000000 );
index 169208c..b535d44 100644 (file)
 #define alpha_dir_pin_checksum                      55887
 #define beta_dir_pin_checksum                       28644
 #define gamma_dir_pin_checksum                      46412
+#define alpha_en_pin_checksum                       35042  
+#define beta_en_pin_checksum                        34680 
+#define gamma_en_pin_checksum                       26335 
+
 
 class Stepper : public Module {
     public:
@@ -64,6 +68,9 @@ class Stepper : public Module {
         Pin* alpha_dir_pin;
         Pin* beta_dir_pin;
         Pin* gamma_dir_pin;
+        Pin* alpha_en_pin;
+        Pin* beta_en_pin;
+        Pin* gamma_en_pin;
         unsigned short step_bits[3];
         int counter_increment;
         bool paused;
index b810264..673d065 100644 (file)
@@ -8,13 +8,13 @@ using namespace std;
 CurrentControl::CurrentControl(){}
 
 void CurrentControl::on_module_loaded(){
-    //if( !this->kernel->config->value( currentcontrol_module_enable_checksum )->by_default(false)->as_bool() ){ return; } 
+    if( !this->kernel->config->value( currentcontrol_module_enable_checksum )->by_default(true)->as_bool() ){ return; } 
 
     // Get configuration
-    this->alpha_current =           this->kernel->config->value(alpha_current_checksum  )->by_default(0)->as_number(); 
-    this->beta_current  =           this->kernel->config->value(beta_current_checksum   )->by_default(0.1)->as_number(); 
-    this->gamma_current =           this->kernel->config->value(gamma_current_checksum  )->by_default(1.9)->as_number(); 
-    this->delta_current =           this->kernel->config->value(delta_current_checksum  )->by_default(2)->as_number();
+    this->alpha_current =           this->kernel->config->value(alpha_current_checksum  )->by_default(0.8)->as_number(); 
+    this->beta_current  =           this->kernel->config->value(beta_current_checksum   )->by_default(0.8)->as_number(); 
+    this->gamma_current =           this->kernel->config->value(gamma_current_checksum  )->by_default(0.8)->as_number(); 
+    this->delta_current =           this->kernel->config->value(delta_current_checksum  )->by_default(0.8)->as_number();
 
     this->kernel->digipot->set_current(0, this->alpha_current);
     this->kernel->digipot->set_current(1, this->beta_current );
index 6da7b1a..f2fada6 100644 (file)
@@ -13,8 +13,8 @@ void PauseButton::on_module_loaded(){
     this->register_for_event(ON_PLAY);
     this->register_for_event(ON_PAUSE);
 
-    this->button     =  this->kernel->config->value( pause_button_pin_checksum )->by_default("0.0")->as_pin()->as_input();
-    this->led        =  this->kernel->config->value( pause_led_pin_checksum    )->by_default("0.1")->as_pin()->as_output();
+    this->button     =  this->kernel->config->value( pause_button_pin_checksum )->by_default("2.12")->as_pin()->as_input();
+    this->led        =  this->kernel->config->value( pause_led_pin_checksum    )->by_default("4.28")->as_pin()->as_output();
 
     this->kernel->slow_ticker->attach( 100, this, &PauseButton::button_tick );
 }