Add support for TM1638 seven segment display

Add support for TM1638 seven segment display by Ajith Vasudevan (#11031)
This commit is contained in:
Theo Arends 2021-03-19 10:15:50 +01:00
parent cea5f6715c
commit 320f0e2776
3 changed files with 48 additions and 47 deletions

View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
## [9.3.1.2]
### Added
- Commands ``MqttKeepAlive 1..100`` to set Mqtt Keep Alive timer (default 30) and ``MqttTimeout 1..100`` to set Mqtt Socket Timeout (default 4) (#5341)
- Support for TM1638 seven segment display by Ajith Vasudevan (#11031)
### Changed
- PubSubClient library from EspEasy v2.7.12 to Tasmota v2.8.12

View File

@ -87,6 +87,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- Support for XPT2046 touch screen digitizer on ILI9341 display by nonix [#11159](https://github.com/arendst/Tasmota/issues/11159)
- Support for zigbee lumi.sensor_wleak [#11200](https://github.com/arendst/Tasmota/issues/11200)
- Support for CSE7761 energy monitor as used in ESP32 based Sonoff Dual R3 Pow [#10793](https://github.com/arendst/Tasmota/issues/10793)
- Support for TM1638 seven segment display by Ajith Vasudevan [#11031](https://github.com/arendst/Tasmota/issues/11031)
- Allow MCP230xx pinmode from output to input [#11104](https://github.com/arendst/Tasmota/issues/11104)
- Berry improvements [#11163](https://github.com/arendst/Tasmota/issues/11163)
- Extent compile time SetOptions support [#11204](https://github.com/arendst/Tasmota/issues/11204)

View File

@ -180,39 +180,43 @@ struct {
uint8_t display_type = TM1637;
uint8_t prev_buttons;
bool driver_inited = false;
bool init_done = false;
bool scroll = false;
bool show_clock = false;
bool clock_24 = false;
bool LED[8] = {false, false, false, false, false, false, false, false};
} TM1637Data;
/*********************************************************************************************\
* Init function
\*********************************************************************************************/
bool TM1637Init(void) {
if(TM1637Data.driver_inited) return true;
void TM1637Init(void) {
if (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB)) {
TM1637Data.display_type = TM1638;
TM1637Data.num_digits = 8;
} else if(PinUsed(GPIO_TM1637CLK) && PinUsed(GPIO_TM1637DIO)) {
TM1637Data.display_type = TM1637;
if(Settings.display_cols[0] <= 6) TM1637Data.num_digits = Settings.display_cols[0];
else TM1637Data.num_digits = 4;
}
else return false;
else if (PinUsed(GPIO_TM1637CLK) && PinUsed(GPIO_TM1637DIO)) {
TM1637Data.display_type = TM1637;
if (Settings.display_cols[0] <= 6) {
TM1637Data.num_digits = Settings.display_cols[0];
} else {
TM1637Data.num_digits = 4;
}
}
else {
return;
}
Settings.display_model == XDSP_15;
if (TM1637Data.display_type == TM1637) {
strcpy(TM1637Data.model_name, "TM1637");
strcpy_P(TM1637Data.model_name, PSTR("TM1637"));
tm1637display = new SevenSegmentTM1637(Pin(GPIO_TM1637CLK), Pin(GPIO_TM1637DIO));
tm1637display->begin(TM1637Data.num_digits, 1);
} else if(TM1637Data.display_type == TM1638) {
strcpy(TM1637Data.model_name, "TM1638");
}
else if (TM1637Data.display_type == TM1638) {
strcpy_P(TM1637Data.model_name, PSTR("TM1638"));
tm1638display = new TM1638plus(Pin(GPIO_TM16STB), Pin(GPIO_TM16CLK), Pin(GPIO_TM16DIO), true );
TM1637Data.num_digits = 8;
tm1638display->displayBegin();
@ -220,10 +224,8 @@ bool TM1637Init(void) {
TM1637ClearDisplay();
TM1637Data.brightness = (Settings.display_dimmer ? Settings.display_dimmer : TM1637Data.brightness);
TM1637SetBrightness(TM1637Data.brightness);
TM1637Data.driver_inited = true;
AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s display driver initialized with %d digits"), TM1637Data.model_name, TM1637Data.num_digits);
return true;
TM1637Data.init_done = true;
AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s with %d digits"), TM1637Data.model_name, TM1637Data.num_digits);
}
/*********************************************************************************************\
@ -820,22 +822,19 @@ bool TM1637MainFunc(uint8_t fn) {
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xdsp15(uint8_t function)
{
bool Xdsp15(uint8_t function) {
bool result = false;
if(function == FUNC_DISPLAY_MODEL) {
return true;
if (FUNC_DISPLAY_INIT_DRIVER == function) {
TM1637Init();
}
if (Settings.display_model == XDSP_15) {
else if (TM1637Data.init_done && (XDSP_15 == Settings.display_model)) {
switch (function) {
case FUNC_DISPLAY_INIT_DRIVER:
result = TM1637Init(); // init
case FUNC_DISPLAY_MODEL:
result = true;
break;
case FUNC_DISPLAY_INIT:
AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: %s: FUNC_DISPLAY_INIT: Display depends on TM1637Data.display_type, currently %d"), TM1637Data.model_name, Settings.display_options.data);
result = true;
break;
case FUNC_DISPLAY_SEVENSEG_TEXT:
case FUNC_DISPLAY_CLEAR: