From 3e96e046903fc631ee21f6964166be6079520412 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Thu, 28 Jun 2018 17:40:37 +0200 Subject: [PATCH] Add experimental (untested) TM1638 support Add experimental (untested) TM1638 switch support (#2226) --- sonoff/_releasenotes.ino | 1 + sonoff/language/bg-BG.h | 3 + sonoff/language/cs-CZ.h | 3 + sonoff/language/de-DE.h | 3 + sonoff/language/el-GR.h | 3 + sonoff/language/en-GB.h | 3 + sonoff/language/es-AR.h | 3 + sonoff/language/fr-FR.h | 3 + sonoff/language/hu-HU.h | 3 + sonoff/language/it-IT.h | 3 + sonoff/language/nl-NL.h | 3 + sonoff/language/pl-PL.h | 3 + sonoff/language/pt-BR.h | 3 + sonoff/language/pt-PT.h | 3 + sonoff/language/ru-RU.h | 3 + sonoff/language/uk-UK.h | 3 + sonoff/language/zh-CN.h | 3 + sonoff/language/zh-TW.h | 3 + sonoff/sonoff.ino | 16 ++- sonoff/sonoff_template.h | 6 +- sonoff/support.ino | 5 + sonoff/user_config.h | 2 + sonoff/xsns_28_tm1638.ino | 219 ++++++++++++++++++++++++++++++++++++++ 23 files changed, 296 insertions(+), 4 deletions(-) create mode 100644 sonoff/xsns_28_tm1638.ino diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index d14c2c7db..71007cc50 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,5 @@ /* 6.0.0b + * Add experimental (untested) TM1638 switch support (#2226) * Change number of switches from 4 to 8 (#2885, #3086) * * 6.0.0a diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 8f397bb82..6d82a843c 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index eec72fc31..cb93ad553 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 98e48e414..4c0fde470 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 2281e2faf..702381ab1 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index f5f0d6e22..8858eea2f 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index 37fa89589..cb50b7377 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index 09f9ffe0f..ce1485513 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 986b18fdf..14fb2a08b 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 1e7ed00b5..6f1c4db0f 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index a764cb667..cf1c2b3b0 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index a039cf333..e250e4c4d 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index 4bcf8efa2..a32a7b5c3 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 4eeeb3965..393a74a87 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index cda108cdc..79df5b2d4 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index c0339b9e8..d925d13fb 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 4310111ee..9e5149125 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "安" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index e6adb4b0e..6d4154cdf 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -471,6 +471,9 @@ #define D_SENSOR_SDM120_RX "SDM120 Rx" #define D_SENSOR_SDM630_TX "SDM630 Tx" #define D_SENSOR_SDM630_RX "SDM630 Rx" +#define D_SENSOR_TM1638_CLK "TM16 CLK" +#define D_SENSOR_TM1638_DIO "TM16 DIO" +#define D_SENSOR_TM1638_STB "TM16 STB" // Units #define D_UNIT_AMPERE "安" diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 344d64967..3a09d446c 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -167,6 +167,7 @@ uint8_t multiwindow[MAX_KEYS] = { 0 }; // Max time between button presses t uint8_t multipress[MAX_KEYS] = { 0 }; // Number of button presses within multiwindow uint8_t lastwallswitch[MAX_SWITCHES]; // Last wall switch states uint8_t holdwallswitch[MAX_SWITCHES] = { 0 }; // Timer for wallswitch push button hold +uint8_t virtualswitch[MAX_SWITCHES] = { 0 }; // Virtual switch states mytmplt my_module; // Active copy of Module name and GPIOs uint8_t pin[GPIO_MAX]; // Possible pin configurations @@ -1431,7 +1432,11 @@ boolean MqttShowSensor() snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str()); int json_data_start = strlen(mqtt_data); for (byte i = 0; i < MAX_SWITCHES; i++) { +#ifdef USE_TM1638 + if ((pin[GPIO_SWT1 +i] < 99) || ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99))) { +#else if (pin[GPIO_SWT1 +i] < 99) { +#endif // USE_TM1638 boolean swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i])); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_SWITCH "%d\":\"%s\""), mqtt_data, i +1, GetStateText(swm ^ lastwallswitch[i])); } @@ -1664,7 +1669,7 @@ void ButtonHandler() * Switch handler \*********************************************************************************************/ -void SwitchHandler() +void SwitchHandler(byte mode) { uint8_t button = NOT_PRESSED; uint8_t switchflag; @@ -1679,7 +1684,12 @@ void SwitchHandler() } } - button = digitalRead(pin[GPIO_SWT1 +i]); + if (mode) { + button = virtualswitch[i]; + } else { + button = digitalRead(pin[GPIO_SWT1 +i]); + } + if (button != lastwallswitch[i]) { switchflag = 3; switch (Settings.switchmode[i]) { @@ -1813,7 +1823,7 @@ void StateLoop() \*-------------------------------------------------------------------------------------------*/ ButtonHandler(); - SwitchHandler(); + SwitchHandler(0); XdrvCall(FUNC_EVERY_50_MSECOND); XsnsCall(FUNC_EVERY_50_MSECOND); diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index b2907d079..38fadf086 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -101,6 +101,9 @@ enum UserSelectablePins { GPIO_SDM120_RX, // SDM120 Serial interface GPIO_SDM630_TX, // SDM630 Serial interface GPIO_SDM630_RX, // SDM630 Serial interface + GPIO_TM16CLK, // TM1638 Clock + GPIO_TM16DIO, // TM1638 Data I/O + GPIO_TM16STB, // TM1638 Strobe GPIO_SENSOR_END }; // Programmer selectable GPIO functionality offset by user selectable GPIOs @@ -146,7 +149,8 @@ const char kSensorNames[] PROGMEM = D_SENSOR_SBR_TX "|" D_SENSOR_SBR_RX "|" D_SENSOR_SR04_TRIG "|" D_SENSOR_SR04_ECHO "|" D_SENSOR_SDM120_TX "|" D_SENSOR_SDM120_RX "|" - D_SENSOR_SDM630_TX "|" D_SENSOR_SDM630_RX; + D_SENSOR_SDM630_TX "|" D_SENSOR_SDM630_RX "|" + D_SENSOR_TM1638_CLK "|" D_SENSOR_TM1638_DIO "|" D_SENSOR_TM1638_STB; /********************************************************************************************/ diff --git a/sonoff/support.ino b/sonoff/support.ino index c052e2487..98be71f8b 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -567,6 +567,11 @@ boolean GetUsedInModule(byte val, uint8_t *arr) #ifndef USE_SDM630 if (GPIO_SDM630_TX == val) { return true; } if (GPIO_SDM630_RX == val) { return true; } +#endif +#ifndef USE_TM1638 + if (GPIO_TM16CLK == val) { return true; } + if (GPIO_TM16DIO == val) { return true; } + if (GPIO_TM16STB == val) { return true; } #endif if ((val >= GPIO_REL1) && (val < GPIO_REL1 + MAX_RELAYS)) { offset = (GPIO_REL1_INV - GPIO_REL1); diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 4b03a47f3..0c4aa66f5 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -312,6 +312,8 @@ #define USE_SR04 // Add support for HC-SR04 ultrasonic devices (+1k code) +//#define USE_TM1638 // Add support for TM1638 switches copying Switch1 .. Switch8 (+1k code) + #define USE_RF_FLASH // Add support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB /*********************************************************************************************\ diff --git a/sonoff/xsns_28_tm1638.ino b/sonoff/xsns_28_tm1638.ino new file mode 100644 index 000000000..a50389c23 --- /dev/null +++ b/sonoff/xsns_28_tm1638.ino @@ -0,0 +1,219 @@ +/* + xsns_28_tm1638.ino - TM1638 8 switch, led and 7 segment unit support for Sonoff-Tasmota + + Copyright (C) 2018 Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_TM1638 +/*********************************************************************************************\ + * TM1638 8 switch, led and 7 segment + * + * Uses GPIO TM16 DIO, TM16 CLK and TM16 STB +\*********************************************************************************************/ + +#define TM1638_COLOR_NONE 0 +#define TM1638_COLOR_RED 1 +#define TM1638_COLOR_GREEN 2 + +uint8_t tm1638_type = 1; +uint8_t tm1638_clock_pin = 0; +uint8_t tm1638_data_pin = 0; +uint8_t tm1638_strobe_pin = 0; +uint8_t tm1638_displays = 8; +uint8_t tm1638_active_display = 0; +uint8_t tm1638_intensity = 0; + +/*********************************************************************************************\ + * Pieces from library https://github.com/rjbatista/tm1638-library +\*********************************************************************************************/ + +void Tm16XXSend(byte data) +{ + for (int i = 0; i < 8; i++) { + digitalWrite(tm1638_clock_pin, LOW); + digitalWrite(tm1638_data_pin, data & 1 ? HIGH : LOW); + data >>= 1; + digitalWrite(tm1638_clock_pin, HIGH); + } +} + +void Tm16XXSendCommand(byte cmd) +{ + digitalWrite(tm1638_strobe_pin, LOW); + Tm16XXSend(cmd); + digitalWrite(tm1638_strobe_pin, HIGH); +} + +void TM16XXSendData(byte address, byte data) +{ + Tm16XXSendCommand(0x44); + digitalWrite(tm1638_strobe_pin, LOW); + Tm16XXSend(0xC0 | address); + Tm16XXSend(data); + digitalWrite(tm1638_strobe_pin, HIGH); +} + +byte Tm16XXReceive() +{ + byte temp = 0; + + // Pull-up on + pinMode(tm1638_data_pin, INPUT); + digitalWrite(tm1638_data_pin, HIGH); + + for (int i = 0; i < 8; i++) { + temp >>= 1; + digitalWrite(tm1638_clock_pin, LOW); + if (digitalRead(tm1638_data_pin)) { + temp |= 0x80; + } + digitalWrite(tm1638_clock_pin, HIGH); + } + + // Pull-up off + pinMode(tm1638_data_pin, OUTPUT); + digitalWrite(tm1638_data_pin, LOW); + + return temp; +} + +/*********************************************************************************************/ + +void Tm16XXClearDisplay() +{ + for (int i = 0; i < tm1638_displays; i++) { + TM16XXSendData(i << 1, 0); + } +} + +void Tm1638SetLED(byte color, byte pos) +{ + TM16XXSendData((pos << 1) + 1, color); +} + +void Tm1638SetLEDs(word leds) +{ + for (int i = 0; i < tm1638_displays; i++) { + byte color = 0; + + if ((leds & (1 << i)) != 0) { + color |= TM1638_COLOR_RED; + } + + if ((leds & (1 << (i + 8))) != 0) { + color |= TM1638_COLOR_GREEN; + } + + Tm1638SetLED(color, i); + } +} + +byte Tm1638GetButtons() +{ + byte keys = 0; + + digitalWrite(tm1638_strobe_pin, LOW); + Tm16XXSend(0x42); + for (int i = 0; i < 4; i++) { + keys |= Tm16XXReceive() << i; + } + digitalWrite(tm1638_strobe_pin, HIGH); + + return keys; +} + +/*********************************************************************************************/ + +void TmInit() +{ + tm1638_type = 0; + if ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99)) { + tm1638_clock_pin = pin[GPIO_TM16CLK]; + tm1638_data_pin = pin[GPIO_TM16DIO]; + tm1638_strobe_pin = pin[GPIO_TM16STB]; + + pinMode(tm1638_data_pin, OUTPUT); + pinMode(tm1638_clock_pin, OUTPUT); + pinMode(tm1638_strobe_pin, OUTPUT); + + digitalWrite(tm1638_strobe_pin, HIGH); + digitalWrite(tm1638_clock_pin, HIGH); + + Tm16XXSendCommand(0x40); + Tm16XXSendCommand(0x80 | (tm1638_active_display ? 8 : 0) | min(7, tm1638_intensity)); + + digitalWrite(tm1638_strobe_pin, LOW); + Tm16XXSend(0xC0); + for (int i = 0; i < 16; i++) { + Tm16XXSend(0x00); + } + digitalWrite(tm1638_strobe_pin, HIGH); + + tm1638_type = 1; + } +} + +void TmLoop() +{ + byte buttons = Tm1638GetButtons(); + for (byte i = 0; i < 8; i++) { + virtualswitch[i] = buttons &1; + byte color = virtualswitch[i] ? TM1638_COLOR_RED : TM1638_COLOR_NONE; + Tm1638SetLED(color, i); + buttons >>= 1; + } + SwitchHandler(1); +} + +void TmShow(boolean json) +{ + +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +#define XSNS_28 + +boolean Xsns28(byte function) +{ + boolean result = false; + + if (tm1638_type) { + switch (function) { + case FUNC_INIT: + TmInit(); + break; + case FUNC_EVERY_50_MSECOND: + TmLoop(); + break; +/* + case FUNC_JSON_APPEND: + TmShow(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_APPEND: + TmShow(0); + break; +#endif // USE_WEBSERVER +*/ + } + } + return result; +} + +#endif // USE_TM1638 \ No newline at end of file