Fixed inclusion mode

This commit is contained in:
Yveaux
2015-08-27 10:53:35 +02:00
parent 64e28005b4
commit 0bb5e223b2
2 changed files with 22 additions and 30 deletions
@@ -57,7 +57,10 @@
* - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC
* - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
* *
* Signing, RF69 radio, inclusion button and a separate SPI flash are not supported yet! * Inclusion mode button:
* - Connect GPIO5 via switch to GND ('inclusion switch')
*
* * Signing, RF69 radio and a separate SPI flash are not supported yet!
* *
* Make sure to fill in your ssid and WiFi password below for ssid & pass. * Make sure to fill in your ssid and WiFi password below for ssid & pass.
*/ */
@@ -78,8 +81,8 @@
const char *ssid = "MySSID"; // cannot be longer than 32 characters! const char *ssid = "MySSID"; // cannot be longer than 32 characters!
const char *pass = "MyVerySecretPassword"; // const char *pass = "MyVerySecretPassword"; //
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
// #define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button #define INCLUSION_MODE_PIN 5 // Digital pin used for inclusion mode button
#define RADIO_CE_PIN 4 // radio chip enable #define RADIO_CE_PIN 4 // radio chip enable
#define RADIO_SPI_SS_PIN 15 // radio SPI serial select #define RADIO_SPI_SS_PIN 15 // radio SPI serial select
@@ -127,9 +130,9 @@ void output(const char *fmt, ... ) {
void setup() void setup()
{ {
// Setup console // Setup console
Serial.begin(115200); hw_init();
Serial.println(); Serial.println(); Serial.println();
Serial.println("ESP8266 MySensors Gateway"); Serial.println("ESP8266 MySensors Gateway");
Serial.print("Connecting to "); Serial.println(ssid); Serial.print("Connecting to "); Serial.println(ssid);
@@ -142,15 +145,8 @@ void setup()
Serial.print("IP: "); Serial.println(WiFi.localIP()); Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.flush(); Serial.flush();
#ifndef INCLUSION_MODE_PIN
setupGateway(255, INCLUSION_MODE_TIME, output);
#else
setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output); setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
// Add interrupt for inclusion button to pin
PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
#endif
// Initialize gateway at maximum PA level, channel 70 and callback for write operations // Initialize gateway at maximum PA level, channel 70 and callback for write operations
gw.begin(incomingMessage, 0, true, 0); gw.begin(incomingMessage, 0, true, 0);
@@ -162,10 +158,8 @@ void setup()
void loop() { void loop() {
gw.process(); gw.process();
#ifdef INCLUSION_MODE_PIN
checkButtonTriggeredInclusion(); checkButtonTriggeredInclusion();
checkInclusionFinished(); checkInclusionFinished();
#endif
//check if there are any new clients //check if there are any new clients
if (server.hasClient()) if (server.hasClient())
@@ -1,20 +1,17 @@
#ifndef __GATEWAYUTIL_H__ #ifndef __GATEWAYUTIL_H__
#define __GATEWAYUTIL_H__ #define __GATEWAYUTIL_H__
#include <MyTransport.h>
#ifdef ARDUINO #ifdef ARDUINO
uint8_t inclusionTime = 1; // Number of minutes inclusion mode is enabled static uint8_t inclusionTime = 1; // Number of minutes inclusion mode is enabled
uint8_t pinInclusion = 3; // Input pin that should trigger inclusion mode static uint8_t pinInclusion = 3; // Input pin that should trigger inclusion mode
#define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from controller #define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from controller
#define MAX_SEND_LENGTH 120 // Max buffersize needed for messages destined for controller #define MAX_SEND_LENGTH 120 // Max buffersize needed for messages destined for controller
volatile boolean buttonTriggeredInclusion; static volatile boolean buttonTriggeredInclusion;
boolean inclusionMode; // Keeps track on inclusion mode static boolean inclusionMode; // Keeps track on inclusion mode
bool inclusionButtonSupported = false; bool inclusionButtonSupported = false;
void (*serial)(const char *fmt, ... ); void (*serial)(const char *fmt, ... );
@@ -26,6 +23,11 @@ char convBuf[MAX_PAYLOAD*2+1];
char serialBuffer[MAX_SEND_LENGTH]; // Buffer for building string when sending data to vera char serialBuffer[MAX_SEND_LENGTH]; // Buffer for building string when sending data to vera
unsigned long inclusionStartTime; unsigned long inclusionStartTime;
void startInclusionInterrupt() {
buttonTriggeredInclusion = true;
}
void setupGateway(uint8_t _inc, uint8_t _incTime, void (* _serial)(const char *, ... )) { void setupGateway(uint8_t _inc, uint8_t _incTime, void (* _serial)(const char *, ... )) {
inclusionMode = 0; inclusionMode = 0;
buttonTriggeredInclusion = false; buttonTriggeredInclusion = false;
@@ -38,17 +40,13 @@ void setupGateway(uint8_t _inc, uint8_t _incTime, void (* _serial)(const char *,
pinInclusion = _inc; pinInclusion = _inc;
// Setup digital in that triggers inclusion mode // Setup digital in that triggers inclusion mode
pinMode(pinInclusion, INPUT); pinMode(pinInclusion, INPUT_PULLUP);
digitalWrite(pinInclusion, HIGH);
// Add interrupt for inclusion button to pin
attachInterrupt(pinInclusion, startInclusionInterrupt, FALLING);
} }
} }
void startInclusionInterrupt() {
buttonTriggeredInclusion = true;
}
void incomingMessage(const MyMessage &message) { void incomingMessage(const MyMessage &message) {
// if (mGetCommand(message) == C_PRESENTATION && inclusionMode) { // if (mGetCommand(message) == C_PRESENTATION && inclusionMode) {
// gw.rxBlink(3); // gw.rxBlink(3);