Normalize wiichuck output somewhat

Normalize wiichuck output somewhat

--- wii_i2c/wii_i2c.ino
+++ wii_i2c/wii_i2c.ino
@@ -19,8 +19,6 @@
 {
     byte error, address;
     int nDevices=0;
-    // delay to let serial monitor connection
-    delay(2000);
     Wire.begin();
     for (address = 0; address < 127; address++) {
         // The i2c_scanner uses the return value of
@@ -52,7 +50,7 @@
 void setup()
 {
     Serial.begin(115200);
-    // i2c_scanner();
+    i2c_scanner();
     Wire.begin(); // master
     delay(1);
     Wire.beginTransmission(0x52);
@@ -98,7 +96,7 @@
 void loop()
 {
     byte cnt;
-    byte buf[6];
+    int buf[6];
     while (1) {
         cnt=0;
         send_zero();
@@ -106,13 +104,24 @@
         while (Wire.available()) {
             buf[cnt++]=Wire.read();
         }
-        putval(buf[0]-128, 2);
-        putval(buf[1]-128, 7);
-        putval(buf[2]-128,16);
-        putval(buf[3]-128,25);
-        putval(buf[4]-128,34);
+        // make everything zero based, -127 -> 127
+        buf[0]-=128;
+        buf[1]-=128;
+        buf[2]-=128;
+        buf[3]-=128;
+        buf[4]-=128;
+        // scale joystick from -127->127 to -10->10
+        buf[0]=(abs(buf[0])/13)*((buf[0]<0)?-1:1);
+        buf[1]=(abs(buf[1])/13)*((buf[1]<0)?-1:1);
+        // build string
+        putval(buf[0], 2);
+        putval(buf[1], 7);
+        putval(buf[2],16);
+        putval(buf[3],25);
+        putval(buf[4],34);
         putval((buf[5]&2)==0,43);
         putval((buf[5]&1)==0,52);
         Serial.print(str);
+        delay(100);
     }
 }


Adding function to emit IR payload

Adding function to emit IR payload

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -1061,6 +1061,25 @@
     active_receiver = receiver;
 }

+
+#ifdef USE_IR_EMITTER
+void sendIRPayload() {
+    uint8_t check_sum = 2;
+    Serial.write(2); // start of payload
+    check_sum += channelIndex;
+    Serial.write(channelIndex); // send channel
+    for(uint8_t i=0; i < 10;i++) {
+        if(call_sign[i] == '\0') {
+            break;
+        }
+        check_sum += (char)call_sign[i];
+        Serial.write(call_sign[i]); // send char of call_sign
+    }
+    Serial.write(3);  // end of payload
+    Serial.write(check_sum); // send ceck_sum for payload validation
+}
+#endif
+
 void setChannelModule(uint8_t channel)
 {
   uint8_t i;


time-averaging for analogRead() now done on Arduino for speed

--- arduino/serial_control/serial_control.ino
+++ arduino/serial_control/serial_control.ino
@@ -68,8 +68,18 @@
       value = readData();
       analogWrite(pin, value); break;
     case 6 :
-      //read analog value
-      Serial.println(analogRead(readData())); break;
+      {
+        //read analog value
+        int pin = readData();
+        int num = 30;
+        float sum = 0, avg;
+        for(int i = 0; i < num; i++) {
+          sum += analogRead(pin);
+          vcc.addValue(readVcc()); //continue averaging vcc during this time
+        }
+        avg = sum/num;
+        Serial.println(avg); break;
+      }
     case 7 :
       //set DAC value
       writeDAC(); break;


Added victory detection

Added victory detection

--- tictactoe/tictactoe.ino
+++ tictactoe/tictactoe.ino
@@ -12,6 +12,22 @@
 //int gameStatus = 0; //0 = ongoing game, 1 = you win, 2 = opponent wins
 //int currentTurn = 0; //0 you, 1 opponent

+int redStatus [] = {0,0,0,0,0,0,0,0,0};
+int greenStatus [] = {0,0,0,0,0,0,0,0,0};
+
+int winConditions [][9] = {{1,1,1,0,0,0,0,0,0},
+                              {0,0,0,1,1,1,0,0,0},
+                              {0,0,0,0,0,0,1,1,1},
+                              {1,0,0,1,0,0,1,0,0},
+                              {0,1,0,0,1,0,0,1,0},
+                              {0,0,1,0,0,1,0,0,1},
+                              {1,0,0,0,1,0,0,0,1},
+                              {0,0,1,0,1,0,1,0,0}
+};
+
+boolean redVictory = false;
+boolean greenVictory = false;
+
 void setup() {
   Serial.begin(9600);
   for (int i = 0; i < 9; i++){
@@ -21,14 +37,30 @@
   clearSquares();
   allGreen();
   delay(1000);
-  clearSquares();
+  clearSquares();
+
 }

 // the loop routine runs over and over again forever:
 void loop() {
-  adjustColors();
-  Serial.println(squares[7]->getColorValue());
+  if (!redVictory && !greenVictory){
+    updateColorStatus();
+  }
+
+  redVictory = checkWin(redStatus);
+  greenVictory = checkWin(greenStatus);
+
+  if (redVictory){
+    clearSquares();
+    allRed();
+  } else if (greenVictory){
+    clearSquares();
+    allGreen();
+  }
+
+  //Serial.println();
 }
+

 //The calibration changes from sensor to sensor
 void calibrateSensors(){
@@ -43,17 +75,51 @@
   squares[8]->calibrateCNY70(330, 290, 220, 180);
 }

-void adjustColors(){
+void updateColorStatus(){
   for (int i=0; i < 9; i++){
     char color = squares[i]->checkColor();
     if (color == 'g'){
       squares[i]->setGreen();
+      greenStatus[i] = 1;
     } else if (color == 'r'){
       squares[i]->setRed();
+      redStatus[i] = 1;
     } else if (color == 'n'){
       squares[i]->clear();
     }
+  }
+}
+
+boolean isSame(int array1[], int array2[]){
+  boolean same = true;
+  for (int i=0; i < 9; i++){
+    if (same==false){
+      break;
+    }
+    if (array1[i] == array2[i]){
+      same = true;
+    } else {
+      same = false;
+    }
+  }
+  return same;
+}
+
+
+boolean checkWin(int statusArray[]){
+  boolean win = false;
+  for (int i=0; i < 8; i++){
+    if (win){
+      break;
+    }
+    //Mask to only take the needed values
+    int result[] = {0,0,0,0,0,0,0,0,0};
+    for (int j=0; j < 9; j++){
+      result[j] = statusArray[j] * winConditions[i][j];
+    }
+    win = isSame(result, winConditions[i]);
   }
+  return win;

 }

@@ -75,3 +141,18 @@
   }
 }

+void printStatus(){
+  Serial.println("Red");
+  for (int i=0; i < 9; i++){
+    Serial.println(redStatus[i]);
+  }
+  Serial.println();
+
+  Serial.println("Green");
+  for (int i=0; i < 9; i++){
+    Serial.println(greenStatus[i]);
+  }
+  Serial.println();
+}
+
+


Reset schedule status on stop

Reset schedule status on stop

--- ableton-midi-foot-controller.ino
+++ ableton-midi-foot-controller.ino
@@ -559,6 +559,7 @@
     midiNoteSendStart = 0;
     midiNoteToSend = STOP_MIDI_NOTE;
     bars = 0;
+    nextPartScheduled = false;
     changeMode(NORMAL_MODE);
     return;
   }
@@ -809,6 +810,7 @@
     currentNumerator = 0;
     denominator = 0;
     numerator = 0;
+    nextPartScheduled = false;
     changeMode(NORMAL_MODE);
   }
 }


add FlapsGaugeServo example

add FlapsGaugeServo example


Added custom Device Name to Setup

Added custom Device Name to Setup

--- sw-machine-control/module-template/src/main.ino
+++ sw-machine-control/module-template/src/main.ino
@@ -137,6 +137,7 @@
   Serial.println("Requesting Bluefruit info:");
   /* Print Bluefruit information */
   ble.info();
+  ble.println("AT+GAPDEVNAME=Ferdinand");

   Serial.println(F("Please use Adafruit Bluefruit LE app to connect in UART mode"));
   Serial.println(F("Then Enter characters to send to Bluefruit"));


ESP8266 changes

ESP8266 changes


Update defaults

Update defaults

Signed-off-by: Robin Hagman <a0ad21b4a5c77bde0f74c8a70cf9b810eabd0434@gmail.com>


Update config.ino

Update config.ino

--- Arduino/nodeMCU/plant/config.ino
+++ Arduino/nodeMCU/plant/config.ino
@@ -12,6 +12,6 @@
 /******************************* WIFI **************************************/

-#define MY_SSID       "FASTWEB-1-casa"
-#define MY_PWD       "0418EE41E8"
+#define MY_SSID       "XXXXXX"
+#define MY_PWD       "XXXXXX"


Update Arduino.ino

Update Arduino.ino

update pinout

--- Arduino/Arduino.ino
+++ Arduino/Arduino.ino
@@ -2,19 +2,19 @@
 #define PRESSEDLOGICLEVEL LOW

 #define GND1 4
-#define GND2 14
-#define GND3 15
+#define GND2 15
+#define GND3 11

-#define SELECT 7
-#define START 12
-#define UP 18
-#define DOWN 2
-#define LEFT 17
-#define RIGHT 19
-#define A 11
+#define SELECT 12
+#define START 8
+#define UP 14
+#define DOWN 18
+#define LEFT 16
+#define RIGHT 17
+#define A 7
 #define B 6

-#define LED 13
+#define LED 10

 byte buttons[] = {SELECT, START, UP, DOWN, LEFT, RIGHT, A, B}; // the analog 0-5 pins are also known as 14-19
 #define NUMBUTTONS sizeof(buttons)


+ Some more changes.

+ Some more changes.

--- ClydeClock/Basic.ino
+++ ClydeClock/Basic.ino
@@ -282,15 +282,96 @@
     clyde.setLight( wl_intensity );
   }else{
     if( cycle_rgb ){
-      double cycle_hsv[3];
-      clyde.rgb2hsv( clyde.current_colour[ 0 ], clyde.current_colour[ 1 ], clyde.current_colour[ 2 ], cycle_hsv );
+      float cycle_hsv[3];
+      rgbToHsv( clyde.current_colour[ 0 ], clyde.current_colour[ 1 ], clyde.current_colour[ 2 ], cycle_hsv );
       Serial << "what's the hsi? " << cycle_hsv[ 0 ] << " " << cycle_hsv[ 1 ] << " " << cycle_hsv[ 2 ] << endl;
-      if( cycle_hsv[ 0 ] >= (double)0.95 ){
-      cycle_hsv[ 0 ] = (double)0.0;
+      if( cycle_hsv[ 0 ] >= 0.95f ){
+      cycle_hsv[ 0 ] = 0.0f;
       }
-      cycle_hsv[ 0 ]+=(double)0.02;
-      clyde.setEyeHSI( (float)cycle_hsv[ 0 ]*360.0, (float)cycle_hsv[ 1 ], (float)cycle_hsv[ 2 ] );
-    }
-  }
-}
-
+      cycle_hsv[ 0 ]+=0.02f;
+      // convert back to rgb:
+      uint8_t new_rgb[3];
+      hsvToRgb( cycle_hsv[ 0 ], cycle_hsv[ 1 ], cycle_hsv[ 2 ], new_rgb );
+      clyde.setEyeRGB( new_rgb[ 0 ], new_rgb[ 1 ], new_rgb[ 2 ] );
+    }
+  }
+}
+
+
+// Color converting; some modidied stuff from https://github.com/ratkins/RGBConverter
+// mostly we ensure to use floats and stuff.
+/**
+* Converts an RGB color value to HSV. Conversion formula
+* adapted from http://en.wikipedia.org/wiki/HSV_color_space.
+* Assumes r, g, and b are contained in the set [0, 255] and
+* returns h, s, and v in the set [0, 1].
+*
+* @param Number r The red color value
+* @param Number g The green color value
+* @param Number b The blue color value
+* @return Array The HSV representation
+*/
+void rgbToHsv(uint8_t r, uint8_t g, uint8_t b, float hsv[]) {
+  float rd = (float)r/255.0f;
+  float gd = (float)g/255.0f;
+  float bd = (float)b/255.0f;
+  float max = threeway_max(rd, gd, bd), min = threeway_min(rd, gd, bd);
+  float h, s, v = max;
+  float d = max - min;
+  s = max == 0 ? 0 : d / max;
+  if (max == min) {
+    h = 0; // achromatic
+  } else {
+    if (max == rd) {
+      h = (gd - bd) / d + (gd < bd ? 6 : 0);
+    } else if (max == gd) {
+      h = (bd - rd) / d + 2;
+    } else if (max == bd) {
+      h = (rd - gd) / d + 4;
+    }
+    h /= 6;
+  }
+  hsv[0] = h;
+  hsv[1] = s;
+  hsv[2] = v;
+}
+
+/**
+* Converts an HSV color value to RGB. Conversion formula
+* adapted from http://en.wikipedia.org/wiki/HSV_color_space.
+* Assumes h, s, and v are contained in the set [0, 1] and
+* returns r, g, and b in the set [0, 255].
+*
+* @param Number h The hue
+* @param Number s The saturation
+* @param Number v The value
+* @return Array The RGB representation
+*/
+void hsvToRgb(float h, float s, float v, uint8_t rgb[]) {
+  float r, g, b;
+  int i = int(h * 6);
+  float f = h * 6 - i;
+  float p = v * (1 - s);
+  float q = v * (1 - f * s);
+  float t = v * (1 - (1 - f) * s);
+  switch(i % 6){
+  case 0: r = v, g = t, b = p; break;
+  case 1: r = q, g = v, b = p; break;
+  case 2: r = p, g = v, b = t; break;
+  case 3: r = p, g = q, b = v; break;
+  case 4: r = t, g = p, b = v; break;
+  case 5: r = v, g = p, b = q; break;
+  }
+  rgb[0] = (uint8_t)(r * 255);
+  rgb[1] = (uint8_t)(g * 255);
+  rgb[2] = (uint8_t)(b * 255);
+}
+
+float threeway_max(float a, float b, float c) {
+  return max(a, max(b, c));
+}
+float threeway_min(float a, float b, float c) {
+  return min(a, min(b, c));
+}
+
+


fixed stepper struct

fixed stepper struct

--- src/resource/Arduino/MRLComm2.ino
+++ src/resource/Arduino/MRLComm2.ino
@@ -853,8 +853,8 @@
 			stepper.speed = 100;

 			if (stepper.type == STEPPER_TYPE_SIMPLE) {
-				stepper.step0 = ioCmd[3]; // dir pin
-				stepper.step1 = ioCmd[4]; // step pin
+				stepper.dirPin = ioCmd[3]; // dir pin
+				stepper.stepPin = ioCmd[4]; // step pin
 			} else {
 				sendError(ERROR_UNKOWN_CMD);
 			}
@@ -1178,17 +1178,17 @@
 				if (stepper.currentPos < stepper.targetPos) {

 				    // step - POLOLU has single step pin (dir is on step0)
-					digitalWrite(stepper.step1, 1);
+					digitalWrite(stepper.stepPin, 1);
 					delayMicroseconds(1); // :P should require another state? loop is ~106us min ?
-					digitalWrite(stepper.step1, 0);
+					digitalWrite(stepper.stepPin, 0);

 					stepper.currentPos++;
 				} else if (stepper.currentPos > stepper.targetPos) {

 				    // step - POLOLU has single step pin (dir is on step0)
-					digitalWrite(stepper.step1, 1);
+					digitalWrite(stepper.stepPin, 1);
 					delayMicroseconds(1); // :P should require another state? loop is ~106us min ?
-					digitalWrite(stepper.step1, 0);
+					digitalWrite(stepper.stepPin, 0);

 					stepper.currentPos--;


Move begin down in example

Move begin down in example

--- examples/simple/simple.ino
+++ examples/simple/simple.ino
@@ -30,9 +30,8 @@
     configManager.addParameter("hour", &config.hour);
     configManager.addParameter("password", config.password, 20, set);
     configManager.addParameter("version", &meta.version, get);
+    configManager.setAPICallback(createCustomRoute);
     configManager.begin(config);
-
-    configManager.setAPICallback(createCustomRoute);

     //
 }


Added support for commands via Serial interface

The debug must be disabled.

--- code/master/master.ino
+++ code/master/master.ino
@@ -17,6 +17,7 @@
 const int CLAW_PIN = 13;
 const int COIN_PIN = 8;

+// Serial enabled if GM_DEBUG is false.
 const bool GM_DEBUG = false;

 //
@@ -47,11 +48,14 @@
   state.motor_w = pin_init (MOTOR_W_PIN, OUTPUT, LOW);

   Wire.begin (GM_MACHINE_ADDRESS);
-  Wire.onReceive (process_command);
+  Wire.onReceive (get_command);

+
   if (GM_DEBUG) {
      Serial.begin (115200);
      Serial.println("Machine Idle");
+  } else {
+  Serial.begin(19200);
   }
 }

@@ -61,21 +65,26 @@

 void loop() {
   delay (100);
+  if (!GM_DEBUG) {
+  serial_process_command();
+  }
 }

-void process_command (int num_command) {
-  byte cmd_buffer;
+void serial_process_command() {
+  if (Serial.available()) {
+	  byte cmd_buffer = Serial.read();
+	  execute_command(cmd_buffer);
+	}

-  while (Wire.available()) {
-
-    cmd_buffer = Wire.read();
-
+}
+
+void execute_command(byte cmd_buffer) {
     if (!state.ready) {
       if (read_command (cmd_buffer, GM_CMD_READY)) {
 	      state.ready = true;
 	      update_machine();
       }
-      continue;
+      return;
     }

     if (GM_DEBUG) {
@@ -100,6 +109,15 @@

     // execute current state
     update_machine();
+}
+
+
+void get_command (int num_command) {
+  byte cmd_buffer;
+
+  while (Wire.available()) {
+    cmd_buffer = Wire.read();
+    execute_command(cmd_buffer);
   }
 }

@@ -144,4 +162,4 @@
     Serial.println (state);
   }
   digitalWrite (pin, state ? HIGH : LOW);
-}
+}


La putain de merde de sa race de nfc.mifareclassic_AuthenticateBlock nike la police ptn j'ai perdu 5h de ma vie


got rid of the <color>_ variables, using globals instead to keep track of current color being set.

--- Helios.ino
+++ Helios.ino
@@ -77,11 +77,11 @@
   for(int a = 0; a <= strip.numPixels()/2; a++) {
     for(int i = 0; i <= 100; i+=5) {
       double percentage = (double)i/100;
-      int red_ = percentage * r;
-      int green_ = percentage * g;
-      int blue_ = percentage * b;
+      red = percentage * r;
+      green = percentage * g;
+      blue = percentage * b;
       strip.setPixelColor(a, strip.Color(red,green,blue));
-      strip.setPixelColor(((strip.numPixels() - 1) - a), strip.Color(red_,green_,blue_));
+      strip.setPixelColor(((strip.numPixels() - 1) - a), strip.Color(red,green,blue));
       strip.show();
       delay(5);
     }


- Adicionado media das medidas e descartes de maximo e minimo

--- rede-firmware.ino
+++ rede-firmware.ino
@@ -75,7 +75,7 @@
 int time_elapsed = 5000;

 // Interval between consecutive data sends (in seconds)
-#define SEND_INTERVAL 3600
+#define SEND_INTERVAL 10//3600
 #define NUM_RETRIES 5

 /*********************************************************************************/
@@ -146,7 +146,6 @@
   wdt_cycles++;
 }
 #endif // WATCHDOG_ENABLE
-

 void setup() {
   Serial.begin(115200);
@@ -364,7 +363,6 @@
       Serial.println(F("HTTP POST Sent!"));
     }
 #endif // SEND_HTTP_POST
-
     disable_fona();
   }

@@ -482,10 +480,16 @@
 void calc_sensors() {
   Wire.begin();
   delay(100);
-
+  float val, minVal,maxVal;
+  int i,j;
 #if HUMIDITY_SENSOR
   // Calc humidity
-  humidity = myHumidity.readHumidity();
+  humidity = 0;
+  for(i = 0; i < 3; i++)
+  {
+    humidity += myHumidity.readHumidity();
+  }
+  humidity = humidity/3;
 #endif // HUMIDITY_SENSOR

 #if AMBIENT_TEMPERATURE_SENSOR
@@ -508,41 +512,124 @@

 #if EC_SENSOR
   // Calc EC
-  delay(500);
-  digitalWrite(S1_EN, LOW);
-  FreqCount.begin(1000);
-  while (!FreqCount.available());
-  ec = FreqCount.read();
-  FreqCount.end();
-  ec = 5000.0 + (ec - ec5kCal) / ecStep;
-  digitalWrite(S1_EN, HIGH);
+  minVal = 100000;
+  maxVal = -100000;
+  val = 0;
+  for(i = 0; i < 5; i++)
+  {
+    delay(500);
+    digitalWrite(S1_EN, LOW);
+    FreqCount.begin(1000);
+    while (!FreqCount.available());
+    ec = FreqCount.read();
+    FreqCount.end();
+    ec = 5000.0 + (ec - ec5kCal) / ecStep;
+    digitalWrite(S1_EN, HIGH);
+    val += ec;
+    if (ec < minVal)
+    {
+      minVal = ec;
+    }
+    if (ec > maxVal)
+    {
+      maxVal = ec;
+    }
+  }
+  //Remove the largest and lowest
+  val -= minVal;
+  val -= maxVal;
+  ec = val/3;
 #endif // EC_SENSOR

 #if ORP_SENSOR
   // Calc orp
-  delay(500);
-  digitalWrite(S2_EN, LOW);
-  delay(1000);
-  orp = analogRead(ORP_PIN) / 1024.0;
-  orp = (30.0 * 5.0 * 1000.0) - (75.0 * orp * 5.0 * 1000);
-  orp = (orp / 75.0) - orpOffset;
-  digitalWrite(S2_EN, HIGH);
+  minVal = 100000;
+  maxVal = -100000;
+  val = 0;
+  for(i = 0; i < 5; i++)
+  {
+    delay(500);
+    digitalWrite(S2_EN, LOW);
+    delay(1000);
+    orp = analogRead(ORP_PIN) / 1024.0;
+    orp = (30.0 * 5.0 * 1000.0) - (75.0 * orp * 5.0 * 1000);
+    orp = (orp / 75.0) - orpOffset;
+    digitalWrite(S2_EN, HIGH);
+    val += orp;
+    if (orp < minVal)
+    {
+      minVal = orp;
+    }
+    if (orp > maxVal)
+    {
+      maxVal = orp;
+    }
+  }
+  //Remove the largest and lowest
+  val -= minVal;
+  val -= maxVal;
+  orp = val/3;
 #endif // ORP_SENSOR

 #if PH_SENSOR
   // Calc pH
-  delay(500);
-  digitalWrite(S3_EN, LOW);
-  delay(1000);
-  ph = ((analogRead(PH_PIN) / 1024.0) * 5.0) * 1000.0;
-  ph = ((((5.0 * ph7Cal) / 1024.0) * 1000.0) - ph) / 5.25;
-  ph = 7.0 - (ph / phStep);
-  digitalWrite(S3_EN, HIGH);
+  // To improve the readings we will do 5 readings,
+  // remove the largest and lowest and average the
+  // remaining 3.
+  minVal = 100000;
+  maxVal = -100000;
+  val = 0;
+  for(i = 0; i < 5; i++)
+  {
+    delay(1000);
+    digitalWrite(S3_EN, LOW);
+    delay(1000);
+    ph = ((analogRead(PH_PIN) / 1024.0) * 5.0) * 1000.0;
+    ph = ((((5.0 * ph7Cal) / 1024.0) * 1000.0) - ph) / 5.25;
+    ph = 7.0 - (ph / phStep);
+    digitalWrite(S3_EN, HIGH);
+    val += ph;
+    if (ph < minVal)
+    {
+      minVal = ph;
+    }
+    if (ph > maxVal)
+    {
+      maxVal = ph;
+    }
+  }
+  //Remove the largest and lowest
+  val -= minVal;
+  val -= maxVal;
+  ph = val/3;
 #endif // PH_SENSOR

 #if WATER_TEMPERATURE_SENSOR
   // Calc water temperature
-  wtemp = get_water_temperature();
+  val = 0;
+  j = 3;
+  for(i = 0; i < 3; i++)
+  {
+    wtemp = get_water_temperature();
+    if(wtemp == -100)
+    {
+      Serial.println("Error with water temperature reading, trying again");
+      wtemp = get_water_temperature();
+      if (wtemp == -100)
+      {
+        Serial.println("Couldn't get water temperature");
+        wtemp = 0;
+        j--;
+      }
+    }
+    val += wtemp;
+  }
+  if (j == 0)
+  {
+    wtemp = -100;
+  } else {
+    wtemp = val/j;
+  }
 #endif // WATER_TEMPERATURE_SENSOR
 }

@@ -557,7 +644,7 @@
   waterTemperature.reset_search();
   if (!waterTemperature.search(addr)) {
     // No sensors found.
-    return 0.0;
+    return -100;
   }

   waterTemperature.reset();


Updates WiFi Connect Module

Updates WiFi Connect Module

Adds a function to get the wifi address.

--- njmakerday_20160318/wifi_connect.ino
+++ njmakerday_20160318/wifi_connect.ino
@@ -22,10 +22,18 @@
   Serial.println ( "" );
   Serial.print ( "Connected to " );
   Serial.println ( ssid );
-  Serial.print ( "IP address: " );
-  Serial.println ( WiFi.localIP() );
+  getWiFiAddress();

   if ( MDNS.begin ( dnsName ) ) {
     Serial.println ( "MDNS responder started" );
   }
 }
+
+char getWiFiAddress(void) {
+  // Print the IP address out to the serial connection
+  Serial.print ( "\n\nIP address: " );
+  Serial.println ( WiFi.localIP() );
+
+  return WiFi.localIP();
+}
+


Switch to two motors controlled by two knobs

--- sketches/spin_motor/spin_motor.ino
+++ sketches/spin_motor/spin_motor.ino
@@ -1,57 +1,35 @@

-const int motorPin = 9;
-const int knobPin = 1;
-const int button = 2;

-boolean lastButton = LOW;
-boolean currentButton = LOW;
-boolean motorOn = false;
-int runningSpeed = 0; // out of 0-255
-int counter = 0;
+const int knobs[] = {0,1};
+const int motors[] = {9, 10};
+
+int speed[] = {0,0};
+int speedRunning[] = {0,0};
+
+const int number_of_motors = sizeof(motors)/sizeof(motors[0]);
+
+static int counter = 0;

 void setup()
 {
-  // Set up the motor pin to be an output:
-
-  pinMode(motorPin, OUTPUT);
-  pinMode(button, INPUT);
-
-  // Set up the serial port:
-
+  for (int m = 0; m < number_of_motors; m++) {
+    pinMode (motors[m], OUTPUT);
+  }
   Serial.begin(9600);
 }

 void loop()
 {
   counter++;
-  /*
-  int val = analogRead(knobPin);
-  Serial.println(val);
-  delay(500);
-  */
-  currentButton = debounce(lastButton);
-  if (lastButton == LOW && currentButton == HIGH) {
-    motorOn = !motorOn;
-    motorOn ? log("motor ON") : log("motor OFF");
-    log("speed set to", runningSpeed);
-  }
-  lastButton = currentButton;
+  readSpeed();
+  setMotorSpeed();

-  int knobSpeed = readKnob(0, 255);
-  if (knobSpeed != runningSpeed) {
-    runningSpeed = knobSpeed;
+  if (counter % 50 == 0) {
+    logSpeeds();
   }

-  if (counter % 50 == 0) {
-    log("speed is set to", runningSpeed);
-  }
-
-  if (motorOn) {
-    runMotor(runningSpeed);
-  } else {
-    stopMotor();
-  }
+  delay(50);
 }

 void log(char *message) {
@@ -64,35 +42,43 @@
   Serial.println(value);
 }

-
-boolean debounce(boolean last)
-{
-  boolean current = digitalRead(button);
-  if (last != current) {
-    delay(5);
-    current = digitalRead(button);
-  }
-
-  return current;
-}
-
-void runMotor(int motorSpeed)
-{
-  int delayTime = 20;
-  analogWrite(motorPin, motorSpeed);
-  delay(delayTime);
-}
-
-void stopMotor() {
-  runMotor(0);
-}
-
-int readKnob(int from, int to) {
-  int value = analogRead(knobPin);
+//-------------------------------------------------------------------
+int readKnob(int pin, int from, int to) {
+  int value = analogRead(pin);
   value = map(value, 0, 1023, from, to);
   return value;
 }

+//-------------------------------------------------------------------
+void stopMotors() {
+  for (int m = 0; m < number_of_motors; m++) {
+    analogWrite(motors[m], 0);
+  }
+  delay(10);
+}
+
+void setMotorSpeed() {
+  for (int m = 0; m < number_of_motors; m++) {
+     analogWrite(motors[m], speedRunning[m]);
+  }
+  delay(10);
+}
+
+void readSpeed() {
+  for (int m = 0; m < number_of_motors; m++) {
+    int knobSpeed = readKnob(knobs[m], 0, 255);
+    if (knobSpeed != speedRunning[m]) {
+      speedRunning[m] = knobSpeed;
+    }
+  }
+}
+
+void logSpeeds() {
+  for (int m = 0; m < number_of_motors; m++) {
+    Serial.print("speed of motor ");
+    Serial.print(m);
+    log("is set to", speedRunning[m]);
+  }
+}

-


Added name/version, debug code

Added name/version, debug code

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -15,22 +15,26 @@
 #include <EEPROM.h>

+// Digital VFO program name & version
+const char *ProgramName = "Digital VFO";
+const char *Version = "0.2";
+
 // display constants - below is for ubiquitous small HD44780 16x2 display
 #define NUM_ROWS        2
 #define NUM_COLS        16

 // define data pins we connect to the LCD
-static byte lcd_RS = 7;
-static byte lcd_ENABLE = 8;
-static byte lcd_D4 = 9;
-static byte lcd_D5 = 10;
-static byte lcd_D6 = 11;
-static byte lcd_D7 = 12;
+const byte lcd_RS = 7;
+const byte lcd_ENABLE = 8;
+const byte lcd_D4 = 9;
+const byte lcd_D5 = 10;
+const byte lcd_D6 = 11;
+const byte lcd_D7 = 12;

 // define data pins used by the rotary encoder
-static int re_pinA = 2;     // encoder A pin
-static int re_pinB = 3;     // encoder B pin
-static int re_pinPush = 4;  // encoder pushbutton pin
+const int re_pinA = 2;     // encoder A pin
+const int re_pinB = 3;     // encoder B pin
+const int re_pinPush = 4;  // encoder pushbutton pin

 // max and min frequency showable
 #define MAX_FREQ        30000000L
@@ -87,17 +91,59 @@
 #define vfo_Click     5
 #define vfo_HoldClick 6

-// old values of 're_delta' and 're_position'
-int oldEncOffset = 1;
-byte oldEncPos = 180;
-
-
 ////////////////////////////////////////////////////////////////////////////////
 // The VFO state variables
 ////////////////////////////////////////////////////////////////////////////////

 unsigned long VfoFrequency;   // VFO frequency (Hz)
-int VfoSelectDigit;           // selected digit, indexed from zero at right
+int VfoSelectDigit;           // selected column index, zero at the right
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Utility routines
+////////////////////////////////////////////////////////////////////////////////
+
+//----------------------------------------------------------
+// Abort the program.
+// Tries to tell the world what went wrong, then just loops.
+//
+// msg  address of error string
+//
+// The message may be truncated at display width.
+//----------------------------------------------------------
+
+void abort(const char *msg)
+{
+  Serial.println(msg);
+  Serial.println("Teensy is paused!");
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  lcd.write(msg);
+  lcd.setCursor(0, 1);
+  lcd.write("Teensy is paused");
+
+  // wait here forever
+  while (1);
+}
+
+//----------------------------------------------------------
+// Convert an event number to a display string
+//----------------------------------------------------------
+
+const char * event2display(byte event)
+{
+  switch (event)
+  {
+    case vfo_None:      return "vfo_None";
+    case vfo_RLeft:     return "vfo_RLeft";
+    case vfo_RRight:    return "vfo_RRight";
+    case vfo_DnRLeft:   return "vfo_DnRLeft";
+    case vfo_DnRRight:  return "vfo_DnRRight";
+    case vfo_Click:     return "vfo_Click";
+    case vfo_HoldClick: return "vfo_HoldClick";
+    default:            return "UNKNOWN!";
+  }
+}

 ////////////////////////////////////////////////////////////////////////////////
@@ -113,9 +159,6 @@

 void push_event(byte event)
 {
-  // Must protect from RE code fiddling with queue
-//  noInterrupts();
-
   // put new event into next empty slot
   event_queue[queue_fore] = event;

@@ -128,11 +171,8 @@
   if (queue_aft == queue_fore)
   {
       dump_queue("ERROR: event queue full:");
-      Serial.println("Teensy is paused!");
-      while (1);    // stop here
-  }
-
-//  interrupts();
+      abort("Event queue full");
+  }
 }

 byte pop_event(void)
@@ -170,20 +210,21 @@
     result += QueueLength;

   interrupts();
-
+
   return result;
 }

 void flush_queue(void)
 {
-
+  queue_fore = 0;
+  queue_aft = 0;
 }

 void dump_queue(const char *msg)
 {
   // Must protect from RE code fiddling with queue
   noInterrupts();
-
+
   Serial.print("Queue: "); Serial.println(msg);
   for (int i = 0; i < QueueLength; ++i)
   {
@@ -197,20 +238,22 @@
   interrupts();
 }

+
 ////////////////////////////////////////////////////////////////////////////////
 // Utility routines for the display.
 ////////////////////////////////////////////////////////////////////////////////

-//------------------------------------------------------------------------------
+//----------------------------------------------------------
 // Function to convert an unsigned long into an array of byte digit values.
 //     buf      address of buffer for byte results
 //     bufsize  size of the 'buf' buffer
 //     value    the unsigned long value to convert
 // The function won't overflow the given buffer, it will truncate at the left.
-//
+//
 // For example, given the value 1234 and a buffer of length 7, will fill the
 // buffer with 0001234.  Given 123456789 it will fill with 3456789.
-//------------------------------------------------------------------------------
+//----------------------------------------------------------
+
 void ltobbuff(char *buf, int bufsize, unsigned long value)
 {
   char *ptr = buf + bufsize - 1;
@@ -218,21 +261,22 @@
   for (int i = 0; i < bufsize; ++i)
   {
     int rem = value % 10;
-
+
     value = value / 10;
     *ptr-- = char(rem);
   }
 }

-//------------------------------------------------------------------------------
+//----------------------------------------------------------
 // Print the frequency on the display with selected colum underlined.
 //     freq     the frequency to display
 //     sel_col  the selection offset of digit to underline
 //              (0 is rightmost digit, increasing to the left)
 //     row      the row to use, 0 is at top
 // The row and columns used to show frequency digits are defined elsewhere.
-// A final "Hz" is written.
-//------------------------------------------------------------------------------
+// A final "Hz" is written.
+//----------------------------------------------------------
+
 void print_freq(unsigned long freq, int sel_col, int row)
 {
   char buf [MAX_FREQ_CHARS];
@@ -265,9 +309,10 @@
         lcd.write(char_val + '0');
     }
   }
-
+
   lcd.write("Hz");
 }
+

 ////////////////////////////////////////////////////////////////////////////////
 // Interrupt driven rotary encoder interface.
@@ -287,21 +332,18 @@
 // expecting rising edge on pinA - at detent
 volatile byte bFlag = 0;

-// this variable stores our current value of encoder position.
-// Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
-//volatile long re_delta = 0;
-
 //----------------------------------------------------------
 // Setup the encoder stuff, pins, etc.
 //----------------------------------------------------------
+
 void re_setup(int position)
 {
   // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
   pinMode(re_pinA, INPUT_PULLUP);
-
+
   // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
   pinMode(re_pinB, INPUT_PULLUP);
-
+
   // set pinPush as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
   pinMode(re_pinPush, INPUT_PULLUP);

@@ -330,10 +372,12 @@
       if (push_time < HoldClickTime)
       {
         push_event(vfo_Click);
+        Serial.println("pinPush_isr pushed vfo_Click to queue");
       }
       else
       {
         push_event(vfo_HoldClick);
+        Serial.println("pinPush_isr pushed vfo_HoldClick to queue");
       }
     }
   }
@@ -354,6 +398,7 @@
     else
     {
       push_event(vfo_RLeft);
+      Serial.println("pinA_isr pushed vfo_RLeft to queue");
     }
     bFlag = 0; //reset flags for the next turn
     aFlag = 0; //reset flags for the next turn
@@ -368,18 +413,20 @@
 void pinB_isr(void)
 {
   byte reading = PIND & 0xC;
-
+
   if (reading == B00001100 && bFlag)
   { // check that we have both pins at detent (HIGH) and that we are expecting detent on
     // this pin's rising edge
     if (re_down)
     {
       push_event(vfo_DnRRight);
+      Serial.println("pinB_isr pushed vfo_DnRRight to queue");
       re_rotation = true;
     }
     else
     {
       push_event(vfo_RRight);
+      Serial.println("pinB_isr pushed vfo_RRight to queue");
     }
     bFlag = 0; //reset flags for the next turn
     aFlag = 0; //reset flags for the next turn
@@ -391,15 +438,16 @@
   }
 }

+
 ////////////////////////////////////////////////////////////////////////////////
 // Code to save/restore in EEPROM.
 ////////////////////////////////////////////////////////////////////////////////

 // address for unsigned long 'frequency'
-static int AddressFreq = 0;
+const int AddressFreq = 0;

 // address for int 'selected digit'
-static int AddressSelDigit = AddressFreq + sizeof(AddressFreq);
+const int AddressSelDigit = AddressFreq + sizeof(AddressFreq);

 // save VFO state to EEPROM
@@ -415,6 +463,7 @@
   EEPROM.get(AddressFreq, VfoFrequency);
   EEPROM.get(AddressSelDigit, VfoSelectDigit);
 }
+

 ////////////////////////////////////////////////////////////////////////////////
 // Code to handle the menus.
@@ -447,7 +496,8 @@
     {
       // get next event and handle it
       byte event = pop_event();
-
+      Serial.print("show_menu: popped event "); Serial.println(event2display(event));
+
       switch (event)
       {
         case vfo_RLeft:
@@ -477,18 +527,24 @@
   }
 }

-////////////////////////////////////////////////////////////////////////////////
-// Code to handle the DDS-60.
+
+////////////////////////////////////////////////////////////////////////////////
+// Code to handle the DDS-60
 ////////////////////////////////////////////////////////////////////////////////

 void update_dds60(unsigned long freq)
 {
-
-}
-
-//------------------------------------------------------------------------------
+
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Main VFO code
+////////////////////////////////////////////////////////////////////////////////
+
+//----------------------------------------------------------
 // The standard Arduino setup() function.
-//------------------------------------------------------------------------------
+//----------------------------------------------------------

 void setup(void)
 {
@@ -500,25 +556,35 @@
   lcd.createChar(SPACE_CHAR, sel_digits[SPACE_INDEX]);

   restore_from_eeprom();
-
+
   // set up the rotary encoder
   re_setup(VfoSelectDigit);

-  Serial.println("Digital VFO 0.1");
-  Serial.print("Frequency="); Serial.println(VfoFrequency);
-
+  // show program anme and version number
+  Serial.print(ProgramName); Serial.print(" "); Serial.println(Version);
+  Serial.println("VK4FAWR");
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  lcd.write(ProgramName);
+  lcd.write(" ");
+  lcd.write(Version);
+  lcd.setCursor(0, 1);
+  lcd.write("VK4FAWR");
+  delay(3000);    // wait a bit
+
+  // get going
   show_main_screen();
 }

 void show_main_screen(void)
 {
   lcd.clear();
-  print_freq(VfoFrequency, VfoSelectDigit, 0);
-}
-
-//------------------------------------------------------------------------------
+  print_freq(VfoFrequency, VfoSelectDigit, 0);
+}
+
+//----------------------------------------------------------
 // Standard Arduino loop() function.
-//------------------------------------------------------------------------------
+//----------------------------------------------------------

 void item_display(int slot_num)
 {
@@ -527,7 +593,7 @@

 void item_action(int slot_num)
 {
-
+  Serial.print("item_action: slot_num="); Serial.println(slot_num);
 }

 const char *main_menu_items[2] = {"Save", "Restore"};
@@ -544,7 +610,8 @@
   {
     // get next event and handle it
     byte event = pop_event();
-
+    Serial.print("loop: popped event "); Serial.println(event2display(event));
+
     switch (event)
     {
       case vfo_RLeft:
@@ -577,7 +644,7 @@
       case vfo_HoldClick:
         Serial.println("Got vfo_HoldClick: calling show_menu()");
         show_menu(&main_menu);
-//        Serial.println("After show_menu()");
+        Serial.println("After show_menu()");
         dump_queue("After show_menu()");
         show_main_screen();
         break;
@@ -585,16 +652,16 @@
         Serial.print("Unrecognized event: "); Serial.println(event);
         break;
     }
-
+
     // display frequency if changed, update DDS-60
     if (old_freq != VfoFrequency || old_position != VfoSelectDigit)
     {
       print_freq(VfoFrequency, VfoSelectDigit, 0);
       old_freq = VfoFrequency;
       old_position = VfoSelectDigit;
-
+
       save_to_eeprom();
-
+
       update_dds60(VfoFrequency);
     }
   }


Using DClick to toggle VFO mode

Using DClick to toggle VFO mode

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -116,10 +116,16 @@
 const unsigned int DefaultLcdContrast = 70;
 const unsigned int DefaultLcdBrightness = 150;

+// VFO modes - online or standby
+#define vfo_Standby   0
+#define vfo_Online    1

 //##############################################################################
 // The VFO state variables and typedefs
 //##############################################################################
+
+typedef unsigned int Mode;
+Mode VfoMode;               // VFO mode

 typedef unsigned long Frequency;
 Frequency VfoFrequency;     // VFO frequency (Hz)
@@ -268,6 +274,21 @@
     value = value / 10;
     *ptr-- = char(rem);
   }
+}
+
+//----------------------------------------
+// Convert a numeric mode to a display string.
+//----------------------------------------
+
+const char *mode2display(Mode mode)
+{
+  switch (mode)
+  {
+    case vfo_Standby: return "standby";
+    case vfo_Online:  return "ON";
+  }
+
+  return "UNKNOWN";
 }

@@ -972,7 +993,29 @@
 }

 //----------------------------------------
-// initialize the DDS hardware
+// Force the DDS into standby mode.
+//----------------------------------------
+
+void dds_standby(void)
+{
+  Serial.printf(F("DDS into standby mode.\n"));
+
+  dds_update(0L);
+}
+
+//----------------------------------------
+// Force the DDS into online mode.
+//----------------------------------------
+
+void dds_online(void)
+{
+  Serial.printf(F("DDS into online mode.\n"));
+  dds_update(VfoFrequency);
+}
+
+//----------------------------------------
+// Initialize the DDS hardware.
+// The VFO 'wakes up' in standby mode.
 //----------------------------------------

 void dds_setup(void)
@@ -988,6 +1031,10 @@
   // set serial load enable (Datasheet page 15 Fig. 17)
   dds_pulse_high(DDS_W_CLK);
   dds_pulse_high(DDS_FQ_UD);
+
+  // wait a bit, then go into standby
+  delay(100);
+  dds_standby();
 }

@@ -1003,6 +1050,9 @@
 {
   // initialize the serial console
   Serial.begin(115200);
+
+  // VFO wakes up in standby mode
+  VfoMode = vfo_Standby;

   // initialize the display
   lcd.begin(NUM_COLS, NUM_ROWS);      // define display size
@@ -1072,6 +1122,11 @@
   lcd.print("Vfo:");
   display_sel_value(VfoFrequency, VfoSelectDigit, MAX_FREQ_CHARS, NUM_COLS - MAX_FREQ_CHARS - 2, 0);
   lcd.print("Hz");
+
+  lcd.setCursor(0, 1);
+  lcd.write(BlankRow);
+  lcd.setCursor(0, 1);
+  lcd.write(mode2display(VfoMode));
 }

 //----------------------------------------
@@ -1640,6 +1695,30 @@
   }
 }

+//----------------------------------------
+// Toggle the VFO mode: vfo_Online or vfo_Standby.
+//----------------------------------------
+void vfo_toggle_mode(void)
+{
+  if (VfoMode == vfo_Online)
+  {
+    // DDS goes into standby, change mode
+    dds_standby();
+    VfoMode = vfo_Standby;
+  }
+  else
+  {
+    // DDS goes online, change mode
+    dds_online();
+    VfoMode = vfo_Online;
+  }
+
+  // update display
+  lcd.setCursor(0, 1);
+  lcd.write(BlankRow);
+  lcd.setCursor(0, 1);
+  lcd.write(mode2display(VfoMode));
+}

 //----------------------------------------
 // Reset menu
@@ -1731,7 +1810,8 @@
         save_to_eeprom();   // save any changes made
         break;
       case vfo_DClick:
-        Serial.printf(F("loop: Got vfo_DClick: ignored\n"));
+        Serial.printf(F("loop: Got vfo_DClick\n"));
+        vfo_toggle_mode();
         break;
       default:
         Serial.printf(F("loop: Unrecognized event: %d\n"), event);


Suggesting longer delay on line 190

Suggesting longer delay on line 190

1) Deleting Telstra APN setting line that was already commented out
2) suggesting longer delay after APN set

--- Arduino/Ashtons_Working_CMAPS.ino
+++ Arduino/Ashtons_Working_CMAPS.ino
@@ -1,300 +1,299 @@
-#include "Adafruit_FONA.h"
-
-#define FONA_RX 2
-#define FONA_TX 3
-#define FONA_RST 4
-
-#ifdef __AVR__
-#include <SoftwareSerial.h>
-SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
-SoftwareSerial *fonaSerial = &fonaSS;
-#else
-HardwareSerial *fonaSerial = &Serial1;
-#endif
-
-// Use this for FONA 800 and 808s
-Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
-// Use this one for FONA 3G
-//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
-
-////////////  LCD I2C DISPLAY /////////////////////////
-#include <Wire.h>
-#include <LCD.h>
-#include <LiquidCrystal_I2C.h>
-
-#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
-#define BACKLIGHT_PIN     3
-#define En_pin  2
-#define Rw_pin  1
-#define Rs_pin  0
-#define D4_pin  4
-#define D5_pin  5
-#define D6_pin  6
-#define D7_pin  7
-
-LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
-
-
-
-///////////////// END LCD I2C DISPLAY //////////////////////////
-
-// Download this library for the 2 PIN LCD screen https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads and rename folder 'LiquidCrystal_I2C' and remove other LCD folders
-
-// floatToString.h
-//
-// Tim Hirzel
-// tim@growdown.com
-// March 2008
-// float to string
-//
-// If you don't save this as a .h, you will want to remove the default arguments
-//     uncomment this first line, and swap it for the next.  I don't think keyword arguments compile in .pde files
-
-char * floatToString(char * outstr, float value, int places, int minwidth, bool rightjustify=false) {
-    // this is used to write a float value to string, outstr.  oustr is also the return value.
-    int digit;
-    float tens = 0.1;
-    int tenscount = 0;
-    int i;
-    float tempfloat = value;
-    int c = 0;
-    int charcount = 1;
-    int extra = 0;
-    // make sure we round properly. this could use pow from <math.h>, but doesn't seem worth the import
-    // if this rounding step isn't here, the value  54.321 prints as 54.3209
-
-    // calculate rounding term d:   0.5/pow(10,places)
-    float d = 0.5;
-    if (value < 0)
-        d *= -1.0;
-    // divide by ten for each decimal place
-    for (i = 0; i < places; i++)
-        d/= 10.0;
-    // this small addition, combined with truncation will round our values properly
-    tempfloat +=  d;
-
-    // first get value tens to be the large power of ten less than value
-    if (value < 0)
-        tempfloat *= -1.0;
-    while ((tens * 10.0) <= tempfloat) {
-        tens *= 10.0;
-        tenscount += 1;
-    }
-
-    if (tenscount > 0)
-        charcount += tenscount;
-    else
-        charcount += 1;
-
-    if (value < 0)
-        charcount += 1;
-    charcount += 1 + places;
-
-    minwidth += 1; // both count the null final character
-    if (minwidth > charcount){
-        extra = minwidth - charcount;
-        charcount = minwidth;
-    }
-
-    if (extra > 0 and rightjustify) {
-        for (int i = 0; i< extra; i++) {
-            outstr[c++] = ' ';
-        }
-    }
-
-    // write out the negative if needed
-    if (value < 0)
-        outstr[c++] = '-';
-
-    if (tenscount == 0)
-        outstr[c++] = '0';
-
-    for (i=0; i< tenscount; i++) {
-        digit = (int) (tempfloat/tens);
-        itoa(digit, &outstr[c++], 10);
-        tempfloat = tempfloat - ((float)digit * tens);
-        tens /= 10.0;
-    }
-
-    // if no places after decimal, stop now and return
-
-    // otherwise, write the point and continue on
-    if (places > 0)
-    outstr[c++] = '.';
-
-
-    // now write out each decimal place by shifting digits one by one into the ones place and writing the truncated value
-    for (i = 0; i < places; i++) {
-        tempfloat *= 10.0;
-        digit = (int) tempfloat;
-        itoa(digit, &outstr[c++], 10);
-        // once written, subtract off that digit
-        tempfloat = tempfloat - (float) digit;
-    }
-    if (extra > 0 and not rightjustify) {
-        for (int i = 0; i< extra; i++) {
-            outstr[c++] = ' ';
-        }
-    }
-
-
-    outstr[c++] = '\0';
-    return outstr;
-
-}
-
-
-
-void setup() {
-  while (!Serial);
-
-    ////////////  LCD I2C DISPLAY /////////////////////////
-   if (analogRead(4) > 600){  //is the circuit complete
-  Serial.println(analogRead(4));
-  lcd.begin(16,2);
-  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
-  lcd.setBacklight(HIGH);
-  lcd.home (); // go home
-  lcd.print("Initializing");
-  lcd.setCursor(0, 1);
-  lcd.print("Please wait");
-  lcd.setCursor(0, 0);
-   }
-
-   ////////////// END LCD   ///////////////////////////
-  Serial.begin(115200);
-  Serial.println(F("CMAPS GPS sketch loaded"));
-  Serial.println(F("Initializing....(May take 3 seconds)"));
-
-  fonaSerial->begin(4800);
-  if (! fona.begin(*fonaSerial)) {
-    Serial.println(F("Couldn't find FONA"));
-    while (1);
-  }
-
-  while (true) {
-    uint8_t stat = fona.getNetworkStatus();
-    if ((stat == 1) || (stat == 5)){
-      Serial.print(F("Network associated!: "));
-      Serial.println(stat);
-      break;
-    }
-    delay(500);
-      Serial.print(F("waiting for network: "));
-      Serial.println(stat);
-  }
-
-  fona.setGPRSNetworkSettings(F("mdata.net.au")); //use this for Aldi SIM card - added by MV to improve lock success
-  Serial.println(F("Setting APN"));
-  //fona.setGPRSNetworkSettings(F("telstra.internet")); //use this for Telstra SIM card - added by MV to improve lock success
-  fona.enableGPS(true);
-  delay(2000);
-  Serial.println(F("Setting GPRS status"));
-  fona.enableGPRS(true);
-  delay(10000);
-
-}
-
-void loop() {
-  // put your main code here, to run repeatedly:
-  float lat, lon, speed_kph, bearing, altitude;
-  boolean didGetLock = fona.getGPS(&lat, &lon, &speed_kph, &bearing, &altitude);
-  if (didGetLock)
-  {
-    Serial.println(lat, 4); // the 4 gives us lat to four decimal places
-    Serial.println(lon, 4);  // the 4 gives us lon to four decimal places
-    uint16_t len;
-    uint16_t statuscode;
-    String url = "http://cmaps.knox.nsw.edu.au/location/push?uuid=501&latitude=";  //IMPORTANT "uuid=" defines the unique ID. LABEL THE ARDUINO UNIT with the number after upload.
-    char buff[120];
-    floatToString(buff, lat , 8, 5);
-    url += buff;
-    url += "&longitude=";
-    floatToString(buff, lon , 8, 5);
-    url += buff;
-    int len2;
-    url.toCharArray(buff, 120);
-
-    //if (!fona.HTTP_GET_start(buff, &statuscode, &len))
-    //{
-      //Serial.println("HTTP failure response, rebooting in 10");
-      ///delay(10000);
-      //asm volatile ("  jmp 0");
-    //}
-
-    fona.HTTP_GET_start(buff, &statuscode, &len);
-    while(fona.available())fona.read();
-
-    fona.HTTP_GET_end();
-
-
-      ////////////  LCD I2C DISPLAY /////////////////////////
-    if (analogRead(4) > 600){  //is the circuit complete
-        lcd.clear(); //clears LCD screen
-      Serial.println("Now doing LCD shiz" + analogRead(4));
-      lcd.begin(16,2);
-      lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
-      lcd.setBacklight(HIGH);
-      lcd.clear();
-      lcd.print("Lat:"); lcd.print(lat,5); // displays lat to 5 decimal places
-      lcd.setCursor(0, 1); // Set cursor to bottom row
-      lcd.print("Lon:"); lcd.print(lon,5); // displays lon to 5 decimal places
-      lcd.setCursor(0, 0); // Set cursor to top row again
-      delay(6000);
-      if (analogRead(4) > 600){
-      }
-    }
-
-     unsigned long start = millis();
-    while ((analogRead(4) < 600) && (millis() < ((start+300000))))
-    {
-     delay(1); // the aim here is to have a 5 minute delay (300000) between sends once lock is achieved
-     //Serial.println("delay");
-     }
-    Serial.println("finished delay");
-
-     //////////// END LCD I2C DISPLAY /////////////////////////
-  }
-  else {
-    Serial.println("No lock");
-
-    ////////////  LCD I2C DISPLAY /////////////////////////
-     if (analogRead(4) > 600)  //is the circuit complete
-      {
-        Serial.println("in nolock if");
-        Serial.println(analogRead(4));
-
-        lcd.begin(16,2);
-        Serial.println("1");
-        lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
-        Serial.println("2");
-        lcd.setBacklight(HIGH);
-        Serial.println("3");
-        lcd.clear();
-        lcd.print("No lock.");
-
-        Serial.println("4");
-        delay(1000);
-        Serial.println("fin nolock if");
-
-//        uint16_t len;
-//        uint16_t statuscode;
-//        String url = "http://cmaps.knox.nsw.edu.au/location/nolock?uuid=503";  //IMPORTANT "uuid=" defines the unique ID. LABEL THE ARDUINO UNIT with the number after upload.
-//        char buff[120];
-//        url.toCharArray(buff, 120);
-//
-//        if (!fona.HTTP_GET_start(buff, &statuscode, &len))
-//        {
-//          Serial.println("HTTP failure response, rebooting in 10");
-//          delay(10000);
-//          asm volatile ("  jmp 0");
-//        }
-//        while(fona.available())fona.read();
-//
-//        fona.HTTP_GET_end();
-//        delay(25000);
-      }
-    ////////////  END LCD I2C DISPLAY /////////////////////////
-  }
-}
-
+#include "Adafruit_FONA.h"
+
+#define FONA_RX 2
+#define FONA_TX 3
+#define FONA_RST 4
+
+#ifdef __AVR__
+#include <SoftwareSerial.h>
+SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
+SoftwareSerial *fonaSerial = &fonaSS;
+#else
+HardwareSerial *fonaSerial = &Serial1;
+#endif
+
+// Use this for FONA 800 and 808s
+Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
+// Use this one for FONA 3G
+//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
+
+////////////  LCD I2C DISPLAY /////////////////////////
+#include <Wire.h>
+#include <LCD.h>
+#include <LiquidCrystal_I2C.h>
+
+#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
+#define BACKLIGHT_PIN     3
+#define En_pin  2
+#define Rw_pin  1
+#define Rs_pin  0
+#define D4_pin  4
+#define D5_pin  5
+#define D6_pin  6
+#define D7_pin  7
+
+LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
+
+
+
+///////////////// END LCD I2C DISPLAY //////////////////////////
+
+// Download this library for the 2 PIN LCD screen https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads and rename folder 'LiquidCrystal_I2C' and remove other LCD folders
+
+// floatToString.h
+//
+// Tim Hirzel
+// tim@growdown.com
+// March 2008
+// float to string
+//
+// If you don't save this as a .h, you will want to remove the default arguments
+//     uncomment this first line, and swap it for the next.  I don't think keyword arguments compile in .pde files
+
+char * floatToString(char * outstr, float value, int places, int minwidth, bool rightjustify=false) {
+    // this is used to write a float value to string, outstr.  oustr is also the return value.
+    int digit;
+    float tens = 0.1;
+    int tenscount = 0;
+    int i;
+    float tempfloat = value;
+    int c = 0;
+    int charcount = 1;
+    int extra = 0;
+    // make sure we round properly. this could use pow from <math.h>, but doesn't seem worth the import
+    // if this rounding step isn't here, the value  54.321 prints as 54.3209
+
+    // calculate rounding term d:   0.5/pow(10,places)
+    float d = 0.5;
+    if (value < 0)
+        d *= -1.0;
+    // divide by ten for each decimal place
+    for (i = 0; i < places; i++)
+        d/= 10.0;
+    // this small addition, combined with truncation will round our values properly
+    tempfloat +=  d;
+
+    // first get value tens to be the large power of ten less than value
+    if (value < 0)
+        tempfloat *= -1.0;
+    while ((tens * 10.0) <= tempfloat) {
+        tens *= 10.0;
+        tenscount += 1;
+    }
+
+    if (tenscount > 0)
+        charcount += tenscount;
+    else
+        charcount += 1;
+
+    if (value < 0)
+        charcount += 1;
+    charcount += 1 + places;
+
+    minwidth += 1; // both count the null final character
+    if (minwidth > charcount){
+        extra = minwidth - charcount;
+        charcount = minwidth;
+    }
+
+    if (extra > 0 and rightjustify) {
+        for (int i = 0; i< extra; i++) {
+            outstr[c++] = ' ';
+        }
+    }
+
+    // write out the negative if needed
+    if (value < 0)
+        outstr[c++] = '-';
+
+    if (tenscount == 0)
+        outstr[c++] = '0';
+
+    for (i=0; i< tenscount; i++) {
+        digit = (int) (tempfloat/tens);
+        itoa(digit, &outstr[c++], 10);
+        tempfloat = tempfloat - ((float)digit * tens);
+        tens /= 10.0;
+    }
+
+    // if no places after decimal, stop now and return
+
+    // otherwise, write the point and continue on
+    if (places > 0)
+    outstr[c++] = '.';
+
+
+    // now write out each decimal place by shifting digits one by one into the ones place and writing the truncated value
+    for (i = 0; i < places; i++) {
+        tempfloat *= 10.0;
+        digit = (int) tempfloat;
+        itoa(digit, &outstr[c++], 10);
+        // once written, subtract off that digit
+        tempfloat = tempfloat - (float) digit;
+    }
+    if (extra > 0 and not rightjustify) {
+        for (int i = 0; i< extra; i++) {
+            outstr[c++] = ' ';
+        }
+    }
+
+
+    outstr[c++] = '\0';
+    return outstr;
+
+}
+
+
+
+void setup() {
+  while (!Serial);
+
+    ////////////  LCD I2C DISPLAY /////////////////////////
+   if (analogRead(4) > 600){  //is the circuit complete
+  Serial.println(analogRead(4));
+  lcd.begin(16,2);
+  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
+  lcd.setBacklight(HIGH);
+  lcd.home (); // go home
+  lcd.print("Initializing");
+  lcd.setCursor(0, 1);
+  lcd.print("Please wait");
+  lcd.setCursor(0, 0);
+   }
+
+   ////////////// END LCD   ///////////////////////////
+  Serial.begin(115200);
+  Serial.println(F("CMAPS GPS sketch loaded"));
+  Serial.println(F("Initializing....(May take 3 seconds)"));
+
+  fonaSerial->begin(4800);
+  if (! fona.begin(*fonaSerial)) {
+    Serial.println(F("Couldn't find FONA"));
+    while (1);
+  }
+
+  while (true) {
+    uint8_t stat = fona.getNetworkStatus();
+    if ((stat == 1) || (stat == 5)){
+      Serial.print(F("Network associated!: "));
+      Serial.println(stat);
+      break;
+    }
+    delay(500);
+      Serial.print(F("waiting for network: "));
+      Serial.println(stat);
+  }
+
+  fona.setGPRSNetworkSettings(F("mdata.net.au")); //use this for Aldi SIM card - added by MV to improve lock success
+  Serial.println(F("Setting APN"));
+  fona.enableGPS(true);
+  delay(2000); //suggest we make this 10000 as this forum said it would reduce AT+CGATT=1 errors or network registration after setting the APN
+  Serial.println(F("Setting GPRS status"));
+  fona.enableGPRS(true);
+  delay(10000);
+
+}
+
+void loop() {
+  // put your main code here, to run repeatedly:
+  float lat, lon, speed_kph, bearing, altitude;
+  boolean didGetLock = fona.getGPS(&lat, &lon, &speed_kph, &bearing, &altitude);
+  if (didGetLock)
+  {
+    Serial.println(lat, 4); // the 4 gives us lat to four decimal places
+    Serial.println(lon, 4);  // the 4 gives us lon to four decimal places
+    uint16_t len;
+    uint16_t statuscode;
+    String url = "http://cmaps.knox.nsw.edu.au/location/push?uuid=501&latitude=";  //IMPORTANT "uuid=" defines the unique ID. LABEL THE ARDUINO UNIT with the number after upload.
+    char buff[120];
+    floatToString(buff, lat , 8, 5);
+    url += buff;
+    url += "&longitude=";
+    floatToString(buff, lon , 8, 5);
+    url += buff;
+    int len2;
+    url.toCharArray(buff, 120);
+
+    //if (!fona.HTTP_GET_start(buff, &statuscode, &len))
+    //{
+      //Serial.println("HTTP failure response, rebooting in 10");
+      ///delay(10000);
+      //asm volatile ("  jmp 0");
+    //}
+
+    fona.HTTP_GET_start(buff, &statuscode, &len);
+    while(fona.available())fona.read();
+
+    fona.HTTP_GET_end();
+
+
+      ////////////  LCD I2C DISPLAY /////////////////////////
+    if (analogRead(4) > 600){  //is the circuit complete
+        lcd.clear(); //clears LCD screen
+      Serial.println("Now doing LCD shiz" + analogRead(4));
+      lcd.begin(16,2);
+      lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
+      lcd.setBacklight(HIGH);
+      lcd.clear();
+      lcd.print("Lat:"); lcd.print(lat,5); // displays lat to 5 decimal places
+      lcd.setCursor(0, 1); // Set cursor to bottom row
+      lcd.print("Lon:"); lcd.print(lon,5); // displays lon to 5 decimal places
+      lcd.setCursor(0, 0); // Set cursor to top row again
+      delay(6000);
+      if (analogRead(4) > 600){
+      }
+    }
+
+     unsigned long start = millis();
+    while ((analogRead(4) < 600) && (millis() < ((start+300000))))
+    {
+     delay(1); // the aim here is to have a 5 minute delay (300000) between sends once lock is achieved
+     //Serial.println("delay");
+     }
+    Serial.println("finished delay");
+
+     //////////// END LCD I2C DISPLAY /////////////////////////
+  }
+  else {
+    Serial.println("No lock");
+
+    ////////////  LCD I2C DISPLAY /////////////////////////
+     if (analogRead(4) > 600)  //is the circuit complete
+      {
+        Serial.println("in nolock if");
+        Serial.println(analogRead(4));
+
+        lcd.begin(16,2);
+        Serial.println("1");
+        lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
+        Serial.println("2");
+        lcd.setBacklight(HIGH);
+        Serial.println("3");
+        lcd.clear();
+        lcd.print("No lock.");
+
+        Serial.println("4");
+        delay(1000);
+        Serial.println("fin nolock if");
+
+//        uint16_t len;
+//        uint16_t statuscode;
+//        String url = "http://cmaps.knox.nsw.edu.au/location/nolock?uuid=503";  //IMPORTANT "uuid=" defines the unique ID. LABEL THE ARDUINO UNIT with the number after upload.
+//        char buff[120];
+//        url.toCharArray(buff, 120);
+//
+//        if (!fona.HTTP_GET_start(buff, &statuscode, &len))
+//        {
+//          Serial.println("HTTP failure response, rebooting in 10");
+//          delay(10000);
+//          asm volatile ("  jmp 0");
+//        }
+//        while(fona.available())fona.read();
+//
+//        fona.HTTP_GET_end();
+//        delay(25000);
+      }
+    ////////////  END LCD I2C DISPLAY /////////////////////////
+  }
+}
+


TravisCI fix

TravisCI fix

- comment out more line to get it to compile

--- Arduino/McLighting/McLighting.ino
+++ Arduino/McLighting/McLighting.ino
@@ -378,11 +378,11 @@
     WiFiManagerParameter custom_mqtt_pass("pass", "MQTT pass", mqtt_pass, 32, " maxlength=31 type='password'");
   #endif

-  sprintf(strip_size, "%d", WS2812FXStripSettings.stripSize);
-  sprintf(led_pin, "%d", WS2812FXStripSettings.pin);
-
-  WiFiManagerParameter custom_strip_size("strip_size", "Number of LEDs", strip_size, 3);
-  WiFiManagerParameter custom_led_pin("led_pin", "LED GPIO", led_pin, 2);
+  // sprintf(strip_size, "%d", WS2812FXStripSettings.stripSize);
+  // sprintf(led_pin, "%d", WS2812FXStripSettings.pin);
+
+  // WiFiManagerParameter custom_strip_size("strip_size", "Number of LEDs", strip_size, 3);
+  // WiFiManagerParameter custom_led_pin("led_pin", "LED GPIO", led_pin, 2);

   //Local intialization. Once its business is done, there is no need to keep it around
   WiFiManager wifiManager;
@@ -403,8 +403,8 @@
     wifiManager.addParameter(&custom_mqtt_pass);
   #endif

-  wifiManager.addParameter(&custom_strip_size);
-  wifiManager.addParameter(&custom_led_pin);
+  // wifiManager.addParameter(&custom_strip_size);
+  // wifiManager.addParameter(&custom_led_pin);

   WiFi.setSleepMode(WIFI_NONE_SLEEP);

@@ -460,15 +460,15 @@
     wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
   #endif

-  strcpy(strip_size, custom_strip_size.getValue());
-  strcpy(led_pin, custom_led_pin.getValue());
-
-  if(atoi(strip_size) != WS2812FXStripSettings.stripSize)
-    WS2812FXStripSettings.stripSize = atoi(strip_size);
-  uint8_t pin = atoi(led_pin);
-  if ((pin == 16 or pin == 5 or pin == 4 or pin == 0 or pin == 2 or pin == 14 or pin == 12 or pin == 13 or pin == 15 or pin == 3 or pin == 1) and (pin != WS2812FXStripSettings.pin) )
-    WS2812FXStripSettings.pin = pin;
-  initStrip();
+  // strcpy(strip_size, custom_strip_size.getValue());
+  // strcpy(led_pin, custom_led_pin.getValue());
+
+  // if(atoi(strip_size) != WS2812FXStripSettings.stripSize)
+  //   WS2812FXStripSettings.stripSize = atoi(strip_size);
+  // uint8_t pin = atoi(led_pin);
+  // if ((pin == 16 or pin == 5 or pin == 4 or pin == 0 or pin == 2 or pin == 14 or pin == 12 or pin == 13 or pin == 15 or pin == 3 or pin == 1) and (pin != WS2812FXStripSettings.pin) )
+  //   WS2812FXStripSettings.pin = pin;
+  // initStrip();

   //if you get here you have connected to the WiFi
   DBG_OUTPUT_PORT.println("connected...yeey :)");


Lowered motor values

Lowered motor values

1 is too fast m8

--- 2018-FirefighterL1/2018-FirefighterL1.ino
+++ 2018-FirefighterL1/2018-FirefighterL1.ino
@@ -58,25 +58,25 @@
 double closeToWall = 2;   //defines how close the robot should be (inches) to the wall to register as being "too close"

 void rollForward() {
-  leftMotor.set(1);
-  rightMotor.set(1);
+  leftMotor.set(0.5);
+  rightMotor.set(0.5);
 }

 void rollBackward() {
-  leftMotor.set(-1);
-  rightMotor.set(-1);
+  leftMotor.set(-0.5);
+  rightMotor.set(-0.5);
 }

 void moveSlightLeft() {
-  leftMotor.set(0.5);
-  rightMotor.set(0.75);
+  leftMotor.set(0.25);
+  rightMotor.set(0.375);
   delay(100);
   stopRobot();
 }

 void moveSlightRight() {
-  leftMotor.set(0.75); //Half power plus additional 25
-  rightMotor.set(0.5);
+  leftMotor.set(0.375); //Half power plus additional 25
+  rightMotor.set(0.25);
   delay(100);
   stopRobot();
 }
@@ -128,8 +128,8 @@
     gyroTargetAngle = 360 + gyroTargetAngle;
   }
   if(gyroTargetAngle < getGyroAngle()){
-    leftMotor.set(1);
-    rightMotor.set(1);
+    leftMotor.set(0.5);
+    rightMotor.set(0.5);
     while(gyroTargetAngle < getGyroAngle()){
       delay(50);
     }


Abigail updates for calibration

Abigail updates for calibration

--- Geek-FLL-Project.ino
+++ Geek-FLL-Project.ino
@@ -24,15 +24,15 @@
 const char pageEnding[]="\
 ";

-char result[10];
+char result[20];

-const float Filling_weight = 0.5f;  // to be changed
-const float Pickup_weight = 2.0f; // to be changed
+const float Filling_weight = 500.0f;  // to be changed
+const float Pickup_weight = 1000.0f; // to be changed

 void handle_weight()
 {
   String filename;
-
+  digitalWrite(LED_PIN, LOW);
   float weight = scale.get_units(5);
   if(weight < Filling_weight){
     filename = "/Empty.html";
@@ -46,6 +46,7 @@
  File file = SPIFFS.open(filename, "r");
  size_t sent = server.streamFile(file, "text/html");
  file.close();
+ digitalWrite(LED_PIN, HIGH);
 }

 void handleCalib()
@@ -55,10 +56,16 @@
   response += pageSecondPart;

   response += "
Our Geeky Prototype
";
-  dtostrf(scale.get_units(5), 1, 1, result);

-  response += "weight = ";
+  dtostrf(scale.get_value(), 1, 2, result);
+  response += "raw result = ";
   response += result;
+
+  dtostrf(scale.get_units(), 1, 2, result);
+
+  response += "
calib weight = ";
+  response += result;
+
   response += pageEnding;

   server.send(200, "text/html", response);
@@ -70,7 +77,8 @@
 }

 //const float calibration = 2280.f; // replace once prototype is made
-const float calibration = 4400.f;
+const float calibration = 154.f;  // came from measured known weight
+
 void setup()
 {
   pinMode(LED_PIN, OUTPUT);


git-svn-id: svn://192.168.1.10/public/Zimodem@14591 0d6f1817-ed0e-0410-87c9-987e46238f29

--- zimodem/zcommand.ino
+++ zimodem/zcommand.ino
@@ -962,7 +962,7 @@
       && (nextConn->client->available()>0))
       {
         int availableBytes = nextConn->client->available();
-        int maxBytes=256;
+        int maxBytes=254;
         if(availableBytes<maxBytes)
           maxBytes=availableBytes;
         nextConn->client->read(nextConn->lastPacketBuf,maxBytes);


More generous with size of incoming network data getting packeted.

git-svn-id: d8bfcd070c2c81762cca1b3912331324182919ba@15310 0d6f1817-ed0e-0410-87c9-987e46238f29

--- zimodem/zcommand.ino
+++ zimodem/zcommand.ino
@@ -2195,8 +2195,8 @@
       int maxBytes=packetSize;
       if(availableBytes<maxBytes)
         maxBytes=availableBytes;
-      if(maxBytes > Serial.availableForWrite()-15)
-        maxBytes = Serial.availableForWrite()-15;
+      //if(maxBytes > Serial.availableForWrite()-15) // how much we read should depend on how much we can IMMEDIATELY write
+      //maxBytes = Serial.availableForWrite()-15;    // .. this is because resendLastPacket ensures everything goes out
       if(maxBytes > 0)
       {
         if((nextConn->delimiters[0] != 0) || (delimiters[0] != 0))


Using mm resolution for ultrasonic water level sensor.

--- Arduino/MainControl/WaterLevel.ino
+++ Arduino/MainControl/WaterLevel.ino
@@ -11,5 +11,5 @@
 }

 unsigned int getWaterLevel() {
-  return sonar.ping() / US_ROUNDTRIP_CM;
+  return sonar.ping() * 10 / US_ROUNDTRIP_CM;
 }


マイナス入力時のエラー表示追加

マイナス入力時のエラー表示追加

--- 2_example/example12_bell/html.ino
+++ 2_example/example12_bell/html.ino
@@ -25,6 +25,7 @@
     client.println("
chimeBells STATUS
");
     if(chime==0) sprintf(s,"
0 (チャイム OFF)
");
     if(chime>0)  sprintf(s,"
%d (チャイム %d回)
",chime,chime);
+    else sprintf(s,"
%d (エラー)
,chime");
     client.println(s);
     client.println("
");
     client.println("
HTTP GET
");


Reminder comment

Reminder comment

--- photon-firmware/nesnet.ino
+++ photon-firmware/nesnet.ino
@@ -12,6 +12,8 @@
 #define FETCH_LATCH_THRESHOLD 80
 #define HANDSHAKE_2_WAIT_TIME 0

+// NOTE: Everything being volatile like this is really sloppy. It's probably costing some time. (Though, maybe not much since
+// the photon can run laps around the NES...)
 volatile unsigned char latchedByte = 0;                 // Controller press byte value = one letter in tweet
 volatile unsigned char bitCount = 0;                    // A single LDA $4017 (get one bit from "controller press")
 volatile unsigned int byteCount = 0;                   // How many bytes have already been printed


refined

refined

--- src/arduino/bear.ino
+++ src/arduino/bear.ino
@@ -82,24 +82,10 @@
       default: break;
     }
     irrecv.resume();
-  }
-
-  if (previous_blink_downbeat && current_millis - previous_blink_downbeat >= BLINK_INTERVAL) stop_blink(true);
-  if (previous_blink_upbeat && current_millis - previous_blink_upbeat >= BLINK_INTERVAL) stop_blink(false);
-
-  if (previous_servo_move && current_millis - previous_servo_move >= SERVO_INTERVAL) {
-    // check if it should return
-    if (current_angle >= current_max_angle) current_velocity_positive = false;
-
-    // move the servo
-    current_angle += (current_velocity_positive ? 1 : -1) * DEGREE_STEP;
-    myservo.write(SERVO_BASE_ANGLE + current_angle);
-
-    if (current_angle == 0 && !current_velocity_positive) {
-      previous_servo_move = 0; // finish moving
-    } else {
-      previous_servo_move += SERVO_INTERVAL;
-    }
+  } else {
+    if (previous_blink_downbeat && current_millis - previous_blink_downbeat >= BLINK_INTERVAL) stop_blink(true);
+    if (previous_blink_upbeat && current_millis - previous_blink_upbeat >= BLINK_INTERVAL) stop_blink(false);
+    if (previous_servo_move && current_millis - previous_servo_move >= SERVO_INTERVAL) move_servo();
   }
 }

@@ -139,6 +125,21 @@
   previous_servo_move = current_millis;
 }

+void move_servo() {
+  // check if it should return
+  if (current_angle >= current_max_angle) current_velocity_positive = false;
+
+  // move the servo
+  current_angle += (current_velocity_positive ? 1 : -1) * DEGREE_STEP;
+  myservo.write(SERVO_BASE_ANGLE + current_angle);
+
+  if (current_angle == 0 && !current_velocity_positive) {
+    previous_servo_move = 0; // finish moving
+  } else {
+    previous_servo_move += SERVO_INTERVAL;
+  }
+}
+
 int translate_ir() {
   // todo control repetition
   switch(results.value) {


Remove the testing sketch.

Remove the testing sketch.

--- arduino/rover-movement/rover-movement.ino
+++ arduino/rover-movement/rover-movement.ino
@@ -1,62 +0,0 @@
-/*
- * Author: Manuel Parra Z.
- * Date: 14/11/2015
- * License: MIT License
- * Materials:
- *      - Arduino Uno R3
- *      - DFRobot DF-MD V1.3
- *      - DFRobot Pirate 4WD
- * Description:
- *  This sketch will use as a movement test, first the rover will go foward
- * on the track, then it will go reverse, then will turn to left and finally
- * will turn to right. This sketch will show you the if you connected the
- * engines and batteries properly. Don't forget to review the fritzing
- * electronic diagram in the document section of the project
- */
-
-
-int M1 = 4;
-int E1 = 5;
-int E2 = 6;
-int M2 = 7;
-
-void setup()
-{
-  Serial.begin(9600);
-  pinMode(M1, OUTPUT);
-  pinMode(E1, OUTPUT);
-  pinMode(M2, OUTPUT);
-  pinMode(E2, OUTPUT);
-  Serial.println("Setup finished.");
-}
-
-void loop()
-{
-  Serial.println("Foward for 3 seconds.");
-  digitalWrite(M1, HIGH);
-  digitalWrite(M2, HIGH);
-  analogWrite(E1, 200);
-  analogWrite(E2, 200);
-  delay(3000);
-
-  Serial.println("Reverse for 3 seconds.");
-  digitalWrite(M1, LOW);
-  digitalWrite(M2, LOW);
-  analogWrite(E1, 200);
-  analogWrite(E2, 200);
-  delay(3000);
-
-  Serial.println("Left for 3 seconds.");
-  digitalWrite(M1, LOW);
-  digitalWrite(M2, HIGH);
-  analogWrite(E1, 200);
-  analogWrite(E2, 200);
-  delay(3000);
-
-  Serial.println("Right for 3 seconds.");
-  digitalWrite(M1, HIGH);
-  digitalWrite(M2, LOW);
-  analogWrite(E1, 200);
-  analogWrite(E2, 200);
-  delay(3000);
-}


Renamed temperatures based on usage

Renamed temperatures based on usage

--- WxStation/WxStation/WxStation.ino
+++ WxStation/WxStation/WxStation.ino
@@ -46,8 +46,8 @@

 /*ReadTemps fetches the values from the temp sensors*/
 void ReadTemps(JsonObject& obj) {
-  obj["temperature1"] = thermometer1.temperature();
-  obj["temperature2"] = thermometer2.temperature();
+  obj["temperature_ext"] = thermometer1.temperature();
+  obj["temperature"] = thermometer2.temperature();
 }

 void ReadSystem(JsonObject& obj) {


Start on storing stuff in EEPROM

Start on storing stuff in EEPROM

--- Lee_Retirement/Lee_Retirement.ino
+++ Lee_Retirement/Lee_Retirement.ino
@@ -56,7 +56,6 @@
 #define BrightMax 255
 #define BrightMin 0
 int brightness_increment = -2;
-int brightness = BrightMax;

 // read the buttons
 int read_LCD_buttons()
@@ -77,19 +76,50 @@
  return btnNONE;  // when all others fail, return this...
 }

+/*
+ EEPROM locations
+*/
+#include <EEPROM.h>
+#define ADDR_RETIRE_TIME 0
+time_t retire_time;
+#define ADDR_BRIGHTNESS  ADDR_RETIRE_TIME + sizeof(time_t)
+int brightness = BrightMax;
+
+/*
+ Menu stuff
+*/
+#define NO_MENU           0
+#define RETIRE_TIME_MENU  1
+#define CURRENT_TIME_MENU 2
+#define BRIGHTNESS_MENU   3
+int menustate = NO_MENU;
+int menuvalue = 0;
+String menuheader = "";
+String menuvalue_label = "";
+
+void menu(){
+  switch (menustate){
+    case RETIRE_TIME_MENU: {
+      break;
+    }
+  }
+}
+
 void setup() {
   // define PWM brightness pin for output
   pinMode(PinBacklight, OUTPUT);
   // set up the LCD's number of columns and rows:
   lcd.begin(16, 2);
   lcd.clear();
+  // get data from EEPROM
+  EEPROM.get(ADDR_RETIRE_TIME, retire_time);
+  EEPROM.get(ADDR_BRIGHTNESS,  brightness);
 }

 void loop() {
   lcd_key = read_LCD_buttons();
   switch (lcd_key){
     case btnNONE: {
-      key = "NONE";
       break;
     }
     case btnRIGHT: {


add new blink{all, lights, background} patterns

--- CocaCola/CocaCola.ino
+++ CocaCola/CocaCola.ino
@@ -237,6 +237,78 @@
 	}

 	delay(normal);
+}
+
+void blinkAllOnRandom() {
+	int state[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
+
+	for (int i = 0; i < sizeof(state); i++) {
+		state[i] = 0;
+	}
+
+	int on = 0;
+
+	while (on != sizeof(state)) {
+		int value = random(0, sizeof(state));
+		if (state[value]) {
+			continue;
+		}
+
+		state[value] = 1;
+		int pin = Lights[value];
+		digitalWrite(pin, PATTERN_ON);
+		on++;
+
+		delay(minimal);
+	}
+}
+
+void blinkBackgroundOnRandom() {
+	int state[] = [ 0, 0, 0, 0, 0, 0 ];
+
+	for (int i = 0; i < sizeof(state); i++) {
+		state[i] = 0;
+	}
+
+	int on = 0;
+
+	while (on != sizeof(state)) {
+		int value = random(0, sizeof(state));
+		if (state[value]) {
+			continue;
+		}
+
+		state[value] = 1;
+		int pin = background[value];
+		digitalWrite(pin, PATTERN_ON);
+		on++;
+
+		delay(minimal);
+	}
+}
+
+void blinkLettersOnRandom() {
+	int state[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
+
+	for (int i = 0; i < sizeof(state); i++) {
+		state[i] = 0;
+	}
+
+	int on = 0;
+
+	while (on != sizeof(state)) {
+		int value = random(0, sizeof(state));
+		if (state[value]) {
+			continue;
+		}
+
+		state[value] = 1;
+		int pin = letters[value];
+		digitalWrite(pin, PATTERN_ON);
+		on++;
+
+		delay(minimal);
+	}
 }

 void flickerPattern(int flickerLetters, int flickerBackground) {


fixed by Mark, + copyright notice

fixed by Mark, + copyright notice

--- dev/utils/setSim900Baud/setSim900Baud.ino
+++ dev/utils/setSim900Baud/setSim900Baud.ino
@@ -1,3 +1,23 @@
+/*
+The OpenTRV project licenses this file to you
+under the Apache Licence, Version 2.0 (the "Licence");
+you may not use this file except in compliance
+with the Licence. You may obtain a copy of the Licence at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the Licence is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the Licence for the
+specific language governing permissions and limitations
+under the Licence.
+
+Author(s) / Copyright (s): Deniz Erbilgin 2015--2016
+                           Mark Hill 2016
+                           Damon Hart-Davis 2015--2016
+*/
+
 #include <SoftwareSerial.h>

 /**
@@ -27,20 +47,27 @@
   digitalWrite(9, HIGH);
   delay(500);
   digitalWrite(9, LOW);
+
   delay(5000);
+  setBaud();
+  delay(500);
+  ser.begin(2400);
+  delay(500);
+  getBaud();
   while(ser.available() > 0) ser.read();

-  setBaud();
+  delay(500);
+  loop();
 }

 void loop() {
   // put your main code here, to run repeatedly:
-//  char c = 0;
-//  if (Serial.available() > 0) c = Serial.read();
-//  if (c == 'l') getPossibleBauds();
-//  else if (c == 'r') getBaud();
-//  else if (c == 's') setBaud();
-
+  char c = 0;
+  if (Serial.available() > 0) c = Serial.read();
+  if (c == 'l') getPossibleBauds();
+  else if (c == 'r') getBaud();
+  else if (c == 's') setBaud();
+
   if (ser.available() > 0) Serial.print((char)ser.read());
 }

@@ -72,4 +99,3 @@

   //getRate();
 }
-


Adjust threshold values

Adjust threshold values

--- EmotionalClothing.ino
+++ EmotionalClothing.ino
@@ -108,21 +108,21 @@
     file.open(root, "gmechngd.wav");
   } else if (light > 0.8) {         // White
     file.open(root, "avemaria.wav");
-  } else if (saturation < 0.25) {   // Gray
+  } else if (saturation < 0.05) {   // Gray
     file.open(root, "veridquo.wav");
-  } else if (hue < 10) {            // Red
+  } else if (hue < 5) {            // Red
     file.open(root, "nitefate.wav");
-  } else if (hue < 40) {            // Orange
+  } else if (hue < 50) {            // Orange
     file.open(root, "mariothm.wav");
-  } else if (hue < 90) {            // Yellow
+  } else if (hue < 110) {            // Yellow
     file.open(root, "wiishopc.wav");
-  } else if (hue < 150) {           // Green
+  } else if (hue < 170) {           // Green
     file.open(root, "swedenmc.wav");
-  } else if (hue < 270) {           // Blue
+  } else if (hue < 230) {           // Blue
     file.open(root, "animcros.wav");
-  } else if (hue < 330) {           // Magenta
+  } else if (hue < 360) {           // Magenta
     file.open(root, "wndrland.wav");
-  } else file.open(root, "nitefate.wav"); // Red
+  }

   if (!wave.create(file)) Serial.println("Can't open the file");
   wave.play();


horloge_cycles_ultradiens

--- files/horloge_cycles_ultradiens/horloge_cycles_ultradiens.ino
+++ files/horloge_cycles_ultradiens/horloge_cycles_ultradiens.ino
@@ -198,7 +198,7 @@
   if( frac16eJour < 5400/2 )
     { frac16eJourPx = map( frac16eJour,
                               0,              5400/2-1,
-                              displayWidth/2, displayWidth ); }
+                              displayWidth/2, displayWidth-1 ); }
   else
     { frac16eJourPx = map( frac16eJour,
                               5400/2,         5400-1,


Fixed Mapping

Fixed Mapping


add second voltage to debug statement

add second voltage to debug statement

--- software/nunradio.ino
+++ software/nunradio.ino
@@ -114,6 +114,7 @@
     Serial.println(volts[0]);
     Serial.println(volts[1]);
     Serial.println(volts[2]);
+    Serial.println(volts[3]);
     Serial.println(signals[0]);
 #endif
   }


Added support for percentages to testmote's dimmer.

--- testmote_v0_1/testmote_v0_1.ino
+++ testmote_v0_1/testmote_v0_1.ino
@@ -32,23 +32,24 @@
 #define DPIN_TOGGLE         8
 #define DPIN_MOTE_LED       9  // moteinos have LEDs on D9

-#define VOLTAGE           3.3
-
-#define COMPONENT_TOGGLE  1
-#define COMPONENT_DIMMER  2
-
-#define COMMAND_INCREASE  1
-#define COMMAND_DECREASE  2
-
-#define MEASURE_PERIOD    1000
-#define REPORT_PERIOD     5000
-#define SMOOTHING_FACTOR  3
-#define BATTERY_CYCLE     5
-#define DIMMER_CYCLE      1
-#define TEMP_CYCLE        5
-#define TOGGLE_CYCLE      1
-
-#define DIMMER_INTERVAL   15
+#define VOLTAGE             3.3
+
+#define COMPONENT_TOGGLE    1
+#define COMPONENT_DIMMER    2
+
+#define COMMAND_INCREASE    1
+#define COMMAND_DECREASE    2
+#define COMMAND_PERCENTAGE  3
+
+#define MEASURE_PERIOD      1000
+#define REPORT_PERIOD       5000
+#define SMOOTHING_FACTOR    3
+#define BATTERY_CYCLE       5
+#define DIMMER_CYCLE        1
+#define TEMP_CYCLE          5
+#define TOGGLE_CYCLE        1
+
+#define DIMMER_INTERVAL     15

 #define NODEID        3   // unique for each node on same network
 #define GATEWAYID     1
@@ -214,23 +215,18 @@
       toggle.measure();
       haveReadings = true;
     } else if (inbound.msg.component == COMPONENT_DIMMER) {
-      Serial.print("rf msg component = ");
-      Serial.print(inbound.msg.component);
-      Serial.print(", command = ");
-      Serial.print(inbound.msg.data[0]);
       if (inbound.msg.data[0] == COMMAND_INCREASE) {
         dimmerState += DIMMER_INTERVAL;
         dimmerState = (dimmerState > 255) ? 255 : dimmerState;
-        analogWrite(DPIN_DIMMER, dimmerState);
-        dimmer.measure();
-        haveReadings = true;
       } else if (inbound.msg.data[0] == COMMAND_DECREASE) {
         dimmerState -= DIMMER_INTERVAL;
         dimmerState = (dimmerState < 0) ? 0 : dimmerState;
-        analogWrite(DPIN_DIMMER, dimmerState);
-        dimmer.measure();
-        haveReadings = true;
+      } else if (inbound.msg.data[0] == COMMAND_PERCENTAGE) {
+        dimmerState = inbound.msg.data[1];
       }
+      analogWrite(DPIN_DIMMER, dimmerState);
+      dimmer.measure();
+      haveReadings = true;
     }
   }
 }


send sensible pixel data

send sensible pixel data

--- arduino/led_matrix/led_matrix.ino
+++ arduino/led_matrix/led_matrix.ino
@@ -20,9 +20,9 @@
   for (y = 0; y < NUM_LEDS; y++) {
     for (x = 0; x < NUM_LEDS; x++) {
       while (Serial.available() < NUM_LEDS * 3);
+      b = Serial.read();
+      g = Serial.read();
       r = Serial.read();
-      g = Serial.read();
-      b = Serial.read();
       leds[x] = CRGB(r, g, b);
     }
     Serial.print('X');


Changed get serial

Changed get serial

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -60,26 +60,26 @@
   int checksum;
   int command;

-  int incomingByte = Serial.read();
+  int incomingByte = get_next_byte();

   if(incomingByte != -1) {
     if(incomingByte == 58) {
       py_log("Parsing message");

-      msg_length = Serial.read();
-      command = Serial.read();
+      msg_length = get_next_byte();
+      command = get_next_byte();

       py_log("Length: " + String(msg_length));
       py_log("Command: " + String(command));

       char message[msg_length];
       for(int i=0; i<msg_length; i++) {
-        message[i] = Serial.read();
+        message[i] = get_next_byte();
       }

       py_log("Message Parsed");

-      checksum = Serial.read();
+      checksum = get_next_byte();

       py_log("checksum: " + String(checksum));

@@ -88,6 +88,13 @@
       py_log("The incomingByte was wrong");
     }

+  }
+}
+
+int get_next_byte() {
+  int incomingByte = Serial.read();
+  if(incomingByte != -1) {
+    return incomingByte;
   }
 }


refactor in arduino project

refactor in arduino project

--- arduino/project.ino
+++ arduino/project.ino
@@ -29,6 +29,42 @@
   root["currentLongitude"] = "";
 }

+void lockCar() {
+  Serial.println("LOCK CAR");
+  digitalWrite(ledPinArmed, HIGH);
+  digitalWrite(ledPinDisarmed, LOW);
+  root["sensorArmed"] = true;
+  root["currentLatitude"] = "-23.566999";
+  root["currentLongitude"] = "-46.6338";
+}
+
+void unlockCar() {
+  Serial.println("UNLOCK CAR");
+  digitalWrite(ledPinArmed, LOW);
+  digitalWrite(ledPinDisarmed, HIGH);
+  root["triggeredAlarm"] = true;
+}
+
+void offBuzzer() {
+  tone(buzzerAlarm, 3000);
+  delay(500);
+  tone(buzzerAlarm, 4000);
+  delay(500);
+  tone(buzzerAlarm, 3000);
+  delay(500);
+  noTone(buzzerAlarm);
+}
+
+void resetAlarm() {
+  offBuzzer();
+  digitalWrite(ledPinArmed, LOW);
+  digitalWrite(ledPinDisarmed, LOW);
+  root["sensorArmed"] = false;
+  root["currentLatitude"] = "";
+  root["currentLongitude"] = "";
+  root["triggeredAlarm"] = false;
+}
+
 void loop() {
   if (Serial.available() > 0) {
     // read the incoming byte:
@@ -37,36 +73,17 @@
     if(incomingByte == 76) {
       // SEND L(OKED)
       if(!root["sensorArmed"]) {
-        Serial.println("LOCK CAR");
-        digitalWrite(ledPinArmed, HIGH);
-        root["sensorArmed"] = true;
-        root["currentLatitude"] = "-23.566999";
-        root["currentLongitude"] = "-46.6338";
+        lockCar();
       }
     } else if(incomingByte == 85) {
+      // SEND U(NLOCKED)
       if(root["sensorArmed"]) {
-        // SEND U(NLOCKED)
-        Serial.println("UNLOCK CAR");
-        digitalWrite(ledPinArmed, LOW);
-        digitalWrite(ledPinDisarmed, HIGH);
-        root["triggeredAlarm"] = true;
+        unlockCar();
       }
     } else if(incomingByte == 82) {
       // SEND R(ESET)
       if(root["sensorArmed"] && root["triggeredAlarm"]) {
-        tone(buzzerAlarm, 3000);
-        delay(500);
-        tone(buzzerAlarm, 4000);
-        delay(500);
-        tone(buzzerAlarm, 3000);
-        delay(500);
-        noTone(buzzerAlarm);
-        digitalWrite(ledPinDisarmed, LOW);
-        digitalWrite(ledPinArmed, HIGH);
-        root["triggeredAlarm"] = false;
-        root["sensorArmed"] = true;
-        root["currentLatitude"] = "";
-        root["currentLongitude"] = "";
+        resetAlarm();
       }
     }

@@ -77,33 +94,19 @@

   stateArmed = digitalRead(buttonArmed);
   if(stateArmed == HIGH) {
-    digitalWrite(ledPinArmed, HIGH);
-    root["sensorArmed"] = true;
-    root["currentLatitude"] = "-23.566999";
-    root["currentLongitude"] = "-46.6338";
+    lockCar();
   }

   stateDisarmed = digitalRead(buttonDisarmed);
   if(stateDisarmed == HIGH && root["sensorArmed"]) {
-    digitalWrite(ledPinArmed, LOW);
-    digitalWrite(ledPinDisarmed, HIGH);
-    root["triggeredAlarm"] = true;
+    unlockCar();
   }

   if(root["sensorArmed"] && root["triggeredAlarm"]) {
     tone(buzzerAlarm, 2000);

     if(stateArmed == HIGH) {
-      tone(buzzerAlarm, 3000);
-      delay(500);
-      tone(buzzerAlarm, 4000);
-      delay(500);
-      tone(buzzerAlarm, 3000);
-      delay(500);
-      noTone(buzzerAlarm);
-      digitalWrite(ledPinDisarmed, LOW);
-      root["triggeredAlarm"] = false;
-      root["sensorArmed"] = true;
+      resetAlarm();
     }
   }


Update ha_mqtt_switch.ino

Update ha_mqtt_switch.ino

--- ha_mqtt_switch/ha_mqtt_switch.ino
+++ ha_mqtt_switch/ha_mqtt_switch.ino
@@ -17,7 +17,8 @@
     - https://www.arduino.cc/en/uploads/Tutorial/button.png

    Samuel M. - 08.2016
-   https://github.com/mertenats
+   If you like this example, please add a star! Thank you!
+   https://github.com/mertenats/open-home-automation
 */

 #include <ESP8266WiFi.h>


Don't leave stale sockets in wifi

Don't leave stale sockets in wifi

--- device.ino
+++ device.ino
@@ -2486,12 +2486,12 @@
 void wifi_read()
 {
   #ifdef WIFI_DEBUG_ON
-  debug_info("E wifi_read()");
+  debug_info("E wr()");
   #endif
   if(gprs_or_wifi_communications_on == false)
   {
     #ifdef WIFI_DEBUG_ON
-    debug_info("QA wifi_read()");
+    debug_info("QA wr()");
     #endif
     return;
   }
@@ -2502,13 +2502,19 @@
     #ifdef WIFI_DEBUG_ON
     debug_info("*** Reseting Wifi (Watchdog)  ***");
     #endif
+    if(wifi_client.connected())
+    {
+      wifi_client.stop();
+      wifi_client.flush();
+      wifi_client.stop();
+    }
     wifi_on_home_network = false;
     WiFi.disconnect();
     wifi_communication_state = idle;
     gprs_or_wifi_watchdog_timestamp = current_timestamp;
     wifi_scan();
     #ifdef WIFI_DEBUG_ON
-    debug_info("QB wifi_read()");
+    debug_info("QB wr()");
     #endif
     return;
   }
@@ -2516,7 +2522,7 @@
   {
     wifi_communication_state = idle;
     #ifdef WIFI_DEBUG_ON
-    debug_info("QC wifi_read()");
+    debug_info("QC wr()");
     #endif
     return;
   }
@@ -2546,7 +2552,7 @@
       else
       {
         #ifdef WIFI_DEBUG_ON
-        debug_info("Wifi can't send");
+        debug_info("Wifi no comm");
         #endif
         wifi_client.stop();
       }
@@ -2593,7 +2599,7 @@
     }
   }
   #ifdef WIFI_DEBUG_ON
-  debug_info("QD wifi_read()");
+  debug_info("QD wr()");
   #endif
 }


qq menue correction comme la suppression de tempo stat en partie

--- calibrateur.ino
+++ calibrateur.ino
@@ -13,7 +13,6 @@
 // améliorer la mesure de vitesse à la fin

 //a faire : faire un réinit propre car si on fait 2 étalonnage à la suite ca marche pas
-

 //a faire tester repetabilité avec tempo à 100 et à 200.
 Avec 100 on a des comportement louche lors des cycles de fin
@@ -287,7 +286,7 @@
                     break;

                 case MESREFPULSE:
-                //mesure des impulsion de reference sur une rotation
+                //mesure des impulsions  de reference en provenance du capteur optique sur une rotation
                 //de delta faite X fois pour plus de certitude
                     compteurRef=0;
                     compteur=0;
@@ -334,7 +333,7 @@
                     //----------------------------------------------------------
                     //find max
 					// Principe : on commande un DELTA déplacement, on laisse
-					//   compter et on regarde si le compteur est égal
+					//   compter et on regarde si le compteur du capteur optique est égal
 					//   à ref +/- une petite erreur autorisée
 					//   Si oui alors on recommence sinon on doit etre en butee


Add much more functionality to RF remote

The remote wakes up in NORMAL mode.

NORMAL mode keys:
A) Cycle brightness through 8 different settings
B) Skip to next video on SD card
AB) Switch to COLOR CEILING mode
CD) Switch to COLOR FLOOR mode
BC) Switch to MISC mode

COLOR CEILING mode keys:
A) Reduce maximum level of red; wrap around when floor is reached
B) Reduce maximum level of green; wrap around when floor is reached
C) Reduce maximum level of blue; wrap around when floor is reached
D) return to normal mode

COLOR FLOOR mode keys:
A) Raise minimum level of red; wrap around when ceiling is reached
B) Raise minimum level of green; wrap around when ceiling is reached
C) Raise minimum level of blue; wrap around when ceiling is reached
D) return to normal mode

MISC mode keys:
A) Photo negative (invert all colors)
B) Reset settings to default
D) return to normal mode

--- Arduino/LightPlayer/LightPlayer.ino
+++ Arduino/LightPlayer/LightPlayer.ino
@@ -2,7 +2,7 @@
 #include <SdFat.h>
 #include <FAB_LED.h>

-#define DEBUG 1
+#define DEBUG

 // ports used:
 // digital 4 - SD card chip select
@@ -35,9 +35,57 @@
   const int all  = abcd;
 }

+enum {
+  NORMAL_MODE,
+  COLOR_CEILING_MODE,
+  COLOR_FLOOR_MODE,
+  VIDEO_PLAYBACK_MODE,
+  MACRO_MODE,
+  MISC_MODE,
+} Mode;
+
 apa106<D, 6>   LEDstrip;
 rgb frame[200];
 uint8_t brightness = 255;
+uint8_t negative;
+
+struct ColorIntensity
+{
+  enum { MIN = 0, MAX = 8 };
+
+  uint8_t floor = MIN;
+  uint8_t ceil = MAX;
+
+  void lowerCeil()
+  {
+    ceil = (ceil == floor ? MAX : ceil - 1);
+  }
+
+  void raiseFloor()
+  {
+    floor = (ceil == floor ? MIN : floor + 1);
+  }
+
+  void reset()
+  {
+    floor = MIN;
+    ceil = MAX;
+  }
+
+  uint8_t minBrightness()
+  {
+    return map(floor, MIN, MAX, negative * brightness, !negative * brightness);
+  }
+
+  uint8_t maxBrightness()
+  {
+    return map(ceil, MIN, MAX, negative * brightness, !negative * brightness);
+  }
+};
+
+ColorIntensity r_intensity;
+ColorIntensity g_intensity;
+ColorIntensity b_intensity;

 // Test with reduced SPI speed for breadboards.
 // Change spiSpeed to SPI_FULL_SPEED for better performance
@@ -105,6 +153,43 @@
   sd.ls();

   nextFile();
+}
+
+#ifdef DEBUG
+void printSettingsIfDebug()
+{
+  Serial.print(F("\nMode: "));
+  Serial.print(Mode);
+  Serial.print(F(" Brightness: max "));
+  Serial.print(brightness);
+  Serial.print(F(" r "));
+  Serial.print(r_intensity.floor);
+  Serial.print(F("-"));
+  Serial.print(r_intensity.ceil);
+  Serial.print(F(" g "));
+  Serial.print(g_intensity.floor);
+  Serial.print(F("-"));
+  Serial.print(g_intensity.ceil);
+  Serial.print(F(" b "));
+  Serial.print(b_intensity.floor);
+  Serial.print(F("-"));
+  Serial.print(b_intensity.ceil);
+  Serial.print(F(" neg "));
+  Serial.print(negative);
+}
+#else
+inline void printSettingsIfDebug()
+{
+}
+#endif
+
+void resetDefaultSettings()
+{
+  r_intensity.reset();
+  g_intensity.reset();
+  b_intensity.reset();
+  brightness = 255;
+  negative = 0;
 }

 void handleRfRemoteButtons()
@@ -139,19 +224,65 @@
   }
 #endif

-  switch (button_states) {
-    case Pressed::a: {
-      brightness -= BRIGHTNESS_STEP; // overflow to 255 at zero
-#ifdef DEBUG
-      Serial.print(F("\nBrightness: "));
-      Serial.print(brightness);
-#endif
+  switch(Mode) {
+    case NORMAL_MODE: {
+      switch (button_states) {
+        case Pressed::d:
+        default: return;
+
+        case Pressed::a: {
+          brightness -= BRIGHTNESS_STEP; // overflow to 255 at zero
+        } break;
+
+        case Pressed::b: {
+          nextFile();
+        } break;
+
+        case Pressed::ab: {
+          Mode = COLOR_CEILING_MODE;
+        } break;
+
+        case Pressed::cd: {
+          Mode = COLOR_FLOOR_MODE;
+        } break;
+
+        case Pressed::bc: {
+          Mode = MISC_MODE;
+        } break;
+      }
     } break;

-    case Pressed::b: {
-      nextFile();
+    case COLOR_CEILING_MODE: {
+      switch (button_states) {
+        case Pressed::d: Mode = NORMAL_MODE;
+        default: return;
+        case Pressed::a: r_intensity.lowerCeil(); break;
+        case Pressed::b: g_intensity.lowerCeil(); break;
+        case Pressed::c: b_intensity.lowerCeil(); break;
+      }
     } break;
-  }
+
+    case COLOR_FLOOR_MODE: {
+      switch (button_states) {
+        case Pressed::d: Mode = NORMAL_MODE;
+        default: return;
+        case Pressed::a: r_intensity.raiseFloor(); break;
+        case Pressed::b: g_intensity.raiseFloor(); break;
+        case Pressed::c: b_intensity.raiseFloor(); break;
+      }
+    } break;
+
+    case MISC_MODE: {
+      switch (button_states) {
+        case Pressed::d: Mode = NORMAL_MODE;
+        default: return;
+        case Pressed::a: negative = !negative; break;
+        case Pressed::b: resetDefaultSettings(); break;
+      }
+    } break;
+  }
+
+  printSettingsIfDebug();
 }

 void nextFile()
@@ -179,45 +310,43 @@
   }
 }

+bool readFrame()
+{
+  return infile.read(frame, sizeof(frame)) == sizeof(frame);
+}
+
+void adjustFrameColors()
+{
+  const uint8_t r_min_brightness = r_intensity.minBrightness();
+  const uint8_t g_min_brightness = g_intensity.minBrightness();
+  const uint8_t b_min_brightness = b_intensity.minBrightness();
+
+  const uint8_t r_max_brightness = r_intensity.maxBrightness();
+  const uint8_t g_max_brightness = g_intensity.maxBrightness();
+  const uint8_t b_max_brightness = b_intensity.maxBrightness();
+
+  for (auto & f : frame) {
+    f.r = map(f.r, 0, 255, r_min_brightness, r_max_brightness);
+    f.g = map(f.g, 0, 255, g_min_brightness, g_max_brightness);
+    f.b = map(f.b, 0, 255, b_min_brightness, b_max_brightness);
+  }
+}
+
 void loop()
 {
   handleRfRemoteButtons();

-  int bytes_read = infile.read(frame, sizeof(frame));
-  if (bytes_read != sizeof(frame)) {
+  if (!readFrame()) {
     nextFile();
     return;
   }

   handleRfRemoteButtons();

-#if defined(DEBUG) && DEBUG > 1
-  Serial.print(F("\nFirst pixel before brightness scaling:\n"));
-  Serial.print(frame[0]);
-  Serial.print(F(" "));
-  Serial.print(frame[1]);
-  Serial.print(F(" "));
-  Serial.print(frame[2]);
-#endif
-
-  // Adjust frame brightness
-  for (int i = 0; i < sizeof(frame) / sizeof(*frame); ++i) {
-    frame[i].r = map(frame[i].r, 0, 255, 0, brightness);
-    frame[i].g = map(frame[i].g, 0, 255, 0, brightness);
-    frame[i].b = map(frame[i].b, 0, 255, 0, brightness);
-  }
-
-#if defined(DEBUG) && DEBUG > 1
-  Serial.print(F("\nFirst pixel after brightness scaling:\n"));
-  Serial.print(frame[0]);
-  Serial.print(F(" "));
-  Serial.print(frame[1]);
-  Serial.print(F(" "));
-  Serial.print(frame[2]);
-#endif
+  adjustFrameColors();

   while (millis() - startMillis < 49UL) {
-      handleRfRemoteButtons();
+    handleRfRemoteButtons();
   }

   while (millis() - startMillis < 50UL) {


Added calibrations for Rigs 3 and 4

Added calibrations for Rigs 3 and 4

--- Arduino/private/ledpuff/ledpuff.ino
+++ Arduino/private/ledpuff/ledpuff.ino
@@ -10,6 +10,12 @@
 //#define LASERSLOPE 27
 //#define LASEROFFSET 2400
 // For laser 11140002, Rig 2
+//#define LASERSLOPE 36
+//#define LASEROFFSET 2100
+// For laser 11140002, Rig 3
+//#define LASERSLOPE 30
+//#define LASEROFFSET 2500
+// For laser 11140002, Rig 4
 #define LASERSLOPE 36
 #define LASEROFFSET 2100
 //For devices with A0 pulled HIGH, use 0x61


Add stringToByte font conversion

Add stringToByte font conversion


Add screen brightness curve recording - Teensy side

--- arduino/walt/walt.ino
+++ arduino/walt/walt.ino
@@ -31,6 +31,7 @@
 #define CMD_AUTO_SCREEN_ON      'C'
 #define CMD_AUTO_SCREEN_OFF     'c'
 #define CMD_SEND_LAST_SCREEN    'E'
+#define CMD_BRIGHTNESS_CURVE      'U'

 #define CMD_AUTO_LASER_ON       'L'
 #define CMD_AUTO_LASER_OFF      'l'
@@ -49,7 +50,7 @@
 // for most LEDs.
 #define LED_PIN_GREEN 16
 #define LED_PIN_RED 17
-#define LED_PIN_YELLOW 5  // or 21
+#define DEBUG_LED2 21

 // Pins for the relay based touch probes, collide with LEDs above
 #define TOUCH_PIN_A 16
@@ -155,7 +156,7 @@
 void setup() {
   pinMode(LED_PIN_RED, OUTPUT);
   pinMode(LED_PIN_GREEN, OUTPUT);
-  pinMode(LED_PIN_YELLOW, OUTPUT);
+  pinMode(DEBUG_LED2, OUTPUT);
   pinMode(LED_PIN_INT, OUTPUT);

   pinMode(TOUCH_PIN_A, OUTPUT);
@@ -176,6 +177,25 @@
   init_vars();
 }

+
+void run_brightness_curve() {
+  int i;
+  long t;
+  short v;
+  digitalWrite(DEBUG_LED2, HIGH);
+  for (i = 0; i < 1000; i++) {
+    v = analogRead(PD_SCREEN_PIN);
+    t = time_us;
+    Serial.print(t);
+    Serial.print(" ");
+    Serial.println(v);
+    delayMicroseconds(450);
+  }
+  digitalWrite(DEBUG_LED2, LOW);
+  Serial.send_now();
+  Serial.println("end");
+  Serial.send_now();
+}

 void process_command(char cmd) {
   int i;
@@ -284,6 +304,10 @@
     } else if (cmd == CMD_SEND_LAST_LASER) {
       send_trigger(laser);
       laser.count = 0;
+    } else if (cmd == CMD_BRIGHTNESS_CURVE) {
+      send_ack(CMD_BRIGHTNESS_CURVE);
+      // This blocks all other execution for about 1 second
+      run_brightness_curve();
     } else {
       Serial.print("Unknown command:");
       Serial.println(cmd);


Update ArduCAM_Mini_Video2SD.ino

Update ArduCAM_Mini_Video2SD.ino

--- ArduCAM/examples/mini/ArduCAM_Mini_Video2SD/ArduCAM_Mini_Video2SD.ino
+++ ArduCAM/examples/mini/ArduCAM_Mini_Video2SD/ArduCAM_Mini_Video2SD.ino
@@ -443,9 +443,10 @@
   myCAM.OV5642_set_JPEG_size(OV5642_320x240);
 #endif

+
+
+  Video2SD();
   delay(30000);
-
-  Video2SD();
 }

 void loop() {


Added an initial threshold for temperature and light resistance to the Galileo Demonstrator

--- code/demonstration/Arduino/Umgebungskachel/Umgebungskachel.ino
+++ code/demonstration/Arduino/Umgebungskachel/Umgebungskachel.ino
@@ -61,6 +61,10 @@
  server.begin();
  showDisplay("Server is at:",getLocalIP());
  lcd.setRGB(150,255,0);
+
+ //initial values for the thresholds
+ sens.data.threshold_brightness = 15;
+ sens.data.threshold_temperature = 29;

  //setup an interrupt for a touch event
  attachInterrupt(2, touchEvent, CHANGE);


Move to 2.0.0 to reflect change in Homie version

--- src/homie-sonoff-touch.ino
+++ src/homie-sonoff-touch.ino
@@ -2,7 +2,7 @@
 #include <Homie.h>

 #define FW_NAME "homie-sonoff-touch"
-#define FW_VERSION "1.0.1"
+#define FW_VERSION "2.0.0"

 /* Magic sequence for Autodetectable Binary Upload */
 const char *__FLAGGED_FW_NAME = "\xbf\x84\xe4\x13\x54" FW_NAME "\x93\x44\x6b\xa7\x75";


corrected lib/file names in SxXbee2.ino

corrected lib/file names in SxXbee2.ino

--- examples/SxXBee2/SxXBee2.ino
+++ examples/SxXBee2/SxXBee2.ino
@@ -4,7 +4,7 @@
  *  Created on: 28.08.2015
  *  Changed on: 30.08.2015
  *  Changed on: 04.09.2015   broadcast of power state
- *
+ *  Changed on: 26.09.2015   new wording: SX22b class
  *  Author and Copyright: Michael Blank
  *
  *  reads date from xbee and sends them to SX Bus
@@ -18,14 +18,14 @@
  */

-#include <SX22.h>   // this is the Selectrix library
+#include <SX22b.h>   // this is the Selectrix library
 #include <SX22Command.h>   // this is the Selectrix Command library
 #include <XBee.h> // XBee library by Andrew Rapp

 #define LED  13   // LED indicator at pin 13

-SX sx;                // selectrix library
-SXCommand sxcmd;      // holds command data
+SX22b sx;                // selectrix library
+SX22Command sxcmd;      // holds command data

 static int ledState = LOW;
 static byte oldSx[MAX_CHANNEL_NUMBER];


Added pwm limit to rover

Added pwm limit to rover

--- firmware/arduino/arduRover.ino
+++ firmware/arduino/arduRover.ino
@@ -76,6 +76,8 @@
       m_pwm = PWM_MID + d * ((float)(m_pwmH - m_pwmM) * m_dir);
     else
       m_pwm = PWM_MID + d * ((float)(m_pwmM - m_pwmL) * m_dir);
+
+    m_pwm = constrain(m_pwm, 1400, 1600);

     m_servo.writeMicroseconds(m_pwm);
   }