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
+1 -1
View File
@@ -100,7 +100,7 @@ void hwWriteConfig(int adr, uint8_t value)
void hwInit() {
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
#ifndef MY_GATEWAY_W5100
#if defined(MY_GATEWAY_SERIAL)
while (!MY_SERIALDEVICE) {}
#endif
Wire.begin();
@@ -116,7 +116,7 @@ void loop()
Serial.print("\n");
if (valMQ != lastMQ) {
send(msg.set((int)ceil(valMQ)));
send(msg.set((int16_t)ceil(valMQ)));
lastMQ = ceil(valMQ);
}
@@ -104,7 +104,7 @@ void loop()
if (value != sentValue) {
// Value has changed from last transmission, send the updated value
send(msg.set(value==HIGH ? 1 : 0));
send(msg.set(value==HIGH));
sentValue = value;
}
@@ -112,7 +112,7 @@ void loop()
if (value != sentValue2) {
// Value has changed from last transmission, send the updated value
send(msg2.set(value==HIGH ? 1 : 0));
send(msg2.set(value==HIGH));
sentValue2 = value;
}
@@ -51,7 +51,7 @@
#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)
static int currentLevel = 0; // Current dim level...
static int16_t currentLevel = 0; // Current dim level...
MyMessage dimmerMsg(0, V_DIMMER);
MyMessage lightMsg(0, V_LIGHT);
@@ -102,7 +102,7 @@ void receive(const MyMessage &message) {
fadeToLevel( requestedLevel );
// 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?
send( dimmerMsg.set(currentLevel) );
@@ -124,4 +124,3 @@ void fadeToLevel( int toLevel ) {
delay( FADE_DELAY );
}
}
+3 -4
View File
@@ -50,8 +50,8 @@
#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);
@@ -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));
}
}
+1 -1
View File
@@ -94,7 +94,7 @@ void loop() {
Serial.println(dustDensity); // unit: ug/m3
if (ceil(dustDensity) != lastDUST) {
send(dustMsg.set((int)ceil(dustDensity)));
send(dustMsg.set((int16_t)ceil(dustDensity)));
lastDUST = ceil(dustDensity);
}
+1 -1
View File
@@ -55,7 +55,7 @@ void presentation() {
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);
if (lightLevel != lastLightLevel) {
send(msg.set(lightLevel));
+2 -9
View File
@@ -733,10 +733,10 @@ void door(){
if (randNumber <= 50) {
Serial.println("Open");
send(msg_S_DOOR_T.set(1));
send(msg_S_DOOR_T.set((int16_t)1));
} else {
Serial.println("Closed");
send(msg_S_DOOR_T.set(0));
send(msg_S_DOOR_T.set((int16_t)0));
}
#ifdef ID_S_ARMED
Serial.print("System is: " );
@@ -1457,10 +1457,3 @@ void receive(const MyMessage &message) {
}
}
@@ -879,7 +879,7 @@ void setup()
(void)key;
Serial.begin(115200);
hwInit();
Serial.println(F("Personalization sketch for MySensors usage."));
Serial.println(F("-------------------------------------------"));
+1 -1
View File
@@ -76,7 +76,7 @@ void loop()
{
if(state>=40){ // basically below 40 so ignire basic level
send(vibrationMsg.set(int(state)));
send(vibrationMsg.set(int16_t(state)));
state = 0;
digitalWrite(SensorLED,HIGH);
} else {