Various fixes for SAMD (#510)

* Only serial GW should hold back on USB

* Fixing some examples on archs other than avr

* HwInit() is needed on samd, to init I2C
This commit is contained in:
Thomas Mørch
2016-07-16 10:01:28 +02:00
committed by Olivier
parent 54c79308e9
commit f0f2542df4
10 changed files with 352 additions and 361 deletions
+19 -20
View File
@@ -20,13 +20,13 @@
*
* REVISION HISTORY
* Version 1.0 - January 30, 2015 - Developed by GizMoCuz (Domoticz)
*
*
* DESCRIPTION
* This sketch provides an example how to implement a Dimmable Light
* This sketch provides an example how to implement a Dimmable Light
* It is pure virtual and it logs messages to the serial output
* It can be used as a base sketch for actual hardware.
* Stores the last light state and level in eeprom.
*
*
*/
// Enable debug prints
@@ -37,7 +37,7 @@
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensors.h>
#include <MySensors.h>
#define CHILD_ID_LIGHT 1
@@ -50,19 +50,19 @@
#define SN "Dimable Light"
#define SV "1.0"
int LastLightState=LIGHT_OFF;
int LastDimValue=100;
int16_t LastLightState=LIGHT_OFF;
int16_t LastDimValue=100;
MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT);
MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
void setup()
{
void setup()
{
//Retreive our last light state from the eprom
int LightState=loadState(EPROM_LIGHT_STATE);
int LightState=loadState(EPROM_LIGHT_STATE);
if (LightState<=1) {
LastLightState=LightState;
int DimValue=loadState(EPROM_DIMMER_LEVEL);
int DimValue=loadState(EPROM_DIMMER_LEVEL);
if ((DimValue>0)&&(DimValue<=100)) {
//There should be no Dim value of 0, this would mean LIGHT_OFF
LastDimValue=DimValue;
@@ -71,8 +71,8 @@ void setup()
//Here you actualy switch on/off the light with the last known dim level
SetCurrentState2Hardware();
Serial.println( "Node ready to receive messages..." );
Serial.println( "Node ready to receive messages..." );
}
void presentation() {
@@ -82,7 +82,7 @@ void presentation() {
present(CHILD_ID_LIGHT, S_DIMMER );
}
void loop()
void loop()
{
}
@@ -90,7 +90,7 @@ void receive(const MyMessage &message)
{
if (message.type == V_LIGHT) {
Serial.println( "V_LIGHT command received..." );
int lstate= atoi( message.data );
if ((lstate<0)||(lstate>1)) {
Serial.println( "V_LIGHT data invalid (should be 0/1)" );
@@ -98,7 +98,7 @@ void receive(const MyMessage &message)
}
LastLightState=lstate;
saveState(EPROM_LIGHT_STATE, LastLightState);
if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) {
//In the case that the Light State = On, but the dimmer value is zero,
//then something (probably the controller) did something wrong,
@@ -106,13 +106,13 @@ void receive(const MyMessage &message)
LastDimValue=100;
saveState(EPROM_DIMMER_LEVEL, LastDimValue);
}
//When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
//This means if you previously set the lights dimmer value to 50%, and turn the light ON
//it will do so at 50%
}
else if (message.type == V_DIMMER) {
Serial.println( "V_DIMMER command received..." );
Serial.println( "V_DIMMER command received..." );
int dimvalue= atoi( message.data );
if ((dimvalue<0)||(dimvalue>100)) {
Serial.println( "V_DIMMER data invalid (should be 0..100)" );
@@ -128,7 +128,7 @@ void receive(const MyMessage &message)
}
}
else {
Serial.println( "Invalid command received..." );
Serial.println( "Invalid command received..." );
return;
}
@@ -153,10 +153,9 @@ void SetCurrentState2Hardware()
void SendCurrentState2Controller()
{
if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
send(dimmerMsg.set(0));
send(dimmerMsg.set((int16_t)0));
}
else {
send(dimmerMsg.set(LastDimValue));
}
}