Skip to content

Commit

Permalink
Support for Digoo/Oxaoxe NX-SP202 (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Mar 4, 2019
1 parent b0ee48e commit b878c71
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/espurna/config/arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
//#define GOSUND_WS1
//#define ARILUX_AL_LC02_V14
//#define BLITZWOLF_BWSHPX_V23
//#define DIGOO_NX_SP202

//--------------------------------------------------------------------------------
// Features (values below are non-default values)
Expand Down
45 changes: 45 additions & 0 deletions code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -3393,6 +3393,51 @@
#define LED1_PIN 4
#define LED1_PIN_INVERSE 1

// -----------------------------------------------------------------------------
// Oxaoxe NX-SP202
// Digoo NX-SP202 (not tested)
// Digoo DG-SP202 (not tested)
// https://github.com/xoseperez/espurna/issues/1502
// -----------------------------------------------------------------------------

#elif defined(DIGOO_NX_SP202)

// Info
#define MANUFACTURER "DIGOO"
#define DEVICE "NX_SP202"

// Buttons
#define BUTTON1_PIN 0
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY 1
#define BUTTON2_PIN 16
#define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP | BUTTON_DEFAULT_HIGH
#define BUTTON2_RELAY 2

// Relays
#define RELAY1_PIN 15
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_PIN 14
#define RELAY2_TYPE RELAY_TYPE_NORMAL

// LEDs
#define LED1_PIN 13
#define LED1_PIN_INVERSE 1

// HJL01 / BL0937
#ifndef HLW8012_SUPPORT
#define HLW8012_SUPPORT 1
#endif
#define HLW8012_SEL_PIN 12
#define HLW8012_CF1_PIN 5
#define HLW8012_CF_PIN 4

#define HLW8012_SEL_CURRENT LOW
#define HLW8012_CURRENT_RATIO 23296
#define HLW8012_VOLTAGE_RATIO 310085
#define HLW8012_POWER_RATIO 3368471
#define HLW8012_INTERRUPT_ON FALLING

// -----------------------------------------------------------------------------
// TEST boards (do not use!!)
// -----------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions code/espurna/migrate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,27 @@ void migrate() {
setSetting("relayGPIO", 1, 15); // Left outlet
setSetting("relayType", 1, RELAY_TYPE_NORMAL);

#elif defined(DIGOO_NX_SP202)

setSetting("board", 95);
setSetting("ledGPIO", 0, 13);
setSetting("ledLogic", 0, 1);
setSetting("btnGPIO", 0, 0);
setSetting("btnRelay", 0, 0);
setSetting("btnGPIO", 1, 16);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 0, 15);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
setSetting("relayGPIO", 1, 14);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("selGPIO", 12);
setSetting("cf1GPIO", 5);
setSetting("cfGPIO", 4);
setSetting("pwrRatioC", 23296);
setSetting("pwrRatioV", 310085);
setSetting("pwrRatioP", 3368471);
setSetting("hlwSelC", LOW);
setSetting("hlwIntM", FALLING);

#else

Expand Down
2 changes: 1 addition & 1 deletion code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ void sensorLoop() {

// Get the first relay state
#if SENSOR_POWER_CHECK_STATUS
bool relay_off = (relayCount() > 0) && (relayStatus(0) == 0);
bool relay_off = (relayCount() == 1) && (relayStatus(0) == 0);
#endif

// Get readings
Expand Down
26 changes: 26 additions & 0 deletions code/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2902,6 +2902,32 @@ upload_port = ${common.upload_port}
upload_flags = ${common.upload_flags}
extra_scripts = ${common.extra_scripts}

[env:digoo-nx-sp202]
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} -DDIGOO_NX_SP202
upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}

[env:digoo-nx-sp202-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} -DDIGOO_NX_SP202
upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
upload_port = ${common.upload_port}
upload_flags = ${common.upload_flags}
extra_scripts = ${common.extra_scripts}

[env:homecube-16a]
platform = ${common.platform}
framework = ${common.framework}
Expand Down

0 comments on commit b878c71

Please sign in to comment.