Try to improve memory leak issue

Try to improve memory leak issue

--- client/client.ino
+++ client/client.ino
@@ -1,15 +1,16 @@
 #include "LiquidCrystal_I2C.h"
-#include "RestClient.h"
 #include "ArduinoJson.h"
 #include "NTPClient.h"
 #include "ESP8266WiFi.h"
+#include "ESP8266WiFiMulti.h"
+#include "ESP8266HTTPClient.h"
 #include "WiFiUdp.h"
 #include "TaskScheduler.h"

 const bool DEBUG = true;
 const char* serverAddress = "dublinpt.herokuapp.com";
 const char* wifiSid = "skyconway_com-2263";
-const char* wifiPassword = "*";
+const char* wifiPassword = "";
 const char* luasDataEndPoint = "/luas/tallaght";
 const char* weatherDataEndPoint = "/weather/Dublin,IE";
 const char* dublinbusDataEndPoint = "/bus/4646";
@@ -24,21 +25,20 @@
 const int   NtpInterval =  oneMinute;    // In miliseconds
 const char* NtpAddress =  "0.ie.pool.ntp.org";

-
 const int buttonPin = D5;
 int buttonState = 0;

-const size_t weatherJsonBufferSize = JSON_OBJECT_SIZE(3) + 90;
+const size_t weatherJsonBufferSize = JSON_OBJECT_SIZE(3) + 80;
 const size_t transportationJsonBufferSize = JSON_ARRAY_SIZE(3) + 3 * JSON_OBJECT_SIZE(2) + 80;

 LiquidCrystal_I2C lcd(0x27, lcdWidth, lcdHeight);

 WiFiUDP ntpUDP;
+ESP8266WiFiMulti WiFiMulti;
 NTPClient timeClient(ntpUDP, NtpAddress, NtpOffset, NtpInterval);

-RestClient client = RestClient(serverAddress);
-
 int lineNumber = MAXLINENUMBER;
+bool getData = false;

 // Callback methods prototypes
 void getWeatherData();
@@ -46,9 +46,7 @@
 void scheduleDataTasks();

 //Tasks
-Task taskGetTransportationData(oneMinute, TASK_FOREVER, &getTransportationData);
-Task taskGetWeatherData(eightHours, TASK_FOREVER, &getWeatherData);
-Task taskScheduleDataTasks(30000, TASK_FOREVER, &scheduleDataTasks);
+Task taskScheduleDataTasks(oneMinute, TASK_FOREVER, &scheduleDataTasks);

 Scheduler runner;

@@ -79,8 +77,6 @@

 void setupTaskManager() {
   runner.init();
-  runner.addTask(taskGetWeatherData);
-  runner.addTask(taskGetTransportationData);
   runner.addTask(taskScheduleDataTasks);
   taskScheduleDataTasks.enable();
   delay(5000);
@@ -92,8 +88,23 @@

 void setupNetwork() {
   serialPrint("Connecting...");
-  client.begin(wifiSid, wifiPassword);
-  serialPrint("Connected!");
+  WiFiMulti.addAP(wifiSid, wifiPassword);
+  tryNetWorkConnectionNthTime(5);
+}
+
+void tryNetWorkConnectionNthTime(int tryCount) {
+
+  while (WiFiMulti.run() != WL_CONNECTED && tryCount != 5) {
+    if ((WiFiMulti.run() == WL_CONNECTED)) {
+      serialPrint("Connected!");
+    }
+    else {
+      serialPrint("Could not connect in setup()");
+    }
+    delay(1000);
+    tryCount++;
+    serialPrint("Retrying connection", tryCount);
+  }
 }

 void setupLcd() {
@@ -104,43 +115,33 @@
 }

 void sleepingMode() {
-  if (!taskGetWeatherData.isEnabled()) {
-    taskGetWeatherData.disable();
-  }
-  if (!taskGetTransportationData.isEnabled()) {
-    taskGetTransportationData.disable();
-  }
-
   lcd.clear();
   lcd.noBacklight();
+  Serial.flush();
 }

 void scheduleDataTasks () {
-  const int hour = timeClient.getHours();
-  const int day = timeClient.getDay(); //0 is sunday 1,2,3,4,5,6
-
-  serialPrint("hour:", hour);
-  serialPrint("day:", day);
-  timeClient.update();
-  //weekdays
-  if (day>=1 && day<=5) {
-    //busy hour more requests here
-    if (hour >= 7 && hour <= 10 ) {
-      serialPrint("Enabling tasks for morning");
-      if (!taskGetWeatherData.isEnabled() && !taskGetTransportationData.isEnabled()) {
-        lcd.backlight();
-        taskGetWeatherData.enable();
-        taskGetTransportationData.enable();
-      }
+
+  if (WiFiMulti.run() != WL_CONNECTED){
+    tryNetWorkConnectionNthTime(2);
+  }
+  else {
+    const int hour = timeClient.getHours();
+    const int day = timeClient.getDay(); //0 is sunday 1,2,3,4,5,6
+
+    serialPrint("hour:", hour);
+    serialPrint("day:", day);
+    timeClient.update();
+    serialPrint("loop heap size:", ESP.getFreeHeap());
+
+    if  ((day >= 1 && day <= 5) && (hour >= 7 && hour <= 10)) {
+      lcd.backlight();
+      getTransportationData();
+      getWeatherData();
     }
     else {
       sleepingMode();
     }
-  }
-  //weekends
-  else {
-    serialPrint("Weekend work on demand");
-    sleepingMode();
   }
 }

@@ -158,7 +159,7 @@
     lcd.backlight();
     getTransportationData();
     getWeatherData();
-    delay(10000);
+    delay(1000);
   }
 }

@@ -179,11 +180,28 @@
 }

 String getRequest(const char* endPoint) {
-  String response = "";
-  const int statusCode = client.get(endPoint, &response);
-  serialPrint("Status code:", statusCode);
-  serialPrint(response);
-  return response;
+  if ((WiFiMulti.run() == WL_CONNECTED)) {
+    serialPrint("Connected!");
+    HTTPClient http;
+    http.begin(serverAddress, 80, endPoint);
+
+    const int statusCode = http.GET();
+    serialPrint("Status code:", statusCode);
+
+    if (statusCode != HTTP_CODE_OK) {
+      return "0";
+    }
+    const String payload = http.getString();
+    serialPrint(payload);
+    http.end();
+
+    return payload;
+  }
+  else {
+    serialPrint("Could not connect network");
+    return "0";
+  }
+  delay(1000);
 }

 void getTransportationData() {
@@ -194,6 +212,11 @@

   const String dublinBusData = getRequest(dublinbusDataEndPoint);
   const String luasData = getRequest(luasDataEndPoint);
+
+  //if there is no data break from function
+  if (dublinBusData == "0" && luasData == "0") {
+    return;
+  }

   JsonArray& rootJsonLuas = jsonBufferTram.parseArray(luasData);
   JsonArray& rootJsonDublinBus = jsonBufferBus.parseArray(dublinBusData);
@@ -303,6 +326,10 @@

   const String weatherData = getRequest(weatherDataEndPoint);

+  if (weatherData == "0") {
+    return;
+  }
+
   JsonObject& rootJson = jsonBuffer.parseObject(weatherData);

   if (!rootJson.success()) {


implement receiving data

implement receiving data

--- ble_heart_rate_template.ino
+++ ble_heart_rate_template.ino
@@ -43,11 +43,23 @@
 static bool radio_ack_pending  = false;
 static bool timing_change_done = false;
 static bool timing_high = false;
+static bool timing_resp = true;
 static uint8_t current_heart_rate_data[HR_MAX_PAYLOAD];

 const int analogInPin = I0;

 int sensorValue = 200;
+
+void printData(aci_evt_t * aci_evt) {
+	int i = 0;
+	Serial.print(F("Data(HEX) : "));
+	for(i = 0; i < aci_evt->len - 2; i++)
+	{
+		Serial.print(aci_evt->params.data_received.rx_data.aci_data[i], HEX);
+		Serial.print(F(" "));
+	}
+	Serial.println(F(""));
+}

 void setup(void)
 {
@@ -98,18 +110,18 @@
 						When the device is in the setup mode
 						*/
 						aci_state.device_state = ACI_DEVICE_SETUP;
-						Serial.println("Evt Device Started: Setup");
+						Serial.println(F("Evt Device Started: Setup"));
 						if (ACI_STATUS_TRANSACTION_COMPLETE != do_aci_setup(&aci_state))
 						{
-							Serial.println("Error in ACI Setup");
+							Serial.println(F("Error in ACI Setup"));
 						}
 						break;

 						case ACI_DEVICE_STANDBY:
 							aci_state.device_state = ACI_DEVICE_STANDBY;
-							Serial.println("Evt Device Started: Standby");
+							Serial.println(F("Evt Device Started: Standby"));
 							lib_aci_connect(180/* in seconds */, 0x0100 /* advertising interval 100ms*/);
-							Serial.println("Advertising started for 180s");
+							Serial.println(F("Advertising started for 180s"));
 							break;
 					}
 				}
@@ -123,17 +135,34 @@
 					//TRANSACTION_CONTINUE and TRANSACTION_COMPLETE
 					//all other ACI commands will have status code of ACI_STATUS_SCUCCESS for a successful command

-					Serial.print("ACI Status of ACI Evt Cmd Rsp 0x");
+					Serial.print(F("ACI Status of ACI Evt Cmd Rsp 0x"));
 					Serial.println(aci_evt->params.cmd_rsp.cmd_status, HEX);
-					Serial.print("ACI Command 0x");
-					Serial.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX);
-					Serial.println("Evt Cmd respone: Error. Arduino is in an while(1); loop");
-					while (1);
-				}
+					Serial.print(F("ACI Command 0x"));
+					Serial.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX);
+					if(aci_evt->params.cmd_rsp.cmd_opcode == ACI_CMD_CHANGE_TIMING) {
+						switch(aci_evt->params.cmd_rsp.cmd_status) {
+							case ACI_STATUS_ERROR_REJECTED:
+							case ACI_STATUS_ERROR_BUSY:
+								break;
+							case ACI_STATUS_ERROR_INVALID_PARAMETER:
+							case ACI_STATUS_ERROR_INVALID_LENGTH:
+							case ACI_STATUS_ERROR_INVALID_DATA:
+								timing_change_done = true;
+								break;
+						}
+					}
+				}  else {
+					Serial.println(F("ACI Status SUCCESSFUL"));
+					Serial.print(F("ACI Status of ACI Evt Cmd Rsp 0x"));
+					Serial.println(aci_evt->params.cmd_rsp.cmd_status, HEX);
+					Serial.print(F("ACI Command 0x"));
+					Serial.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX);
+					timing_change_done = true;
+				}
 				break;

 			case ACI_EVT_PIPE_STATUS:
-				Serial.println("Evt Pipe Status");
+				Serial.println(F("Evt Pipe Status"));
 				/** check if the peer has subscribed to the Heart Rate Measurement Characteristic for Notifications
 				*/
 				if (lib_aci_is_pipe_available(&aci_state, PIPE_HEART_RATE_HEART_RATE_MEASUREMENT_TX)
@@ -152,24 +181,24 @@
 				/*
 				Link timing has changed.
 				*/
-				Serial.println("Timing changed");
+				Serial.print(F("Timing changed -> 0x"));
 				Serial.println(aci_evt->params.timing.conn_rf_interval, HEX);

-				Serial.print("Connection interval: ");
-				Serial.println(aci_state.connection_interval);
-
-				Serial.print("slave_latency: ");
+				Serial.print(F("Connection interval: "));
+				Serial.println(aci_state.connection_interval * 1.25);
+
+				Serial.print(F("Slave_latency: "));
 				Serial.println(aci_state.slave_latency);
 				break;

 			case ACI_EVT_CONNECTED:
 				radio_ack_pending  = false;
 				timing_change_done = false;
-				Serial.println("Evt Connected");
-				Serial.print("Connection interval: ");
+				Serial.println(F("Evt Connected"));
+				Serial.print(F("Connection interval: "));
 				Serial.println(aci_state.connection_interval);

-				Serial.print("slave_latency: ");
+				Serial.print(F("slave_latency: "));
 				Serial.println(aci_state.slave_latency);
 				break;

@@ -192,29 +221,44 @@
 				radio_ack_pending = false;
 				break;
 	 	    case ACI_EVT_DATA_RECEIVED:
-		        Serial.print(F("DATA RECEIVED"));
+		        Serial.println(F("DATA RECEIVED"));
 		        Serial.print(F("Pipe #: 0x"));
 		        Serial.println(aci_evt->params.data_received.rx_data.pipe_number, HEX);
-		        {
-		          int i=0;
-		          Serial.print(F(" Data(HEX) : "));
-		          for(i=0; i<aci_evt->len - 2; i++)
-		          {
-		            Serial.print(aci_evt->params.data_received.rx_data.aci_data[i], HEX);
-		            Serial.print(F(" "));
-		          }
+
+		        switch(aci_evt->params.data_received.rx_data.pipe_number) {
+		        	case PIPE_CONNECTIONCONTROL_CONNECTIONINTERVAL_RX_ACK_AUTO:
+		        		Serial.println(F("CONNECTION_INTERVAL: "));
+
+		        		printData(aci_evt);
+
+		        		int x;
+
+		        		uint8_t value_array[aci_evt->len - 2];
+		        		uint16_t value;
+
+						for(x = 0; x < aci_evt->len - 2; x++)
+						{
+							value_array[x] = aci_evt->params.data_received.rx_data.aci_data[x];
+							Serial.print(value_array[x], BIN);
+							Serial.print(" ");
+						}
+						Serial.println("");
+
+						value = value_array[1] + ((uint16_t)value_array[0] << 8);
+		        		Serial.print(F("Value in decimal: "));
+		        		Serial.println(value, BIN);
+		        		Serial.println(value, DEC);
+		        		break;
+		        	case PIPE_CONNECTIONCONTROL_SLAVELATENCY_RX_ACK_AUTO:
+		        		Serial.println(F("SLAVELATENCY: "));
+		        		break;
+		        	case PIPE_CONNECTIONCONTROL_SAMPLINGRATE_RX_ACK_AUTO:
+		        		Serial.println(F("SAMPLING_RATE: "));
+		        		printData(aci_evt);
+		        		break;
+		        	default:
+		        		printData(aci_evt);
 		        }
-		        Serial.println(F(""));
-		        lib_aci_send_ack(&aci_state, aci_evt->params.data_received.rx_data.pipe_number);
-		        Serial.println(F("Setting connection parameter"));
-		        if(timing_high) {
-			        lib_aci_change_timing(1250, 1250, 2, 600);
-					timing_high = false;
-		        } else {
-			        lib_aci_change_timing(625, 625, 0, 100);
-			        timing_high = true;
-		        }
-
 		        break;
 			 case ACI_EVT_DISCONNECTED:
 				/**
@@ -222,18 +266,18 @@
 				*/
 				if(ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status)
 				{
-					Serial.println("Evt Disconnected -> Advertising timed out");
+					Serial.println(F("Evt Disconnected -> Advertising timed out"));
 					{
-						Serial.println("nRF8001 going to sleep");
+						Serial.println(F("nRF8001 going to sleep"));
 						lib_aci_sleep();
 						aci_state.device_state = ACI_DEVICE_SLEEP;
 					}
 				}
 				else
 				{
-					Serial.println("Evt Disconnected -> Link lost.");
+					Serial.println(F("Evt Disconnected -> Link lost."));
 					lib_aci_connect(180/* in seconds */, 0x0050 /* advertising interval 50ms*/);
-					Serial.println("Advertising started for 180s");
+					Serial.println(F("Advertising started for 180s"));
 				}
 				break;

@@ -292,11 +336,11 @@
 		current_heart_rate_data[data_index] = buffer_pop();
 		data_index++;
 	}
-	Serial.print("Data Index - ");
+	Serial.print(F("Data Index - "));
 	Serial.println(data_index);
 	boolean success = lib_aci_send_data(PIPE_HEART_RATE_HEART_RATE_MEASUREMENT_TX, (uint8_t *)&current_heart_rate_data[0] ,data_index);

-	Serial.print("Send Data - ");
+	Serial.print(F("Send Data - "));
 	Serial.println(success);
 	if(success) {
 		radio_ack_pending = true;
@@ -306,30 +350,49 @@
 void loop()
 {
 	// sensorValue = analogRead(analogInPin);
-	sensorValue++;
-
-	int push = buffer_push(sensorValue);
-
-	if(push == 1) {
-		Serial.print(sensorValue);
-		Serial.print(" @ ");
-		Serial.println(buffer_size());
-	} else {
-		Serial.println(F("Data buffering failed!"));
-	}
-
-	analyseData();
+	// sensorValue++;
+
+	// Serial.println(sensorValue);
+	// if(sensorValue > 215 && timing_change_done == true) {
+	// 	Serial.println(F("Setting connection parameter"));
+	// 	if(timing_high) {
+
+	// 		Serial.println(F("HIGH"));
+	// 	    timing_resp = lib_aci_change_timing((uint16_t) 2560, (uint16_t) 2560, (uint16_t) 2, (uint16_t) 200);
+	// 		timing_high = false;
+	// 		timing_change_done = false;
+	// 	} else {
+	// 		Serial.println(F("LOW"));
+	// 	    timing_resp = lib_aci_change_timing((uint16_t) 900, (uint16_t) 900, (uint16_t) 0, (uint16_t) 200);
+	// 	    timing_high = true;
+	// 		timing_change_done = false;
+	// 	}
+	// 	Serial.print(F("Resp: "));
+	// 	Serial.println(timing_resp);
+	// 	sensorValue = 200;
+	// }
+	// int push = buffer_push(sensorValue);
+
+	// if(push == 1) {
+		// Serial.print(sensorValue);
+	// 	Serial.print(" @ ");
+	// 	Serial.println(buffer_size());
+	// } else {
+	// 	Serial.println(F("Data buffering failed!"));
+	// }
+
+	// analyseData();

 	aci_loop();

-	if (isChannelOpen())
-	{
-		Serial.println("Channel open");
-		handleCommands();
-		if(checkTransmissionCriteria()) {
-			sendData();
-		}
-	}
+	// if (isChannelOpen())
+	// {
+	// 	Serial.println("Channel open");
+	// 	handleCommands();
+	// 	if(checkTransmissionCriteria()) {
+	// 		sendData();
+	// 	}
+	// }

 	delay(1000);
 }


Added link to FSK wiki page

Added link to FSK wiki page

--- examples/FSKModem/FSKModem.ino
+++ examples/FSKModem/FSKModem.ino
@@ -5,6 +5,9 @@

    For more detailed information, see the LoRaLib Wiki
    https://github.com/jgromes/LoRaLib/wiki
+
+   For more information on FSK modem, see
+   https://github.com/jgromes/LoRaLib/wiki/FSK-Modem
 */

 // include the library


working ard attiny85 non sound code

working ard attiny85 non sound code

--- eggfckr_ard/eggfckr_ard.ino
+++ eggfckr_ard/eggfckr_ard.ino
@@ -6,18 +6,18 @@
   http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html
 */

-#define speaker_pin   0    // speaker_pin on GPIO #0
-#define SCALE     2.0  // You can change this to change the tone scale
+//#define speaker_pin   0    // speaker_pin on GPIO #0
+//#define SCALE     2.0  // You can change this to change the tone scale

 #define led1 2
-#define led2 1
-#define pot A3
+#define led2 3
+#define pot A2
 #define hightimes 10 //time to keep led on in cycle

 int logy = 5;

 void setup() {
-  pinMode(speaker_pin, OUTPUT);
+  //pinMode(speaker_pin, OUTPUT);

   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);
@@ -46,7 +46,7 @@
   */
 }

-
+/*
 // the sound producing function
 void beep (unsigned char speaker_pinPin, int frequencyInHertz, long timeInMilliseconds)
 { // http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html
@@ -81,4 +81,4 @@
   if (note == 'H')
     beep(speaker_pin, 4186, 500); //C
 }
-
+*/


Update dht_11.ino

Update dht_11.ino

Agregando Codigo de Ethernet shield

--- dht_11.ino
+++ dht_11.ino
@@ -1,3 +1,11 @@
+#include <Dhcp.h>
+#include <Dns.h>
+#include <Ethernet.h>
+#include <EthernetClient.h>
+#include <EthernetServer.h>
+#include <EthernetUdp.h>
+#include <stdlib.h>
+#include <SPI.h>
 #include "DHT.h"
 #define DHTPIN 2
 #define DHTTYPE DHT11
@@ -5,10 +13,23 @@
 int pinLDR = A0;
 int valorLDR = 0;

+byte mac[] = {
+0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10,2,50,59 };
+byte server[] = { 31,170,165,240 };
+IPAddress dnServer(8,8,8,8);
+// the router's gateway address:
+IPAddress gateway(10, 2, 50,1);
+
+IPAddress subnet(255, 255, 255, 0);
+EthernetClient client;
+String readString=String(30);
 //librerias del DHT 11
 void setup() {
+Ethernet.begin(mac, ip, dnServer, gateway, subnet);
+dht.begin(); //Se inicia el sensor
+delay(1000);
 Serial.begin(9600); //Se inicia la comunicación serial
-dht.begin(); //Se inicia el sensor
 }

 void loop(){


Fully functioning prototype.  NO ERROR HANDLING

--- fingerprint.ino
+++ fingerprint.ino
@@ -2,6 +2,7 @@

 //Error pin to flash on error
 int ERROR_PIN = 13;
+int LIGHT_PIN = 7;
 /**
  * Enumeration of commands
  * Value set to control code of command
@@ -22,8 +23,8 @@
   IDENTIFY = 0x51,
   CAPTURE_FINGER = 0x60,
   ACK = 0x30,
-  NO_ACK = 0x31
-
+  NAK = 0x31,
+  DELETE_ALL = 0x41
 } Command;

 /**
@@ -42,17 +43,26 @@
   long len;
 } CommandPacket;

-
+//Builtin functions
 void setup();
 void loop();
-void error(int error);
+//Table of Contents functions
+void start();
+void enroll(Command cmd, uint32_t param);
+//Utility functions
+void flash(uint32_t num,int time);
+//Error leaf function
+void error(uint32_t error);
+//Send packet functions
 CommandPacket* getCommand(Command cmd);
 void setParameter(CommandPacket* packet,uint16_t value);
 void fillChecksum(uint8_t* bytes,long len);
-CommandPacket* sendCommand(CommandPacket* packet);
+uint32_t sendCommand(CommandPacket* packet);
+//Read packet functions
+CommandPacket* readCommand();
+//Bytes read send
 void sendBytes(uint8_t* bytes,long len);
-CommandPacket* readCommand();
-void readBytes(uint8_t* bytes,long len);
+void recvBytes(uint8_t* bytes,long len);

 /**
  * Setups up the baudrate to be 9600 and
@@ -61,13 +71,94 @@
 void setup()
 {
   pinMode(ERROR_PIN, OUTPUT);
+  pinMode(LIGHT_PIN, OUTPUT);
+  digitalWrite(LIGHT_PIN,HIGH);
   Serial.begin(9600);
   //Wait for the serial pins to connect (May only be needed for Leonardo board)
   while (!Serial) {}
-  CommandPacket* init = getCommand(OPEN);
-  CommandPacket* resp = sendCommand(init);
-  free(init);
-  free(resp);
+  //Turn on light
+  CommandPacket* led = getCommand(CMOS_LED);
+  setParameter(led,1);
+  sendCommand(led);
+  delay(1000);
+  setParameter(led,0);
+  sendCommand(led);
+  free(led);
+  //Start: enroll if needed
+  //led = getCommand(DELETE_ALL);
+  //sendCommand(led);
+  //free(led);
+  start();
+}
+/**
+ * Flash the CMOS LED
+ * num - number of times to flash
+ */
+void flash(uint32_t num,int time)
+{
+  CommandPacket* led = getCommand(CMOS_LED);
+  while (num-- > 0) {
+    setParameter(led,1);
+    sendCommand(led);
+    delay(time);
+    setParameter(led,0);
+    sendCommand(led);
+    delay(time);
+  }
+  free(led);
+}
+/**
+ * Start by enrolling, if none enrolled
+ */
+void start() {
+  CommandPacket* cmd = getCommand(OPEN);
+  sendCommand(cmd);
+  free(cmd);
+  //Get number enrolled...if zero, enroll
+  cmd = getCommand(GET_ENROLL_COUNT);
+  uint32_t param = sendCommand(cmd);
+  free(cmd);
+  flash(param,100);
+  if (param == 0)
+  {
+    //Signal enroll
+    flash(3,300);
+    enroll(ENROLL_START,param);
+  }
+}
+/**
+ * Enroll.  Recursively runs the command 4 times.
+ * cmd - command ENROLL_START, ENROLL!, ENROLL2, ENROLL3
+ * param - id to enroll (used only for start)
+ */
+void enroll(Command cmd, uint32_t param)
+{
+  //LED on for capture
+  CommandPacket* led = getCommand(CMOS_LED);
+  setParameter(led,1);
+  sendCommand(led);
+  //For enroll commands wait until finger pressed
+  CommandPacket* finger = getCommand(IS_PRESS_FINGER);
+  while (cmd >= ENROLL1 && cmd <= ENROLL3 && sendCommand(finger) != 0) {}
+  free(finger);
+  //Enroll commands in order: START, 1,2,3
+  CommandPacket* packet = getCommand(cmd);
+  switch(cmd) {
+    case ENROLL_START:
+      setParameter(packet,param);
+    case ENROLL1:
+    case ENROLL2:
+    case ENROLL3:
+      param = sendCommand(packet);
+      setParameter(led,0);
+      sendCommand(led);
+      delay(1000);
+      enroll((Command)(cmd+1),0);
+    case ENROLL3+1:
+      break;
+  }
+  free(packet);
+  free(led);
 }
 /**
  * Flashes LED
@@ -75,46 +166,35 @@
 void loop()
 {
   CommandPacket* led = getCommand(CMOS_LED);
-  CommandPacket* res;
-  while (true)
-  {
-    setParameter(led,1);
-    res = sendCommand(led);
-    //if (res->cmd == ACK)
-    digitalWrite(ERROR_PIN, LOW);
-    //else
-    //  digitalWrite(ERROR_PIN, LOW);
-    free(res);
-    delay(5000);
+  setParameter(led,1);
+  sendCommand(led);
+
+  CommandPacket* finger = getCommand(IS_PRESS_FINGER);
+  while (sendCommand(finger) != 0) {}
+  free(finger);
+  CommandPacket* id = getCommand(IDENTIFY);
+  if(sendCommand(id) < 199) {
+    digitalWrite(LIGHT_PIN,!digitalRead(LIGHT_PIN));
     setParameter(led,0);
-    res = sendCommand(led);
-    //if (res->cmd == ACK)
-      digitalWrite(ERROR_PIN, HIGH);
-    //else
-    //  digitalWrite(ERROR_PIN, HIGH);
-    free(res);
-    delay(5000);
-  }
+    sendCommand(led);
+    delay(1000);
+  }
+  free(id);
+  free(led);
+
 }
 /**
  * Flash arduino LED on error
  * error - number of times to flash
  */
-void error(int error)
+void error(uint32_t error)
 {
   Serial.end();
   int i = 0;
   while(true)
   {
-    //Flash "error" number of times.
-    for (i = 0; i < error; i++)
-    {
-      digitalWrite(ERROR_PIN, HIGH);
-      delay(200);
-      digitalWrite(ERROR_PIN, LOW);
-      delay(200);
-    }
-    delay(1800);
+    flash(error,500);
+    delay(1500);
   }
 }

@@ -165,11 +245,19 @@
 /**
  * Send a command packet recieves responce
  * packet - command packet to send
- */
-CommandPacket* sendCommand(CommandPacket* packet)
+ * return - parameter from command
+ */
+uint32_t sendCommand(CommandPacket* packet)
 {
   sendBytes((uint8_t*)packet,packet->len);
-  return readCommand();
+  packet = readCommand();
+  //If NAK error, otherwise return param
+  uint32_t param = packet->param;
+  uint16_t cmd = packet->cmd;
+  free(packet);
+  //if (cmd == NAK)
+  //  error(param);
+  return param;
 }
 /**
  * Sends bytes.  All is little endian so no conversion necessary.
@@ -179,7 +267,13 @@
 void sendBytes(uint8_t* bytes,long len)
 {
   fillChecksum(bytes,len);
-
+  int i = 0;
+  /*Serial.print("< ");
+  for (i = 0; i < len; i++) {
+    Serial.print(bytes[i],HEX);
+    Serial.print(" ");
+  }
+  Serial.println();*/
   if (Serial.write(bytes,len) != len)
     error(10);
 }
@@ -191,23 +285,39 @@
 {
   //Get empty command so memory is zeroed, and len is set
   CommandPacket* packet = getCommand(NIL);
-  readBytes((uint8_t*)packet,packet->len);
+  recvBytes((uint8_t*)packet,packet->len);
+  return packet;
 }
 /**
  * Reads bytes.  All is little endian so no conversion necessary.
  * bytes - pointer to bytes to read into
  * len - length of bytes
  */
-void readBytes(uint8_t* bytes,long len)
+void recvBytes(uint8_t* bytes,long len)
 {
   //Read bytes waiting if data is not found
   long i = 0;
-  for (i = 0; i < len; i++)
+  long j = 0;
+  for (i = 0; i < len;)
   {
     int b = Serial.read();
     if (b == -1)
-      delay(10);
-    bytes[i] = (uint8_t) b;
-  }
-}
-
+    {
+      /*for (j = 0; j < i+1; j++) {
+        digitalWrite(ERROR_PIN, HIGH);
+        delay(100);
+        digitalWrite(ERROR_PIN, LOW);
+        delay(100);
+      }
+      delay(1000);*/
+      continue;
+    }
+    bytes[i++] = (uint8_t) b;
+  }
+  /*Serial.print("< ");
+  for (i = 0; i < len; i++) {
+    Serial.print(bytes[i],HEX);
+    Serial.print(" ");
+  }
+  Serial.println();*/
+}


Fixed to reference error of SPIFFS.

Fixed to reference error of SPIFFS.

--- esp4scratch/esp4scratch.ino
+++ esp4scratch/esp4scratch.ino
@@ -4,6 +4,7 @@
 #include <ESP8266WebServer.h>
 #include <ESP8266mDNS.h>
 #include <EEPROM.h>
+#include <FS.h>

 #include "WiFiConfServer.h"


Initialize prev_text

Initialize prev_text

--- moros/moros.ino
+++ moros/moros.ino
@@ -62,6 +62,7 @@
   TFT *tft;
   Screen(unsigned int cs_pin, unsigned int dc_pin, unsigned int rst_pin) {
     tft = new TFT(cs_pin, dc_pin, rst_pin);
+    prev_text[0] = '\0';
   };
   void init() {
     tft->begin();


+ Proxy Sensor works now well.

+ Proxy Sensor works now well.

--- ClydeClock/ProxySens.ino
+++ ClydeClock/ProxySens.ino
@@ -4,7 +4,7 @@
 // connection notes:
 // Has to be connected to digital pins (NOT A...)
 // Gnd -> GND
-// Echo -> 4
+// Echo -> 10
 // Trig -> 12
 // Vcc -> +5V

@@ -12,8 +12,8 @@

 #include <NewPing.h>

+#define proxy_sens_echo 10           // the pin to which the HC-SR04 echo pin has been attached.
 #define proxy_sens_trig 12          // the pin to which the HC-SR04 trigger pin has been attached.
-#define proxy_sens_echo 4           // the pin to which the HC-SR04 echo pin has been attached.
 #define proxy_sens_max_distance 300 // the maximum distance.

 int proxy_sens_basal_dist = 0;  // the basal, initial distance measured by the sensor.
@@ -21,7 +21,7 @@
 //int PROXY_SENS_THRESH = 1;      // the threshold value, if we get closer by PROXY_SENS_THRESH cm we trigger an action.
 int PROXY_SENS_TRIGGER_DISTANCE = 4;    // trigger distance in cm. if we get closer we trigger an action.
 uint32_t PROXY_SENS_TRIGGER_SLEEP = 1000;  // time in ms we don't trigger another action if one was triggered.
-uint32_t PROXY_SENS_PING_SLEEP = 100;       // time in ms we wait between pings.
+uint32_t PROXY_SENS_PING_SLEEP = 70;        // time in ms we wait between pings.
 uint32_t proxy_sens_last_ping = 0;          // last time we sent a ping.

 NewPing sonar( proxy_sens_trig, proxy_sens_echo, proxy_sens_max_distance );
@@ -48,16 +48,18 @@
 // threshold value we trigger an action.
 // we may want to wait 50ms between readings, since the waves may echo around for a while...
 void updateProxySens(){
-  if( ( millis() - proxy_sens_last_ping ) < PROXY_SENS_PING_SLEEP ){
+  uint32_t ps_current_time = millis();
+  if( ( ps_current_time - proxy_sens_last_ping ) < PROXY_SENS_PING_SLEEP ){
     // we return, since we want to have some time between pings.
     return;
   }
-  if( ( millis() - proxy_sens_last_action_triggered ) < PROXY_SENS_TRIGGER_SLEEP ){
+  if( ( ps_current_time - proxy_sens_last_action_triggered ) < PROXY_SENS_TRIGGER_SLEEP ){
     // means we will sleep for some time and don't trigger another action.
     return;
   }
-  unsigned int uS = sonar.ping();
-  //unsigned int uS = sonar.ping_median( 5 );
+  //unsigned int uS = sonar.ping();
+  unsigned int uS = sonar.ping_median( 5 );
+  proxy_sens_last_ping = ps_current_time;
   int current_distance = (int)( uS / US_ROUNDTRIP_CM );
 #ifdef PROXYSENS_DEBUG
   Serial << "ProxySens: distance is: " << current_distance << endl;
@@ -65,6 +67,7 @@
   // simple stuff, if we are closer than 4cm trigger an action.
   if( current_distance < PROXY_SENS_TRIGGER_DISTANCE ){
     switchLights();
+    proxy_sens_last_action_triggered = ps_current_time;
   }
 }


interrupt example fix

interrupt example fix

--- examples/More/ButtonInterrupt/ButtonInterrupt.ino
+++ examples/More/ButtonInterrupt/ButtonInterrupt.ino
@@ -30,6 +30,8 @@
 // Go to the Project Settings (nut icon).
 char auth[] = "YourAuthToken";

+WidgetLED led1(V1);
+
 void setup()
 {
   Serial.begin(9600);
@@ -44,8 +46,11 @@
 void checkPin()
 {
   // Invert state, since button is "Active LOW"
-  int state = !digitalRead(2);
-  Blynk.virtualWrite(V1, state);
+  if (digitalRead(2)) {
+      led1.off();
+  } else {
+      led1.on();
+  }
 }

 void loop()


ZigBee

ZigBee

--- examples/Unit/Zigbee_CC2630/P2P_TEST/P2P_TEST.ino
+++ examples/Unit/Zigbee_CC2630/P2P_TEST/P2P_TEST.ino
@@ -1,9 +1,22 @@
 /*
-    Description:
-    Supports configuring the Zigbee module into 3 working modes `Coordinator`, `Router`, `End Device`
-    You need to configure a `Coordinator` when using, and other devices can be configured as `End Device` for data sending and receiving.
-    Note: 16 and 17 of the DIP switch are set to ON. This case needs to use the Keyboard in the FACE Kit for information input
+*******************************************************************************
+* Copyright (c) 2021 by M5Stack
+*                  Equipped with M5Core sample source code
+*                          配套  M5Core 示例源代码
+* Visit the website for more information：https://docs.m5stack.com/en/unit/zigbee
+* 获取更多资料请访问：https://docs.m5stack.com/zh_CN/unit/zigbee
+*
+* describe: zigbee.
+* date：2021/8/27
+*******************************************************************************
+  Please connect to Port C,Supports configuring the Zigbee module into 3 working modes `Coordinator`, `Router`, `End Device`
+  请连接端口C,支持将Zigbee模块配置为3种工作模式“协调器”、“路由器”、“终端设备”
+  You need to configure a `Coordinator` when using, and other devices can be configured as `End Device` for data sending and receiving.
+  使用时需要配置一个“Coordinator”，其他设备可以配置为“End Device”，用于数据的发送和接收。
+  Note: 16 and 17 of the DIP switch are set to ON. This case needs to use the Keyboard in the FACE Kit for information input
+  注:拨码开关16、17为ON。这种情况需要使用FACE Kit中的键盘进行信息输入
 */
+

 #include "M5Stack.h"
 #include "byteArray.h"
@@ -18,20 +31,20 @@

 uint16_t atNow = 29999;
 uint16_t iconpos[3][6] = {
-    {0, 40, 120, 140, 53, 0},
-    {100, 40, 120, 140, 0, 0},
-    {257, 40, 63, 140, 0, 0},
+  {0, 40, 120, 140, 53, 0},
+  {100, 40, 120, 140, 0, 0},
+  {257, 40, 63, 140, 0, 0},
 };

 const uint8_t *iconptrbuff[3] = {
-    coordinator_jpeg_120x140,
-    endDevice_jpeg_120x140,
-    router_jpeg_120x140,
+  coordinator_jpeg_120x140,
+  endDevice_jpeg_120x140,
+  router_jpeg_120x140,
 };
 size_t iconSizeBuff[3] = {
-    27537,
-    24609,
-    26433,
+  27537,
+  24609,
+  26433,
 };

 char asciiHexList[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
@@ -40,352 +53,352 @@

 int drawChatBubbles(String str,uint16_t addr)
 {
-    uint16_t posY = 76;
-    M5.Lcd.drawJpg(chatBubblesTop, 10561, 60, 66, 229, 10);
-    M5.Lcd.setTextDatum(TL_DATUM);
-    M5.Lcd.setTextColor(M5.Lcd.color565(0x44, 0x44, 0x44));
-    while (str.length() > 0)
+  uint16_t posY = 76;
+  M5.Lcd.drawJpg(chatBubblesTop, 10561, 60, 66, 229, 10);
+  M5.Lcd.setTextDatum(TL_DATUM);
+  M5.Lcd.setTextColor(M5.Lcd.color565(0x44, 0x44, 0x44));
+  while (str.length() > 0)
+  {
+      M5.Lcd.fillRect(60, posY, 228, 30, M5.Lcd.color565(0x88, 0xd1, 0xff));
+      String dispalyStr = str.substring(0, 24);
+      M5.Lcd.drawString(dispalyStr, 75, posY + 2, 2);
+      str.remove(0, 24);
+      posY += 20;
+  }
+  M5.Lcd.drawJpg(chatBubblesBottom, 11546, 60, posY, 229, 20);
+
+  M5.Lcd.fillEllipse(27,posY+18,23,23,M5.Lcd.color565(200, 200, 200));
+
+  char panIDchar[5] = {0, 0, 0, 0, 0};
+  for (int i = 0; i < 4; i++)
+  {
+      panIDchar[i] = asciiHexList[addr & 0x000f];
+      addr >>= 4;
+  }
+
+  M5.Lcd.setTextDatum(CC_DATUM);
+  M5.Lcd.setTextColor(M5.Lcd.color565(20, 20, 20));
+  M5.Lcd.drawString(panIDchar,27,posY+20);
+  return posY;
+}
+
+void setup()
+{
+  M5.begin();
+  Serial2.begin(38400, SERIAL_8N1, 16, 17);
+
+  zigbee.begin(Serial2);
+
+  M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
+
+  M5.Lcd.drawJpg(router_jpeg_120x140, 26433, 0, 40, 120, 140, 53, 0);
+  M5.Lcd.drawJpg(coordinator_jpeg_120x140, 26433, 100, 40, 120, 140, 0, 0);
+  M5.Lcd.drawJpg(endDevice_jpeg_120x140, 26433, 257, 40, 63, 140, 0, 0);
+
+  DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
+  zigbee.linkMoudle();
+  zigbee.readModuleparm(arg);
+
+  Serial.printf("PAIN ID:%04X\r\n", arg->main_PANID);
+
+  //drawChatBubbles(" STC!!!!!");
+
+  /*
+  xTaskCreate([](void *arg){
+      uint8_t readbuff[128];
+      while(1){
+          int length = Serial2.available();
+          if( length > 0) { Serial2.readBytes(readbuff,length);Serial.write(readbuff,length);}
+          delay(10);
+      }
+  }, "reviceTask", 2048, nullptr, 2, nullptr);
+  */
+
+  /*
+  if( zigbee.sendCMDAndWaitRevice(0xfc,ZIGBEE_CMD_LINKMODULE) != DRFZigbee::kReviceOK )
+  {
+      Serial.printf("Link Zigbee module faild! code:%d\r\n",zigbee.lastErrorcode);
+      while(1) delay(100);
+  }
+
+  byteArray array;
+  if( zigbee.sendCMDAndWaitRevice(0xfc,ZIGBEE_CMD_READPARM,&array) != DRFZigbee::kReviceOK )
+  {
+      Serial.printf("Read module pram faild! code:%d\r\n",zigbee.lastErrorcode);
+      while(1) delay(100);
+  }
+
+  if(( array.at(0) != 0x0A )||( array.at(1) != 0x0E ))
+  {
+      Serial.println("Read module pram faild!");
+      while(1) delay(100);
+  }
+  array = array.mid(2);
+
+  array.printfArray<HardwareSerial>(&Serial);
+
+  DRFZigbee::zigbee_arg arg;
+  memcpy(arg.Wave,array.dataptr(),sizeof(DRFZigbee::zigbee_arg));
+
+  arg.main_pointType = DRFZigbee::kCoordinator;
+  arg.main_PANID = DRFZigbee::swap<uint16_t>(0x6889);
+  arg.main_channel = 20;
+  arg.main_ATN = DRFZigbee::kANTEXP;
+  arg.main_transmissionMode = DRFZigbee::kN2Ntransmission;
+  arg.main_customID = DRFZigbee::swap<uint16_t>(0x1213);
+  arg.res3 = 0x01;
+
+  byteArray sendArray;
+  sendArray += 0x07;
+  sendArray += byteArray(&arg.Wave[0],16);
+  sendArray += byteArray(&arg.Wave[24],16);
+  sendArray += byteArray(&arg.Wave[42],6);
+
+  sendArray.printfArray<HardwareSerial>(&Serial);
+
+  if( zigbee.sendCMDAndWaitRevice(0xfc,sendArray,&array) != DRFZigbee::kReviceOK )
+  {
+      Serial.printf("Read module pram faild! code:%d\r\n",zigbee.lastErrorcode);
+      while(1) delay(100);
+  }
+
+  if( zigbee.sendCMDAndWaitRevice(0xfc,{0x06,0x44,0x54,0x4b,0xaa,0xbb}) != DRFZigbee::kReviceOK )
+  {
+      Serial.printf("reboot Zigbee module faild! code:%d\r\n",zigbee.lastErrorcode);
+      while(1) delay(100);
+  }
+
+  delay(1000);
+  */
+
+  //zigbee.sendDataP2P(DRFZigbee::kP2PShortAddrMode,0x0000,{0x01,0x02,0x03,0x04});
+
+  delay(1000);
+  /*
+  zigbee.nodeList.clear();
+  for (int i = 0; i < 10; i++)
+  {
+      zigbee.getNetworksTopology();
+      delay(100);
+  }
+  */
+
+  /*
+  M5.Lcd.fillRect(0,0,320,240,TFT_BLACK);
+  int count = 0;
+  for (int i = 0; i < 20; i++)
+  {
+      int n = ( count < 3 ) ? 0 : (int)log2(1-(((count + 3) * (-1)/3)));
+      int angle2 = 120 * pow(0.5,n);
+      int angle = (n > 0) ? angle2 + ( count - 3 * pow(2,n - 1))* angle2 * 2 : ( count % 3 ) * 120;
+      //int angle = ( count < 3 ) ? ( count % 3 ) * 120 : ((120 / (((count / 3) * 2))) + ( count % 3 ) * 120);
+      double posX = cos(PI*angle/180) * 100 + 160;
+      double posY = sin(PI*angle/180) * 100 + 120;
+
+      Serial.printf("Point %02d:%03d,%03d\r\n",count,(int)posX,(int)posY);
+
+      M5.Lcd.fillEllipse((int)posX,(int)posY,10,10,TFT_WHITE);
+      delay(200);
+      count++;
+  }
+  */
+
+  /*
+  if( !zigbee.nodeList.empty() )
+  {
+      int count = 0;
+      std::map<int,DRFZigbee::node>::iterator iter;
+      for( iter = zigbee.nodeList.begin(); iter != zigbee.nodeList.end();iter ++ )
+      {
+
+
+          iter->first;
+          iter->second;
+          count++;
+      }
+  }
+  */
+}
+
+void AppCoordinator()
+{
+  Serial.printf("AppCoordinator\r\n");
+  M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
+  M5.Lcd.drawJpg(coordinatorTitle, 21823, 0, 10, 320, 35);
+
+  DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
+  zigbee.readModuleparm(arg);
+  arg->main_pointType = DRFZigbee::kCoordinator;
+
+  M5.Lcd.setTextColor(TFT_WHITE);
+  M5.Lcd.setTextDatum(TC_DATUM);
+
+  char panIDchar[5] = {0, 0, 0, 0, 0};
+  uint16_t panID = DRFZigbee::swap<uint16_t>(arg->main_PANID);
+  for (int i = 0; i < 4; i++)
+  {
+      panIDchar[i] = asciiHexList[panID & 0x000f];
+      panID >>= 4;
+  }
+
+  M5.Lcd.setTextColor(M5.Lcd.color565(30, 30, 30));
+  M5.Lcd.drawString(panIDchar, 165, 95, 8);
+  M5.Lcd.setTextColor(TFT_WHITE);
+  M5.Lcd.drawString(panIDchar, 160, 90, 8);
+  zigbee.setModuleparm(*arg);
+  zigbee.rebootModule();
+  while (1)
+  {
+      M5.update();
+      if (M5.BtnB.wasPressed())
+          break;
+  }
+
+  delete arg;
+}
+
+void AppRouter()
+{
+  Serial.printf("AppRouter\r\n");
+  M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
+  M5.Lcd.drawJpg(EndDeviceTitle, 17470, 0, 10, 320, 35);
+
+  DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
+  zigbee.readModuleparm(arg);
+  arg->main_pointType = DRFZigbee::kRouter;
+  arg->main_PANID = DRFZigbee::swap<uint16_t>(0x1617);
+  arg->main_transmissionMode = DRFZigbee::kN2Ntransmission;
+  arg->main_channel = 20;
+  arg->main_ATN = DRFZigbee::kANTEXP;
+  zigbee.setModuleparm(*arg);
+  zigbee.rebootModule();
+
+  pinMode(5, INPUT_PULLUP);
+
+  while (1)
+  {
+    DRFZigbee::reviceData_t revice;
+    if (zigbee.reviceData(&revice) == DRFZigbee::kReviceOK)
     {
-        M5.Lcd.fillRect(60, posY, 228, 30, M5.Lcd.color565(0x88, 0xd1, 0xff));
-        String dispalyStr = str.substring(0, 24);
-        M5.Lcd.drawString(dispalyStr, 75, posY + 2, 2);
-        str.remove(0, 24);
-        posY += 20;
+      revice.array->printfArray<HardwareSerial>(&Serial);
     }
-    M5.Lcd.drawJpg(chatBubblesBottom, 11546, 60, posY, 229, 20);
-
-    M5.Lcd.fillEllipse(27,posY+18,23,23,M5.Lcd.color565(200, 200, 200));
-
-    char panIDchar[5] = {0, 0, 0, 0, 0};
-    for (int i = 0; i < 4; i++)
-    {
-        panIDchar[i] = asciiHexList[addr & 0x000f];
-        addr >>= 4;
-    }
-
-    M5.Lcd.setTextDatum(CC_DATUM);
-    M5.Lcd.setTextColor(M5.Lcd.color565(20, 20, 20));
-    M5.Lcd.drawString(panIDchar,27,posY+20);
-    return posY;
+  }
 }

-void setup()
-{
-    M5.begin();
-    Serial2.begin(38400, SERIAL_8N1, 16, 17);
-
-    zigbee.begin(Serial2);
-
-    M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
-
-    M5.Lcd.drawJpg(router_jpeg_120x140, 26433, 0, 40, 120, 140, 53, 0);
-    M5.Lcd.drawJpg(coordinator_jpeg_120x140, 26433, 100, 40, 120, 140, 0, 0);
-    M5.Lcd.drawJpg(endDevice_jpeg_120x140, 26433, 257, 40, 63, 140, 0, 0);
-
-    DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
-    zigbee.linkMoudle();
-    zigbee.readModuleparm(arg);
-
-    Serial.printf("PAIN ID:%04X\r\n", arg->main_PANID);
-
-    //drawChatBubbles(" STC!!!!!");
-
-    /*
-    xTaskCreate([](void *arg){
-        uint8_t readbuff[128];
-        while(1){
-            int length = Serial2.available();
-            if( length > 0) { Serial2.readBytes(readbuff,length);Serial.write(readbuff,length);}
-            delay(10);
-        }
-    }, "reviceTask", 2048, nullptr, 2, nullptr);
-    */
-
-    /*
-    if( zigbee.sendCMDAndWaitRevice(0xfc,ZIGBEE_CMD_LINKMODULE) != DRFZigbee::kReviceOK )
-    {
-        Serial.printf("Link Zigbee module faild! code:%d\r\n",zigbee.lastErrorcode);
-        while(1) delay(100);
-    }
-
-    byteArray array;
-    if( zigbee.sendCMDAndWaitRevice(0xfc,ZIGBEE_CMD_READPARM,&array) != DRFZigbee::kReviceOK )
-    {
-        Serial.printf("Read module pram faild! code:%d\r\n",zigbee.lastErrorcode);
-        while(1) delay(100);
-    }
-
-    if(( array.at(0) != 0x0A )||( array.at(1) != 0x0E ))
-    {
-        Serial.println("Read module pram faild!");
-        while(1) delay(100);
-    }
-    array = array.mid(2);
-
-    array.printfArray<HardwareSerial>(&Serial);
-
-    DRFZigbee::zigbee_arg arg;
-    memcpy(arg.Wave,array.dataptr(),sizeof(DRFZigbee::zigbee_arg));
-
-    arg.main_pointType = DRFZigbee::kCoordinator;
-    arg.main_PANID = DRFZigbee::swap<uint16_t>(0x6889);
-    arg.main_channel = 20;
-    arg.main_ATN = DRFZigbee::kANTEXP;
-    arg.main_transmissionMode = DRFZigbee::kN2Ntransmission;
-    arg.main_customID = DRFZigbee::swap<uint16_t>(0x1213);
-    arg.res3 = 0x01;
-
-    byteArray sendArray;
-    sendArray += 0x07;
-    sendArray += byteArray(&arg.Wave[0],16);
-    sendArray += byteArray(&arg.Wave[24],16);
-    sendArray += byteArray(&arg.Wave[42],6);
-
-    sendArray.printfArray<HardwareSerial>(&Serial);
-
-    if( zigbee.sendCMDAndWaitRevice(0xfc,sendArray,&array) != DRFZigbee::kReviceOK )
-    {
-        Serial.printf("Read module pram faild! code:%d\r\n",zigbee.lastErrorcode);
-        while(1) delay(100);
-    }
-
-    if( zigbee.sendCMDAndWaitRevice(0xfc,{0x06,0x44,0x54,0x4b,0xaa,0xbb}) != DRFZigbee::kReviceOK )
-    {
-        Serial.printf("reboot Zigbee module faild! code:%d\r\n",zigbee.lastErrorcode);
-        while(1) delay(100);
-    }
-
-    delay(1000);
-    */
-
-    //zigbee.sendDataP2P(DRFZigbee::kP2PShortAddrMode,0x0000,{0x01,0x02,0x03,0x04});
-
-    delay(1000);
-    /*
-    zigbee.nodeList.clear();
-    for (int i = 0; i < 10; i++)
-    {
-        zigbee.getNetworksTopology();
-        delay(100);
-    }
-    */
-
-    /*
-    M5.Lcd.fillRect(0,0,320,240,TFT_BLACK);
-    int count = 0;
-    for (int i = 0; i < 20; i++)
-    {
-        int n = ( count < 3 ) ? 0 : (int)log2(1-(((count + 3) * (-1)/3)));
-        int angle2 = 120 * pow(0.5,n);
-        int angle = (n > 0) ? angle2 + ( count - 3 * pow(2,n - 1))* angle2 * 2 : ( count % 3 ) * 120;
-        //int angle = ( count < 3 ) ? ( count % 3 ) * 120 : ((120 / (((count / 3) * 2))) + ( count % 3 ) * 120);
-        double posX = cos(PI*angle/180) * 100 + 160;
-        double posY = sin(PI*angle/180) * 100 + 120;
-
-        Serial.printf("Point %02d:%03d,%03d\r\n",count,(int)posX,(int)posY);
-
-        M5.Lcd.fillEllipse((int)posX,(int)posY,10,10,TFT_WHITE);
-        delay(200);
-        count++;
-    }
-    */
-
-    /*
-    if( !zigbee.nodeList.empty() )
-    {
-        int count = 0;
-        std::map<int,DRFZigbee::node>::iterator iter;
-        for( iter = zigbee.nodeList.begin(); iter != zigbee.nodeList.end();iter ++ )
-        {
-
-
-            iter->first;
-            iter->second;
-            count++;
-        }
-    }
-    */
+void AppEndDevice()
+{
+  Serial.printf("AppEndDevice\r\n");
+  M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
+  M5.Lcd.drawJpg(EndDeviceTitle, 17470, 0, 10, 320, 35);
+
+  DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
+  zigbee.readModuleparm(arg);
+  arg->main_pointType = DRFZigbee::kEndDevice;
+  arg->main_PANID = DRFZigbee::swap<uint16_t>(0x1617);
+  arg->main_transmissionMode = DRFZigbee::kN2Ntransmission;
+  zigbee.setModuleparm(*arg);
+  zigbee.rebootModule();
+
+  pinMode(5, INPUT_PULLUP);
+  Wire.begin(21,22);
+
+  M5.Lcd.fillRect(20, 200, 280, 30, M5.Lcd.color565(56, 56, 56));
+  M5.Lcd.drawRect(20, 200, 280, 30, M5.Lcd.color565(200, 200, 200));
+
+  uint8_t senduff[256];
+  char    revicechar[256];
+  uint16_t charPos = 0;
+
+  memset(senduff,0,256);
+
+  while (1)
+  {
+      DRFZigbee::reviceData_t revice;
+      if (zigbee.reviceData(&revice,10) == DRFZigbee::kReviceOK)
+      {
+          revice.array->printfArray<HardwareSerial>(&Serial);
+          M5.Lcd.fillRect(0, 66, 320, 128, M5.Lcd.color565(56, 56, 56));
+          memset(revicechar,0,256);
+          memcpy(revicechar,revice.array->dataptr(),revice.length);
+          drawChatBubbles(String(revicechar),revice.fromAddr);
+      }
+
+      if (digitalRead(5) == LOW)
+      {
+          Wire.requestFrom(0x08, 1);
+          while (Wire.available())
+          {
+              uint8_t key_val = Wire.read();
+              if (key_val != 0)
+              {
+                  if (key_val >= 0x20 && key_val < 0x7F)
+                  {
+                      senduff[charPos] = key_val;
+                      Serial.print((char)key_val);
+                      M5.Lcd.setTextDatum(TL_DATUM);
+                      M5.Lcd.setTextColor(M5.Lcd.color565(200, 200, 200));
+                      M5.Lcd.drawString(String((char*)senduff),30,206,2);
+                      charPos++;
+                  }
+                  else if( key_val == 0x0d)
+                  {
+                      M5.Lcd.fillRect(20, 200, 280, 30, M5.Lcd.color565(56, 56, 56));
+                      M5.Lcd.drawRect(20, 200, 280, 30, M5.Lcd.color565(200, 200, 200));
+                      zigbee.sendDataP2P(DRFZigbee::kP2PShortAddrMode,0xffff,senduff,charPos);
+                      memset(senduff,0,256);
+                      charPos = 0;
+                  }
+              }
+          }
+      }
+  }
 }

-void AppCoordinator()
-{
-    Serial.printf("AppCoordinator\r\n");
-    M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
-    M5.Lcd.drawJpg(coordinatorTitle, 21823, 0, 10, 320, 35);
-
-    DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
-    zigbee.readModuleparm(arg);
-    arg->main_pointType = DRFZigbee::kCoordinator;
-
-    M5.Lcd.setTextColor(TFT_WHITE);
-    M5.Lcd.setTextDatum(TC_DATUM);
-
-    char panIDchar[5] = {0, 0, 0, 0, 0};
-    uint16_t panID = DRFZigbee::swap<uint16_t>(arg->main_PANID);
-    for (int i = 0; i < 4; i++)
-    {
-        panIDchar[i] = asciiHexList[panID & 0x000f];
-        panID >>= 4;
-    }
-
-    M5.Lcd.setTextColor(M5.Lcd.color565(30, 30, 30));
-    M5.Lcd.drawString(panIDchar, 165, 95, 8);
-    M5.Lcd.setTextColor(TFT_WHITE);
-    M5.Lcd.drawString(panIDchar, 160, 90, 8);
-    zigbee.setModuleparm(*arg);
-    zigbee.rebootModule();
-    while (1)
-    {
-        M5.update();
-        if (M5.BtnB.wasPressed())
-            break;
-    }
-
-    delete arg;
-}
-
-void AppRouter()
-{
-    Serial.printf("AppRouter\r\n");
-    M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
-    M5.Lcd.drawJpg(EndDeviceTitle, 17470, 0, 10, 320, 35);
-
-    DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
-    zigbee.readModuleparm(arg);
-    arg->main_pointType = DRFZigbee::kRouter;
-    arg->main_PANID = DRFZigbee::swap<uint16_t>(0x1617);
-    arg->main_transmissionMode = DRFZigbee::kN2Ntransmission;
-    arg->main_channel = 20;
-    arg->main_ATN = DRFZigbee::kANTEXP;
-    zigbee.setModuleparm(*arg);
-    zigbee.rebootModule();
-
-    pinMode(5, INPUT_PULLUP);
-
-    while (1)
-    {
-        DRFZigbee::reviceData_t revice;
-        if (zigbee.reviceData(&revice) == DRFZigbee::kReviceOK)
-        {
-            revice.array->printfArray<HardwareSerial>(&Serial);
-        }
-    }
-}
-
-void AppEndDevice()
-{
-    Serial.printf("AppEndDevice\r\n");
-    M5.Lcd.fillRect(0, 0, 320, 240, M5.Lcd.color565(56, 56, 56));
-    M5.Lcd.drawJpg(EndDeviceTitle, 17470, 0, 10, 320, 35);
-
-    DRFZigbee::zigbee_arg_t *arg = new DRFZigbee::zigbee_arg_t;
-    zigbee.readModuleparm(arg);
-    arg->main_pointType = DRFZigbee::kEndDevice;
-    arg->main_PANID = DRFZigbee::swap<uint16_t>(0x1617);
-    arg->main_transmissionMode = DRFZigbee::kN2Ntransmission;
-    zigbee.setModuleparm(*arg);
-    zigbee.rebootModule();
-
-    pinMode(5, INPUT_PULLUP);
-    Wire.begin(21,22);
-
-    M5.Lcd.fillRect(20, 200, 280, 30, M5.Lcd.color565(56, 56, 56));
-    M5.Lcd.drawRect(20, 200, 280, 30, M5.Lcd.color565(200, 200, 200));
-
-    uint8_t senduff[256];
-    char    revicechar[256];
-    uint16_t charPos = 0;
-
-    memset(senduff,0,256);
-
-    while (1)
-    {
-        DRFZigbee::reviceData_t revice;
-        if (zigbee.reviceData(&revice,10) == DRFZigbee::kReviceOK)
-        {
-            revice.array->printfArray<HardwareSerial>(&Serial);
-            M5.Lcd.fillRect(0, 66, 320, 128, M5.Lcd.color565(56, 56, 56));
-            memset(revicechar,0,256);
-            memcpy(revicechar,revice.array->dataptr(),revice.length);
-            drawChatBubbles(String(revicechar),revice.fromAddr);
-        }
-
-        if (digitalRead(5) == LOW)
-        {
-            Wire.requestFrom(0x08, 1);
-            while (Wire.available())
-            {
-                uint8_t key_val = Wire.read();
-                if (key_val != 0)
-                {
-                    if (key_val >= 0x20 && key_val < 0x7F)
-                    {
-                        senduff[charPos] = key_val;
-                        Serial.print((char)key_val);
-                        M5.Lcd.setTextDatum(TL_DATUM);
-                        M5.Lcd.setTextColor(M5.Lcd.color565(200, 200, 200));
-                        M5.Lcd.drawString(String((char*)senduff),30,206,2);
-                        charPos++;
-                    }
-                    else if( key_val == 0x0d)
-                    {
-                        M5.Lcd.fillRect(20, 200, 280, 30, M5.Lcd.color565(56, 56, 56));
-                        M5.Lcd.drawRect(20, 200, 280, 30, M5.Lcd.color565(200, 200, 200));
-                        zigbee.sendDataP2P(DRFZigbee::kP2PShortAddrMode,0xffff,senduff,charPos);
-                        memset(senduff,0,256);
-                        charPos = 0;
-                    }
-                }
-            }
-        }
-    }
-}
-
 void loop()
 {
-    if (M5.BtnA.wasPressed())
-    {
-        atNow = (atNow >= 60000) ? 30000 : atNow;
-        atNow++;
-        flushFlag = true;
-    }
-    else if (M5.BtnB.wasPressed())
-    {
-        switch ((atNow + 2) % 3)
-        {
-        case 0:
-            AppRouter();
-            break;
-        case 1:
-            AppCoordinator();
-            break;
-        case 2:
-            AppEndDevice();
-            break;
-        }
-        flushFlag = true;
-    }
-    else if (M5.BtnC.wasPressed())
-    {
-        atNow = (atNow == 0) ? 30000 : atNow;
-        atNow--;
-        flushFlag = true;
-    }
-    if (flushFlag)
-    {
-        flushFlag = false;
-        for (int i = 0; i < 3; i++)
-        {
-            M5.Lcd.drawJpg(iconptrbuff[(atNow + i) % 3],
-                           iconSizeBuff[(atNow + i) % 3],
-                           iconpos[i][0],
-                           iconpos[i][1],
-                           iconpos[i][2],
-                           iconpos[i][3],
-                           iconpos[i][4],
-                           iconpos[i][5]);
-        }
-    }
-    M5.update();
-    delay(10);
+  if (M5.BtnA.wasPressed())
+  {
+      atNow = (atNow >= 60000) ? 30000 : atNow;
+      atNow++;
+      flushFlag = true;
+  }
+  else if (M5.BtnB.wasPressed())
+  {
+      switch ((atNow + 2) % 3)
+      {
+      case 0:
+          AppRouter();
+          break;
+      case 1:
+          AppCoordinator();
+          break;
+      case 2:
+          AppEndDevice();
+          break;
+      }
+      flushFlag = true;
+  }
+  else if (M5.BtnC.wasPressed())
+  {
+      atNow = (atNow == 0) ? 30000 : atNow;
+      atNow--;
+      flushFlag = true;
+  }
+  if (flushFlag)
+  {
+      flushFlag = false;
+      for (int i = 0; i < 3; i++)
+      {
+          M5.Lcd.drawJpg(iconptrbuff[(atNow + i) % 3],
+                          iconSizeBuff[(atNow + i) % 3],
+                          iconpos[i][0],
+                          iconpos[i][1],
+                          iconpos[i][2],
+                          iconpos[i][3],
+                          iconpos[i][4],
+                          iconpos[i][5]);
+      }
+  }
+  M5.update();
+  delay(10);
 }


fix merge error

fix merge error

--- BrewManiac.ino
+++ BrewManiac.ino
@@ -349,7 +349,6 @@
 	EventHandlerFunc eventHandler;
 }CScreen;

-#if 0 //opt-code

 #define MAIN_SCREEN 0
 #define SETUP_SCREEN 1
@@ -1929,7 +1928,17 @@
 			// boiling time;

 			_editingStageAux=0;
-			_editingStage++;
+			int hopsNum=readSetting(PS_NumberOfHops);
+			if(hopsNum){
+				_editingStage++;
+
+			}else{
+				finishAutomationEdit();
+
+				uiClearSettingRow();
+				switchApplication(SETUP_SCREEN);
+				return;
+			}
 		}
 		else // if(_editingStage == 10)
 		{


More carefull atomic executions.

More carefull atomic executions.

--- examples/Comparator/comparator.ino
+++ examples/Comparator/comparator.ino
@@ -67,10 +67,18 @@
     }
   }

-  // Process interruption flag atomically.
+  // Get interruption flag atomically due to possible race conditions.
+  bool localInterruption;
   ATOMIC_BLOCK(ATOMIC_FORCEON) {
-    if(interruption) {
-      Serial.println("Interruption triggered!\n");
+    localInterruption = interruption;
+  }
+
+  // Process interruption flag.
+  if(localInterruption) {
+    Serial.println("Interruption triggered!\n");
+
+    // Reset interruption flag atomically.
+    ATOMIC_BLOCK(ATOMIC_FORCEON) {
       interruption = false;
     }
   }


Fixed example benchmark logging.

Fixed example benchmark logging.

--- examples/DemoArcRPM/DemoArcRPM.ino
+++ examples/DemoArcRPM/DemoArcRPM.ino
@@ -202,8 +202,13 @@
 		RPMStart = micros();
 		RPMDriver.UpdateRPM(DemoRPM, Now);
 		RPMEnd = micros();
+
+		Serial.print("Update RPM took: ");
+		Serial.print((RPMEnd - RPMStart));
+		Serial.println(" us");
+
 		//Serial.println(RPMDriver.Debug());
-		Serial.print("Update RPM took: ");
+
 	}

 	if (Now - LastRPMUpdate > DEMO_RPM_UPDATE_INTERVAL - 1)


Increase the baud rate of the serial port a bit

--- projects/arduino/led_matrix_256/led_matrix_256.ino
+++ projects/arduino/led_matrix_256/led_matrix_256.ino
@@ -89,15 +89,13 @@
 void setup() {
     irrecv.enableIRIn(); // Start the remote control receiver

-    Serial.begin(9600); // setup serial printing so you can troubleshoot
+    Serial.begin(115200); // setup serial printing so you can troubleshoot

     strip.begin();
     strip.setBrightness(1);
     strip.show(); // Initialize all pixels to 'off'

-
     Serial.print("Total number of frames: "); Serial.println(MAX_FRAME + 1);
-
 }

 void loop() {


Set positioning default to local instead of remote

--- examples/ready_to_localize/ready_to_localize.ino
+++ examples/ready_to_localize/ready_to_localize.ino
@@ -18,7 +18,7 @@
 ////////////////////////////////////////////////

 uint16_t remote_id = 0x6000;                            // set this to the ID of the remote device
-bool remote = true;                                    // set this to true to use the remote ID
+bool remote = false;                                    // set this to true to use the remote ID

 boolean use_processing = false;                         // set this to true to output data for the processing sketch


Update display of code license

Update display of code license

--- cirkit_unit03_driver/arduino/steer_ctrl/steer_ctrl.ino
+++ cirkit_unit03_driver/arduino/steer_ctrl/steer_ctrl.ino
@@ -1,4 +1,6 @@
 /**
+The original code:
+
 Copyright (c) 2015, Yusuke Doi
 All rights reserved.


Presetup with GPS waypoints

Presetup with GPS waypoints


Fix for the following issue #43

Fix for the following issue #43

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -363,9 +363,12 @@
                 }
                 else if(digitalRead(buttonDown) == LOW) {
                     menu_id--;
+
+#ifdef USE_DIVERSITY
                     if(!isDiversity() && menu_id == 3) { // make sure we back up two menu slots.
                         menu_id--;
                     }
+#endif
                 }

                 if (menu_id > MAX_MENU)
@@ -764,7 +767,7 @@
     if(state == STATE_SETUP_MENU)
     {
         // simple menu
-        char menu_id=diversity_mode;
+        char menu_id=0;
         in_menu=1;
         drawScreen.setupMenu();
         int editing = -1;


Added translation comment

Added translation comment

--- signalboxes/kelberg/kelberg.ino
+++ signalboxes/kelberg/kelberg.ino
@@ -38,6 +38,8 @@

+// Locking table = verschlusstafel
+
 void setup() {
 }


fixed issue with Flash library, it seems this isnt't required

--- TreibBoje1.ino
+++ TreibBoje1.ino
@@ -27,8 +27,11 @@
  // http://arduiniana.org/libraries/streaming/
  // has to be included BEFORE Flash
  #include <Streaming.h>
- #include <Flash.h>
-
+ // // I guess we don't need this out-dated (?) library
+ // #if (defined(ARDUINO) && ARDUINO <= 156)
+ //  #include <Flash.h>
+ // #endif // ARDUINO
+
  // UART baud rate
  #define UART_BAUD_RATE  9600
 #endif // DEBUG


cosmetics

cosmetics

--- demoboard/DemoBoard/DemoBoard.ino
+++ demoboard/DemoBoard/DemoBoard.ino
@@ -61,7 +61,13 @@
 // SRDP channel to communicate with host
 //
 srdp_channel_t channel;
-
+
+
+// Here we track which registers are watched by the host
+// When bit N is set, the host watched register N.
+//
+int watched = 0;
+

 // Transport reader function used by the SRDP channel
 //
@@ -93,6 +99,7 @@
          case IDX_REG_BTN1:
          case IDX_REG_BTN2:
             if (pos == 0 && len == 1) {
+
                if (reg == IDX_REG_BTN1) {
                   data[0] = btn1.getState();
                } else {
@@ -102,6 +109,12 @@
             } else {
                return SRDP_ERR_INVALID_REG_POSLEN;
             }
+
+         case IDX_REG_LED1:
+         case IDX_REG_LED2:
+         case IDX_REG_LED3:
+            return SRDP_ERR_INVALID_REG_OP;
+
          default:
             return SRDP_ERR_NO_SUCH_REGISTER;
       }
@@ -123,6 +136,7 @@
          case IDX_REG_LED1:
          case IDX_REG_LED2:
             if (pos == 0 && len == 1) {
+
                int pin = reg == IDX_REG_LED1 ? PIN_LED1 : PIN_LED2;
                if (data[0]) {
                   digitalWrite(pin, HIGH);
@@ -138,11 +152,17 @@
          //
          case IDX_REG_LED3:
             if (pos == 0 && len == 3) {
+
                led3.write(data[0], data[1], data[2]);
                return len;
             } else {
                return SRDP_ERR_INVALID_REG_POSLEN;
             }
+
+         case IDX_REG_BTN1:
+         case IDX_REG_BTN2:
+            return SRDP_ERR_INVALID_REG_OP;
+
          default:
             return SRDP_ERR_NO_SUCH_REGISTER;
       }
@@ -151,7 +171,6 @@
    }
 }

-int watched = 0;

 // Register watch handler called when host requests to watch a register
 //
@@ -179,12 +198,6 @@
 }

-// Register unwatch handler called when host requests to unwatch a register
-//
-int register_unwatch(int dev, int reg) {
-}
-
-
 // Arduino setup function executed once after reset
 //
 void setup() {
@@ -198,10 +211,11 @@
    // setup SRDP channel over serial
    //
    srdp_init_channel(&channel);
+   channel.transport_read = transport_read;
    channel.transport_write = transport_write;
-   channel.transport_read = transport_read;
+   channel.register_read = register_read;
    channel.register_write = register_write;
-   channel.register_read = register_read;
+   channel.register_watch = register_watch;

    // LED 1
    pinMode(PIN_LED1, OUTPUT);
@@ -271,13 +285,15 @@

    // process buttons
    //
-   if (btn1.process() && (watched |= 1 << IDX_REG_BTN1)) {
+   if (btn1.process() && (watched & 1 << IDX_REG_BTN1)) {
+      // OR: simply trigger a read register .. code only once.
+
       // when button changed, report change to SRDP
       uint8_t data = btn1.getState();
       srdp_register_change(&channel, IDX_DEV, IDX_REG_BTN1, 0, 1, &data);
    }

-   if (btn2.process() && (watched |= 1 << IDX_REG_BTN2)) {
+   if (btn2.process() && (watched & 1 << IDX_REG_BTN2)) {
       uint8_t data = btn2.getState();
       srdp_register_change(&channel, IDX_DEV, IDX_REG_BTN2, 0, 1, &data);
    }


alright. last commit. Making sure it reads the cloud events

--- particle/examples/local-compile/local-compile.ino
+++ particle/examples/local-compile/local-compile.ino
@@ -102,7 +102,7 @@

   if(!pseudopod.isConfigured()) {
     Serial.println(F("I'm not configured. Requesting configuration."));
-    delay(100);
+    delay(300);
     pseudopod.requestConfiguration();
   }

@@ -112,6 +112,8 @@
     Serial.print(configSize);
     Serial.print(F(" bytes written while broadcasting pins"));
   }
+
+  Spark.process();
 }

 void readData() {


Corrected names in interrupt routine after copy/paste

--- z_interrupt_events_3Motors.ino
+++ z_interrupt_events_3Motors.ino
@@ -19,15 +19,15 @@
 void EncoderEvent_Beta4B() {
   if (digitalRead(ENCODER_Beta4B_A) == HIGH) {
     if (digitalRead(ENCODER_Beta4B_B) == LOW) {
-      Count_Beta2B++;
+      Count_Beta4B++;
     } else {
-      Count_Beta2B--;
+      Count_Beta4B--;
     }
   } else {
     if (digitalRead(ENCODER_Beta4B_B) == LOW) {
-      Count_Beta2B--;
+      Count_Beta4B--;
     } else {
-      Count_Beta2B++;
+      Count_Beta4B++;
     }
   }
 }
@@ -35,15 +35,15 @@
 void EncoderEvent_PSARJ() {
   if (digitalRead(ENCODER_PSARJ_A) == HIGH) {
     if (digitalRead(ENCODER_PSARJ_B) == LOW) {
-      Count_Beta2B++;
+      Count_PSARJ++;
     } else {
-      Count_Beta2B--;
+      Count_PSARJ--;
     }
   } else {
     if (digitalRead(ENCODER_PSARJ_B) == LOW) {
-      Count_Beta2B--;
+      Count_PSARJ--;
     } else {
-      Count_Beta2B++;
+      Count_PSARJ++;
     }
   }
 }


Adding feature toggles for USE_DIP and USE_DIVERSITY Adding Diversity setting to EEPROM Creating Diversity menu for selecting receivers. Removing experimental code for video overlay. Adding mode quick save. (Hold mode for 1 second to save) Adding LED status blink to beep function for visual indication of beeps.

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -34,14 +34,28 @@
 #include <avr/pgmspace.h>
 #include <EEPROM.h>

-#include <PinChangeInt.h>
-//#include <PinChangeIntConfig.h>
-
+// Feature Togglels
+//define USE_DIP
+#define USE_DIVERSITY
+//#define DEBUG

 #define spiDataPin 10
 #define slaveSelectPin 11
 #define spiClockPin 12
-#define rssiPin A6
+
+// Receiver PINS
+#define receiverA_led A1
+#define rssiPinA A7
+
+#ifdef USE_DIVERSITY
+// Diversity
+#define receiverB_led A0
+#define rssiPinB A6
+#define useReceiverAuto 0
+#define useReceiverA 1
+#define useReceiverB 2
+#endif
+
 // this two are minimum required
 #define buttonSeek 2
 #define buttonMode 3
@@ -50,17 +64,18 @@
 #define buttonSave 5
 // Buzzer
 #define buzzer 6
+
 // pins for DIP switch
-#define dip_ch0 A0
-#define dip_ch1 A1
-#define dip_ch2 A2
-#define dip_band0 A3
-#define dip_band1 A4
-#define dip_enable A5
-
-// genlock vsync input
-#define vsync_in 13
-#define hsync_in 8
+//#define USE_DIP
+#ifdef USE_DIP
+    #define dip_ch0 A0
+    #define dip_ch1 A1
+    #define dip_ch2 A2
+    #define dip_band0 A3
+    #define dip_band1 A4
+    #define dip_enable 0
+#endif
+
 // key debounce delay in ms
 // NOTE: good values are in the range of 100-200ms
 // shorter values will make it more reactive, but may lead to double trigger
@@ -88,6 +103,9 @@
 #define STATE_SWITCH 4
 #define STATE_SAVE 5
 #define STATE_RSSI_SETUP 6
+#ifdef USE_DIVERSITY
+#define STATE_DIVERSITY 7
+#endif

 #define START_STATE STATE_SEEK
 #define MAX_STATE STATE_MANUAL
@@ -115,6 +133,9 @@
 #define EEPROM_ADR_RSSI_MIN_H 3
 #define EEPROM_ADR_RSSI_MAX_L 4
 #define EEPROM_ADR_RSSI_MAX_H 5
+#ifdef USE_DIVERSITY
+#define EEPROM_ADR_DIVERSITY 6
+#endif
 //#define DEBUG

 // Channels to sent to the SPI registers
@@ -152,6 +173,9 @@
 uint8_t channelIndex = 0;
 uint8_t rssi = 0;
 uint8_t rssi_scaled = 0;
+#ifdef USE_DIVERSITY
+uint8_t diversity_mode = useReceiverAuto;
+#endif
 uint8_t hight = 0;
 uint8_t state = START_STATE;
 uint8_t state_last_used=START_STATE;
@@ -179,18 +203,11 @@
 uint16_t rssi_seek_found=0;
 uint16_t rssi_setup_run=0;

-// genlock hander
-#define GENLOCK_DLY 0
-
-uint8_t genlock_dly = GENLOCK_DLY;
-
 TVout TV;
-

 // SETUP ----------------------------------------------------------------------------
 void setup()
 {
-
     // IO INIT
     // initialize digital pin 13 LED as an output.
     pinMode(led, OUTPUT); // status pin for TV mode errors
@@ -207,7 +224,15 @@
     digitalWrite(buttonDown, INPUT_PULLUP);
     pinMode(buttonSave, INPUT);
     digitalWrite(buttonSave, INPUT_PULLUP);
+    //Receiver Setup
+    pinMode(receiverA_led,OUTPUT);
+    digitalWrite(buzzer, HIGH);
+#ifdef USE_DIVERSITY
+    pinMode(receiverB_led,OUTPUT);
+    digitalWrite(buzzer, LOW);
+#endif
     // dip switches
+#ifdef USE_DIP
     pinMode(dip_ch0, INPUT);
     digitalWrite(dip_ch0, INPUT_PULLUP);
     pinMode(dip_ch1, INPUT);
@@ -220,6 +245,7 @@
     digitalWrite(dip_band1, INPUT_PULLUP);
     pinMode(dip_enable, INPUT);
     digitalWrite(dip_enable, INPUT_PULLUP);
+#endif
 #ifdef DEBUG
     Serial.begin(115200);
     Serial.println(F("START:"));
@@ -228,10 +254,6 @@
     pinMode (slaveSelectPin, OUTPUT);
     pinMode (spiDataPin, OUTPUT);
 	pinMode (spiClockPin, OUTPUT);
-    // genlock input
-    pinMode(vsync_in, INPUT);
-    pinMode(hsync_in, INPUT);
-
     // tune to first channel

@@ -248,26 +270,9 @@
             delay(100);
         }
     }
-    // init overlay
-
-    //initOverlay();
-
     TV.select_font(font4x6);
-    // setup Genlock
-    //PCintPort::attachInterrupt(vsync_in,genlock ,RISING); // attach a PinChange Interrupt to our pin on the rising edge
-
-    //PCintPort::attachInterrupt(vsync_in,genlock ,FALLING); // attach a PinChange Interrupt to our pin on the rising edge
-
-    //PCintPort::attachInterrupt(vsync_in,genlock ,FALLING); // attach a PinChange Interrupt to our pin on the rising edge
-
-    // hsync
-    PCintPort::attachInterrupt(vsync_in,display.vsync_handle ,FALLING); // attach a PinChange Interrupt to our pin on the rising edge
-
-
-    genlock_dly=GENLOCK_DLY;
-
     // Setup Done - LED ON
-    digitalWrite(13, HIGH);
+    digitalWrite(led, HIGH);

     // use values only of EEprom is not 255 = unsaved
     uint8_t eeprom_check = EEPROM.read(EEPROM_ADR_STATE);
@@ -281,6 +286,10 @@
         // save 16 bit
         EEPROM.write(EEPROM_ADR_RSSI_MAX_L,lowByte(RSSI_MAX_VAL));
         EEPROM.write(EEPROM_ADR_RSSI_MAX_H,highByte(RSSI_MAX_VAL));
+#ifdef USE_DIVERSITY
+        // diversity
+        EEPROM.write(EEPROM_ADR_DIVERSITY,diversity_mode);
+#endif
     }
     // debug reset EEPROM
     //EEPROM.write(EEPROM_ADR_STATE,255);
@@ -290,65 +299,11 @@
     channelIndex=EEPROM.read(EEPROM_ADR_TUNE);
     rssi_min=((EEPROM.read(EEPROM_ADR_RSSI_MIN_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MIN_L)));
     rssi_max=((EEPROM.read(EEPROM_ADR_RSSI_MAX_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MAX_L)));
+#ifdef USE_DIVERSITY
+    diversity_mode = EEPROM.read(EEPROM_ADR_DIVERSITY);
+#endif
     force_menu_redraw=1;
 }
-
-// genlock ISR
-void genlock()
-{
-display.scanLine = 0;
-    //uint8_t sreg = SREG;
-#if 0
-    if(genlock_dly)
-    {
-        genlock_dly--;
-    }
-    else
-    {
-    genlock_dly=GENLOCK_DLY;
-    }
-    //SREG=sreg;
-#endif
-}
-
-#if 0
-    ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
- {
-    //digitalWrite(13,digitalRead(8) and digitalRead(9));
-    digitalWrite(led, !digitalRead(led));
-    display.scanLine = 0;
- }
- #endif
-// interup setup for input pin
-void pciSetup(byte pin)
-{
-    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
-    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
-    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
-}
-
- // Initialize ATMega registers for video overlay capability.
-// Must be called after tv.begin().
-void initOverlay() {
-  // disable timer for free running video
-  TCCR1A = 0;
-  // Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.
-  // get hsync to state machine
-  TCCR1B = _BV(CS10);
-
-  //pciSetup(8);
-
-
-  // Enable input capture interrupt
-  TIMSK1 |= _BV(ICIE1);
-
-  // Enable external interrupt INT0 on pin 2 with falling edge.
-  //EIMSK = _BV(INT0); // enable interrupt
-  //EICRA = _BV(ISC11); // Falling edge int0
-}
-
-
-

 // LOOP ----------------------------------------------------------------------------
 void loop()
@@ -363,9 +318,13 @@
         delay(KEY_DEBOUNCE/2); // debounce
         beep(50); // beep & debounce
         delay(KEY_DEBOUNCE/2); // debounce
+
+        uint8_t press_time=0;
         // on entry wait for release
         while(digitalRead(buttonMode) == LOW)
         {
+            delay(10);
+            press_time++;
                 // wait for MODE release
         }
         #define MAX_MENU 4
@@ -388,6 +347,13 @@
         */
         do
         {
+            if(press_time >= 10) // if menu held for 1 second invoke quick save.
+            {
+                // user held the mode button and wants to quick save.
+                in_menu=0; // EXIT
+                state = STATE_SAVE;
+                break;
+            }
             TV.clear_screen();
             // simple menu
             TV.select_font(font8x8);
@@ -397,7 +363,11 @@
             TV.printPGM(10, 5+1*MENU_Y_SIZE, PSTR("Auto Search"));
             TV.printPGM(10, 5+2*MENU_Y_SIZE, PSTR("Band Scanner"));
             TV.printPGM(10, 5+3*MENU_Y_SIZE, PSTR("Manual Mode"));
+#ifdef USE_DIVERSITY
+            TV.printPGM(10, 5+4*MENU_Y_SIZE, PSTR("Diversity"));
+#else
             TV.printPGM(10, 5+4*MENU_Y_SIZE, PSTR("Switch Mode"));
+#endif
             TV.printPGM(10, 5+5*MENU_Y_SIZE, PSTR("Save Setup"));
             // selection by inverted box
             switch (menu_id)
@@ -417,18 +387,20 @@
                     TV.draw_rect(8,3+3*MENU_Y_SIZE,100,12,  WHITE, INVERT);
                     state=STATE_MANUAL;
                 break;
-                case 3: // DIP mode
+                case 3: // DIP mode or diversity
                     TV.draw_rect(8,3+4*MENU_Y_SIZE,100,12,  WHITE, INVERT);
+#ifdef USE_DIVERSITY
+                    state=STATE_DIVERSITY;
+#else
                     state=STATE_SWITCH;
                     last_dip_channel=255; // force update
+#endif
                 break;
                 case 4: // Save settings
                     TV.draw_rect(8,3+5*MENU_Y_SIZE,100,12,  WHITE, INVERT);
                     state=STATE_SAVE;
                 break;
             } // end switch
-
-

             while(digitalRead(buttonMode) == LOW)
             {
@@ -474,6 +446,7 @@
     { // reset debounce
         switch_count = 0;
     }
+#ifdef USE_DIP
     /***********************/
     /*   Static SWITCH MODE   */
     /***********************/
@@ -482,19 +455,14 @@
     {
         state=STATE_SWITCH;
     }
+#endif
     /***********************/
     /*     Save buttom     */
     /***********************/
     // hardware save buttom support (if no display is used)
     if(digitalRead(buttonSave) == LOW)
     {
-        //state=STATE_SAVE;
-        // DEBUG DEBUG
-        TV.video_clock(CLOCK_EXTERN);
-    }
-    else
-    {
-        TV.video_clock(CLOCK_INTERN);
+        state=STATE_SAVE;
     }
     /***************************************/
     /*   Draw screen if mode has changed   */
@@ -581,9 +549,17 @@
                 update_frequency_view=1;
                 force_seek=1;
             break;
+#ifdef USE_DIVERSITY
+            case STATE_DIVERSITY:
+                // diversity menu is below this is just a place holder.
+            break;
+#endif
             case STATE_SAVE:
+                EEPROM.write(EEPROM_ADR_TUNE,channelIndex);
                 EEPROM.write(EEPROM_ADR_STATE,state_last_used);
-                EEPROM.write(EEPROM_ADR_TUNE,channelIndex);
+#ifdef USE_DIVERSITY
+                EEPROM.write(EEPROM_ADR_DIVERSITY,diversity_mode);
+#endif
                 TV.select_font(font8x8);
                 TV.draw_rect(0,0,127,95,  WHITE);
                 TV.draw_line(0,14,127,14,WHITE);
@@ -672,7 +648,64 @@
     /*************************************/
     /*   Processing depending of state   */
     /*************************************/
-
+#ifdef USE_DIVERSITY
+    if(state == STATE_DIVERSITY) {
+        // simple menu
+        uint8_t menu_id=diversity_mode;
+        uint8_t in_menu=1;
+        uint8_t in_menu_time_out=10; // 10x 200ms = 2 seconds
+        do{
+            if(digitalRead(buttonMode) == LOW)        // channel UP
+            {
+                in_menu_time_out=10;
+                beep(50); // beep & debounce
+                delay(KEY_DEBOUNCE); // debounce
+                menu_id++;
+                if(menu_id > 2) {
+                    menu_id = 0;
+                }
+            }
+            TV.clear_screen();
+            TV.select_font(font8x8);
+            TV.draw_rect(0,0,127,95,  WHITE);
+            TV.draw_line(0,14,127,14,WHITE);
+            TV.printPGM(10, 3,  PSTR("DIVERSITY"));
+            TV.printPGM(10, 5+1*MENU_Y_SIZE, PSTR("Auto"));
+            TV.printPGM(10, 5+2*MENU_Y_SIZE, PSTR("Receiver A"));
+            TV.printPGM(10, 5+3*MENU_Y_SIZE, PSTR("Receiver B"));
+            switch (menu_id)
+            {
+                case useReceiverAuto:
+                    TV.draw_rect(8,3+1*MENU_Y_SIZE,100,12,  WHITE, INVERT); // auto
+                    digitalWrite(receiverA_led, HIGH);
+                    digitalWrite(receiverB_led, HIGH);
+                    break;
+                case useReceiverA:
+                    TV.draw_rect(8,3+2*MENU_Y_SIZE,100,12,  WHITE, INVERT); // receiver a
+                    digitalWrite(receiverA_led, HIGH);
+                    digitalWrite(receiverB_led, LOW);
+                    break;
+                case useReceiverB:
+                    TV.draw_rect(8,3+3*MENU_Y_SIZE,100,12,  WHITE, INVERT); // receiver b
+                    digitalWrite(receiverA_led, LOW);
+                    digitalWrite(receiverB_led, HIGH);
+                    break;
+            }
+
+            while(--in_menu_time_out && (digitalRead(buttonMode) == HIGH)) // wait for next mode or time out
+            {
+                delay(200); // timeout delay
+            }
+            if(in_menu_time_out <= 0) {
+                diversity_mode = menu_id;
+                in_menu = 0; // exit menu
+            }
+        }
+        while(in_menu);
+
+        state=state_last_used;
+    }
+#endif
     /*****************************************/
     /*   Processing MANUAL MODE / SEEK MODE  */
     /*****************************************/
@@ -704,6 +737,7 @@
                 update_frequency_view=1;
             }
         }
+#ifdef USE_DIP
         if(state == STATE_SWITCH) // SWITCH MODE
         {
             // read band DIP switch (invert since switch pulls to gnd)
@@ -720,6 +754,7 @@
             }

         }
+#endif
         // display refresh handler
         if(update_frequency_view) // only updated on changes
         {
@@ -947,8 +982,10 @@

 void beep(uint16_t time)
 {
+    digitalWrite(led, LOW);
     digitalWrite(buzzer, LOW);
     delay(time);
+    digitalWrite(led, HIGH);
     digitalWrite(buzzer, HIGH);
 }

@@ -986,10 +1023,51 @@
 uint16_t readRSSI()
 {
     uint16_t rssi = 0;
+    uint16_t rssiA = 0;
+    uint16_t rssiB = 0;
+
     for (uint8_t i = 0; i < 10; i++)
     {
-        rssi += analogRead(rssiPin);
-    }
+        rssiA += analogRead(rssiPinA);
+#ifdef USE_DIVERSITY
+        rssiB += analogRead(rssiPinB);
+#endif
+    }
+#ifdef USE_DIVERSITY
+    switch(diversity_mode)
+    {
+        case useReceiverAuto:
+            // select receiver
+            if(rssiA/10 > rssiB/10)
+            {
+                rssi=rssiA;
+                digitalWrite(receiverA_led, HIGH);
+                digitalWrite(receiverB_led, LOW);
+            }
+            else
+            {
+                rssi=rssiB;
+                digitalWrite(receiverB_led, HIGH);
+                digitalWrite(receiverA_led, LOW);
+            }
+            break;
+        case useReceiverA:
+            rssi=rssiA;
+            digitalWrite(receiverA_led, HIGH);
+            digitalWrite(receiverB_led, LOW);
+            break;
+        case useReceiverB:
+            rssi=rssiB;
+            digitalWrite(receiverB_led, HIGH);
+            digitalWrite(receiverA_led, LOW);
+            break;
+    }
+#else
+    rssi=rssiA;
+    digitalWrite(receiverA_led, HIGH);
+#endif
+
+
     rssi=rssi/10; // average
     // special case for RSSI setup
     if(state==STATE_RSSI_SETUP)


display less redundant in example ReadNumberString

--- examples/ReadNumberString/ReadNumberString.ino
+++ examples/ReadNumberString/ReadNumberString.ino
@@ -52,21 +52,32 @@
   kpd.addEventListener(key_event_handler);
 }

-//int sum = 0;
+float f, oldf=0;
+int i, oldi=0;
+long l, oldl=0;

 void loop() {
   kpd.getKey();

-  float f;
-  if(kpd.readQueue(TYPE_FLOAT, &f)) {
+
+  if(kpd.readQueue(TYPE_FLOAT, &f) && f!=oldf) {
+    oldf = f;
     Serial.print("f = ");
     Serial.print(f);
     Serial.print("\r\n");
   }
-  int i;
-  if(kpd.readQueue(TYPE_INT, &i)) {
+
+  if(kpd.readQueue(TYPE_INT, &i) && i!=oldi) {
+    oldi = i;
     Serial.print("i = ");
     Serial.print(i);
+    Serial.print("\r\n");
+  }
+
+  if(kpd.readQueue(TYPE_LONG, &l) && l!=oldl) {
+    oldl = l;
+    Serial.print("l = ");
+    Serial.print(l);
     Serial.print("\r\n");
   }


radio_pipe updated - still not ready for use

--- firmware/2016/radio_pipe/radio_pipe.ino
+++ firmware/2016/radio_pipe/radio_pipe.ino
@@ -12,7 +12,7 @@

 void setup() {
   Serial.begin(250000);
-  Serial.println("Inicio");
+  Serial.println("Inicio - central");
   radio.begin();

   radio.setPALevel(RF24_PA_MAX);
@@ -40,24 +40,38 @@
 }

 void send_data_to_ROS() {
+
   Serial.println(msg_from_robot[0]); //Serial.write() may be a better choice for this
   Serial.println(msg_from_robot[1]); //Serial.write() may be a better choice for this
+}
+
+int commands[2];
+int robotPipe=0;
+
+void parseROStoRobot(){
+  robotPipe=msg_from_ROS[0];
+  commands[0]=msg_from_ROS[1];
+  commands[1]=msg_from_ROS[2];
 }

 bool receive_data_from_ROS() {
   if(Serial.available()){
     int i=0;
     while (Serial.available()) {
-      msg_from_ROS[i] = Serial.read();
+      msg_from_ROS[i++] = Serial.read();
     }
+    parseROStoRobot();
     return true;
   }
   return false;
 }

+int online=0;
+
 void send_data_to_robot() {
   radio.stopListening();
-  radio.write(msg_from_ROS, sizeof(msg_from_ROS));
+  radio.openWritingPipe(pipe[robotPipe]);
+  online = radio.write(commands, sizeof(commands));
   radio.startListening();
 }


Position platform in initial state before starting pano.

--- gigapanplus.ino
+++ gigapanplus.ino
@@ -115,6 +115,26 @@
     display.display();
 }

+void positionCamera(void){
+    int pos_x, pos_y;
+    display.clearDisplay();
+    display.setCursor(0,0);
+    display.println("  \x1e  \n"
+                    "\x11 x \x10\n"
+                    "  \x1f");
+    display.display();
+    while (!Joystick::isEventClick(joystick.read())){
+        pos_x = joystick.getPositionX();
+        pos_y = joystick.getPositionY();
+        if (pos_x){
+            horiz_motor.move(4*pos_x);
+        }
+        if (pos_y){
+            vert_motor.move(4*pos_y);
+        }
+    }
+}
+
 void loop() {
     if (!running){
         int event = joystick.read();
@@ -137,6 +157,8 @@
                 pano.setFOV(horiz, vert);
                 pano.setShutter(shutter, pre_shutter);
                 pano.setShots(shots);
+
+                positionCamera();

                 stop_running = false;
                 attachInterrupt(digitalPinToInterrupt(JOYSTICK_SW), button_click, FALLING);


All peripherals added (I think)

All peripherals added (I think)

--- Arduino/hardware/V0p2_Main_PCB_REV7_DORM1_and_REV8/testsuite/201611/REV7Minimal/REV7Minimal.ino
+++ Arduino/hardware/V0p2_Main_PCB_REV7_DORM1_and_REV8/testsuite/201611/REV7Minimal/REV7Minimal.ino
@@ -79,6 +79,19 @@
  * - UART       Disable
  */

+/**
+ * Dummy Types
+ */
+// Placeholder class with dummy static status methods to reduce code complexity.
+typedef OTV0P2BASE::DummySensorOccupancyTracker OccupancyTracker;
+
+/**
+ * Supply Voltage instance
+ */
+// Sensor for supply (eg battery) voltage in millivolts.
+// Singleton implementation/instance.
+OTV0P2BASE::SupplyVoltageCentiVolts Supply_cV;
+
 /*
  * Radio instance
  */
@@ -114,12 +127,12 @@
 /**
  * Temp pot
  */
-//#define TEMP_POT_AVAILABLE
-//// Sensor for temperature potentiometer/dial UI control.
-//// Correct for DORM1/TRV1 with embedded REV7.
-//// REV7 does not drive pot from IO_POWER_UP.
-//typedef OTV0P2BASE::SensorTemperaturePot<decltype(Occupancy), &Occupancy, 48, 296, false> TempPot_t;
-//TempPot_t TempPot;
+#define TEMP_POT_AVAILABLE
+// Sensor for temperature potentiometer/dial UI control.
+// Correct for DORM1/TRV1 with embedded REV7.
+// REV7 does not drive pot from IO_POWER_UP.
+typedef OTV0P2BASE::SensorTemperaturePot<OccupancyTracker, nullptr, 48, 296, false> TempPot_t;
+TempPot_t TempPot;

 /**
  * Ambient Light Sensor
@@ -131,16 +144,16 @@
 /**
  * Valve Actuator
  */
-//// DORM1/REV7 direct drive motor actuator.
-//static constexpr bool binaryOnlyValveControl = false;
-//#define HAS_DORM1_VALVE_DRIVE
-//static constexpr uint8_t m1 = MOTOR_DRIVE_ML;
-//static constexpr uint8_t m2 = MOTOR_DRIVE_MR;
-//typedef OTRadValve::ValveMotorDirectV1<m1, m2, MOTOR_DRIVE_MI_AIN, MOTOR_DRIVE_MC_AIN, decltype(Supply_cV), &Supply_cV, binaryOnlyValveControl> ValveDirect_t;
-//// Singleton implementation/instance.
-//// Suppress unnecessary activity when room dark, eg to avoid disturbance if device crashes/restarts,
-//// unless recent UI use because value is being fitted/adjusted.
-//ValveDirect_t ValveDirect([](){return((!valveUI.veryRecentUIControlUse()) && AmbLight.isRoomDark());});
+// DORM1/REV7 direct drive motor actuator.
+static constexpr bool binaryOnlyValveControl = false;
+#define HAS_DORM1_VALVE_DRIVE
+static constexpr uint8_t m1 = MOTOR_DRIVE_ML;
+static constexpr uint8_t m2 = MOTOR_DRIVE_MR;
+typedef OTRadValve::ValveMotorDirectV1<m1, m2, MOTOR_DRIVE_MI_AIN, MOTOR_DRIVE_MC_AIN, decltype(Supply_cV), &Supply_cV, binaryOnlyValveControl> ValveDirect_t;
+// Singleton implementation/instance.
+// Suppress unnecessary activity when room dark, eg to avoid disturbance if device crashes/restarts,
+// unless recent UI use because value is being fitted/adjusted.
+ValveDirect_t ValveDirect([](){return(AmbLight.isRoomDark());});

 // FUNCTIONS

@@ -223,25 +236,29 @@
     // Collect full set of environmental values before entering loop() in normal mode.
     // This should also help ensure that sensors are properly initialised.

-    // No external sensors are *assumed* present if running alt main loop.
+    // No external sensors are *assumed* present if running alt main loop
     // This may mean that the alt loop/POST will have to initialise them explicitly,
     // and the initial seed entropy may be marginally reduced also.
+    const int cV = Supply_cV.read();
+    DEBUG_SERIAL_PRINT_FLASHSTRING("V: ");
+    DEBUG_SERIAL_PRINT(cV);
+    DEBUG_SERIAL_PRINTLN();
     const int heat = TemperatureC16.read();
     DEBUG_SERIAL_PRINT_FLASHSTRING("T: ");
     DEBUG_SERIAL_PRINT(heat);
     DEBUG_SERIAL_PRINTLN();
+    const uint8_t rh = RelHumidity.read();
+    DEBUG_SERIAL_PRINT_FLASHSTRING("RH%: ");
+    DEBUG_SERIAL_PRINT(rh);
+    DEBUG_SERIAL_PRINTLN();
     const int light = AmbLight.read();
     DEBUG_SERIAL_PRINT_FLASHSTRING("L: ");
     DEBUG_SERIAL_PRINT(light);
     DEBUG_SERIAL_PRINTLN();
-    const uint8_t rh = RelHumidity.read();
-    DEBUG_SERIAL_PRINT_FLASHSTRING("RH%: ");
-    DEBUG_SERIAL_PRINT(rh);
-    DEBUG_SERIAL_PRINTLN();
-//    const int tempPot = TempPot.read();
-//    DEBUG_SERIAL_PRINT_FLASHSTRING("temp pot: ");
-//    DEBUG_SERIAL_PRINT(tempPot);
-//    DEBUG_SERIAL_PRINTLN();
+    const int tempPot = TempPot.read();
+    DEBUG_SERIAL_PRINT_FLASHSTRING("temp pot: ");
+    DEBUG_SERIAL_PRINT(tempPot);
+    DEBUG_SERIAL_PRINTLN();

     // Initialised: turn main/heatcall UI LED off.
     OTV0P2BASE::LED_HEATCALL_OFF();


Update MRLCommOculus2.ino

Update MRLCommOculus2.ino

--- home/Alessandruino/MRLCommOculus2.ino
+++ home/Alessandruino/MRLCommOculus2.ino
@@ -212,8 +212,6 @@
 // ------ error types ------
 #define SENSOR_ULTRASONIC				1

-#define CUSTOM_MSG						50
-
 // need a method to identify type of board
 // http://forum.arduino.cc/index.php?topic=100557.0

@@ -340,8 +338,7 @@
 servo_type servos[MAX_SERVOS];

 // Motors
-typedef struct
-{
+typedef struct {
     int index; // index of this motor
     int speed;
     int targetPos;
@@ -465,7 +462,7 @@
 	Serial.write(MAGIC_NUMBER);
 	Serial.write(paramBuffIndex + 2); // = param buff size + FN + paramCnt
 	//Serial.write(2); // = param buff size + FN + paramCnt
-	Serial.write(CUSTOM_MSG);
+	Serial.write(PUBLISH_CUSTOM_MSG);
 	Serial.write(paramCnt);

 	for (int i = 0; i < paramBuffIndex; ++i){


Servo control

Servo control

--- robot/robot.ino
+++ robot/robot.ino
@@ -2,12 +2,22 @@

 // if you need PWM, just use the PWM outputs on the Arduino
 // and instead of digitalWrite, you should use the analogWrite command
+
+#include <Servo.h>
+
+Servo servo;
+int pos = 0;
+
+// Servo degree increment
+#define SERVO_INC 3

 // Bit masks for commands
 #define FULL_STOP 0xc0
 #define AXIS_Y 0x20
 #define DIRECTION_POS 0x10
 #define SPEED_MASK 0x0f
+#define SERVO_CTRL 0x80
+#define SERVO_MASK 0x3f

 // Motor pins
 int motor_y[] = {3, 5};
@@ -15,6 +25,9 @@

 void setup() {
   Serial.begin(9600);
+
+  // Use pin 7 for the servo
+  servo.attach(7);

   // Setup motors
   int i;
@@ -27,9 +40,6 @@
   digitalWrite(motor_x[1], LOW);
   digitalWrite(motor_y[0], LOW);
   digitalWrite(motor_y[1], LOW);
-
-  while (!Serial.available());
-  Serial.println("Starting Serial Communication");
 }

 void loop() {
@@ -38,13 +48,21 @@
     Serial.readBytes(&command, 1);
     Serial.println(command, BIN);

-    // Determine whether to full stop motors or not
+    // Determine whether to full stop motors, servo command, or move command
     if (command & FULL_STOP) {
       Serial.println("Full stop");
       digitalWrite(motor_x[0], LOW);
       digitalWrite(motor_x[1], LOW);
       digitalWrite(motor_y[0], LOW);
       digitalWrite(motor_y[1], LOW);
+    } else if (command & SERVO_CONTROL) {
+      uint8_t angle = command & SERVO_MASK;
+      if (angle > 60) {
+        angle = 60;
+      }
+
+      int real_angle = angle * SERVO_INC;
+      servo.write(real_angle);
     } else {
       uint8_t axis = 0;
       if (command & AXIS_Y) {


Add SM3.0 note

Add SM3.0 note

--- SmartMatrix_Fadecandy.ino
+++ SmartMatrix_Fadecandy.ino
@@ -21,6 +21,8 @@
  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
+
+// Requires SmartMatrix 3.0 branch

 // There are issues compiling, if you see "undefined reference" and "error: ld return 1", wait a few seconds then try compiling again
 // the order of #includes is very sensitive, including <SmartMatrix.h> before "Layer_Fadecandy.h" will break things for example


--- examples/IRremoteInfo/IRremoteInfo.ino
+++ examples/IRremoteInfo/IRremoteInfo.ino
@@ -12,6 +12,22 @@

 #include <IRremote.h>
+
+// Function declarations for non Arduino IDE's
+void dumpHeader();
+void dumpRAWBUF();
+void dumpTIMER();
+void dumpTimerPin();
+void dumpClock();
+void dumpPlatform();
+void dumpPulseParams();
+void dumpSignalParams();
+void dumpArduinoIDE();
+void dumpDebugMode();
+void dumpProtocols();
+void dumpFooter();
+void printSendEnabled(int flag);
+void printDecodeEnabled(int flag);

 void setup()
 {
@@ -112,23 +128,23 @@
 #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__)
   Serial.println(F("ATmega644"));
 #elif defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) || defined(__AVR_ATmega324PA__)
-  Serial.println(F("ATmega324"));
+  Serial.println(F("ATmega324"));
 #elif defined(__AVR_ATmega164A__) || defined(__AVR_ATmega164P__)
   Serial.println(F("ATmega164"));
 #elif defined(__AVR_ATmega128__)
   Serial.println(F("ATmega128"));
 #elif defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__)
-  Serial.println(F("ATmega88"));
+  Serial.println(F("ATmega88"));
 #elif defined(__AVR_ATmega64__)
   Serial.println(F("ATmega64"));
 #elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega48P__)
   Serial.println(F("ATmega48"));
 #elif defined(__AVR_ATmega32__)
-  Serial.println(F("ATmega32"));
+  Serial.println(F("ATmega32"));
 #elif defined(__AVR_ATmega16__)
   Serial.println(F("ATmega16"));
 #elif defined(__AVR_ATmega8535__)
-  Serial.println(F("ATmega8535"));
+  Serial.println(F("ATmega8535"));
 #elif defined(__AVR_ATmega8__)
   Serial.println(F("Atmega8"));
 #elif defined(__AVR_ATtiny84__)


Torque control

Torque control

--- examples/SerialDriver/SerialDriver.ino
+++ examples/SerialDriver/SerialDriver.ino
@@ -6,6 +6,7 @@
  * 1.1 Added variable speed control
  * 1.2 Added support for driving multiple motors
  * 1.3 Moved all Armdroid routines into new class library
+ * 1.4 Added Torque control enhancements
  */

 #include "Armdroid.h"
@@ -125,9 +126,16 @@
       Serial.println(rxCmdVal);
       rxCmdVal = 0;
     }
+    else if (ch == 't') {
+      // torque enablement
+      myArm.torqueMotors( (boolean) rxCmdVal );
+      Serial.print("torque = ");
+      Serial.println(rxCmdVal ? "enabled" : "disabled");
+      rxCmdVal = 0;
+    }
     else if (ch == 'v') {
       // returns firmware/protocol version
-      Serial.println("version = 1.3");
+      Serial.println("firmware version = 2.0/protocol = 1.0a");
     }
   }
 }


Update class name. ToDo: search slave address.

--- examples/ambientlight/ambientlight.ino
+++ examples/ambientlight/ambientlight.ino
@@ -6,6 +6,8 @@

 #include <Wire.h>
 #include "fabo-isl29034.h"
+
+FaBoAmbientLight faboAmbientLight;

 void setup()
 {


better comments to sync with diagram

better comments to sync with diagram

--- sensors/letterbox/letterbox.ino
+++ sensors/letterbox/letterbox.ino
@@ -2,11 +2,11 @@
 // Written by Adafruit! Public domain.
 // To use: Connect:

-// VCC to 3.3-5V (5V is best if it is available)
-// GND to ground
-// SDA to i2c data (on classic arduinos Analog 4)
-// SCL to i2c clock (on classic arduinos, Analog 5)
-// The 3.3v pin is an ouptut if you need 3.3V
+// VCC to 3.3-5V (5V is best if it is available)     [pin 7 in diagram]
+// GND to ground                                     [pin 12 in diagram]
+// SDA to i2c data (on classic arduinos Analog 4)    [pin 4 in diagram]
+// SCL to i2c clock (on classic arduinos, Analog 5)  [pin 5 in diagram]
+// The 3.3v pin is an ouptut if you need 3.3V

 // This sensor is 5V compliant so you can use it with 3.3 or 5V micros


working, had an issue after several minutes of runningm need to investigate why

--- src/src.ino
+++ src/src.ino
@@ -48,7 +48,7 @@
 	dht = new DHT(DHT11_PIN, DHTTYPE, 11);
 	timer->forceUpdate();

-	instruction = new Instruction(timer, 16.0, 18.0, (long) 0);
+	instruction = new Instruction(timer, 16.0, 18.0, (long) 1509812400);

 	smoother = new DHTSmoother(dht, timer, 0.08, (long)2);


Added echoback of PUART from BLE

Added echoback of PUART from BLE

--- Sensorizer.ino
+++ Sensorizer.ino
@@ -248,6 +248,11 @@
     SerialUSB.write(Serial.read());
   }

+  #if ENABLE_ECHO_PUART_FROM_BLE
+  while(Serial1.available()) {
+    SerialUSB.write(Serial1.read());
+  }
+  #endif
 #endif


Fix comment

Fix comment

--- Rxspeed/Rxspeed.ino
+++ Rxspeed/Rxspeed.ino
@@ -1,5 +1,5 @@
 /***************************************************
-  select() and CC3000 read() speed tests
+  select() and CC3000 library available() speed tests

   Run generator.py on a machine first, then update the network
   and server IP/port info below to run.


Fix rx tx pins Change_Baud_Rate Example

Fix rx tx pins Change_Baud_Rate Example

--- examples/Change_Baud_Rate/Change_Baud_Rate.ino
+++ examples/Change_Baud_Rate/Change_Baud_Rate.ino
@@ -1,7 +1,7 @@

 #include<CS5490.h>

-#define rx 13
+#define rx 11
 #define tx 12

 /* Choose your board */


Cleanup of output.

Cleanup of output.

--- examples/Sandbox/CosaVigenere/CosaVigenere.ino
+++ examples/Sandbox/CosaVigenere/CosaVigenere.ino
@@ -79,7 +79,7 @@
   s = msg;
   while ((c = pgm_read_byte(s++)) != 0)
     trace << sender.encode(c);
-
+  trace << endl;
   // Test#3: Running the message through the encoder/decoder
   trace << PSTR("DECODED MESSAGE") << endl;
   Vigenere<32> receiver("QUEENLY");


If no new NTP broadcast in maxTimeAge seconds (24 hours), forget time

It's not going to be near real world time anyway.

--- SetTime/SetTime.ino
+++ SetTime/SetTime.ino
@@ -222,6 +222,9 @@
 static const unsigned int timerPreload = 65536 - systemHz / prescaler / (1 / bitLength) + finetuning;

 static const double two_to_32 = 4294967296.0;
+static const uint32_t maxTimeAge = 10 /* 24ul * 3600ul */; // maximum number of seconds we maintain a time without hearing from network
+
+uint32_t timeExpireSeconds = 0; // how long till we forget the time (as it has probably become stale)

 // how much to advance curTimeFractions in the interrupt handler
 volatile uint32_t fractionsPerOverflow = two_to_32 * bitLength;
@@ -358,7 +361,16 @@
       uint32_t now = curTime;
       bool curShowColon = !(curTimeFractions >> 31);
       interrupts();
-      if (now != prevTime || prevShowColon != curShowColon) {
+      if (now != prevTime) {
+        if (timeExpireSeconds > 0) {
+          --timeExpireSeconds;
+        } else {
+          timeExpireSeconds = 0;
+          knowTime = 0;
+          setDigits(10, 10, 10, 10, B8(0110000));
+        }
+      }
+      if (knowTime && (now != prevTime || prevShowColon != curShowColon)) {
         prevTime = now;
         struct tm tm;
         gmtime_r(now, &tm);
@@ -477,6 +489,7 @@
       previousNtp = t1;
       previousNtpFractions = t2;
       knowTime = true;
+      timeExpireSeconds = maxTimeAge;
     }
   }
   digitalWrite(debug, LOW);


Update blink_tiny.ino: changed blinkrate argument to uint32_t

--- examples/blink_tiny/blink_tiny.ino
+++ examples/blink_tiny/blink_tiny.ino
@@ -1,61 +1,61 @@
-#include <Automaton.h>
-
-class Blink : public TinyMachine {
-
-  public:
-    Blink( void ) : TinyMachine() { };
-
-    short pin;
-    atm_timer_millis timer;
-
-	enum { LED_ON, LED_OFF } STATES;
-	enum { EVT_TIMER, ELSE } EVENTS;
-	enum { ACT_ON, ACT_OFF } ACTIONS;
-
-    Blink & begin( int attached_pin, int blinkrate )
-    {
-      const static tiny_state_t state_table[] PROGMEM = {
-      /*            ON_ENTER    ON_LOOP  ON_EXIT  EVT_TIMER   ELSE */
-      /* LED_ON  */   ACT_ON,        -1,      -1,   LED_OFF,    -1,
-      /* LED_OFF */  ACT_OFF,        -1,      -1,    LED_ON,    -1 };
-      TinyMachine::begin( state_table, ELSE );
-      pin = attached_pin;
-      timer.begin( this, blinkrate );
-      pinMode( pin, OUTPUT );
-      return *this;
-    }
-
-    int event( int id )
-    {
-      switch ( id ) {
-        case EVT_TIMER :
-          return timer.expired();
-       }
-       return 0;
-    }
-
-    void action( int id )
-    {
-      switch ( id ) {
-        case ACT_ON :
-          digitalWrite( pin, HIGH );
-          return;
-        case ACT_OFF :
-          digitalWrite( pin, LOW );
-          return;
-       }
-    }
-};
-
-Blink led;
-
-void setup()
-{
-  led.begin( 3, 200 );
-}
-
-void loop()
-{
-  led.cycle();
-}
+#include <Automaton.h>

+class Blink : public TinyMachine {
+
+  public:
+    Blink( void ) : TinyMachine() { };
+
+    short pin;
+    atm_timer_millis timer;
+
+	enum { LED_ON, LED_OFF } STATES;
+	enum { EVT_TIMER, ELSE } EVENTS;
+	enum { ACT_ON, ACT_OFF } ACTIONS;
+
+    Blink & begin( int attached_pin, uint32_t blinkrate )
+    {
+      const static tiny_state_t state_table[] PROGMEM = {
+      /*            ON_ENTER    ON_LOOP  ON_EXIT  EVT_TIMER   ELSE */
+      /* LED_ON  */   ACT_ON,        -1,      -1,   LED_OFF,    -1,
+      /* LED_OFF */  ACT_OFF,        -1,      -1,    LED_ON,    -1 };
+      TinyMachine::begin( state_table, ELSE );
+      pin = attached_pin;
+      timer.begin( this, blinkrate );
+      pinMode( pin, OUTPUT );
+      return *this;
+    }
+
+    int event( int id )
+    {
+      switch ( id ) {
+        case EVT_TIMER :
+          return timer.expired();
+       }
+       return 0;
+    }
+
+    void action( int id )
+    {
+      switch ( id ) {
+        case ACT_ON :
+          digitalWrite( pin, HIGH );
+          return;
+        case ACT_OFF :
+          digitalWrite( pin, LOW );
+          return;
+       }
+    }
+};
+
+Blink led;
+
+void setup()
+{
+  led.begin( 3, 200 );
+}
+
+void loop()
+{
+  led.cycle();
+}
+


Use some other registers to free up ram.

--- lampka.ino
+++ lampka.ino
@@ -7,7 +7,7 @@

 // Change this to be at least as long as your pixel string (too long will work fine, just be a little slower)

-#define PIXELS 12  // Number of pixels in the string
+#define PIXELS 14  // Number of pixels in the string

 // These values depend on which pin your string is connected to and what board you are using
 // More info on how to find these at http://www.arduino.cc/en/Reference/PortManipulation
@@ -365,17 +365,27 @@
     PCMSK |= (1<<constantButtonPin); //PCINT[5:0]: Pin Change Enable Mask 5:0
 }

+#define constant_color_index OCR0B
+#define direction OCR0A
+#define set_constant_1 DDRB |= (1<<2)
+#define set_constant_0 DDRB &= ~(1<<2)
+#define constant_eq_1 DDRB & (1<<2)
+#define current_hue EEDR
+
 void setup() {
     interruptSetup();
     ledsetup();
+    direction = 1;
+    constant_color_index = 0;
+    set_constant_0;
 }

 const uint8_t delta = (256/PIXELS); //delta of hue between each pixel, spread out evenly
-boolean constant=0;
-int8_t direction = 1;
+//boolean constant=0;
+//int8_t direction = 1;
 uint8_t led_colors[PIXELS][3];
-uint8_t constant_color_index=0;
-uint8_t current_hue=0;
+//uint8_t constant_color_index=0;
+//uint8_t current_hue=0;

 ISR(PCINT0_vect) {
     cli();
@@ -387,7 +397,9 @@
         direction -= 1;
     }
     if (PINB & 1) { //constant color
-        DDRB |= (1<<2); //constant=1
+        set_constant_1;
+        //DDRB |= (1<<2); //constant=1
+
         constant_color_index++;
         constant_color_index = constant_color_index % 9; //8 is white
     }
@@ -411,7 +423,7 @@
     clear_led_colors();
     uint8_t hue_to_compute = 0;
     for (uint8_t index=0; index < PIXELS; index++) {
-        if (DDRB & (1<<2)) {
+        if (constant_eq_1) {
             if (constant_color_index == 8) { //white
                 led_colors[index][0]=255;
                 led_colors[index][1]=255;


updated parallel out 2

updated parallel out 2

--- proj/parallel_out_test_2/parallel_out_test_2.ino
+++ proj/parallel_out_test_2/parallel_out_test_2.ino
@@ -12,9 +12,6 @@
 //

 void setup() {
-  // LEDS.addLeds<WS2811_PORTA,NUM_STRIPS>(leds, NUM_LEDS_PER_STRIP);
-  // LEDS.addLeds<WS2811_PORTB,NUM_STRIPS>(leds, NUM_LEDS_PER_STRIP);
-  // LEDS.addLeds<WS2811_PORTD,NUM_STRIPS>(leds, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
   LEDS.addLeds<WS2811_PORTD, NUM_STRIPS>(leds, NUM_LED);
   LEDS.setBrightness(32);

@@ -22,12 +19,21 @@
 }

 void loop() {
-
+  static uint8_t hue = 0;
   for (int i = 0; i < NUM_STRIPS; i++) {
     for (int j = 0; j < NUM_LED; j++) {
-      leds[(i * NUM_LED) + j] = CHSV((32 * i), 192, 255);
+      leds[(i * NUM_LED) + j] = CHSV((32 * i) + hue + j, 192, 255);
     }
   }
+
+  // Set the first n leds on each strip to show which strip it is
+  for (int i = 0; i < NUM_STRIPS; i++) {
+    for (int j = 0; j <= i; j++) {
+      leds[(i * NUM_LED) + j] = CRGB::Red;
+    }
+  }
+
+  hue++;

   LEDS.show();
   LEDS.delay(10);