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:
+1
-1
@@ -100,7 +100,7 @@ void hwWriteConfig(int adr, uint8_t value)
|
|||||||
|
|
||||||
void hwInit() {
|
void hwInit() {
|
||||||
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
|
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
|
||||||
#ifndef MY_GATEWAY_W5100
|
#if defined(MY_GATEWAY_SERIAL)
|
||||||
while (!MY_SERIALDEVICE) {}
|
while (!MY_SERIALDEVICE) {}
|
||||||
#endif
|
#endif
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ void loop()
|
|||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
if (valMQ != lastMQ) {
|
if (valMQ != lastMQ) {
|
||||||
send(msg.set((int)ceil(valMQ)));
|
send(msg.set((int16_t)ceil(valMQ)));
|
||||||
lastMQ = ceil(valMQ);
|
lastMQ = ceil(valMQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ void loop()
|
|||||||
|
|
||||||
if (value != sentValue) {
|
if (value != sentValue) {
|
||||||
// Value has changed from last transmission, send the updated value
|
// Value has changed from last transmission, send the updated value
|
||||||
send(msg.set(value==HIGH ? 1 : 0));
|
send(msg.set(value==HIGH));
|
||||||
sentValue = value;
|
sentValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ void loop()
|
|||||||
|
|
||||||
if (value != sentValue2) {
|
if (value != sentValue2) {
|
||||||
// Value has changed from last transmission, send the updated value
|
// Value has changed from last transmission, send the updated value
|
||||||
send(msg2.set(value==HIGH ? 1 : 0));
|
send(msg2.set(value==HIGH));
|
||||||
sentValue2 = value;
|
sentValue2 = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
#define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin
|
#define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin
|
||||||
#define FADE_DELAY 10 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
|
#define FADE_DELAY 10 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
|
||||||
|
|
||||||
static int currentLevel = 0; // Current dim level...
|
static int16_t currentLevel = 0; // Current dim level...
|
||||||
MyMessage dimmerMsg(0, V_DIMMER);
|
MyMessage dimmerMsg(0, V_DIMMER);
|
||||||
MyMessage lightMsg(0, V_LIGHT);
|
MyMessage lightMsg(0, V_LIGHT);
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ void receive(const MyMessage &message) {
|
|||||||
fadeToLevel( requestedLevel );
|
fadeToLevel( requestedLevel );
|
||||||
|
|
||||||
// Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
|
// Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
|
||||||
send(lightMsg.set(currentLevel > 0 ? 1 : 0));
|
send(lightMsg.set(currentLevel > 0));
|
||||||
|
|
||||||
// hek comment: Is this really nessesary?
|
// hek comment: Is this really nessesary?
|
||||||
send( dimmerMsg.set(currentLevel) );
|
send( dimmerMsg.set(currentLevel) );
|
||||||
@@ -124,4 +124,3 @@ void fadeToLevel( int toLevel ) {
|
|||||||
delay( FADE_DELAY );
|
delay( FADE_DELAY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,8 @@
|
|||||||
#define SN "Dimable Light"
|
#define SN "Dimable Light"
|
||||||
#define SV "1.0"
|
#define SV "1.0"
|
||||||
|
|
||||||
int LastLightState=LIGHT_OFF;
|
int16_t LastLightState=LIGHT_OFF;
|
||||||
int LastDimValue=100;
|
int16_t LastDimValue=100;
|
||||||
|
|
||||||
MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT);
|
MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT);
|
||||||
MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
|
MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
|
||||||
@@ -153,10 +153,9 @@ void SetCurrentState2Hardware()
|
|||||||
void SendCurrentState2Controller()
|
void SendCurrentState2Controller()
|
||||||
{
|
{
|
||||||
if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
|
if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
|
||||||
send(dimmerMsg.set(0));
|
send(dimmerMsg.set((int16_t)0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send(dimmerMsg.set(LastDimValue));
|
send(dimmerMsg.set(LastDimValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void loop() {
|
|||||||
Serial.println(dustDensity); // unit: ug/m3
|
Serial.println(dustDensity); // unit: ug/m3
|
||||||
|
|
||||||
if (ceil(dustDensity) != lastDUST) {
|
if (ceil(dustDensity) != lastDUST) {
|
||||||
send(dustMsg.set((int)ceil(dustDensity)));
|
send(dustMsg.set((int16_t)ceil(dustDensity)));
|
||||||
lastDUST = ceil(dustDensity);
|
lastDUST = ceil(dustDensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ void presentation() {
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
|
int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
|
||||||
Serial.println(lightLevel);
|
Serial.println(lightLevel);
|
||||||
if (lightLevel != lastLightLevel) {
|
if (lightLevel != lastLightLevel) {
|
||||||
send(msg.set(lightLevel));
|
send(msg.set(lightLevel));
|
||||||
|
|||||||
@@ -733,10 +733,10 @@ void door(){
|
|||||||
|
|
||||||
if (randNumber <= 50) {
|
if (randNumber <= 50) {
|
||||||
Serial.println("Open");
|
Serial.println("Open");
|
||||||
send(msg_S_DOOR_T.set(1));
|
send(msg_S_DOOR_T.set((int16_t)1));
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Closed");
|
Serial.println("Closed");
|
||||||
send(msg_S_DOOR_T.set(0));
|
send(msg_S_DOOR_T.set((int16_t)0));
|
||||||
}
|
}
|
||||||
#ifdef ID_S_ARMED
|
#ifdef ID_S_ARMED
|
||||||
Serial.print("System is: " );
|
Serial.print("System is: " );
|
||||||
@@ -1457,10 +1457,3 @@ void receive(const MyMessage &message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -879,7 +879,7 @@ void setup()
|
|||||||
(void)key;
|
(void)key;
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
hwInit();
|
||||||
Serial.println(F("Personalization sketch for MySensors usage."));
|
Serial.println(F("Personalization sketch for MySensors usage."));
|
||||||
Serial.println(F("-------------------------------------------"));
|
Serial.println(F("-------------------------------------------"));
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ void loop()
|
|||||||
{
|
{
|
||||||
|
|
||||||
if(state>=40){ // basically below 40 so ignire basic level
|
if(state>=40){ // basically below 40 so ignire basic level
|
||||||
send(vibrationMsg.set(int(state)));
|
send(vibrationMsg.set(int16_t(state)));
|
||||||
state = 0;
|
state = 0;
|
||||||
digitalWrite(SensorLED,HIGH);
|
digitalWrite(SensorLED,HIGH);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user