Browse Source

Preliminary support for Itead Sonoff IFAN02

rfm69
Xose Pérez 6 years ago
parent
commit
b44258ac41
6 changed files with 137 additions and 0 deletions
  1. +1
    -0
      code/espurna/config/arduino.h
  2. +1
    -0
      code/espurna/config/general.h
  3. +30
    -0
      code/espurna/config/hardware.h
  4. +21
    -0
      code/espurna/migrate.ino
  5. +60
    -0
      code/espurna/relay.ino
  6. +24
    -0
      code/platformio.ini

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

@ -88,6 +88,7 @@
//#define PILOTAK_ESP_DIN_V1 //#define PILOTAK_ESP_DIN_V1
//#define BLITZWOLF_BWSHP2 //#define BLITZWOLF_BWSHP2
//#define BH_ONOFRE //#define BH_ONOFRE
//#define ITEAD_SONOFF_IFAN02
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Features (values below are non-default values) // Features (values below are non-default values)


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

@ -706,6 +706,7 @@
#define MQTT_TOPIC_LOADAVG "loadavg" #define MQTT_TOPIC_LOADAVG "loadavg"
#define MQTT_TOPIC_BOARD "board" #define MQTT_TOPIC_BOARD "board"
#define MQTT_TOPIC_PULSE "pulse" #define MQTT_TOPIC_PULSE "pulse"
#define MQTT_TOPIC_SPEED "speed"
// Light module // Light module
#define MQTT_TOPIC_CHANNEL "channel" #define MQTT_TOPIC_CHANNEL "channel"


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

@ -880,6 +880,36 @@
#define CSE7766_SUPPORT 1 #define CSE7766_SUPPORT 1
#define CSE7766_PIN 1 #define CSE7766_PIN 1
#elif defined(ITEAD_SONOFF_IFAN02)
// Info
#define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF_IFAN02"
// These are virtual buttons triggered by the remote
#define BUTTON1_PIN 0
#define BUTTON2_PIN 9
#define BUTTON3_PIN 10
#define BUTTON4_PIN 14
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON3_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON4_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
// Relays
#define RELAY1_PIN 12
#define RELAY2_PIN 5
#define RELAY3_PIN 4
#define RELAY4_PIN 15
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
#define RELAY3_TYPE RELAY_TYPE_NORMAL
#define RELAY4_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
#define LED1_PIN_INVERSE 1
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// YJZK // YJZK
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


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

@ -1043,6 +1043,27 @@ void migrate() {
setSetting("board", 80); setSetting("board", 80);
setSetting("btnGPIO", 0, 0); setSetting("btnGPIO", 0, 0);
#elif defined(ITEAD_SONOFF_IFAN02)
setSetting("board", 81);
setSetting("btnGPIO", 0, 0);
setSetting("btnGPIO", 1, 9);
setSetting("btnGPIO", 2, 10);
setSetting("btnGPIO", 3, 14);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("relayGPIO", 0, 12);
setSetting("relayGPIO", 1, 5);
setSetting("relayGPIO", 2, 4);
setSetting("relayGPIO", 3, 15);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
setSetting("relayType", 3, RELAY_TYPE_NORMAL);
#else #else
// Allow users to define new settings without migration config // Allow users to define new settings without migration config


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

@ -205,6 +205,34 @@ void _relayProcess(bool mode) {
} }
#if defined(ITEAD_SONOFF_IFAN02)
unsigned char _relay_ifan02_speeds[] = {0, 1, 3, 5};
unsigned char getSpeed() {
unsigned char speed =
(_relays[1].target_status ? 1 : 0) +
(_relays[2].target_status ? 2 : 0) +
(_relays[3].target_status ? 4 : 0);
for (unsigned char i=0; i<4; i++) {
if (_relay_ifan02_speeds[i] == speed) return i;
}
return 0;
}
void setSpeed(unsigned char speed) {
if ((0 <= speed) & (speed <= 3)) {
if (getSpeed() == speed) return;
unsigned char states = _relay_ifan02_speeds[speed];
for (unsigned char i=0; i<3; i++) {
relayStatus(i+1, states & 1 == 1);
states >>= 1;
}
}
}
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// RELAY // RELAY
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -654,6 +682,19 @@ void relaySetupAPI() {
} }
); );
#if defined(ITEAD_SONOFF_IFAN02)
apiRegister(MQTT_TOPIC_SPEED,
[relayID](char * buffer, size_t len) {
snprintf(buffer, len, "%u", getSpeed());
},
[relayID](const char * payload) {
setSpeed(atoi(payload));
}
);
#endif
} }
} }
@ -686,6 +727,14 @@ void relayMQTT(unsigned char id) {
mqttSendRaw(t.c_str(), status ? "1" : "0"); mqttSendRaw(t.c_str(), status ? "1" : "0");
} }
} }
// Send speed for IFAN02
#if defined (ITEAD_SONOFF_IFAN02)
char buffer[5];
snprintf(buffer, sizeof(buffer), "%u", getSpeed());
mqttSend(MQTT_TOPIC_SPEED, buffer);
#endif
} }
void relayMQTT() { void relayMQTT() {
@ -731,6 +780,10 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
snprintf_P(pulse_topic, sizeof(pulse_topic), PSTR("%s/+"), MQTT_TOPIC_PULSE); snprintf_P(pulse_topic, sizeof(pulse_topic), PSTR("%s/+"), MQTT_TOPIC_PULSE);
mqttSubscribe(pulse_topic); mqttSubscribe(pulse_topic);
#if defined(ITEAD_SONOFF_IFAN02)
mqttSubscribe(MQTT_TOPIC_SPEED);
#endif
// Subscribe to group topics // Subscribe to group topics
for (unsigned int i=0; i < _relays.size(); i++) { for (unsigned int i=0; i < _relays.size(); i++) {
String t = getSetting("mqttGroup", i, ""); String t = getSetting("mqttGroup", i, "");
@ -810,6 +863,13 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
} }
} }
// Itead Sonoff IFAN02
#if defined (ITEAD_SONOFF_IFAN02)
if (t.startsWith(MQTT_TOPIC_SPEED)) {
setSpeed(atoi(payload));
}
#endif
} }
if (type == MQTT_DISCONNECT_EVENT) { if (type == MQTT_DISCONNECT_EVENT) {


+ 24
- 0
code/platformio.ini View File

@ -958,6 +958,30 @@ upload_flags = ${common.upload_flags}
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts} extra_scripts = ${common.extra_scripts}
[env:itead-sonoff-ifan02]
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} -DITEAD_SONOFF_IFAN02
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:itead-sonoff-ifan02-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} -DITEAD_SONOFF_IFAN02
upload_port = ${common.upload_port}
upload_flags = ${common.upload_flags}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
[env:electrodragon-wifi-iot] [env:electrodragon-wifi-iot]


Loading…
Cancel
Save