Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
42:c4e9c1116af4
Parent:
38:9b522ef2c519
Child:
43:5ff1a26d99ac
--- a/hardwareIO/hardwareIO.cpp	Wed Mar 26 10:04:01 2014 +0000
+++ b/hardwareIO/hardwareIO.cpp	Fri Mar 28 10:18:38 2014 +0000
@@ -18,7 +18,11 @@
  InterruptIn switchOne(SWITCH_ONE);   
  DigitalOut ledSwitchOne(LED_SWITCH_ONE);
  InterruptIn switchTwo(SWITCH_TWO); 
- AnalogIn ainPot(POT_ANALOG_INPUT);   
+ AnalogIn ainPot(POT_ANALOG_INPUT);  
+ //DigitalIn RotaryEncoderPinA(ROTARY_ENCODER_PINA); // not needed: this is done in the CRotaryEncoder library (as input or interrupt)
+ //DigitalIn RotaryEncoderPinB(ROTARY_ENCODER_PINB);
+ 
+ DigitalIn twoStateSwitch(TWO_STATE_SWITCH);
 
 void HardwareIO::init(void) {
 
@@ -46,6 +50,14 @@
     writeOutX(CENTER_AD_MIRROR_X);
     writeOutY(CENTER_AD_MIRROR_Y);
     
+    // Rotary encoder 1 (to set the FIXED THRESHOLD VALUE): 
+    rotaryEncoder1.SetMinMax(0,255);
+    rotaryEncoder1.Set(0); // initial value
+    
+     // Rotary encoder 2 (to set the additional correction angle):   
+    rotaryEncoder1.SetMinMax(0,360);
+    rotaryEncoder2.Set(0); // initial value
+    
     // Load LUT table:
     setLUT();
     
@@ -63,7 +75,12 @@
   
   // ATTENTION: initial state of the switch should correspond to the inital state of the threshold mode in the constructor of the laser trajectory objects (not nice):
     setSwitchOneState(true); //equal to switchOneState=true, plus set led value. False means fixed threshold, true AUTO THRESHOLD (will be the default mode)
+    // NOTE: actually this interrupt switches are not used anymore to change threhold... 
      
+    // Initial state of the two state switch: 
+    twoStateSwitchState=twoStateSwitch; // attention: twoStateSwitch is actually a method...
+    twoStateSwitchChange=true; // this will force reading the initial threshold mode the first time the program runs
+    
     // Read and update pot value:
    // updatePotValue(); // the value will be ajusted in the range 0-255
 }
@@ -80,28 +97,42 @@
     ledSwitchOne=(switchOneState? 1 :0); // this switch has a built-in led
     switchOneChange=true;
 }
+
 void HardwareIO::switchTwoInterrupt() {
     switchTwoState=!switchTwoState;
     switchTwoChange=true;
 }
 
-bool HardwareIO::switchOneCheck(bool& state) {
+bool HardwareIO::switchOneCheck(bool& new_state) {
+    new_state=switchOneState;
     if (switchOneChange) {
         switchOneChange=false;
-        state=switchOneState;
         return(true);
-    } else 
+    } else     
     return(false);
 }
 
-bool HardwareIO::switchTwoCheck(bool& state) {
+bool HardwareIO::switchTwoCheck(bool& new_state) {
+    new_state=switchTwoState;
     if (switchTwoChange) {
         switchTwoChange=false;
-        state=switchTwoState;
         return(true);
     } else return(false);
 }
 
+// NOT interrupt-based switch:
+bool HardwareIO::twoStateSwitchCheck(bool& new_state) {
+    new_state=twoStateSwitch; // note: twoStateSwitch is a method!
+    if (twoStateSwitchState==new_state) {
+        // this means that the switch did not change state:
+        return(false);
+    } else {
+        twoStateSwitchState=new_state;
+        return(true);
+    }
+}
+    
+
 // THIS IS NOT WORKING!!!!!!
 unsigned char HardwareIO::updatePotValue() { // this will update the pot value, and return it too.
    //The value will be ajusted in the range 0-255