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
@@ -22,16 +22,16 @@
*
* Interrupt driven binary switch example with dual interrupts
* Author: Patrick 'Anticimex' Fallberg
* Connect one button or door/window reed switch between
* Connect one button or door/window reed switch between
* digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
* one in similar fashion on digital I/O pin 2.
* This example is designed to fit Arduino Nano/Pro Mini
*
*
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
@@ -62,14 +62,14 @@
#if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
#error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
#endif
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
void setup()
{
void setup()
{
// Setup the buttons
pinMode(PRIMARY_BUTTON_PIN, INPUT);
pinMode(SECONDARY_BUTTON_PIN, INPUT);
@@ -84,14 +84,14 @@ void presentation() {
sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
// Register binary input sensor to sensor_node (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
present(PRIMARY_CHILD_ID, S_DOOR);
present(SECONDARY_CHILD_ID, S_DOOR);
present(PRIMARY_CHILD_ID, S_DOOR);
present(SECONDARY_CHILD_ID, S_DOOR);
}
// Loop will iterate on changes on the BUTTON_PINs
void loop()
void loop()
{
uint8_t value;
static uint8_t sentValue=2;
@@ -99,23 +99,23 @@ void loop()
// Short delay to allow buttons to properly settle
sleep(5);
value = digitalRead(PRIMARY_BUTTON_PIN);
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;
}
value = digitalRead(SECONDARY_BUTTON_PIN);
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;
}
// Sleep until something happens with the sensor
sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
}
}