Add IRQ on Gateway
This commit is contained in:
@@ -8,8 +8,11 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:pro16MHzatmega328]
|
||||
[env:pro8MHzatmega328]
|
||||
platform = atmelavr
|
||||
board = pro16MHzatmega328
|
||||
board = pro8MHzatmega328
|
||||
framework = arduino
|
||||
lib_deps = mysensors/MySensors@^2.3.2
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
mysensors/MySensors@^2.3.2
|
||||
thomasfredericks/Bounce2 @ ^2.55
|
||||
|
||||
@@ -3,30 +3,100 @@
|
||||
#define MY_RADIO_RF24
|
||||
#define MY_RF24_CHANNEL (105)
|
||||
#define MY_RF24_PA_LEVEL RF24_PA_HIGH
|
||||
#include <MySensors.h>
|
||||
|
||||
#define SOCK1 2
|
||||
#define SOCK2 3
|
||||
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
||||
#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin
|
||||
#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
|
||||
#define RELAY1 A0
|
||||
#define RELAY2 A1
|
||||
#define MY_DEFAULT_ERR_LED_PIN (4) // Error led pin
|
||||
#define MY_DEFAULT_RX_LED_PIN (5) // Receive led pin
|
||||
#define MY_DEFAULT_TX_LED_PIN (6) // the PCB, on board LED
|
||||
#define BUTT1 8
|
||||
#define BUTT2 7
|
||||
|
||||
#include <MySensors.h>
|
||||
#include <Bounce2.h>
|
||||
|
||||
|
||||
// #undef MY_NODE_ID
|
||||
// #define MY_NODE_ID 14
|
||||
|
||||
bool stat1, stat2;
|
||||
void presentation();
|
||||
void sendData(MyMessage msg, bool status);
|
||||
void sendData(MyMessage msg, bool status, mysensors_data_t msd);
|
||||
void receive(const MyMessage &message);
|
||||
|
||||
MyMessage msgMillis(2, V_VAR1);
|
||||
MyMessage msgSock1s(0, V_STATUS);
|
||||
MyMessage msgSock2s(1, V_STATUS);
|
||||
MyMessage msgSock1(2, V_VAR2);
|
||||
MyMessage msgSock2(2, V_VAR3);
|
||||
|
||||
Bounce butt1 = Bounce(), butt2 = Bounce();
|
||||
|
||||
void setup() {
|
||||
pinMode(SOCK1, OUTPUT);
|
||||
pinMode(SOCK2, OUTPUT);
|
||||
pinMode(RELAY1, OUTPUT);
|
||||
pinMode(RELAY2, OUTPUT);
|
||||
butt1.attach(BUTT1, INPUT_PULLUP);
|
||||
butt2.attach(BUTT2, INPUT_PULLUP);
|
||||
butt1.interval(25);
|
||||
butt2.interval(25);
|
||||
stat1 = loadState(0);
|
||||
digitalWrite(SOCK1, stat1);
|
||||
digitalWrite(RELAY1, !stat1);
|
||||
stat2 = loadState(1);
|
||||
digitalWrite(SOCK2, stat2);
|
||||
digitalWrite(RELAY2, !stat2);
|
||||
sendData(msgSock1s, !stat1, V_STATUS);
|
||||
wait(100);
|
||||
sendData(msgSock2s, !stat2, V_STATUS);
|
||||
wait(100);
|
||||
sendData(msgSock1, !stat1, V_VAR2);
|
||||
wait(100);
|
||||
sendData(msgSock2, !stat2, V_VAR3);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint32_t cRun = millis();
|
||||
if((cRun + 10000) <= millis()){
|
||||
static uint32_t cRun = millis() - 60000;
|
||||
butt1.update();
|
||||
butt2.update();
|
||||
if(butt1.fell()){
|
||||
stat1 = !stat1;
|
||||
digitalWrite(SOCK1, stat1);
|
||||
digitalWrite(RELAY1, !stat1);
|
||||
sendData(msgSock1s, !stat1, V_STATUS);
|
||||
sendData(msgSock1, !stat1, V_VAR2);
|
||||
saveState(0, stat1);
|
||||
Serial.print(F("Change Sock1: ")); Serial.println(stat1);
|
||||
}
|
||||
if(butt2.fell()){
|
||||
stat2 = !stat2;
|
||||
digitalWrite(SOCK2, stat2);
|
||||
digitalWrite(RELAY2, !stat2);
|
||||
sendData(msgSock2s, !stat2, V_VAR3);
|
||||
sendData(msgSock2, !stat2, V_STATUS);
|
||||
saveState(1, stat2);
|
||||
Serial.print(F("Change Sock2: ")); Serial.println(stat2);
|
||||
}
|
||||
if(stat1 != digitalRead(SOCK1)){
|
||||
Serial.print(F("Curr Sock1: ")); Serial.println(digitalRead(SOCK1));
|
||||
Serial.print(F("Change Sock1: ")); Serial.println(stat1);
|
||||
digitalWrite(SOCK1, stat1);
|
||||
digitalWrite(RELAY1, !stat1);
|
||||
saveState(0, digitalRead(SOCK1));
|
||||
sendData(msgSock1, !stat1, V_VAR2);
|
||||
}
|
||||
if(stat2 != digitalRead(SOCK2)){
|
||||
Serial.print(F("Curr Sock2: ")); Serial.println(digitalRead(SOCK2));
|
||||
digitalWrite(SOCK2, stat2);
|
||||
digitalWrite(RELAY2, !stat2);
|
||||
saveState(1, digitalRead(SOCK2));
|
||||
sendData(msgSock2, !stat2, V_VAR3);
|
||||
Serial.print(F("Change Sock2: ")); Serial.println(stat2);
|
||||
}
|
||||
if((cRun + 60000) <= millis()){
|
||||
cRun = millis();
|
||||
send(msgMillis.set(cRun));
|
||||
}
|
||||
@@ -40,14 +110,14 @@ void presentation()
|
||||
present(2, S_CUSTOM, "ESMillis");
|
||||
}
|
||||
|
||||
void sendData(MyMessage msg, bool status)
|
||||
void sendData(MyMessage msg, bool status, mysensors_data_t msd)
|
||||
{
|
||||
bool send_data = false;
|
||||
uint8_t count = 0;
|
||||
while(send_data == false){
|
||||
count++;
|
||||
send_data = send(msg.set(status));
|
||||
wait(100, C_SET, V_STATUS);
|
||||
wait(100, C_SET, msg.type);
|
||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||
count = 0; // Обнуляем счётчик
|
||||
send_data = 1; // Выходим из цикла
|
||||
@@ -57,15 +127,16 @@ void sendData(MyMessage msg, bool status)
|
||||
|
||||
void receive(const MyMessage &message)
|
||||
{
|
||||
if(message.getType() != V_STATUS) return;
|
||||
switch (message.sensor)
|
||||
{
|
||||
case 0:
|
||||
digitalWrite(SOCK1, message.getBool());
|
||||
sendData(msgSock1, digitalRead(SOCK1));
|
||||
stat1 = !message.getBool();
|
||||
Serial.print(F("Recv1: ")); Serial.println(stat1);
|
||||
break;
|
||||
case 1:
|
||||
digitalWrite(SOCK1, message.getBool());
|
||||
sendData(msgSock2, digitalRead(SOCK2));
|
||||
stat2 = !message.getBool();
|
||||
Serial.print(F("Recv2: ")); Serial.println(stat2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#define MY_RF24_PA_LEVEL RF24_PA_HIGH
|
||||
#define MY_GATEWAY_SERIAL
|
||||
#define MY_RF24_CHANNEL (105)
|
||||
#define MY_RX_MESSAGE_BUFFER_FEATURE
|
||||
#define MY_RF24_IRQ_PIN 2
|
||||
// Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
|
||||
#if F_CPU == 8000000L
|
||||
#define MY_BAUD_RATE 38400
|
||||
|
||||
Reference in New Issue
Block a user