temp update

temp update

--- _09_ir_tx_rx/_09_ir_tx_rx.ino
+++ _09_ir_tx_rx/_09_ir_tx_rx.ino
@@ -97,6 +97,10 @@
 unsigned long tv_onoff = 0x20DF10EF;

+//
+int r   = 0;
+int o_r = 0;
+
 // PIR
 volatile int pirOnOff = LOW;
 int o_pirOnOff        = LOW;
@@ -191,8 +195,7 @@
   lcd.backlight();
   lcd.clear();

-  // when connected to usb of TV...
-  delay(10000);
+  delay(5000);

   // Timer start
   temp_Mills = millis();
@@ -205,16 +208,18 @@
   pinMode(WRK_MODE_IN_PIN, INPUT);
   // SETUP_IN_PIN and WRK_MODE_IN_PIN is analog pin, to pull-up
   digitalWrite(SETUP_IN_PIN, HIGH);
-  digitalWrite(WRK_MODE_IN_PIN, HIGH);
-
-  pinMode(PIR_IN_PIN, INPUT_PULLUP);
+  digitalWrite(WRK_MODE_IN_PIN, HIGH);
+
+  pinMode(PIR_IN_PIN, INPUT);

   // buzzer
   pinMode(BZ_OU_PIN, OUTPUT);
   digitalWrite(BZ_OU_PIN, HIGH);

-
   delay(300);
+
+  // PIR
+  attachInterrupt(0, PIRCHECKING, CHANGE);

   // read pin status
   setUpStatus   = digitalRead(SETUP_IN_PIN);
@@ -266,25 +271,25 @@
       lcd.write(3);
     }

-      // if powered by TV
-      if ( o_pwrSrc == 1 ) {
-
-        // input change
-        o_offMode = 0;
-        tvPowerStatus = 1;
-        timerStatus = 1;
-
-        tvOnTimer();
-
-        lcd.setCursor(4, 1);
-        lcd.write(4);
-
-        lcd.setCursor(6, 1);
-        lcd.write(5);
-
-      } else {
-        timerStatus = 0 ;
-      }
+    // if powered by TV
+    if ( o_pwrSrc == 1 ) {
+
+      // input change
+      o_offMode = 0;
+      tvPowerStatus = 1;
+      timerStatus = 1;
+
+      tvOnTimer();
+
+      lcd.setCursor(4, 1);
+      lcd.write(4);
+
+      lcd.setCursor(6, 1);
+      lcd.write(5);
+
+    } else {
+      timerStatus = 0 ;
+    }
   }

   // event Timer
@@ -293,9 +298,6 @@
   /*
   int updateTempCArrayEvent = t.every(300000, doUpdateTempCArray);
   */
-
-  // PIR
-  attachInterrupt(0, PIRCHECKING, CHANGE);

 }

@@ -304,17 +306,16 @@
 {
   // receiving ir and change status
   // remote on / off, tv remote on / off
-  decode_results results;
+  decode_results results;

   t.update();

   // PIR
   if ( pirOnOff != o_pirOnOff) {
-    Serial.println("PIR rising called");
     if ( pirOnOff == 1 ) {
-      doTvControlbyPir("off");
+      doTvControlbyPir(0);
     } else {
-      doTvControlbyPir("on");
+      doTvControlbyPir(1);
     }
     o_pirOnOff = pirOnOff;
   }
@@ -332,7 +333,7 @@
   }
 }

-oid changelcdicon()
+void changelcdicon()
 {

   if ( o_wrkMode == 1 && o_startMode == 1 ) {
@@ -381,7 +382,7 @@
         break;
       case 0x20DF10EF: // tv remore on/off
         tvPowerStatus = ! tvPowerStatus;
-        r = !r;
+        r = !r;
         break;
     }
   }
@@ -390,145 +391,154 @@
 void PIRCHECKING()
 {
   pirOnOff = digitalRead(PIR_IN_PIN);
-}
-
-
-void tvOnTimer()
-{
-    t.stop(tvIsOffEvent);
-    tvIsOnEvent = t.every(3000000, doTvOnOffbyTimer("off"));
+  Serial.println("PIR rising called");
+}
+
+
+void tvOnTimer()
+{
+  t.stop(tvIsOffEvent);
+  tvIsOnEvent = t.every(3000000, doTvOffTimer);
 }

 void tvOffTimer()
 {
-    t.stop(tvIsOnEvent);
-    tvIsOffEvent = t.every(600000, doTvOnOffbyTimer("on"));
-}
-
-void doTvOnOffbyTimer(String onoff)
+  t.stop(tvIsOnEvent);
+  tvIsOffEvent = t.every(600000, doTvOnTimer);
+}
+
+void doTvOffTimer()
+{
+  irSendTv(0);
+  tvOffTimer();
+  lcd.setCursor(15, 0);
+  lcd.write(6);
+}
+
+void doTvOnTimer()
+{
+  irSendTv(1);
+  tvOnTimer();
+  lcd.setCursor(15, 0);
+  lcd.print(" ");
+}
+
+
+
+void doTvControlbyPir(int onoff)
 {
   switch (onoff) {
-    case on:
-      irSendTv("on");
-      tvOnTimer();
+    case 1:
       lcd.setCursor(15, 0);
-      lcd.print(" ");
+      lcd.print(" ");
+      irSendTv(1);
       break;
-    case off:
-      irSendTv("off");
-      tvOffTimer();
+    case 0:
       lcd.setCursor(15, 0);
-      lcd.write(6);
+      lcd.write(6);
+      irSendTv(0);
       break;
   }
-}
-
-void doTvControlbyPir(String onoff)
-{
-  switch (onoff) {
-    case on:
-      irSendTv("on");
-      break;
-    case off:
-      irSendTv("off");
-      break;
-  }
-}
-
-void irSendTv(String onoff)
-{
-  if ( wrkMode == 1 && startMode == 1 )
+  r = !r;
+}
+
+void irSendTv(int onoff)
+{
+  if ( o_wrkMode == 1 && o_startMode == 1 )
   {
-    if ( offMode == 1 )
+    if ( o_offMode == 1 )
     {
-        switch (onoff) {
-          case on:
-            if ( tvPowerStatus == 0 )
-            {
-                  irsend.sendNEC(tv_onoff, 32);
-                  tvPowerStatus = 1;
-                  temp_Mills = millis();
-                  delay(300);
-                  irrecv.enableIRIn();
+      switch (onoff) {
+        case 1:
+          if ( tvPowerStatus == 0 )
+          {
+            irsend.sendNEC(tv_onoff, 32);
+            tvPowerStatus = 1;
+            temp_Mills = millis();
+            delay(300);
+            irrecv.enableIRIn();
+          }
+          break;
+        case 0:
+          if ( tvPowerStatus == 1 )
+          {
+            irsend.sendNEC(tv_onoff, 32);
+            tvPowerStatus = 0;
+            temp_Mills = millis();
+            delay(300);
+            irrecv.enableIRIn();
+          }
+          break;
+        default:
+          return;
+          break;
+      }
+    } else {
+      switch (onoff) {
+        case 1:
+          if ( tvPowerStatus == 0 )
+          {
+            irsend.sendNEC(tv_input, 32);
+            delay(3000);
+            for ( int i = 0 ; i < o_channelGap ; i++ ) {
+              irsend.sendNEC(tv_left, 32);
+              delay(300);
             }
-            break;
-          case off:
-            if ( tvPowerStatus == 1 )
-            {
-                  irsend.sendNEC(tv_onoff, 32);
-                  tvPowerStatus = 0;
-                  temp_Mills = millis();
-                  delay(300);
-                  irrecv.enableIRIn();
-            }
-            break;
-          default:
-            return;
-            break;
-        }
-    } else {
-        switch (onoff) {
-          case on:
-            if ( tvPowerStatus == 0 )
-            {
-                  irsend.sendNEC(tv_input, 32);
-                  delay(3000);
-                  for ( int i = 0 ; i < o_channelGap ; i++ ) {
-                    irsend.sendNEC(tv_left, 32);
-                    delay(300);
-                  }
-                  irsend.sendNEC(tv_enter, 32);
-                  tvPowerStatus = 1;
-                  delay(300);
-                  irrecv.enableIRIn();
+            irsend.sendNEC(tv_enter, 32);
+            tvPowerStatus = 1;
+            delay(300);
+            irrecv.enableIRIn();
+          }
+          break;
+        case 0:
+          if ( tvPowerStatus == 1 )
+          {
+            irsend.sendNEC(tv_input, 32);
+            delay(3000);
+            for ( int i = 0 ; i < o_channelGap ; i++ ) {
+              irsend.sendNEC(tv_right, 32);
+              delay(300);
             }
-            break;
-          case off:
-            if ( tvPowerStatus == 1 )
-            {
-                  irsend.sendNEC(tv_input, 32);
-                  delay(3000);
-                  for ( int i = 0 ; i < o_channelGap ; i++ ) {
-                    irsend.sendNEC(tv_right, 32);
-                    delay(300);
-                  }
-                  irsend.sendNEC(tv_enter, 32);
-                  tvPowerStatus = 0;
-                  delay(300);
-                  irrecv.enableIRIn();
-            }
-            break;
-          default:
-            return;
-            break;
-        }
-
+            irsend.sendNEC(tv_enter, 32);
+            tvPowerStatus = 0;
+            delay(300);
+            irrecv.enableIRIn();
+          }
+          break;
+        default:
+          return;
+          break;
+      }
     }
   } else {
-
+
     return;
-
-  }
-
+
+  }
+
 }

 // TimeTime
 void displaytimeleft() {
-
+  float timeleft;
   if ( tvPowerStatus == 1) {
-    float timeleft = o_tvOnTime - ((millis() - temp_Mills) / 1000 / 60) ;
+    timeleft = o_tvOnTime - ((millis() - temp_Mills) / 1000 / 60) ;
   } else {
-    float timeleft = o_tvOffTime - ((millis() - temp_Mills) / 1000 / 60) ;
+    timeleft = o_tvOffTime - ((millis() - temp_Mills) / 1000 / 60) ;
   }

   String str_a = String(int(timeleft));
   int length_a = str_a.length();

   lcd.setCursor(10, 1);
-  for ( int i = 0; i < ( 3 - length_a ) ; i++ ) {
-    lcd.print(" ");
-  }
-  lcd.print(str_a);
+  if ( timerStatus == 1 &&  o_wrkMode == 1 && o_startMode == 1 ) {
+    for ( int i = 0; i < ( 3 - length_a ) ; i++ ) {
+      lcd.print(" ");
+    }
+    lcd.print(str_a);
+  } else {
+    lcd.print("   ");
+  }

 }

@@ -537,16 +547,15 @@
 {
   tempCinside = getdalastemp();
   displayTemperature(tempCinside);
-  if ( timerStatus == 1) {
-    displaytimeleft();
-  }
+  displaytimeleft();
+  Serial.println(digitalRead(PIR_IN_PIN));
 }

 // update every 5 mins
 void doUpdateTempCArray()
 {
   for ( int i = 0 ; i < 11 ; i++ ) {
-    tempCprevious[i] = tempCprevious[i+1];
+    tempCprevious[i] = tempCprevious[i + 1];
   }
   tempCprevious[11] = tempCinside;
 }
@@ -563,7 +572,7 @@

   lcd.print(Temperature, 1);

-  if ( tempCprevious[0] != 100 ){
+  if ( tempCprevious[0] != 100 ) {
     float tempdiff = tempCinside - tempCprevious[0];

     lcd.setCursor(8, 0);
@@ -580,7 +589,7 @@
     lcd.print(abs(tempdiff), 1);
     if ( length_tempdiff == 1) {
       lcd.print(" ");
-    }
+    }
   }
 }


Arduino RFID code - currently in progress - Get works only once

--- Delegated/Delegated.ino
+++ Delegated/Delegated.ino
@@ -49,42 +49,82 @@

 }

-void loop()
-{
+void loop() {
+  // put your main code here, to run repeatedly:
   // Receive data from com port
   while (Serial.available() > 0) {
     int inChar = Serial.read();
-    if (isDigit(inChar)) {
-      // Получаем 1 символ,
-      // Прибавляем его к строке
+
+    if (inChar != '\n') {
       inString += (char)inChar;
-    }
-
-    // Доходим до новой строки
-    if (inChar == '\n') {
-      //Serial.println(inString);
-      // inString = "Action@Arg1:Arg2..."
-      String Action = inString.substring(1,3);
-      Serial.println(Action);
-      //byte Action[3],Args[1];
-      //String Arguments = "";
-      //int n = sscanf(inString.c_str(), "%s@%s", Action,Args);
-      if (Action =="Set") {
-        Serial.println("0");
-      } else if (Action =="Get") {
-        Serial.println("1");
+    } else {
+      // New line
+      String Action = inString.substring(0, 3);
+      if (Action == "Set") {
+        SetCard(inString);
+      } else if (Action == "Get") {
+        Serial.println("GetStart");
+        while (!initcard());
+
+        readBlockToCom(2);
+        Serial.println("GetDone");
       } else {
         Serial.println(Action);
       }
       inString = "";
     }
-    /*while (!initcard());
+  }
+}
+
+void SetCard(String Data) {
+  Serial.println(Data);
+  // Data Set@user1@user2@pass1@pass2
+  // Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
+  byte user1[16], user2[16], pass1[16], pass2[16];
+
+  String user1str = inString.substring(4, 20);
+  String user2str = inString.substring(21, 37);
+  String pass1str = inString.substring(38, 54);
+  String pass2str = inString.substring(55, 71);
+
+  Serial.println("Arrays");
+
+  stringToArray(user1str, user1, sizeof(user1));
+  stringToArray(user2str, user2, sizeof(user2));
+  stringToArray(pass1str, pass1, sizeof(pass1));
+  stringToArray(pass2str, pass2, sizeof(pass2));
+
+  writeByteArray(user1, 16);
+  writeByteArray(user2, 16);
+  writeByteArray(pass1, 16);
+  writeByteArray(pass2, 16);
+
+  while (!initcard());

-    writeBlock(block, blockcontent);//the blockcontent array is written into the card block
-    readBlockToCom(2);*/
+  //writeBlock(block, blockcontent);//the blockcontent array is written into the card block
+  //readBlockToCom(2);
+
+}
+
+void stringToArray(String str, byte array[], int arrlength)
+{
+  for (int j = 0 ; j < arrlength ; j++)
+  {
+    array[j] =  str.charAt(j);
   }
 }
+
+void writeByteArray(byte array[], int arrlength)
+{
+  for (int j = 0 ; j < arrlength ; j++) //print the block contents
+  {
+    Serial.write (array[j]);//Serial.write() transmits the ASCII numbers as human readable characters to serial monitor
+  }
+  Serial.println("");
+}
+
+

 bool initcard()
 {


Fixed processing code for Processing 3

Fixed processing code for Processing 3

As pointed out in #4214 I changed the processing code to make it working wit Processing 3

--- build/shared/examples/04.Communication/Graph/Graph.ino
+++ build/shared/examples/04.Communication/Graph/Graph.ino
@@ -44,71 +44,71 @@
  // Graphing sketch

- // This program takes ASCII-encoded strings
- // from the serial port at 9600 baud and graphs them. It expects values in the
- // range 0 to 1023, followed by a newline, or newline and carriage return
+// This program takes ASCII-encoded strings
+// from the serial port at 9600 baud and graphs them. It expects values in the
+// range 0 to 1023, followed by a newline, or newline and carriage return

- // Created 20 Apr 2005
- // Updated 18 Jan 2008
- // by Tom Igoe
- // This example code is in the public domain.
+// Created 20 Apr 2005
+// Updated 24 Nov 2015
+// by Tom Igoe
+// This example code is in the public domain.

- import processing.serial.*;
+import processing.serial.*;

- Serial myPort;        // The serial port
- int xPos = 1;         // horizontal position of the graph
+Serial myPort;        // The serial port
+int xPos = 1;         // horizontal position of the graph
+float inByte = 0;

- void setup () {
- // set the window size:
- size(400, 300);
+void setup () {
+  // set the window size:
+  size(400, 300);

- // List all the available serial ports
- // if using Processing 2.1 or later, use Serial.printArray()
- println(Serial.list());
+  // List all the available serial ports
+  // if using Processing 2.1 or later, use Serial.printArray()
+  println(Serial.list());

- // I know that the first port in the serial list on my mac
- // is always my  Arduino, so I open Serial.list()[0].
- // Open whatever port is the one you're using.
- myPort = new Serial(this, Serial.list()[0], 9600);
+  // I know that the first port in the serial list on my mac
+  // is always my  Arduino, so I open Serial.list()[0].
+  // Open whatever port is the one you're using.
+  myPort = new Serial(this, Serial.list()[0], 9600);

- // don't generate a serialEvent() unless you get a newline character:
- myPort.bufferUntil('\n');
+  // don't generate a serialEvent() unless you get a newline character:
+  myPort.bufferUntil('\n');

- // set inital background:
- background(0);
- }
- void draw () {
- // everything happens in the serialEvent()
- }
+  // set inital background:
+  background(0);
+}
+void draw () {
+  // draw the line:
+  stroke(127, 34, 255);
+  line(xPos, height, xPos, height - inByte);

- void serialEvent (Serial myPort) {
- // get the ASCII string:
- String inString = myPort.readStringUntil('\n');
+  // at the edge of the screen, go back to the beginning:
+  if (xPos >= width) {
+    xPos = 0;
+    background(0);
+  } else {
+    // increment the horizontal position:
+    xPos++;
+  }
+}

- if (inString != null) {
- // trim off any whitespace:
- inString = trim(inString);
- // convert to an int and map to the screen height:
- float inByte = float(inString);
- inByte = map(inByte, 0, 1023, 0, height);

- // draw the line:
- stroke(127,34,255);
- line(xPos, height, xPos, height - inByte);
+void serialEvent (Serial myPort) {
+  // get the ASCII string:
+  String inString = myPort.readStringUntil('\n');

- // at the edge of the screen, go back to the beginning:
- if (xPos >= width) {
- xPos = 0;
- background(0);
- }
- else {
- // increment the horizontal position:
- xPos++;
- }
- }
- }
+  if (inString != null) {
+    // trim off any whitespace:
+    inString = trim(inString);
+    // convert to an int and map to the screen height:
+    inByte = float(inString);
+    println(inByte);
+    inByte = map(inByte, 0, 1023, 0, height);
+  }
+}

- */
+*/

 /* Max/MSP v5 patch for this example
  ----------begin_max5_patcher----------


Add additional agenda items. Add typedef for UIStringType. Replace hard-coded row numbers in loop() with UIStringType enumerations. Test  on functors and see it have no impact.

--- dremelfuge.ino
+++ dremelfuge.ino
@@ -23,6 +23,10 @@
   variables and functions, as if all globals were declared `static` (see large
   comment in loop() for details on `static`)
   */
+
+// 1) Mode structs in PROGMEM, Mode::id in PROGMEM
+// 2) constexpr function and named variables for timeIndex and speedIndex, to be put
+// in printfval

 namespace
 {
@@ -260,6 +264,8 @@
   // Functor that encapsulates (hides the implementation of) changing UI ONCE
   // per the current mode's own UIStringPtrs; extension of LiquidCrystal:

+  typedef Mode::UIStringType line;
+
   struct UIChanger {

     private:
@@ -289,12 +295,12 @@
         // Partial overwrite due to overwriteStrs that do not span the entire row

         // "Set time:" => "Finished in:"
-        lcdPtr->setCursor(0, Mode::UIStringType::Time);
-        lcdPtr->print( (PGM_P) pgm_read_word(&(currentModePtr->UIStringPtrs[Mode::UIStringType::Time])));
+        lcdPtr->setCursor(0, line::Time);
+        lcdPtr->print( (PGM_P) pgm_read_word(&(currentModePtr->UIStringPtrs[line::Time])));

         // "Push to Start!" => "Push to Stop!"
-        lcdPtr->setCursor(0, Mode::UIStringType::Instruction);
-        lcdPtr->print( (PGM_P) pgm_read_word(&(currentModePtr->UIStringPtrs[Mode::UIStringType::Instruction])));
+        lcdPtr->setCursor(0, line::Instruction);
+        lcdPtr->print( (PGM_P) pgm_read_word(&(currentModePtr->UIStringPtrs[line::Instruction])));

         initialized = true;

@@ -377,13 +383,15 @@
       setDuration = map(analogRead(POT_PIN), 0, 1024, 0, 901);

       // Add selector braces: "Set time: <15:00>"
-      lcdPrinter.formatValue(setDuration, fsecs, ValueDecor::SELECTING, 10, 1);
+      lcdPrinter.formatValue(setDuration, fsecs, ValueDecor::SELECTING,
+                             10, line::Time);

       if(wpb.pressed())
       {

         // Erase "<>" selector braces
-        lcdPrinter.formatValue(setDuration, fsecs, ValueDecor::DESELECTING, 10, 1);
+        lcdPrinter.formatValue(setDuration, fsecs, ValueDecor::DESELECTING,
+                               10, line::Time);

         // Convert mapped time to calculatable millis after printing from seconds
         setDuration *= 1000;
@@ -406,7 +414,8 @@
       motorSpeed = map(analogRead(POT_PIN), 0, 1024, 0, 255);

       // Add selector braces: "Set speed: <255>"
-      lcdPrinter.formatValue(motorSpeed, raw, ValueDecor::SELECTING, 11, 2);
+      lcdPrinter.formatValue(motorSpeed, raw, ValueDecor::SELECTING,
+                             11, line::Speed);
       // Map printing of motorSpeed to rpm range?!

       if(wpb.pressed()) {
@@ -415,7 +424,8 @@
         // updated in becomes unreachable

         // Erase "<>" selector braces
-        lcdPrinter.formatValue(motorSpeed, raw, ValueDecor::DESELECTING, 11, 2);
+        lcdPrinter.formatValue(motorSpeed, raw, ValueDecor::DESELECTING,
+                               11, line::Speed);

         // Change the mode for next loop() call
         currentModePtr = &spinningMode;
@@ -441,7 +451,7 @@
       (setDuration - (millis() - spinningStartTime))/1000;

       // Print countdown (no special functions needed)
-      lcd.setCursor(13, 1);
+      lcd.setCursor(13, line::Time);
       lcd.print(timeLeft);

       if(wpb.pressed() || timeLeft == 0) {


use new rf12_sendNow call in DIJN example

--- examples/DIJN/test1/test1.ino
+++ examples/DIJN/test1/test1.ino
@@ -21,11 +21,8 @@
 void loop () {
   led(true);

-  // standard idiom for waiting until we can send a new packet
-  while (!rf12_canSend())
-    rf12_recvDone();
   // actual packet send: broadcast to all, current counter, 1 byte long
-  rf12_sendStart(0, &counter, 1);
+  rf12_sendNow(0, &value, 1);;
   rf12_sendWait(1);

   led(false);


fix KISS example

fix KISS example

--- examples/KISS/KISS.ino
+++ examples/KISS/KISS.ino
@@ -11,12 +11,14 @@

 #include <HamShield.h>
 #include <KISS.h>
+#include <DDS.h>
 #include <packet.h>
+#include <avr/wdt.h>

 HamShield radio;
 DDS dds;
-KISS kiss(&Serial, &radio, &dds);
 AFSK afsk;
+KISS kiss(&Serial, &radio, &dds, &afsk);

 #define PWM_PIN 3
 #define RESET_PIN A3
@@ -32,27 +34,44 @@

   // set up the reset control pin
   pinMode(RESET_PIN, OUTPUT);
-  digitalWrite(RESET_PIN, LOW);
+  digitalWrite(RESET_PIN, HIGH);

   Serial.begin(9600);

-  while (digitalRead(SWITCH_PIN));
-
-  // let the AU ot of reset
-  digitalWrite(RESET_PIN, HIGH);
-
   radio.initialize();
-  radio.setSQOff();
+  //radio.setSQOff();
+  radio.setVolume1(0xFF);
+  radio.setVolume2(0xFF);
+  radio.setSQHiThresh(-100);
+  radio.setSQLoThresh(-100);
+  radio.setSQOn();
   radio.frequency(144390);

   dds.start();
   afsk.start(&dds);
+  delay(100);
+  radio.setModeReceive();
 }

 void loop() {
   kiss.loop();
 }

+ISR(TIMER2_OVF_vect) {
+  TIFR2 = _BV(TOV2);
+  static uint8_t tcnt = 0;
+  if(++tcnt == 8) {
+    dds.clockTick();
+    tcnt = 0;
+  }
+}
+
 ISR(ADC_vect) {
-  kiss.isr();
-}
+  static uint8_t tcnt = 0;
+  TIFR1 = _BV(ICF1); // Clear the timer flag
+  dds.clockTick();
+  if(++tcnt == 1) {
+    afsk.timer();
+    tcnt = 0;
+  }
+}


Fix color parsing from response

Fix color parsing from response

--- esp8266/cheerlights.ino
+++ esp8266/cheerlights.ino
@@ -290,23 +290,25 @@
  * aproximates target color.
 */
 void updateColor() {
-  int redDiff, greenDiff, blueDiff;
-  if (config.smoothUpdate) {
-    redDiff = constrain (reqPixelColor.red - actPixelColor.red, -1, 1);
-    greenDiff = constrain (reqPixelColor.green - actPixelColor.green, -1, 1);
-    blueDiff = constrain (reqPixelColor.blue - actPixelColor.blue, -1, 1);
-  } else {
-    redDiff = reqPixelColor.red - actPixelColor.red;
-    greenDiff = reqPixelColor.green - actPixelColor.green;
-    blueDiff = reqPixelColor.blue - actPixelColor.blue;
-  }
+  int redDiff = 1, greenDiff = 1, blueDiff = 1;
+  while ((redDiff != 0) || (greenDiff != 0) || (blueDiff != 0)) {
+    if (config.smoothUpdate) {
+      redDiff = constrain (reqPixelColor.red - actPixelColor.red, -1, 1);
+      greenDiff = constrain (reqPixelColor.green - actPixelColor.green, -1, 1);
+      blueDiff = constrain (reqPixelColor.blue - actPixelColor.blue, -1, 1);
+    } else {
+      redDiff = reqPixelColor.red - actPixelColor.red;
+      greenDiff = reqPixelColor.green - actPixelColor.green;
+      blueDiff = reqPixelColor.blue - actPixelColor.blue;
+    }

-  if ((redDiff != 0) || (greenDiff != 0) || (blueDiff != 0)) {
     actPixelColor.red += redDiff;
     actPixelColor.green += greenDiff;
     actPixelColor.blue += blueDiff;

     setColor();
+
+    delay(10);
   }
 }

@@ -381,7 +383,9 @@
           while (!isError) {
             String resp = client.readStringUntil ('\n');

-            if ((resp[0] == '#') && (resp.length() == 8)) {
+            Serial.print (resp.length()); Serial.print (F(" > ")); Serial.println (resp);
+
+            if ((resp.length() == 7) && (resp[0] == '#')) {
               unsigned long color = strtoul (resp.c_str() + 1, NULL, 16);

               Serial.print ("Readed color: ");
@@ -403,6 +407,8 @@
               errorCount++;
               isError = true;
             }
+
+            yield();
           }

           // Disconnect client


Cleanup

Cleanup

--- examples/ArtnetOctoWS2811/ArtnetOctoWS2811.ino
+++ examples/ArtnetOctoWS2811/ArtnetOctoWS2811.ino
@@ -13,6 +13,8 @@
 // OctoWS2811 settings
 const int ledsPerStrip = 240; // change for your setup
 const byte numStrips= 2; // change for your setup
+const int numLeds = ledsPerStrip * numStrips;
+const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
 DMAMEM int displayMemory[ledsPerStrip*6];
 int drawingMemory[ledsPerStrip*6];
 const int config = WS2811_GRB | WS2811_800kHz;
@@ -21,8 +23,6 @@
 // Artnet settings
 Artnet artnet;
 const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
-const int numLeds = ledsPerStrip * numStrips;
-const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)

 // Check if we got all universes
 const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
@@ -87,19 +87,19 @@

 void initTest()
 {
-  for (int i = 0 ; i < ledsPerStrip * numStrips ; i++)
+  for (int i = 0 ; i < numLeds ; i++)
     leds.setPixel(i, 127, 0, 0);
   leds.show();
   delay(500);
-  for (int i = 0 ; i < ledsPerStrip * numStrips  ; i++)
+  for (int i = 0 ; i < numLeds  ; i++)
     leds.setPixel(i, 0, 127, 0);
   leds.show();
   delay(500);
-  for (int i = 0 ; i < ledsPerStrip * numStrips  ; i++)
+  for (int i = 0 ; i < numLeds  ; i++)
     leds.setPixel(i, 0, 0, 127);
   leds.show();
   delay(500);
-  for (int i = 0 ; i < ledsPerStrip * numStrips  ; i++)
+  for (int i = 0 ; i < numLeds  ; i++)
     leds.setPixel(i, 0, 0, 0);
   leds.show();
-}+}


improve comments

improve comments

--- examples/JetExample.ino
+++ examples/JetExample.ino
@@ -26,13 +26,16 @@
 uint32_t ip;

 Adafruit_CC3000_Client client;
+
+/* jet global vars: peer and states/methods */
 JetPeer peer;
 JetState* ledState;
 JetState* analog1State;
 JetState* analog2State;

-#define JET_DAEMON  "192.168.1.149"
+#define JET_DAEMON  "YOUR_IP"

+/* a jet state callback function example */
 bool set_led(aJsonObject* led_val, void* context)
 {
   if (led_val->valuebool) {
@@ -44,6 +47,11 @@
   }
   return true;
 }
+
+/* a jet fetch callback function example */
+void print_analog_1(const char* path, const char* event, aJsonObject* val, void* context) {
+  Serial.print(path);Serial.print(F(" "));Serial.print(event);Serial.print(F(" "));Serial.println(val->valueint);
+}
 /**************************************************************************/
 /*!
     @brief  Sets up the HW and the CC3000 module (called automatically
@@ -53,28 +61,19 @@
 void setup(void)
 {
   Serial.begin(115200);
-  Serial.println(F("Hello, CC3000!\n"));
+  Serial.println(F("Hello, Jet Folks!\n"));
   if (!cc3000.begin())
   {
     Serial.println(F("Unable to initialise the CC3000!"));
     while(1);
   }

+  Serial.println(F("creating network connection to daemon...\n"));
+
   /* Attempt to connect to an access point */
   char *ssid = WLAN_SSID;             /* Max 32 chars */
   Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid);

-  /* NOTE: Secure connections are not available in 'Tiny' mode!
-     By default connectToAP will retry indefinitely, however you can pass an
-     optional maximum number of retries (greater than zero) as the fourth parameter.
-
-     ALSO NOTE: By default connectToAP will retry forever until it can connect to
-     the access point.  This means if the access point doesn't exist the call
-     will _never_ return!  You can however put in an optional maximum retry count
-     by passing a 4th parameter to the connectToAP function below.  This should
-     be a number of retries to make before giving up, for example 5 would retry
-     5 times and then fail if a connection couldn't be made.
-  */
   if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
     Serial.println(F("Failed!"));
     while(1);
@@ -102,20 +101,31 @@
     Serial.println("not connected");
   }

+  /* tell the peer which is the network client */
   peer.init(client);

-  ledState = peer.state("ARDU/led", aJson.createItem((bool)true));
-  ledState->set_handler(set_led);
+  /* create a state with a "set" callback function (set_led).
+    the initial value is "true".
+    */
+  ledState = peer.state("ARDU/led", aJson.createItem((bool)true), set_led);

+  /* create two states for the analog inputs. no "set" callback function is
+    provided, so this is read-only.
+    in the loop function (every 100ms) new values a read out and are posted.
+   */
   analog1State = peer.state("ARDU/analog1", aJson.createItem(analogRead(0)));
   analog2State = peer.state("ARDU/analog2", aJson.createItem(analogRead(1)));
-   // initialize digital pin 13 as an output.
-  //pinMode(13, OUTPUT);
+
+  /* create a fetcher which is subsribed to the "own" state ARDU/analog1.
+     every time the value changes, the print_analog_1 function is called.
+     this is not very useful but demonstrates the principle.
+   */
+  peer.fetch("ARDU/analog1", print_analog_1);
+
 }

 long previousMillis = 0;
-long interval = 50;
-
+long interval = 100;

 void loop(void)
 {
@@ -123,7 +133,6 @@
   unsigned long currentMillis = millis();

   if(currentMillis - previousMillis > interval) {
-    // save the last time you blinked the LED
     previousMillis = currentMillis;
     analog1State->value(aJson.createItem(analogRead(0)));
     analog2State->value(aJson.createItem(analogRead(1)));


#85 #83 direction only encoder mode now supported

--- examples/directionOnlyEncoder/directionOnlyEncoder.ino
+++ examples/directionOnlyEncoder/directionOnlyEncoder.ino
@@ -55,7 +55,8 @@
   switches.addSwitch(spinwheelClickPin, onSpinwheelClicked);

   // now we set up the rotary encoder, first we give the A pin and the B pin.
-  // we give the encoder a max value of 128, always minumum of 0.
+  // we only want directional indications so we set the precision to max 0, current 0.
+  // when we do this, the callback either gets 0 no change, -1 down or 1 up.
   setupRotaryEncoderWithInterrupt(encoderAPin, encoderBPin, onEncoderChange);
   switches.changeEncoderPrecision(0, 0);
 }


stuff for james

stuff for james

--- display/display.ino
+++ display/display.ino
@@ -15,6 +15,8 @@
 #define CS_SCREEN  10
 #define DC 9
 #define RST 7
+#define HOMESCREEN 0
+#define ALARMSCREEN 1

 // This is calibration data for the raw touch data to the screen coordinates
 #define TS_MINX 150
@@ -34,6 +36,7 @@
 int biasECGMin = 0;
 int biasSP02Max = 0;
 int biasSP02Min = 0;
+int i = 0;

 Adafruit_ILI9341 tft = Adafruit_ILI9341(CS_SCREEN, DC);
 Adafruit_STMPE610 ts = Adafruit_STMPE610(CS_TOUCH);
@@ -55,10 +58,15 @@
 Button cancel_button = Button(BOXSIZE*3,200,BOXSIZE,BOXSIZE,ILI9341_LIGHTGREY,true,&tft);

 // Create settings page buttons
-Button ECGPlus = Button(30,70,18,18,ILI9341_BLACK,true,&tft);
-Button ECGMinus = Button(100,70,18,18,ILI9341_BLACK,true,&tft);
-Button ECGPlus1 = Button(180,70,18,18,ILI9341_BLACK,true,&tft);
-Button ECGMinus1 = Button(250,70,18,18,ILI9341_BLACK,true,&tft);
+
+/*for ECGMin value*/
+Button ECGPlus = Button(100,70,18,18,ILI9341_BLACK,true,&tft);
+Button ECGMinus = Button(30,70,18,18,ILI9341_BLACK,true,&tft);
+/*for ECGMax value*/
+Button ECGPlus1 = Button(250,70,18,18,ILI9341_BLACK,true,&tft);
+Button ECGMinus1 = Button(180,70,18,18,ILI9341_BLACK,true,&tft);
+
+
 Button SP02Plus = Button(30,120,18,18,ILI9341_WHITE,true,&tft);
 Button SP02Minus = Button(100,120,18,18,ILI9341_WHITE,true,&tft);
 Button SP02Plus1 = Button(180,120,18,18,ILI9341_WHITE,true,&tft);
@@ -218,6 +226,31 @@

 void ECGSettings_setup(void){
   /* MINIMUM VALUE */
+  tft.setCursor(63, 72);
+  tft.setTextSize(2);
+  tft.setTextColor(ILI9341_GREEN);
+  tft.printf("%d", DEFAULT_ECG_MIN);
+
+  createVLabel(0, 55, ecgLabel, 2, ILI9341_GREEN);
+  ECGPlus.draw();
+  ECGMinus.draw();
+  createHLabel(34, 72, "-", 2, ILI9341_WHITE);
+  createHLabel(104, 72, "+", 2, ILI9341_WHITE);
+
+  /* MAXIMUM VALUE */
+  tft.setCursor(213, 72);
+  tft.setTextSize(2);
+  tft.setTextColor(ILI9341_GREEN);
+  tft.printf("%d", DEFAULT_ECG_MAX + biasECGMax);
+
+  ECGPlus1.draw();
+  ECGMinus1.draw();
+  createHLabel(184, 72, "-", 2, ILI9341_WHITE);
+  createHLabel(254, 72, "+", 2, ILI9341_WHITE);
+}
+
+void SP02Settings_setup(void){
+  /* MINIMUM VALUE */
   if (DEFAULT_ECG_MIN + biasECGMin < 100){
     tft.setCursor(63, 72);
     tft.setTextSize(2);
@@ -231,8 +264,8 @@
     tft.printf("%d", DEFAULT_ECG_MIN + biasECGMin);
   }
   createVLabel(0, 55, ecgLabel, 2, ILI9341_GREEN);
-  ECGPlus.draw();
-  ECGMinus.draw();
+  //ECGPlus.draw();
+  //ECGMinus.draw();
   createHLabel(34, 72, "-", 2, ILI9341_WHITE);
   createHLabel(104, 72, "+", 2, ILI9341_WHITE);

@@ -249,47 +282,8 @@
     tft.setTextColor(ILI9341_GREEN);
     tft.printf("%d", DEFAULT_ECG_MAX + biasECGMax);
   }
-  ECGPlus1.draw();
-  ECGMinus1.draw();
-  createHLabel(184, 72, "-", 2, ILI9341_WHITE);
-  createHLabel(254, 72, "+", 2, ILI9341_WHITE);
-}
-
-void SP02Settings_setup(void){
-  /* MINIMUM VALUE */
-  if (DEFAULT_ECG_MIN + biasECGMin < 100){
-    tft.setCursor(63, 72);
-    tft.setTextSize(2);
-    tft.setTextColor(ILI9341_GREEN);
-    tft.printf("%d", DEFAULT_ECG_MIN + biasECGMin);
-  }
-  if (DEFAULT_ECG_MIN + biasECGMin > 99){
-    tft.setCursor(56, 72);
-    tft.setTextSize(2);
-    tft.setTextColor(ILI9341_GREEN);
-    tft.printf("%d", DEFAULT_ECG_MIN + biasECGMin);
-  }
-  createVLabel(0, 55, ecgLabel, 2, ILI9341_GREEN);
-  ECGPlus.draw();
-  ECGMinus.draw();
-  createHLabel(34, 72, "-", 2, ILI9341_WHITE);
-  createHLabel(104, 72, "+", 2, ILI9341_WHITE);
-
-  /* MAXIMUM VALUE */
-  if (DEFAULT_ECG_MAX + biasECGMax < 100){
-    tft.setCursor(213, 72);
-    tft.setTextSize(2);
-    tft.setTextColor(ILI9341_GREEN);
-    tft.printf("%d", DEFAULT_ECG_MAX + biasECGMax);
-  }
-  if (DEFAULT_ECG_MAX + biasECGMax > 99){
-    tft.setCursor(206, 72);
-    tft.setTextSize(2);
-    tft.setTextColor(ILI9341_GREEN);
-    tft.printf("%d", DEFAULT_ECG_MAX + biasECGMax);
-  }
-  ECGPlus1.draw();
-  ECGMinus1.draw();
+  //ECGPlus1.draw();
+  //ECGMinus1.draw();
   createHLabel(184, 72, "-", 2, ILI9341_WHITE);
   createHLabel(254, 72, "+", 2, ILI9341_WHITE);
 }
@@ -343,7 +337,10 @@
 }

 TS_Point getFixedCoordinates(void){
-   TS_Point p = ts.getPoint();
+   p = ts.getPoint();
+   while(!ts.bufferEmpty()){
+       TS_Point throwaway = ts.getPoint();
+   }
    // Scale from 0-4000 to tft.width() using calibration numbers
    p.x = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
@@ -389,20 +386,22 @@
       }
 }
 void isr(void) {
-  if (currentMode == 0 && confirm_button.isTapped(p.x,p.y)){
-        currentMode = 1;
-  }
-  if (currentMode == 1 && alarm_button.isTapped(p.x,p.y)){
-        currentMode = 0;
+  if (currentMode == HOMESCREEN && alarm_button.isTapped(p.x,p.y)){
+    currentMode = ALARMSCREEN;
+  }
+  if (currentMode == ALARMSCREEN){
+    if(confirm_button.isTapped(p.x,p.y)){
+      currentMode = HOMESCREEN;
+    }
   }
 }

 void loop(void) {
   /*main screen*/
-  if (currentMode == 1){
+  if (currentMode == HOMESCREEN){
     MainScreenInit();
-    while (currentMode == 1){
+    while (currentMode == HOMESCREEN){
       dispECGWave();
       // Retrieve the touch point
       p = getFixedCoordinates();
@@ -414,10 +413,58 @@
     }
   }
   /*alarm screen*/
-  if (currentMode == 0){
+  if (currentMode == ALARMSCREEN){
     SettingsScreenInit();
-    while (currentMode == 0){
+    while(currentMode == ALARMSCREEN){
       p = getFixedCoordinates();
+      if(ECGPlus.isTapped(p.x,p.y)){
+        biasECGMin += 1;
+        /*for two digit numbers*/
+        if (DEFAULT_ECG_MIN + biasECGMin < 100){
+          tft.fillRect(56, 72, 45, 20, ILI9341_BLACK);
+          tft.setCursor(63, 72);
+          tft.setTextSize(2);
+          tft.setTextColor(ILI9341_GREEN);
+          tft.printf("%d", DEFAULT_ECG_MIN + biasECGMin);
+            if (ts.bufferEmpty()){
+        p.x = 0;
+        p.y = 0;
+      }
+        }
+        else if (DEFAULT_ECG_MIN + biasECGMin > 99){
+          /*for three digit numbers*/
+          tft.fillRect(56, 72, 45, 20, ILI9341_BLACK);
+          tft.setCursor(56, 72);
+          tft.setTextSize(2);
+          tft.setTextColor(ILI9341_GREEN);
+          tft.printf("%d", DEFAULT_ECG_MIN + biasECGMin);
+            if (ts.bufferEmpty()){
+        p.x = 0;
+        p.y = 0;
+      }
+        }
+      }
+
+      /*if(ECGMinus.isTapped(p.x,p.y)){
+      biasECGMin -= 1;
+      //for two digit numbers
+        if (DEFAULT_ECG_MIN + biasECGMin < 100){
+          tft.setCursor(63, 72);
+          tft.setTextSize(2);
+          tft.setTextColor(ILI9341_GREEN);
+
+          tft.printf("%d", DEFAULT_ECG_MIN + biasECGMin);
+        }
+        if (DEFAULT_ECG_MIN + biasECGMin > 99){
+          //for three digit numbers
+          tft.setCursor(56, 72);
+          tft.setTextSize(2);
+          tft.setTextColor(ILI9341_GREEN);
+          tft.printf("%d", DEFAULT_ECG_MIN + biasECGMin);
+        }
+      }*/
+
+      /*before the isr was implemented*/
       //TS_Point p = ts.getPoint();
       // Scale from 0-4000 to tft.width() using calibration numbers
       //p.x = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());


Don't forget to add the code for an unknown state. Also further stub out the method for retrieving the return codes over serial.

--- RoverMain/RoverMain.ino
+++ RoverMain/RoverMain.ino
@@ -29,6 +29,7 @@
 #define HAPPY 0b1111
 #define CALM 0b1110
 #define FOCUSED 0b1100
+#define UNKNOWN 0b0100

 // limit ourselves to possibly four actions for a given context pair
 #define A0_MASK   0b1111000000000000
@@ -106,9 +107,14 @@
 byte reccodes2ctx() {
 	//we should read in the serial from here
 	//and determine the contexts we have and want to get to
-
+	if (Serial.available() > 0) {
+		int incomingByte = Serial.read();
+		//now that we have the byte corresponding to the current ctx,
+		//determine which ctx we want to trigger
+		return (0 |(0 << 4)); //placeholder statement for the ctx we want to trigger and the ctx we have currently
+	}
 	//example ctxes: happy, sad, angry, fearful, calm, focused, distracted
-	return 0;
+	return (UNKNOWN | (UNKNOWN << 4));
 }

 /*** Pin Layout ***/


added first Adafruit BNO055 code, removed forgotten unneed old code.

--- test/Arduino/MicroView/MicroView.ino
+++ test/Arduino/MicroView/MicroView.ino
@@ -1,22 +1,28 @@
+// MicroView OLED
 #include <MicroView.h>
-#include <Time.h>

-#define clocksize 24
-
-uint16_t 	onDelay=5;		// this is the on delay in milliseconds, if there is no on delay, the erase will be too fast to clean up the screen.
+// Adafruit BNO055
+#include <Wire.h>
+#include <Adafruit_Sensor.h>
+#include <Adafruit_BNO055.h>
+#include <utility/imumaths.h>

-void setup() {
-	uView.begin();		// begin of MicroView
+void setup()
+{
+        // begin of MicroView
+	uView.begin();
 	uView.clear(ALL);	// erase hardware memory inside the OLED controller
 	uView.display();	// display the content in the buffer memory, by default it is the MicroView logo
-	setTime(10,10,01,17,1,2014);
 	delay(700);
 	uView.clear(PAGE);	// erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
+
 }

-void loop() {
+void loop()
+{
+        // MicroView
         // TEXT Font 0
 	uView.clear(PAGE);
 	uView.setCursor(0,40);


/ ‘Touch_Screen/Touch_Screen.ino’

/ ‘Touch_Screen/Touch_Screen.ino’

--- Touch_Screen/Touch_Screen.ino
+++ Touch_Screen/Touch_Screen.ino
@@ -1,6 +1,7 @@
 /* This is my Sketch for the Touch Screen interface for the relay box that will be installed in my Jeep
     Robert L. Wardecker
     cna2rn@gmail.com
+
     This code is in public domain.

 Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.


change some constants names

change some constants names

--- first_one/first_one.ino
+++ first_one/first_one.ino
@@ -32,6 +32,7 @@
 bool HW_DEBUG = true;
 bool SYS_DEBUG = true;

+#define TIME_MULTIPLIER 1
 #define MORSE_UNIT_TIME SLEEP_250MS
 #define NUM_LEDS        9
 #define LDR_PIN         A0
@@ -44,7 +45,6 @@

 unsigned long arTime         = millis();
 unsigned long reset          = millis();
-unsigned int TIME_MULTIPLIER = 1; // x1
 unsigned int WAIT            = 150*TIME_MULTIPLIER;
 unsigned int waitLynch       = 33*TIME_MULTIPLIER;
 unsigned int actualPin       = 2;


Update comments

Update comments

--- XV_Lidar_Controller.ino
+++ XV_Lidar_Controller.ino
@@ -16,17 +16,18 @@

 struct EEPROM_Config {
   byte id;
-  int motor_pwm_pin;
-  double rpm_setpoint;  // desired RPM (double to be compatible with PID library)
-  double pwm_max;
-  double pwm_min;
-
+  int motor_pwm_pin;  // pin connected to mosfet for motor speed control
+  double rpm_setpoint;  // desired RPM (uses double to be compatible with PID library)
+  double pwm_max;  // max analog value.  probably never needs to change from 1023
+  double pwm_min;  // min analog pulse value to spin the motor
+
+  // PID tuning values
   double Kp;
   double Ki;
   double Kd;

-  boolean motor_enable;
-  boolean relay;
+  boolean motor_enable;  // to spin the laser or not.  No data when not spinning
+  boolean relay;  // to retransmit the seiral data to the USB port
 }
 xv_config;

@@ -36,7 +37,7 @@
 double pwm_last;
 double motor_rpm;

-boolean debug_motor_rpm = false;
+boolean debug_motor_rpm = false;  // controlled by ShowRPM and HideRPM commands

 PID rpmPID(&motor_rpm, &pwm_val, &xv_config.rpm_setpoint, xv_config.Kp, xv_config.Ki, xv_config.Kd, DIRECT);

@@ -191,16 +192,16 @@
   sCmd.addCommand("SetKi",   setKi);
   sCmd.addCommand("SetKd",   setKd);

-  sCmd.addCommand("ShowRPM",       showRPM);
-  sCmd.addCommand("HideRPM",       hideRPM);
-  sCmd.addCommand("MotorOff",      motorOff);
-  sCmd.addCommand("MotorOn",       motorOn);
+  sCmd.addCommand("ShowRPM",  showRPM);
+  sCmd.addCommand("HideRPM",  hideRPM);
+  sCmd.addCommand("MotorOff", motorOff);
+  sCmd.addCommand("MotorOn",  motorOn);
   sCmd.addCommand("RelayOff", relayOff);
   sCmd.addCommand("RelayOn",  relayOn);

   // XV Commands
   sCmd.addCommand("GetPrompt",  getPrompt);
-  sCmd.addCommand("GetVersion",  getVersion);
+  sCmd.addCommand("GetVersion", getVersion);
 }

 void showRPM() {
@@ -242,7 +243,7 @@

   arg = sCmd.next();
   if (arg != NULL) {
-    sVal = atof(arg);    // Converts a char string to an integer
+    sVal = atof(arg);    // Converts a char string to a float
   }
   else {
     syntax_error = true;
@@ -272,7 +273,7 @@

   arg = sCmd.next();
   if (arg != NULL) {
-    sVal = atof(arg);    // Converts a char string to an integer
+    sVal = atof(arg);    // Converts a char string to a float
   }
   else {
     syntax_error = true;
@@ -301,7 +302,7 @@

   arg = sCmd.next();
   if (arg != NULL) {
-    sVal = atof(arg);    // Converts a char string to an integer
+    sVal = atof(arg);    // Converts a char string to a float
   }
   else {
     syntax_error = true;
@@ -313,7 +314,7 @@
   }

   if (syntax_error) {
-    Serial.println("Incorrect syntax.  Example: SetKp 1.0");
+    Serial.println("Incorrect syntax.  Example: SetKi 0.5");
   }
   else {
     Serial.print("Setting Ki to: ");
@@ -330,7 +331,7 @@

   arg = sCmd.next();
   if (arg != NULL) {
-    sVal = atof(arg);    // Converts a char string to an integer
+    sVal = atof(arg);    // Converts a char string to a float
   }
   else {
     syntax_error = true;
@@ -342,7 +343,7 @@
   }

   if (syntax_error) {
-    Serial.println("Incorrect syntax.  Example: SetKp 1.0");
+    Serial.println("Incorrect syntax.  Example: SetKd 0.001");
   }
   else {
     Serial.print("Setting Kd to: ");


update

update

--- _09_ir_tx_rx/_09_ir_tx_rx.ino
+++ _09_ir_tx_rx/_09_ir_tx_rx.ino
@@ -70,11 +70,9 @@

 // timer
 long startMills;
-long tv_off_Mills;
-long tv_on_Mills;
+long tv_onoff_Mills;
 long tempMills;
 long o_tempMills;
-long pir_Mills;

 // temp
 int o_tempminpassed = 0;
@@ -198,8 +196,7 @@
   startMills = millis();
   tempMills = millis();
   o_tempMills = millis();
-  tv_off_Mills = millis();
-  tv_on_Mills = millis();
+  tv_onoff_Mills = millis();

   // lcd
   lcd.init();
@@ -316,22 +313,52 @@
   // remote on / off, tv remote on / off
   decode_results results;

+  long onofftimediff = (millis() - tv_onoff_Mills ) / 1000 / 60 ;
+
+
+  // PIR
+  if ( pirOnOff != o_pirOnOff && timerOnOff == 0) {
+    if (pirOnOff == 1) {
+      Serial.println("PIR rising called");
+      o_pirOnOff = pirOnOff;
+
+      lcd.setCursor(15, 0);
+      lcd.write(6);
+
+      turn_onoff_tv(1);
+      delay(100);
+    } else {
+      Serial.println("PIR timer called");
+      o_pirOnOff = pirOnOff;
+
+      lcd.setCursor(15, 0);
+      lcd.print(" ");
+
+      turn_onoff_tv(0);
+      delay(100);
+    }
+  }
+
+  // IR receive
   if (irrecv.decode(&results)) {
     changemodebyir(&results);
     irrecv.enableIRIn();
   }

+  // display Temperature
   if ((millis() - tempMills) >= 2000 ) {
     getdalastemp();
     displayTemperature();
     tempMills = millis();

+/*
     if (timerOnOff == 0) {
-      displaytimeleft(o_tvOnTime - ((millis() - tv_off_Mills) / 1000 / 60) );
+      displaytimeleft(o_tvOnTime - ((millis() - tv_onoff_Mills) / 1000 / 60) );
     } else {
       displaytimeleft(o_tvOffTime - ((millis() - tv_on_Mills) / 1000 / 60) );
     }
-
+*/
+    // display difference -60 mims Temperature 3600000
     if ( (millis() - o_tempMills) >= 600000 ) {
       Serial.println("o_tempCinside called");
       o_tempCinside = c_tempCinside;
@@ -341,18 +368,27 @@
     }
   }

-  if (((millis() - tv_off_Mills) >= ( o_tvOnTime * 60 * 1000 )) && (timerOnOff == 0) && ( o_pirOnOff != 1) ) {
-    Serial.println("Timer off called");
-    turn_onoff_tv(1);
-  }
-
-  if (((millis() - tv_on_Mills) >= ( o_tvOffTime * 60 * 1000 )) && (timerOnOff == 1) && ( o_pirOnOff != 1)) {
-    Serial.println("Timer on called");
-    turn_onoff_tv(0);
-  }
+  // timer of/off
+  if ( timerOnOff == 0 ) {
+      if ( onofftimediff >= o_tvOnTime ) {
+          Serial.println("Timer off called");
+          turn_onoff_tv(1);
+          timerOnOff = 1;
+          tv_onoff_Mills = millis();
+      }
+  } else {
+      if ( onofftimediff >= o_tvOffTime ) {
+          Serial.println("Timer on called");
+          turn_onoff_tv(0);
+          timerOnOff = 0;
+          tv_onoff_Mills = millis();
+      }
+
+  }
+

   if (t != o_t) {
-    tv_off_Mills = millis();
+    tv_onoff_Mills = millis();
     o_t = t;
   }

@@ -362,27 +398,7 @@
     o_r = r;
   }

-
-  if ( pirOnOff != o_pirOnOff ) {
-    if (pirOnOff == 1) {
-      Serial.println("PIR rising called");
-      o_pirOnOff = pirOnOff;
-      lcd.setCursor(15, 0);
-      lcd.write(6);
-      turn_onoff_tv(1);
-      delay(100);
-    } else {
-      Serial.println("PIR timer called");
-      o_pirOnOff = pirOnOff;
-      lcd.setCursor(15, 0);
-      lcd.print(" ");
-      if ( timerOnOff == 1) {
-        turn_onoff_tv(0);
-      }
-      delay(100);
-    }
-  }
-  delay(100);
+  delay(500);
 }

 void displaytimeleft(float a) {
@@ -399,40 +415,12 @@
 void turn_onoff_tv(int a)
 {
   if ( o_wrkMode == 1 && o_startMode == 1 ) {
-    if ( o_pwrSrc == 0 ) {
-        if ( a == 1 && tvPowerStatus == 1) {
-          irSendTv(0);
-          tv_off_Mills = millis();
-          tv_on_Mills = millis();
-          timerOnOff = 1;
-          r = !r;
-        }
-
-        if ( a == 0 && tvPowerStatus == 0) {
-          irSendTv(1);
-          tv_off_Mills = millis();
-          tv_on_Mills = millis();
-          timerOnOff = 0;
-          r = !r;
-        }
-    } else {
-        if ( a == 1 ) {
-          irSendTv(0);
-          tv_off_Mills = millis();
-          tv_on_Mills = millis();
-          timerOnOff = 1;
-          r = !r;
-        }
-
-        if ( a == 0 ) {
-          irSendTv(1);
-          tv_off_Mills = millis();
-          tv_on_Mills = millis();
-          timerOnOff = 0;
-          r = !r;
-        }
-    }
-
+      if ( a == 1 ) {
+        irSendTv(1);
+      } else {
+        irSendTv(0);
+      }
+      r = !r;
   }
 }

@@ -446,7 +434,7 @@
     irrecv.enableIRIn();
   } else {
     Serial.println("IRSend CH change called");
-    if ( a == 1) {
+    if ( a == 0) {
       irsend.sendNEC(tv_input, 32);
       delay(3000);
       for ( int i = 0 ; i < o_channelGap ; i++ ) {
@@ -519,6 +507,10 @@
         break;
       case 0x20DF10EF: // tv remore on/off
         tvPowerStatus = ! tvPowerStatus ;
+        if ( tvPowerStatus == 1 ){
+          timerOnOff = 0 ;
+        }
+        t = !t;
         r = !r;
         break;
     }


remove ch selection delay using Timer

remove ch selection delay using Timer

--- _09_ir_tx_rx/_09_ir_tx_rx.ino
+++ _09_ir_tx_rx/_09_ir_tx_rx.ino
@@ -77,7 +77,13 @@
 Timer t;
 long temp_Mills;
 long pir_Mills;
+
 int tvIsOnEvent;
+
+int irSendTvOutToCurChEvent ;
+int irSendTvOutToBlnkChEvent ;
+
+

 // eeprom status
 int o_pwrSrc;
@@ -96,6 +102,9 @@

 // Timer status
 int timerStatus = 0;
+
+// channel input selection delay ( smart tv need this)
+long channelselectiondelay = 3000;

 // tv IR code
 unsigned long tv_input = 0x20DFD02F;
@@ -504,6 +513,29 @@
   r = !r;
 }

+void irSendTvOutToBlnkCh()
+{
+  for ( int i = 0 ; i < o_channelGap ; i++ ) {
+    irsend.sendNEC(tv_right, 32);
+    delay(100);
+  }
+  irsend.sendNEC(tv_enter, 32);
+  delay(100);
+  irrecv.enableIRIn();
+}
+
+void irSendTvOutToCurCh()
+{
+  for ( int i = 0 ; i < o_channelGap ; i++ ) {
+    irsend.sendNEC(tv_left, 32);
+    delay(100);
+  }
+  irsend.sendNEC(tv_enter, 32);
+  delay(100);
+  irrecv.enableIRIn();
+}
+
+

 void irSendTvOutbypir(int a)
 {
@@ -511,26 +543,16 @@
   if (DEBUG_PRINT) {
     Serial.println("IRSend PIR input change called");
   }
-  // need to update, remove delay, use timer.
+  // need to update, remove delay, use timer.
   if ( wrkModeStatus == 1 && o_startMode == 1 && tvPowerStatus == 1) {
     switch (a) {
       case 0:
         irsend.sendNEC(tv_input, 32);
-        delay(3000);
-        for ( int i = 0 ; i < o_channelGap ; i++ ) {
-          irsend.sendNEC(tv_left, 32);
-          delay(100);
-        }
-        irsend.sendNEC(tv_enter, 32);
+        irSendTvOutToCurChEvent = t.after(channelselectiondelay, irSendTvOutToCurCh);
         break;
       case 1:
         irsend.sendNEC(tv_input, 32);
-        delay(3000);
-        for ( int i = 0 ; i < o_channelGap ; i++ ) {
-          irsend.sendNEC(tv_right, 32);
-          delay(100);
-        }
-        irsend.sendNEC(tv_enter, 32);
+        irSendTvOutToBlnkChEvent = t.after(channelselectiondelay, irSendTvOutToBlnkCh);
         break;
     }

@@ -609,13 +631,13 @@

   lcd.print(Temperature, 1);

-   if ( ( second() % 2 ) == 0 ) {
+  if ( ( second() % 2 ) == 0 ) {
     lcd.setCursor(15, 1);
     lcd.print(".");
-   } else {
+  } else {
     lcd.setCursor(15, 1);
     lcd.print(" ");
-   }
+  }

   if ( tempCprevious[0] != 100 ) {
@@ -881,3 +903,4 @@
   return 1;
 }

+


Fixed max lives 0 back to 4.

Fixed max lives 0 back to 4.

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -27,7 +27,7 @@
 #include <EEPROM.h>

 #define DEBOUNCE_DELAY 100
-#define MAX_LIVES 0
+#define MAX_LIVES 4
 #define NUM_HIGH_SCORES 3
 #define NUM_STARS 15
 #define NOT_NEW_HI_SCORE 5


Supporting disabling motor driver when motor stopped to save power

--- arduino/autofowl/autofowl.ino
+++ arduino/autofowl/autofowl.ino
@@ -60,6 +60,8 @@
 const int STEPS_PER_REVOLUTION              = 200;
 const int MOTOR_SPEED_STEPS_PER_SECOND      = ( MOTOR_MAX_RPMS / 60 ) * STEPS_PER_REVOLUTION;
 const int MOTOR_ACCEL_STEPS_PER_SEC_PER_SEC = 50;
+// Disable motor driver when stopped. Decreases power consumption and heat from motor. 0 = no, 1 = yes.
+const int MOTOR_DISABLE_ON_STOP             = 1;

 // Number of ticks beyond threshold to wait before changing door position
 const int LIGHT_THRESH_TICKS_TO_CHANGE      = 100;
@@ -87,12 +89,13 @@
 const int PIN_LCD_D7      = 2;
 const int PIN_LCD_BL      = 9;
 // Arduino Uno / Photocell
-const int PIN_PHOTOCELL   = A0;
+const int PIN_PHOTOCELL     = A0;
 // Arduino Uno / Motor controller
-const int PIN_MOTOR_1     = 13; // pin 2 on L293D
-const int PIN_MOTOR_2     = 12; // pin 7 on L293D
-const int PIN_MOTOR_3     = 11; // pin 15 on L293D
-const int PIN_MOTOR_4     = 10; // pin 10 on L293D
+const int PIN_MOTOR_1       = 13; // pin 2 on L293D
+const int PIN_MOTOR_2       = 12; // pin 7 on L293D
+const int PIN_MOTOR_3       = 11; // pin 15 on L293D
+const int PIN_MOTOR_4       = 10; // pin 10 on L293D
+const int PIN_MOTOR_ENABLE  = A3;

 // --------------------------------------
 // -- Runtime variables
@@ -146,7 +149,11 @@
   pinMode(PIN_MOTOR_2,      OUTPUT);
   pinMode(PIN_MOTOR_3,      OUTPUT);
   pinMode(PIN_MOTOR_4,      OUTPUT);
+  pinMode(PIN_MOTOR_ENABLE, OUTPUT);
   pinMode(PIN_LCD_BL,       OUTPUT);
+
+  // Motor is disabled by default
+  disableMotor();

   // Set backlight brightness
   analogWrite(PIN_LCD_BL, 30); // 0 = off, 255 = fully on
@@ -363,13 +370,13 @@

   // Determine if door should move up or down
   if ( LightCurrent > LightThreshUp || totalseconds(Now) > ClockThreshUp.totalseconds() ) {
-
+
     // See if we could potentially change door position
     // If not, there's nothing else to do here
     if ( DoorPosition == DOOR_POSITION_UP ) {
       return;
     }
-
+
     LightThreshTicks++;
     updateLCD();
     if ( LightThreshTicks > LIGHT_THRESH_TICKS_TO_CHANGE ) {
@@ -444,15 +451,19 @@
   // Set the motor target position i.e. number of steps to move
   Motor.move(revolutions * (long) STEPS_PER_REVOLUTION);

+  enableMotor();
+
   // Start stepping motor
   while (true) {

     // Handle buttons to allow abort
     handleButton();

-    // Eject from loop if we stopped the door manually
+    // Eject from loop if we stopped the door manually via handleButton() calling stopDoor()
     if ( DoorDirection == DOOR_STATIONARY ) {
-      // Reset the stepper library
+      // Tell AccelStepper to stop and reset its position counter
+      Motor.setCurrentPosition(0);
+      // This break is redundant because Motor.run() will return false past here
       break;
     }

@@ -462,6 +473,8 @@
       break;
     }
   }
+
+  disableMotor();
 }

 // Stop door motion
@@ -469,6 +482,14 @@
   // Update status
   DoorDirection = DOOR_STATIONARY;
   EEPROM.write(DOOR_POSITION_ADDRESS, DoorPosition);
+}
+
+void enableMotor() {
+  digitalWrite(PIN_MOTOR_ENABLE, 1);
+}
+
+void disableMotor() {
+  digitalWrite(PIN_MOTOR_ENABLE, MOTOR_DISABLE_ON_STOP);
 }

 bool doorIsMoving() {
@@ -605,7 +626,7 @@

   Serial.print(" LightThreshUp=");
   Serial.print(LightThreshUp);
-  Serial.print(" LightCurrent=");
+  Serial.print(" LightThreshDown=");
   Serial.print(LightThreshDown);
   Serial.print(" LightCurrent=");
   Serial.print(LightThreshDown);
@@ -623,6 +644,14 @@
   Serial.print(':');
   Serial.print(ClockThreshDown.seconds(), DEC);

+  Serial.print(" CurrentMode=");
+  Serial.print(prettyMode());
+
+  Serial.print(" DoorPosition=");
+  Serial.print(prettyDoorPosition());
+  Serial.print(" DoorDirection=");
+  Serial.print(prettyDoorDirection());
+
   Serial.println();
 }
 #endif


[lmr] Set RF state back to converging if locked and miss a packet. Also:

-- Sleep the RFM12 as soon as possible after RX failure
-- Don't do any temp measuring if no probe pins are enabled

--- arduino/lmremote/lmremote.ino
+++ arduino/lmremote/lmremote.ino
@@ -82,7 +82,6 @@

 static unsigned int _previousReads[RF_PINS_PER_SOURCE];
 static unsigned long _tempReadLast;
-static unsigned int _loopCnt;
 static unsigned char _sameCount;
 static unsigned char _isRecent = BYTE1_RECENT_BOOT;
 static unsigned char _isBattLow;
@@ -277,6 +276,8 @@
     recvTime = millis();
     if (recvTime - wakeTime > (_recvWindow * 2))
     {
+      rf12_sleep(RF12_SLEEP);
+
 #if defined(LMREMOTE_SERIAL) && defined(_DEBUG)
       Serial.print(" f "); Serial.print(_recvLost);
       //Serial.print(" s "); Serial.print(sleepDur);
@@ -290,10 +291,14 @@
       ++_recvLost;
       if (_recvLost > 10)
         rfResetEstimate();
-      else if (_recvLost % 2 == 1 && _recvWindow < MAX_RECV_WIN)
-        _recvWindow *= 2;
-
-      rf12_sleep(RF12_SLEEP);
+      else
+      {
+        if (_recvLost % 2 == 1 && _recvWindow < MAX_RECV_WIN)
+          _recvWindow *= 2;
+        if (_recvState == RECVSTATE_LOCKED)
+          rfSetRecvState(RECVSTATE_CONVERGING);
+      }
+
       return false;
     }
   } while (!rf12_doWork());
@@ -426,6 +431,8 @@
 static void checkTemps(void)
 {
   _tempReadLast = millis();
+  if (_enabledProbePins == 0)
+    return;

   const unsigned char OVERSAMPLE_COUNT[] = {1, 4, 16, 64};  // 4^n
   boolean modified = false;


Implement temperature reading

Implement temperature reading

--- Computer_Switch/Computer_Switch.ino
+++ Computer_Switch/Computer_Switch.ino
@@ -27,9 +27,17 @@
 #define RELAY_PIN D1
 #define POWER_BUTTON D4
 #define POWER_LED D2
+#define DHT_PIN D5
+
+#define DHTTYPE DHT22        // DHT 22
+DHT dht(DHT_PIN, DHTTYPE);

 // The port to listen for incoming TCP connections
 ESP8266WebServer server(80);
+
+// How often to report temperature
+unsigned long lastTempCheck = millis();
+#define TEMP_CHECK_FREQUENCY 10000

 // How often to check for power off state
 unsigned long lastPowerCheck = millis();
@@ -45,10 +53,12 @@
 int relayOn =               0;
 int computerOn =            0;
 int relayOffWhenPowerDown = 0;
+char temp[8] =             "";

 void setup() {
   Serial.begin(115200);
   initWifi();
+  dht.begin();

   server.on("/", getStatus);
   server.on("/on", powerOn);
@@ -81,6 +91,11 @@
       }
     }
     lastPowerCheck = millis();
+  }
+  // Check the temperature and update the server
+  if (millis() > lastTempCheck + TEMP_CHECK_FREQUENCY) {
+    checkTempHumid();
+    lastTempCheck = millis();
   }
   // Check status to update variables
   computerOn = digitalRead(POWER_LED);
@@ -120,7 +135,7 @@
 }

 void getStatus() {
-  String preString = "{\"relayOn\":\"" + String(relayOn) + "\",\"computerOn\":\"" + String(computerOn) + "\",\"relayOffWhenPowerDown\":\"" + String(relayOffWhenPowerDown) + "\",\"heapFree\":\"" + String(ESP.getFreeHeap()) + "\"}";
+  String preString = "{\"relayOn\":\"" + String(relayOn) + "\",\"computerOn\":\"" + String(computerOn) + "\",\"relayOffWhenPowerDown\":\"" + String(relayOffWhenPowerDown) + "\",\"temp\":\"" + String(temp) + "\"}";
   const char * result = preString.c_str();
   server.send(200, "application/json", result);
 }
@@ -166,3 +181,17 @@
   }
   server.send(200, "application/json", "{\"status\":\"complete\"}");
 }
+
+// Literally returns the temperature
+float getTemperature() {
+  return dht.readTemperature(true);
+}
+
+// Send temp / humidity update
+void checkTempHumid() {
+  Serial.println("Checking temp...");
+  float readTemp = getTemperature();
+  dtostrf(readTemp, -6, 2, temp); // Leave room for too large numbers!
+
+  Serial.println(temp);
+}


adding ds18b20

adding ds18b20

--- _56-gopro-control/a-93-config-on-rtc-with-external-poweron-signal-autoexec/a-93-config-on-rtc-with-external-poweron-signal-autoexec.ino
+++ _56-gopro-control/a-93-config-on-rtc-with-external-poweron-signal-autoexec/a-93-config-on-rtc-with-external-poweron-signal-autoexec.ino
@@ -2,6 +2,11 @@
 /*
   gopro wifi : https://github.com/KonradIT/goprowifihack
   twitter api : https://dev.twitter.com/rest/reference/post/media/upload
+*/
+/*
+  D5 - I2c
+  D4 - I2C
+  D2 - DS18B20
 */
 #include <Arduino.h>
 #include <TimeLib.h>
@@ -15,6 +20,7 @@
 #include <WiFiUdp.h>
 #include <ArduinoJson.h>
 #include <LiquidCrystal_I2C.h>
+#include <DallasTemperature.h>
 #include <base64.h>
 #include <FS.h>
 /* --- */
@@ -169,12 +175,13 @@
 char* hellotopic  = "HELLO";
 char* willTopic   = "clients/solar";
 char* willMessage = "0";
+char* topic       = "esp8266/arduino/solar";

 // subscribe
 const char subrpi[]     = "raspberrypi/data";
 const char subtopic_0[] = "esp8266/arduino/s03"; // lcd temp
 const char subtopic_1[] = "esp8266/arduino/s07"; // power
-const char subtopic_3[] = "radio/test/2";        //Outside temp
+const char subtopic_3[] = "radio/test/2";        // Outside temp
 const char subtopic_4[] = "raspberrypi/doorpir";
 const char subtopic_5[] = "raspberrypi/data2";

@@ -182,6 +189,21 @@

 unsigned int localPort = 12390;
 const int timeZone = 9;
+
+// DS18B20
+#define ONE_WIRE_BUS 2
+#define TEMPERATURE_PRECISION 9
+
+OneWire oneWire(ONE_WIRE_BUS);
+DallasTemperature sensors(&oneWire);
+DeviceAddress insideThermometer;
+
+// ds18b20
+bool bDalasstarted;
+float tempCinside;
+unsigned long startMills;
+#define REPORT_INTERVAL 5000 // in msec
+

 //
 String clientName;
@@ -195,7 +217,8 @@
 WiFiClientSecure sslclient;

 LiquidCrystal_I2C lcd(0x27, 20, 4);
-PubSubClient mqttclient(mqtt_server, 1883, callback, wifiClient);
+//PubSubClient mqttclient(mqtt_server, 1883, callback, wifiClient);
+PubSubClient mqttclient(wifiClient);
 WiFiUDP udp;
 RtcDS3231 Rtc;

@@ -530,14 +553,14 @@
 }
 /* -- */

-void sendmqttMsg(char* topictosend, String topicpayload)
+void sendmqttMsg(char* topictosend, String topicpayload, bool retain = 1)
 {
   unsigned int msg_length = topicpayload.length();

   byte* p = (byte*)malloc(msg_length);
   memcpy(p, (char*) topicpayload.c_str(), msg_length);

-  if (mqttclient.publish(topictosend, p, msg_length, 1))
+  if (mqttclient.publish(topictosend, p, msg_length, retain))
   {
     free(p);
   }
@@ -649,11 +672,14 @@
       mqttclient.loop();
       yield();

-      for (int i = 0; i < 6; ++i)
-      {
-        mqttclient.subscribe(substopic[i]);
-        mqttclient.loop();
-        yield();
+      if (!rtc_boot_mode.gopro_mode)
+      {
+        for (int i = 0; i < 6; ++i)
+        {
+          mqttclient.subscribe(substopic[i]);
+          mqttclient.loop();
+          yield();
+        }
       }
     } //else {
     //}
@@ -763,7 +789,8 @@

   pinMode(goproPowerPin, OUTPUT);

-  Wire.begin(0, 2);
+  //Wire.begin(0, 2);
+  Wire.begin(5, 4);
   //twi_setClock(200000);
   //delay(100);

@@ -846,6 +873,32 @@
   delay(1000);
   lcd.clear();

+  // ds18b20
+  sensors.begin();
+  if (!sensors.getAddress(insideThermometer, 0)) {
+    lcd.setCursor(0, 0);
+    lcd.print("ds18b20 : ");
+    lcd.setCursor(0, 1);
+    lcd.print("can't find");
+    delay(1000);
+    lcd.clear();
+  }
+
+  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
+  sensors.requestTemperatures();
+  tempCinside = sensors.getTempC(insideThermometer);
+  sensors.setWaitForConversion(false);
+
+  if ( tempCinside < -30 ) {
+    lcd.setCursor(0, 0);
+    lcd.print("ds18b20 : ");
+    lcd.setCursor(0, 1);
+    lcd.print("Failed to read");
+    delay(1000);
+    lcd.clear();
+  }
+
+
   if (!SPIFFS.begin())
   {
     lcd.setCursor(0, 0);
@@ -907,12 +960,15 @@
   if (!rtc_boot_mode.gopro_mode || rtc_boot_mode.attempt_this > 4)
   {
     wifi_connect();
+    mqttclient.setServer(mqtt_server, 1883);
+    mqttclient.setCallback(callback);
   }
   else
   {
     if ( rtc_boot_mode.twitter_phase > 1 )
     {
       wifi_connect();
+      mqttclient.setServer(mqtt_server, 1883);
     }
     else
     {
@@ -1060,12 +1116,23 @@
     attachInterrupt(1, alm_isr, FALLING);
   }

+  startMills = millis();
   x = true;
 }

 time_t prevDisplay = 0;

 void loop() {
+
+  if (bDalasstarted)
+  {
+    if (millis() > (startMills + (750 / (1 << (12 - TEMPERATURE_PRECISION)))))
+    {
+      tempCinside  = sensors.getTempC(insideThermometer);
+      bDalasstarted = false;
+    }
+  }
+
   if (!rtc_boot_mode.gopro_mode)
   {
     if (balm_isr)
@@ -1131,12 +1198,12 @@

           if (
             curr_data.data1 != solar_data.data1 ||
-            curr_data.data2 != solar_data.data2
-            )
+            curr_data.data2 != solar_data.data2
+          )
           {
             displayData();
             curr_data.data1 = solar_data.data1;
-            curr_data.data2 = solar_data.data2;
+            curr_data.data2 = solar_data.data2;
           }

           if (
@@ -1203,6 +1270,28 @@
             }
           }
         }
+
+        //-----------------------------------------------
+        if ((millis() - startMills) > REPORT_INTERVAL )
+        {
+
+          payload = "{\"DS18B20\":";
+          payload += tempCinside;
+          payload += ",\"FreeHeap\":";
+          payload += ESP.getFreeHeap();
+          payload += ",\"RSSI\":";
+          payload += WiFi.RSSI();
+          payload += ",\"millis\":";
+          payload += millis();
+          payload += "}";
+
+          sendmqttMsg(topic, payload, 0);
+
+          sensors.requestTemperatures();
+          bDalasstarted = true;
+
+          startMills = millis();
+        }
         mqttclient.loop();
       }
       ArduinoOTA.handle();
@@ -1218,6 +1307,31 @@
     if (WiFi.status() == WL_CONNECTED)
     {
       // gopro mode
+
+      if ( rtc_boot_mode.twitter_phase > 1 )
+      {
+        //-----------------------------------------------
+        if ((millis() - startMills) > REPORT_INTERVAL )
+        {
+
+          payload = "{\"DS18B20\":";
+          payload += tempCinside;
+          payload += ",\"FreeHeap\":";
+          payload += ESP.getFreeHeap();
+          payload += ",\"RSSI\":";
+          payload += WiFi.RSSI();
+          payload += ",\"millis\":";
+          payload += millis();
+          payload += "}";
+
+          sendmqttMsg(topic, payload, 0);
+
+          sensors.requestTemperatures();
+          bDalasstarted = true;
+
+          startMills = millis();
+        }
+      }

       if (x)
       {
@@ -1325,6 +1439,26 @@
             break;
         }
       }
+      if ( rtc_boot_mode.twitter_phase > 1 )
+      {
+        if (!mqttclient.connected())
+        {
+          unsigned long now = millis();
+          if (now - lastReconnectAttempt > 100)
+          {
+            lastReconnectAttempt = now;
+            if (reconnect())
+            {
+              lastReconnectAttempt = 0;
+            }
+          }
+        }
+        else
+        {
+          mqttclient.loop();
+        }
+      }
+
     }
   }
 }
@@ -1414,13 +1548,30 @@

 void displayTemperature()
 {
-  lcd.setCursor(1, 1);
-  displayTemperaturedigit(solar_data.Temperature1);
-
-  lcd.setCursor(7, 1);
-
-  float tempdiff = solar_data.Temperature2 - solar_data.Temperature1;
-  displayTemperaturedigit(solar_data.Temperature2);
+  float tempdiff;
+  if (second() % 2 == 0 )
+  {
+    lcd.setCursor(1, 1);
+    displayTemperaturedigit(tempCinside);
+
+    lcd.setCursor(7, 1);
+
+    tempdiff = solar_data.Temperature2 - tempCinside;
+    displayTemperaturedigit(solar_data.Temperature2);
+
+    lcd.setCursor(1, 1);
+    lcd.write(7);
+  }
+  else
+  {
+    lcd.setCursor(1, 1);
+    displayTemperaturedigit(solar_data.Temperature1);
+
+    lcd.setCursor(7, 1);
+
+    tempdiff = solar_data.Temperature2 - solar_data.Temperature1;
+    displayTemperaturedigit(solar_data.Temperature2);
+  }

   lcd.setCursor(14, 1);
   if ( tempdiff > 0 )


update governers to use thorttle positon. Changed governers. Adjusted logic to calm down noise. Car is working well

--- arduino/car_control/src/main_control.ino
+++ arduino/car_control/src/main_control.ino
@@ -4,28 +4,34 @@
 */
 #include <Servo.h>

-
-const int STEER_IN = 5;
-const int STEER_OUT = 9;
-const int STEER_BASE = 1277;
-const int STEER_MIN = 847;
-const int STEER_MAX = 1710;
-const float STEER_SENSITIVITY = 1.0;
-
-const int THROTTLE_IN = 6;
-const int THROTTLE_OUT = 11;
-const int THROTTLE_BASE = 1273;
-const int THROTTLE_MIN = 843;
-const int THROTTLE_MAX = 1710;
-const float THROTTLE_SENSITIVITY = 1.0;
-
-const int LED_GREEN = 4;
-const int LED_RED = 3;
-
-const int RPM_INTERRUPT = 0; //pin 2
+#define STEER_IN 5
+#define STEER_OUT 9
+#define STEER_BASE 1277
+#define STEER_MIN 847
+#define STEER_MAX 1710
+#define STEER_SENSITIVITY 1.2
+
+#define THROTTLE_IN 6
+#define THROTTLE_OUT 11
+#define THROTTLE_BASE 1273
+#define THROTTLE_MIN 843
+#define THROTTLE_MAX 1710
+#define THROTTLE_SENSITIVITY 3.0
+
+#define LED_GREEN 4
+#define LED_RED 3
+
+#define RPM_PIN 2
+#define RPM_INTERRUPT 0
+
+// left and right sonar trigger at the same time
+#define TRIGGER_PIN     7
+#define ECHO_PIN_LEFT   8
+#define ECHO_PIN_RIGHT  12

 int _STEER_BIAS = 0; //set this to adjust steering
-int _GOVERNER = 1710; //cap the forward speed
+int _GOVERNER_F = 10; //cap the forward speed
+int _GOVERNER_R = -12;

 //servos
@@ -52,13 +58,27 @@
 unsigned int rpm;
 unsigned long timeold;

+//reverse
+bool in_reverse = false;
+

 //sets the steering angle between -45, 45 for full left /right respectively. set to zero for straight ahead
 void set_steer_angle(int angle) {
   //dont set unless a delta has been acheived
   if (abs(steering_angle - angle) / 2.0 < STEER_SENSITIVITY){
-    return;
+    if (abs(angle) <= 2){
+      angle = 0;
+    }
+    else {
+      //not a big of change to change noise
+      return;
+    }
+
+    //if this value has already been set zero, no reason to set it again
+    if (steering_angle == 0) {
+      return;
+    }
   }

   steering_angle = angle;
@@ -83,20 +103,45 @@
 void set_throttle_position(int pos) {
   //dont set unless a delta has been acheived
   if (abs(throttle_pos - pos)/2.0 < THROTTLE_SENSITIVITY){
-    return;
-  }
-
+    if (abs(pos) <= 5){
+      pos = 0;
+    }
+    else {
+      //not a big of change to change noise
+      return;
+    }
+
+    //if this value has already been set zero, no reason to set it again
+    if (throttle_pos == 0) {
+      return;
+    }
+  }
+
+
+  //determine if in reverse
+  if (pos > 0){
+    in_reverse = false;
+  }
+  else if (throttle_pos == 0){
+    //only go in reverse if the throttle was zero
+    in_reverse = true;
+  }
+
+
+  //dont allow input past the limits, note we only limit reverse if the
+  //standing throttle position is at zero. This allows for full breaking
+  if (in_reverse){
+    pos = max(_GOVERNER_R, pos);
+  }
+
+  pos = min(_GOVERNER_F, pos);
+
   throttle_pos = pos;
   Serial.println(String("V79-T:") + throttle_pos);

+  //note!!!!! the 1000 and 2000 here are the min and max PWM that the controller accepts
   int map_throttle = map(pos, -100, 100, 1000, 2000);
-  //set minimum is 1400 for reverse and 1550 for slow forward
-  if (map_throttle < 1200) {
-    map_throttle = 1200;
-  }
-  if (map_throttle > _GOVERNER) {
-    map_throttle = _GOVERNER;
-  }
+

   throttle_servo.writeMicroseconds(map_throttle);
 }
@@ -169,6 +214,7 @@
   Serial.begin(115200);
   Serial.println("V79: starting...");
   attachInterrupt(RPM_INTERRUPT, monitor_rpm, RISING);
+  digitalWrite(RPM_PIN, HIGH);

   //set up red/green led indicators
   pinMode(LED_GREEN, OUTPUT);
@@ -282,12 +328,12 @@
         _STEER_BIAS = command.toInt();
       }

-      //governer
-      if (command.startsWith("G")) {
-        command.replace("G", " ");
+      //governer forward
+      if (command.startsWith("GF")) {
+        command.replace("GF", " ");
         command.trim();
-        if (command.toInt() > THROTTLE_BASE) {
-          _GOVERNER = command.toInt();
+        if (command.toInt() > 0) {
+          _GOVERNER_F = command.toInt();
         }
       }


Formatting

Formatting

--- trikebox/squares.ino
+++ trikebox/squares.ino
@@ -5,7 +5,7 @@
     int hue = 0;

     for (int y = 0; y < 12; y+=2) {
-        for (int x = 0; x < 72; x+=2) {
+      for (int x = 0; x < 72; x+=2) {
         uint16_t index = y * 72 + x;
         hue += 36;
         uint16_t bpm = bpms[index];


added speed variation

added speed variation

--- LEDguide_actual/LEDguide_actual.ino
+++ LEDguide_actual/LEDguide_actual.ino
@@ -23,7 +23,7 @@
 #include "WS2812_Definitions.h"

 #define PIN 4
-#define LED_COUNT 48
+#define LED_COUNT 35

 // Create an instance of the Adafruit_NeoPixel class called "leds".
 // That'll be what we refer to from here on...
@@ -33,6 +33,10 @@
 int switchPin = A0;
 int switchValue = 0;
 int viconTriggerPin = 6;
+int nat = 527;
+int wait_nat;
+int wait_60;
+int wait_30;

 void setup()
 {
@@ -49,6 +53,13 @@
   leds.show();
   switchValue = analogRead(switchPin);
   Serial.println(switchValue);
+  wait_nat = 320000/(20*nat);
+
+  wait_60 = wait_nat/.6;
+
+  wait_30 = wait_nat/.3;
+
+
   if(switchValue < 100){
     analogWrite(viconTriggerPin, 20);
     digitalWrite(13, HIGH);
@@ -59,7 +70,8 @@
     digitalWrite(13,LOW);
       readySetGo(1500);
       // First parameter is the color, second is direction, third is ms between falls
-      cascade(MEDIUMSPRINGGREEN, TOP_DOWN, 100);
+      // 20 LEDs
+      cascade(MEDIUMSPRINGGREEN, TOP_DOWN, wait_60);
       clearLEDs();
       leds.show();


バッファ以上のサイズのコマンドが来た場合に備えた.

バッファ以上のサイズのコマンドが来た場合に備えた.

--- arduino/GeneralIoSerial/GeneralIoSerial.ino
+++ arduino/GeneralIoSerial/GeneralIoSerial.ino
@@ -112,7 +112,13 @@
         buf_index = 0;
         break;
       }
-      buf_index++;
+      if(++buf_index >= ARRAYSIZE(read_buf)){
+        // なくなるまで読み捨てる.
+        Serial.println(NgReturnJson("Command is too long.", String(buf_index)));
+        while(Serial.available() > 0){Serial.read();}
+        memset(read_buf, 0, ARRAYSIZE(read_buf));
+        buf_index = 0;
+      }
     }
   }
 }


No storage required

No storage required

--- contrib/life.ino
+++ contrib/life.ino
@@ -15,7 +15,7 @@

 void setup()
 {
-  GD.begin();
+  GD.begin(~GD_STORAGE);

   LOAD_ASSETS();


Replacing trace with pure IOStream and binding to LCD. Cleaning up.

--- examples/LCD/CosaLCDbench/CosaLCDbench.ino
+++ examples/LCD/CosaLCDbench/CosaLCDbench.ino
@@ -25,49 +25,51 @@

 #include "Cosa/RTC.hh"
 #include "Cosa/Watchdog.hh"
-#include "Cosa/Trace.hh"
+#include "Cosa/IOStream.hh"
 #include "Cosa/LCD/Driver/HD44780.hh"

-// Select the LCD port for the benchmark
-// HD44780::Port port;
+// Select the port for the benchmark
+HD44780::Port port;
 // HD44780::SR3W port;
 // HD44780::SR3WSPI port;
-HD44780::MJKDZ port;
+// HD44780::MJKDZ port;
 // HD44780::DFRobot port;
 HD44780 lcd(&port);
+IOStream cout(&lcd);

-// Benchmarks
+// Display configuration
+const uint16_t WIDTH = 16;
+const uint16_t HEIGHT = 2;
+
+// Measurement support
 typedef void (*benchmark_t)(uint16_t);
+void measure(const char* name, benchmark_t fn, uint16_t nr, uint16_t bytes);
+#define MEASURE(fn,bytes) measure(PSTR(#fn),fn,10,bytes)
+
+// The benchmarks
 void benchmark1(uint16_t nr);
 void benchmark2(uint16_t nr);
 void benchmark3(uint16_t nr);
 void benchmark4(uint16_t nr);

-// Measurement support
-void measure(const char* name, benchmark_t fn, uint16_t nr, uint16_t bytes);
-#define MEASURE(fn,bytes)						\
-  do {									\
-    measure(PSTR(#fn),fn,10,bytes);					\
-    SLEEP(4);								\
-  } while (0)
+// Benchmark configuration
+#define CHAR_MAX 6
+#define NUM_STR   "1234567890123456"
+#define ALPHA_STR "ABCDEFGHIJKLMNOP"

 void setup()
 {
   RTC::begin();
   Watchdog::begin();
   lcd.begin();
-  trace.begin(&lcd, PSTR("CosaLCDbench: "));
+  cout << PSTR("CosaLCDbench:");
   SLEEP(2);
 }
-
-// Display configuration
-const uint16_t WIDTH = 16;
-const uint16_t HEIGHT = 2;

 void loop()
 {
   MEASURE(benchmark1, WIDTH * HEIGHT + 2);
-  MEASURE(benchmark2, WIDTH * HEIGHT * 6 * 2);
+  MEASURE(benchmark2, WIDTH * HEIGHT * CHAR_MAX * 2);
   MEASURE(benchmark3, WIDTH * HEIGHT + 2);
   MEASURE(benchmark4, WIDTH * HEIGHT + 2);
 }
@@ -87,7 +89,7 @@
 void benchmark2(uint16_t nr)
 {
   while (nr--) {
-    for (uint8_t c = 'A'; c <= 'A' + 5; c++) {
+    for (uint8_t c = 'A'; c < 'A' + CHAR_MAX; c++) {
       for (uint8_t height = 0; height < HEIGHT; height++) {
 	for (uint8_t width = 0; width < WIDTH; width++) {
 	  lcd.set_cursor(width, height);
@@ -97,9 +99,6 @@
     }
   }
 }
-
-#define NUM_STR   "1234567890123456"
-#define ALPHA_STR "ABCDEFGHIJKLMNOP"

 void benchmark3(uint16_t nr)
 {
@@ -123,14 +122,14 @@

 void measure(const char* name, benchmark_t fn, uint16_t nr, uint16_t bytes)
 {
-  lcd.display_clear();
-  lcd.puts_P(name);
+  cout << clear << name;
   uint32_t start = RTC::micros();
   {
     fn(nr);
   }
   uint32_t us = (RTC::micros() - start) / nr;
-  trace << clear << name << endl;
-  trace << us << PSTR(" us (") << us / bytes << PSTR(")");
+  cout << clear << name << endl;
+  cout << us << PSTR(" us (") << us / bytes << PSTR(")");
+  SLEEP(4);
 }


arduino program

arduino program

--- Arduino/RobotControl/RobotControl.ino
+++ Arduino/RobotControl/RobotControl.ino
@@ -1,96 +1,127 @@
-#include <SPI.h>
 #include <WiFi.h>
 #include <WiFiUdp.h>

+
+char ssid[] = "Freebox-779353";
+char pass[] = "acervandam-coutimini!4-undum-coactiv4";
 int status = WL_IDLE_STATUS;
-char ssid[] = "yourNetwork"; //  your network SSID (name)
-char pass[] = "secretPassword";    // your network password (use for WPA, or use as key for WEP)
-int keyIndex = 0;            // your network key Index number (needed only for WEP)

-unsigned int localPort = 2390;      // local port to listen on
+int localPort = 12345;

-char packetBuffer[255]; //buffer to hold incoming packet
-char  ReplyBuffer[] = "acknowledged";       // a string to send back
+char packetBuffer[255];
+char ReplyBuffer[] = "pong";
+

 WiFiUDP Udp;

+
+//set up the pins
+int enableMD = 11;
+int enableMG = 12;
+int MD1 = 2;
+int MD2 = 3;
+int MG1 = 8;
+int MG2 = 13;
+
+void rmove(int dir){
+  //1 forward
+  //2 right
+  //3 backward
+  //4 left
+
+  switch (dir){
+    case (1):
+      //avancer
+      digitalWrite(MD1,LOW);
+      digitalWrite(MD2,HIGH);
+
+      digitalWrite(MG1,HIGH);
+      digitalWrite(MG2,LOW);
+      break;
+    case (2):
+      //droite
+      digitalWrite(MD1,HIGH);
+      digitalWrite(MD2,LOW);
+
+      digitalWrite(MG1,HIGH);
+      digitalWrite(MG2,LOW);
+      break;
+
+    case (3):
+      //reculer
+      digitalWrite(MD1,LOW);
+      digitalWrite(MD2,HIGH);
+
+      digitalWrite(MG1,HIGH);
+      digitalWrite(MG2,LOW);
+      break;
+
+    case (4):
+      //gauche
+      digitalWrite(MD1,LOW);
+      digitalWrite(MD2,HIGH);
+
+      digitalWrite(MG1,LOW);
+      digitalWrite(MG2,HIGH);
+      break;
+
+    default:
+      digitalWrite(MD1,LOW);
+      digitalWrite(MD2,LOW);
+
+      digitalWrite(MG1,LOW);
+      digitalWrite(MG2,LOW);
+      break;
+  }
+}
+
 void setup() {
-  //Initialize serial and wait for port to open:
   Serial.begin(9600);
-  while (!Serial) {
-    ; // wait for serial port to connect. Needed for Leonardo only
-  }
-
-  // check for the presence of the shield:
+
+  pinMode(MD1,OUTPUT);
+  pinMode(MD2,OUTPUT);
+  pinMode(MG1,OUTPUT);
+  pinMode(MD2,OUTPUT);
+  pinMode(enableMD,OUTPUT);
+  pinMode(enableMG,OUTPUT);
+
+  digitalWrite(enableMD,HIGH);
+  digitalWrite(enableMG,HIGH);
+
+
   if (WiFi.status() == WL_NO_SHIELD) {
     Serial.println("WiFi shield not present");
-    // don't continue:
-    while (true);
+    while(true);
   }
-
-  String fv = WiFi.firmwareVersion();
-  if ( fv != "1.1.0" )
-    Serial.println("Please upgrade the firmware");
-
-  // attempt to connect to Wifi network:
-  while ( status != WL_CONNECTED) {
-    Serial.print("Attempting to connect to SSID: ");
+  Serial.println(WiFi.firmwareVersion());
+  while ( status != WL_CONNECTED) {
+    Serial.print("Attempting to connect to WPA SSID: ");
     Serial.println(ssid);
-    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
-    status = WiFi.begin(ssid);
-
-    // wait 10 seconds for connection:
+    status = WiFi.begin(ssid, pass);
     delay(10000);
   }
-  Serial.println("Connected to wifi");
-  printWifiStatus();
-
-  Serial.println("\nStarting connection to server...");
-  // if you get a connection, report back via serial:
-  Udp.begin(localPort);
+
+  Serial.println(WiFi.localIP());
+
+  if (Udp.begin(localPort)){
+    Serial.println("Now listenning on ");
+    Serial.println(localPort);
+  }
+  else{
+    Serial.println("Socket unavaiable");
+  }
 }

 void loop() {
-
-  // if there's data available, read a packet
   int packetSize = Udp.parsePacket();
-  if (packetSize)
-  {
-    Serial.print("Received packet of size ");
-    Serial.println(packetSize);
-    Serial.print("From ");
-    IPAddress remoteIp = Udp.remoteIP();
-    Serial.print(remoteIp);
-    Serial.print(", port ");
-    Serial.println(Udp.remotePort());
-
-    // read the packet into packetBufffer
+  if (packetSize){
     int len = Udp.read(packetBuffer, 255);
     if (len > 0) packetBuffer[len] = 0;
-    Serial.println("Contents:");
+
     Serial.println(packetBuffer);

-    // send a reply, to the IP address and port that sent us the packet we received
     Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
     Udp.write(ReplyBuffer);
     Udp.endPacket();
   }
 }
-
-
-void printWifiStatus() {
-  // print the SSID of the network you're attached to:
-  Serial.print("SSID: ");
-  Serial.println(WiFi.SSID());
-
-  // print your WiFi shield's IP address:
-  IPAddress ip = WiFi.localIP();
-  Serial.print("IP Address: ");
-  Serial.println(ip);
-
-  // print the received signal strength:
-  long rssi = WiFi.RSSI();
-  Serial.print("signal strength (RSSI):");
-  Serial.print(rssi);
-  Serial.println(" dBm");
-}


More testing fluff

More testing fluff

--- esp8266-arm-swd.ino
+++ esp8266-arm-swd.ino
@@ -3,6 +3,9 @@
 //    Proof of Concept ESP8266 Wifi + HTTP web interface
 //     for remote control of an ARM microcontroller
 //      via its Serial Wire Debug port.
+//
+//    Designed for the FRDM-KE04Z dev kit as an example target,
+//    with its MKE04Z8VFK4 Cortex M0+ micro.
 //
 ////////////////////////////////////////////////////////////////

@@ -23,19 +26,67 @@
 const int swd_clock_pin = 0;
 const int swd_data_pin = 2;

+////////////////////////////////////////////////////////////////
+
 #include <ESP8266WiFi.h>
 #include <WiFiClient.h>
 #include <ESP8266WebServer.h>
 #include <ESP8266mDNS.h>
 #include "arm_debug.h"
 #include "arm_kinetis_debug.h"
+#include "arm_kinetis_reg.h"

 ESP8266WebServer server(80);
-ARMKinetisDebug target(swd_clock_pin, swd_data_pin);
+ARMKinetisDebug target(swd_clock_pin, swd_data_pin, ARMDebug::LOG_TRACE_MEM);
+
+void appendHex32(String &buffer, uint32_t word)
+{
+    char tmp[10];
+    sprintf(tmp, "0x%08X", word);
+    buffer += tmp;
+}

 void handleWebRoot()
 {
-    server.send(200, "text/html", "Ohai again!");
+    String output = "
";
+
+    output += "Howdy, neighbor!\n";
+    output += "Nice to meet you.\n\n";
+
+    if (!target.begin()) {
+        output += "Unfortunately,\n";
+        output += "I failed to connect to the debug port.\n";
+        output += "Check your wiring maybe?\n";
+    } else {
+        output += "Connected to the ARM debug port.\n";
+
+        uint32_t idcode;
+        if (target.getIDCODE(idcode)) {
+            output += "This processor has an IDCODE of ";
+            appendHex32(output, idcode);
+            output += "\n";
+        }
+
+        if (target.detect()) {
+            output += "Freescale Kinetis extensions too.\n";
+            if (target.startup()) {
+                output += "Putting the target into debug-halt, to keep things from getting too crazy just yet.\n";
+            }
+        }
+    }
+
+    output += "Some memory... ";
+    uint32_t addr = 0x1ffff000;
+    uint32_t word;
+    for (unsigned i = 0; i < 8; i++) {
+        if (target.memLoad(addr, word)) {
+            appendHex32(output, word);
+        }
+        addr += 4;
+    }
+
+    output += "
";
+    server.send(200, "text/html", output);
 }

 void setup(void)


 All right. Sending client in shape ... with SPIFFS/EEPROM filesystem storage for old messages.

 Main next task is heartbeat feedback on console of id, key, and connection status

--- esp8266/esp8266.ino
+++ esp8266/esp8266.ino
@@ -58,6 +58,8 @@
 #define MDNS_DEBUG_ON
 #define STAT_DEBUG_ON
 #define INPT_DEBUG_ON
+#define WIFI_DEBUG_ON
+#define FILE_DEBUG_ON

 //
 //  Global defines
@@ -111,6 +113,30 @@

 //
+//	Othe global stuff
+//
+
+#define MAX_LATEST_MESSAGE_SIZE 512
+String latest_message_to_send = "";
+WiFiClient fdr_client;
+
+#define MAX_WIFI_READ_BUFFER_SIZE 32
+String wifi_read_buffer;
+
+enum communication_state
+{
+    idle,
+    waiting_for_response
+};
+
+communication_state current_communication_state = idle;
+
+bool filesystem_is_working;
+bool latest_message_from_file;
+long unsigned int low_file_pointer;
+long unsigned int high_file_pointer;
+
+//
 //	Struct to hold out authentication cookies
 //

@@ -134,12 +160,16 @@
 unsigned long nmea_housekeeping_interval 	   = 1000;  // Check on nmea connections every second
 unsigned long virtual_serial_housekeeping_interval = 500;   // Check on virtual serial connections every 1/2 second
 unsigned long console_read_interval		   = 300;   // Check on "console" (mostly stuff from main board) every 3/10's of a second
+unsigned long fdr_communications_interval	   = 200;   // Check ono status of pushing out FDR messages every 1/5 of a second

 unsigned long house_keeping_previous_timestamp = 0;
 unsigned long nmea_housekeeping_previous_timestamp = 0;
 unsigned long virtual_serial_housekeeping_previous_timestamp = 0;
 unsigned long console_previous_timestamp = 0;
+unsigned long fdr_communications_previous_timestamp = 0;
+
+
 //
 // Servers of many types and size for such a small little microprocessor :-)
 //
@@ -1806,6 +1836,141 @@

 }

+
+void showFileList(bool actually_show = true)
+{
+  low_file_pointer = 0;
+  high_file_pointer = 0;
+  if(!filesystem_is_working)
+  {
+    return;
+  }
+  if(true)
+  {
+    help_info(F("XXXXX BEG FILE LISTING XXXXX"));
+  }
+  String file_name;
+  int file_name_number = 0;
+  Dir dir = SPIFFS.openDir("/");
+  while(dir.next())
+  {
+    file_name = String(dir.fileName()).substring(1);
+    if(actually_show)
+    {
+      help_info(file_name);
+    }
+    if(file_name != "floathub.txt")
+    {
+      file_name_number = file_name.toInt();
+      if(file_name_number > 0)
+      {
+        if(low_file_pointer  == 0)
+        {
+          low_file_pointer = file_name_number;
+        }
+        else if(file_name_number < low_file_pointer)
+        {
+	  low_file_pointer = file_name_number;
+        }
+        if(file_name_number > high_file_pointer)
+        {
+          high_file_pointer = file_name_number;
+        }
+      }
+    }
+  }
+  if(actually_show)
+  {
+    help_info(String("LP=") + low_file_pointer + String(", HP=") + high_file_pointer);
+    help_info(F("XXXXX END FILE LISTING XXXXX"));
+  }
+}
+
+
+void popMessageQueue()
+{
+
+  if(!filesystem_is_working)
+  {
+    return;
+  }
+
+  if(low_file_pointer > 0)
+  {
+    latest_message_from_file = true;
+    #ifdef FILE_DEBUG_ON
+    debug_info(F("Rebuilding message ..."));
+    #endif
+    File f = SPIFFS.open("/" + String(low_file_pointer), "r");
+    if(!f)
+    {
+      debug_info("Oy Vey!");
+      return;
+    }
+    latest_message_to_send = "";
+    while(f.available())
+    {
+      latest_message_to_send += (char) f.read();
+    }
+    f.close();
+    #ifdef FILE_DEBUG_ON
+    debug_info(F("... done"));
+    #endif
+  }
+
+}
+
+
+
+
+
+
+bool initFileSystem()
+{
+  File checker = SPIFFS.open("/floathub.txt","r");
+  help_info(F("Formatting new filesystem"));
+  if(!SPIFFS.format())
+  {
+    help_info(F("BROKEN FILE SYSTEM A"));
+    filesystem_is_working = false;
+    return false;
+  }
+  checker = SPIFFS.open("/floathub.txt","w");
+  if(!checker)
+  {
+    help_info(F("BROKEN FILE SYSTEM B"));
+    filesystem_is_working = false;
+    return false;
+  }
+  checker.print("424242424242");
+  checker.close();
+  filesystem_is_working = true;
+  return true;
+}
+
+void setupFileSystem()
+{
+  SPIFFS.begin();
+
+  //
+  //  See if we can read our floathub.txt file. If we can't, this is a
+  // virgin filesystem and needs to be formatted
+  //
+
+  File checker = SPIFFS.open("/floathub.txt","r");
+
+  if(!checker)
+  {
+    initFileSystem();
+    return;
+  }
+
+  checker.close();
+  filesystem_is_working = true;
+
+  showFileList();
+}
+
 void setup(void)
 {

@@ -1815,7 +1980,10 @@

   console_read_buffer.reserve(MAX_CONSOLE_BUFFER);
   virtual_serial_read_buffer.reserve(MAX_CONSOLE_BUFFER);
-
+  latest_message_to_send.reserve(MAX_LATEST_MESSAGE_SIZE);
+  wifi_read_buffer.reserve(MAX_WIFI_READ_BUFFER_SIZE);
+  latest_message_to_send = "";
+  wifi_read_buffer = "";

   Serial.begin ( 115200 );

@@ -1854,6 +2022,11 @@
   help_info("");
   displayCurrentVariables();

+  //
+  //  Setup filesystem (do some checks, format if first time run, etc.)
+  //
+
+  setupFileSystem();

   //
   // Fire up the WiFi
@@ -1910,16 +2083,15 @@

   kickVirtualSerial();

-
-  uint32 flash_id = spi_flash_get_id();
-
-  Serial.print("I See the flash id as ");
-  Serial.println(flash_id);
-
-  Serial.print("And other method sees ");
-  Serial.println(ESP.getFlashChipId());
-
-
+  //
+  // If we have some, pop off an old message
+  //
+
+  if(low_file_pointer > 0)
+  {
+    popMessageQueue();
+    latest_message_from_file = true;
+  }
 }

 void echoNMEA(String a_message)
@@ -1936,6 +2108,96 @@
   }
 }

+void nukeOldestFile()
+{
+  if(!SPIFFS.remove("/" + String(low_file_pointer)))
+  {
+    debug_info(F("Can't delete file"), (int) low_file_pointer);
+  }
+  low_file_pointer += 1;
+}
+
+
+void pushMessageQueue(String a_message)
+{
+  if(filesystem_is_working)
+  {
+    //
+    // First check how much space we have left
+    //
+
+    #ifdef FILE_DEBUG_ON
+    debug_info(F("Free file space ..."));
+    #endif
+    FSInfo fs_info;
+    SPIFFS.info(fs_info);
+
+    long int space_left = fs_info.totalBytes - fs_info.usedBytes;
+
+    if(space_left > 1024)
+    {
+      #ifdef FILE_DEBUG_ON
+      debug_info(F("Enough free: "), (int) space_left);
+      #endif
+
+    }
+    else
+    {
+      #ifdef FILE_DEBUG_ON
+      debug_info(F("Not enough free: "), (int) space_left);
+      #endif
+      while(space_left <= 1024)
+      {
+        nukeOldestFile();
+        SPIFFS.info(fs_info);
+        space_left = fs_info.totalBytes - fs_info.usedBytes;
+      }
+    }
+
+    high_file_pointer += 1;
+    if(low_file_pointer == 0)
+    {
+      low_file_pointer += 1;
+    }
+
+    //
+    // Create a file called high_file_pointer and write the message inside it
+    //
+
+    File f = SPIFFS.open("/" + String(high_file_pointer), "w");
+    if(!f)
+    {
+      debug_info("very bad, can't creat file");
+    }
+    else
+    {
+      f.print(a_message);
+      f.close();
+    }
+  }
+  else
+  {
+    //
+    //  This is bad, we have nowhere to store previous message that we still
+    // have not sent. Best we can is to throw it away and replace with previous messaahe,
+    //
+
+    latest_message_to_send = a_message;
+  }
+}
+
+void queueMessage(String a_message)
+{
+  if(latest_message_to_send.length() == 0)
+  {
+    latest_message_to_send = a_message;
+    latest_message_from_file = false;
+  }
+  else
+  {
+    pushMessageQueue(a_message);
+  }
+}

 void nmeaHouseKeeping()
 {
@@ -1956,8 +2218,6 @@
     if(nmea_client[i] && !nmea_client[i].connected())
     {
       nmea_client[i].stop();
-      Serial.print("Nuked nmea client at position ");
-      Serial.println(i);
     }
   }
   //
@@ -1979,8 +2239,6 @@
     }
     nmea_client[i].stop();
     nmea_client[i] = nmea_server->available();
-    Serial.print("Added nmea client at position ");
-    Serial.println(i);
   }

   //
@@ -2033,12 +2291,20 @@
   {
     displayCurrentVariables();
   }
+  else if(the_input.charAt(0) == 'f')
+  {
+    showFileList();
+  }
+
   if(the_input.startsWith("factory"))
   {
     help_info("Doing factory reset ...");
     //init_eeprom_memory();
     //read_eeprom_memory();
-  }
+    help_info("FIX THIS HACK");
+    initFileSystem();
+  }
+
   else if(the_input.startsWith("E=") && the_input.length() >= 5) // Minimum NMEA sentence length (?)
   {
     echoNMEA(the_input.substring(2));
@@ -2047,6 +2313,17 @@
   else if(the_input.startsWith("E="))
   {
     debug_info(F("Bad NMEA"));
+  }
+  #endif
+
+  else if(the_input.startsWith("S=") && the_input.length() >= 5) // Minimum FHUB sentence length (?)
+  {
+    queueMessage(the_input.substring(2));
+  }
+  #ifdef INPT_DEBUG_ON
+  else if(the_input.startsWith("S="))
+  {
+    debug_info(F("Bad FHx"));
   }
   #endif

@@ -2537,11 +2814,67 @@
   }
 }

+bool openFdr()
+{
+  // Open a connection to the floathub server (usually fdr.floathub.net)
+
+
+  #ifdef WIFI_DEBUG_ON
+  debug_info(F("Opening fdr socket"));
+  #endif
+  if(fdr_client.connect(float_hub_server.c_str(), float_hub_server_port))
+  {
+    fdr_client.setNoDelay(true);
+    #ifdef WIFI_DEBUG_ON
+    debug_info(F("Success "));
+    #endif
+    return true;
+  }
+  else
+  {
+    #ifdef WIFI_DEBUG_ON
+    debug_info(F("Failure "));
+    #endif
+  }
+
+  return false;
+}
+
+
+bool push_latest_message_out_socket()
+{
+
+  if(fdr_client.connected())
+  {
+    if(fdr_client.write(latest_message_to_send.c_str(), latest_message_to_send.length()) == latest_message_to_send.length())
+    {
+      if(fdr_client.write("\r\n", 2) == 2)
+      {
+        return true;
+      }
+
+    }
+    #ifdef WIFI_DEBUG_ON
+    debug_info("Socket write failed");
+    #endif
+    return false;
+  }
+  #ifdef WIFI_DEBUG_ON
+  else
+  {
+    debug_info(F("socket write called, but not connected"));
+  }
+  #endif
+
+  return false;
+}
+
+
 void houseKeeping()
 {
   #ifdef STAT_DEBUG_ON
   IPAddress local = WiFi.localIP();
-  debug_info(String(F("WiFi.status()=")) + WiFi.status() + String(F(", IP address: ")) + local.toString());
+  debug_info(String(F("WiFi.status()=")) + WiFi.status() + String(F(", IP address: ")) + local.toString() + String(F(", latest_message=")) + latest_message_to_send) ;
   #endif

   long now = millis();
@@ -2552,6 +2885,10 @@
        nukeCookie(i);
     }
   }
+}
+
+void fdrHouseKeeping()
+{

   if(WiFi.status() == WL_CONNECTED && WiFi.localIP() > 0)
   {
@@ -2559,6 +2896,115 @@
     {
       called_mdns_after_connection = true;
       kickMDNS();
+    }
+
+    //
+    //	We are appear to be connected to something. If there's a message to send, we should do so
+    //
+
+    unsigned long current_timestamp = millis();
+    if(current_communication_state == idle)
+    {
+      if(latest_message_to_send.length() > 0)
+      {
+        if(openFdr())
+        {
+          if(push_latest_message_out_socket())
+          {
+            #ifdef WIFI_DEBUG_ON
+            debug_info(F("wifi Sent FHx"));
+            #endif
+            //gprs_or_wifi_watchdog_timestamp = current_timestamp;
+            current_communication_state = waiting_for_response;
+            wifi_read_buffer = "";
+          }
+          #ifdef WIFI_DEBUG_ON
+          else
+          {
+            debug_info(F("wifi sock prob"));
+            fdr_client.stop();
+          }
+          #endif
+        }
+        else
+        {
+          fdr_client.stop();
+        }
+      }
+    }
+    else if(current_communication_state == waiting_for_response)
+    {
+      unsigned long last_read = millis();
+      while (fdr_client.connected() && (millis() - last_read < 5000))
+      {
+        while (fdr_client.available() && wifi_read_buffer.length() < MAX_WIFI_READ_BUFFER_SIZE)
+        {
+          wifi_read_buffer += (char) fdr_client.read();
+          last_read = millis();
+        }
+      }
+      if(wifi_read_buffer.indexOf("$FHR$ OK") > -1)
+      {
+        //
+        // Yay! We have succesfully sent something
+        //
+	// Adjust message pointers if need be
+        //
+
+        if(latest_message_from_file)
+        {
+          if(low_file_pointer > 0)
+          {
+            nukeOldestFile();
+            if(low_file_pointer > high_file_pointer)
+            {
+	      // We have emptied the queue ..
+              low_file_pointer = 0;
+              high_file_pointer = 0;
+	    }
+          }
+	}
+
+
+        //gprs_or_wifi_watchdog_counter = 0;
+        //current_timestamp = millis();
+        //gprs_or_wifi_watchdog_timestamp = current_timestamp;
+
+        latest_message_to_send = "";
+        popMessageQueue();
+
+        if(latest_message_to_send.length() > 0)
+        {
+          if(push_latest_message_out_socket())
+          {
+            #ifdef WIFI_DEBUG_ON
+            debug_info(F("wifi more FHx"));
+            #endif
+            //current_timestamp = millis();
+            //gprs_or_wifi_watchdog_timestamp = current_timestamp;
+            current_communication_state = waiting_for_response;
+            wifi_read_buffer = "";
+          }
+          else
+          {
+            #ifdef WIFI_DEBUG_ON
+            debug_info(F("wifi Hangup"));
+            #endif
+            fdr_client.stop();
+            current_communication_state = idle;
+          }
+
+        }
+        else
+        {
+          #ifdef WIFI_DEBUG_ON
+          debug_info(F("WiFi queue done"));
+          #endif
+          wifi_read_buffer = "";
+          fdr_client.stop();
+          current_communication_state = idle;
+	}
+      }
     }
   }
   else
@@ -2602,6 +3048,13 @@

   unsigned long current_timestamp = millis();

+
+  if(current_timestamp - fdr_communications_previous_timestamp >  fdr_communications_interval)
+  {
+    fdr_communications_previous_timestamp = current_timestamp;
+    fdrHouseKeeping();
+
+  }
   if(current_timestamp - console_previous_timestamp > console_read_interval)
   {
     console_previous_timestamp = current_timestamp;


fix rgb client

fix rgb client

--- client/RGB_control/RGB_control.ino
+++ client/RGB_control/RGB_control.ino
@@ -153,7 +153,7 @@

 void setup_wifi() {
-
+  WiFi.mode(WIFI_STA);
   delay(10);
   // We start by connecting to a WiFi network
   Serial.println();
@@ -181,28 +181,26 @@

-void mqttReconnect() {
-  // Loop until we're reconnected
-  while (!mqttClient.connected()) {
-    Serial.print("Attempting MQTT connection...");
-    // Attempt to connect
-    if (mqttClient.connect(clientID.c_str())) {
-      Serial.println("connected");
-      for (int i = 0; i < subscriptions_length; i++ )
-      {
-        mqttClient.subscribe(subscriptions[i].c_str());
-        #if DEBUG
-          Serial.print("Subscribing to: ");
-          Serial.println(subscriptions[i]);
-        #endif
-      }
-    } else {
-      Serial.print("failed, rc=");
-      Serial.print(mqttClient.state());
-      Serial.println(" try again in 5 seconds");
-      // Wait 5 seconds before retrying
-      delay(5000);
+void mqttTryReconnect() {
+  Serial.print("Attempting MQTT connection...");
+  // Attempt to connect
+  if (mqttClient.connect(clientID.c_str())) {
+    Serial.println("connected");
+    for (int i = 0; i < subscriptions_length; i++ )
+    {
+      mqttClient.subscribe(subscriptions[i].c_str());
+      #if DEBUG
+        Serial.print("Subscribing to: ");
+        Serial.println(subscriptions[i]);
+      #endif
     }
+  } else {
+    Serial.print("failed, rc=");
+    Serial.print(mqttClient.state());
+    Serial.println(" try again in 5 seconds");
+    // Wait 5 seconds before retrying
+    delay(5000);
+
   }
 }

@@ -252,15 +250,15 @@
   setupOTA();
   mqttClient.setServer(mqtt_server, 1883);
   mqttClient.setCallback(callback);
-  mqttReconnect();
+  mqttTryReconnect();
   registration();
 }

 void loop() {
-  ArduinoOTA.handle();
-  if (!mqttClient.connected()) {
-    mqttReconnect();
+  while(!mqttClient.connected()) {
+    mqttTryReconnect();
+    ArduinoOTA.handle();
   }
   mqttClient.loop();
   fadeLoop();


lege testsketch weg

lege testsketch weg

--- software/arduino/test/test.ino
+++ software/arduino/test/test.ino
@@ -1,15 +0,0 @@
-// APA102 use the Rainbow example sketch
-// Button push turns on the led
-// TEMT6000 output the analogRead value to the serial monitor
-// LM75B output the temperature to the serial monitor
-
-
-void setup() {
-  // put your setup code here, to run once:
-
-}
-
-void loop() {
-  // put your main code here, to run repeatedly:
-
-}