Browse Source

First try for LightFox dual

rules-rpn
Andrey F. Kupreychik 6 years ago
parent
commit
4202d3769c
7 changed files with 95 additions and 3 deletions
  1. +37
    -2
      code/espurna/button.ino
  2. +1
    -0
      code/espurna/config/arduino.h
  3. +21
    -0
      code/espurna/config/hardware.h
  4. +10
    -0
      code/espurna/migrate.ino
  5. +2
    -0
      code/espurna/relay.ino
  6. +1
    -1
      code/espurna/system.ino
  7. +23
    -0
      code/platformio.ini

+ 37
- 2
code/espurna/button.ino View File

@ -140,13 +140,25 @@ void buttonEvent(unsigned int id, unsigned char event) {
void buttonSetup() { void buttonSetup() {
#ifdef ITEAD_SONOFF_DUAL
#if defined(ITEAD_SONOFF_DUAL)
unsigned int actions = buttonStore(BUTTON_MODE_NONE, BUTTON_MODE_TOGGLE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE); unsigned int actions = buttonStore(BUTTON_MODE_NONE, BUTTON_MODE_TOGGLE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE);
_buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 1}); _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 1});
_buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 2}); _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 2});
_buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, BUTTON3_RELAY}); _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, BUTTON3_RELAY});
#elif defined(FOXEL_LIGHTFOX_DUAL)
unsigned int actions = buttonStore(BUTTON_MODE_NONE, BUTTON_MODE_TOGGLE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE);
unsigned int btn1Relay = getSetting("btnRelay", 0, BUTTON1_RELAY - 1).toInt() + 1;
_buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, btn1Relay});
unsigned int btn2Relay = getSetting("btnRelay", 1, BUTTON2_RELAY - 1).toInt() + 1;
_buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, btn2Relay});
unsigned int btn3Relay = getSetting("btnRelay", 2, BUTTON3_RELAY - 1).toInt() + 1;
_buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, btn3Relay});
unsigned int btn4Relay = getSetting("btnRelay", 3, BUTTON4_RELAY - 1).toInt() + 1;
_buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, btn4Relay});
#else #else
unsigned long btnDelay = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt(); unsigned long btnDelay = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt();
@ -216,7 +228,7 @@ void buttonSetup() {
void buttonLoop() { void buttonLoop() {
#ifdef ITEAD_SONOFF_DUAL
#if defined(ITEAD_SONOFF_DUAL)
if (Serial.available() >= 4) { if (Serial.available() >= 4) {
if (Serial.read() == 0xA0) { if (Serial.read() == 0xA0) {
@ -256,6 +268,29 @@ void buttonLoop() {
} }
} }
#elif defined(FOXEL_LIGHTFOX_DUAL)
if (Serial.available() >= 4) {
if (Serial.read() == 0xA0) {
if (Serial.read() == 0x04) {
unsigned char value = Serial.read();
if (Serial.read() == 0xA1) {
DEBUG_MSG_P(PSTR("[BUTTON] [LIGHTFOX] Received buttons mask: %d\n"), value);
for (unsigned int i=0; i<_buttons.size(); i++) {
bool clicked = (value & (1 << i)) > 0;
if (clicked) {
buttonEvent(i, BUTTON_EVENT_CLICK);
}
}
}
}
}
}
#else #else
for (unsigned int i=0; i < _buttons.size(); i++) { for (unsigned int i=0; i < _buttons.size(); i++) {


+ 1
- 0
code/espurna/config/arduino.h View File

@ -100,6 +100,7 @@
//#define PHYX_ESP12_RGB //#define PHYX_ESP12_RGB
//#define IWOOLE_LED_TABLE_LAMP //#define IWOOLE_LED_TABLE_LAMP
//#define EXS_WIFI_RELAY_V50 //#define EXS_WIFI_RELAY_V50
//#define FOXEL_LIGHTFOX_DUAL
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Features (values below are non-default values) // Features (values below are non-default values)


+ 21
- 0
code/espurna/config/hardware.h View File

@ -2852,6 +2852,27 @@
#define LED1_PIN 4 #define LED1_PIN 4
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// -----------------------------------------------------------------------------
// Foxel's LightFox dual
// https://github.com/foxel/esp-dual-rf-switch
// -----------------------------------------------------------------------------
#elif defined(FOXEL_LIGHTFOX_DUAL)
// Info
#define MANUFACTURER "Foxel"
#define DEVICE "LightFox dual"
#define SERIAL_BAUDRATE 19200
#define RELAY_PROVIDER RELAY_PROVIDER_DUAL
#define DUMMY_RELAY_COUNT 2
#define DEBUG_SERIAL_SUPPORT 0
// Buttons
#define BUTTON1_RELAY 1
#define BUTTON2_RELAY 2
#define BUTTON3_RELAY 2
#define BUTTON4_RELAY 1
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// TEST boards (do not use!!) // TEST boards (do not use!!)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 10
- 0
code/espurna/migrate.ino View File

@ -1223,6 +1223,16 @@ void migrate() {
setSetting("ledGPIO", 1, 15); setSetting("ledGPIO", 1, 15);
setSetting("ledLogic", 1, 0); setSetting("ledLogic", 1, 0);
#elif defined(FOXEL_LIGHTFOX_DUAL)
setSetting("board", 92);
setSetting("btnRelay", 0, 0);
setSetting("btnRelay", 1, 1);
setSetting("btnRelay", 2, 1);
setSetting("btnRelay", 3, 0);
setSetting("relayProvider", RELAY_PROVIDER_DUAL);
setSetting("relays", 2);
#else #else
// Allow users to define new settings without migration config // Allow users to define new settings without migration config


+ 2
- 0
code/espurna/relay.ino View File

@ -67,6 +67,8 @@ void _relayProviderStatus(unsigned char id, bool status) {
if (_relays[i].current_status) mask = mask + (1 << i); if (_relays[i].current_status) mask = mask + (1 << i);
} }
DEBUG_MSG_P(PSTR("[RELAY] [DUAL] Sending relay mask: %d\n"), mask);
// Send it to F330 // Send it to F330
Serial.flush(); Serial.flush();
Serial.write(0xA0); Serial.write(0xA0);


+ 1
- 1
code/espurna/system.ino View File

@ -144,7 +144,7 @@ void _systemSetupSpecificHardware() {
// These devices use the hardware UART // These devices use the hardware UART
// to communicate to secondary microcontrollers // to communicate to secondary microcontrollers
#if defined(ITEAD_SONOFF_RFBRIDGE) || defined(ITEAD_SONOFF_DUAL) || (RELAY_PROVIDER == RELAY_PROVIDER_STM)
#if defined(ITEAD_SONOFF_RFBRIDGE) || (RELAY_PROVIDER == RELAY_PROVIDER_DUAL) || (RELAY_PROVIDER == RELAY_PROVIDER_STM)
Serial.begin(SERIAL_BAUDRATE); Serial.begin(SERIAL_BAUDRATE);
#endif #endif


+ 23
- 0
code/platformio.ini View File

@ -394,6 +394,29 @@ extra_scripts = ${common.extra_scripts}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
[env:foxel-lightfox-dual]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_1m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DFOXEL_LIGHTFOX_DUAL
extra_scripts = ${common.extra_scripts}
[env:foxel-lightfox-dual-ota]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_1m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DFOXEL_LIGHTFOX_DUAL
upload_speed = ${common.upload_speed}
upload_port = ${common.upload_port}
upload_flags = ${common.upload_flags}
extra_scripts = ${common.extra_scripts}
[env:itead-sonoff-basic] [env:itead-sonoff-basic]
platform = ${common.platform} platform = ${common.platform}
framework = ${common.framework} framework = ${common.framework}


Loading…
Cancel
Save