From 7e7c00594bf34ebfc331485befc9feaf66cc32ff Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 4 Oct 2024 13:16:57 +0100 Subject: [PATCH] Working --- IO_TM1638.h | 44 ++++++++++++++++++++++++++-- Release - Architecture Doc/TM1638.md | 0 TM1638x.cpp | 1 + 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 Release - Architecture Doc/TM1638.md diff --git a/IO_TM1638.h b/IO_TM1638.h index e8df926..36c4561 100644 --- a/IO_TM1638.h +++ b/IO_TM1638.h @@ -1,6 +1,5 @@ /* - * © 2024, Henk Kruisbrink & Chris Harlow. All rights reserved. - * © 2023, Neil McKechnie. All rights reserved. + * © 2024, Chris Harlow. All rights reserved. * * This file is part of DCC++EX API * @@ -22,9 +21,9 @@ #define IO_TM1638_h #include #include "IODevice.h" -#include "I2CManager.h" #include "DIAG.h" #include "TM1638x.h" + class TM1638 : public IODevice { private: @@ -81,8 +80,47 @@ int _read(VPIN vpin) override { // digital write sets led state void _write(VPIN vpin, int value) override { + // TODO.. skip if no state change tm->writeLed(vpin - _firstVpin + 1,value!=0); } +// Analog write sets digit displays + +void _writeAnalogue(VPIN vpin, int lowBytes, uint8_t mode, uint16_t highBytes) override { + DIAG(F("TM1638 writeAnalogue(v=%d,l=%d,m=%d,h=%d"),vpin,lowBytes,mode,highBytes); + byte formatLength=mode & 0x0f; + byte formatType=mode>>4; + int8_t leftDigit=vpin-_firstVpin; // 0..7 from left + int8_t rightDigit=leftDigit+formatLength-1; // 0..7 from left + + // loading is done right to left startDigit first + int8_t startDigit=7-rightDigit; // reverse as 7 on left + int8_t lastDigit=7-leftDigit; // reverse as 7 on left + auto value= ((uint32_t)highBytes<<16) | (uint32_t)lowBytes; + + DIAG(F("TM1638 fl=%d ft=%x sd=%d ld=%d v=%l"),formatLength,formatType, + startDigit,lastDigit,value); + while(startDigit<=lastDigit) { + switch (formatType) { + case 0:// decimal (leading zeros) + tm->displayVal(startDigit,value%10); + value=value/10; + break; + case 1:// HEX (leading zeros) + tm->displayVal(startDigit,value & 0x0F); + value>>=4; + break; + case 2:// Raw 7-segment pattern + tm->displayDig(startDigit,value & 0xFF); + value>>=8; + break; + default: + tm->displayDig(startDigit,0); + break; + } + startDigit++; + } + +} }; #endif // IO_TM1638_h diff --git a/Release - Architecture Doc/TM1638.md b/Release - Architecture Doc/TM1638.md new file mode 100644 index 0000000..e69de29 diff --git a/TM1638x.cpp b/TM1638x.cpp index 8ae343c..7df23b9 100644 --- a/TM1638x.cpp +++ b/TM1638x.cpp @@ -39,6 +39,7 @@ void TM1638x::reset(){ } void TM1638x::displayVal(uint8_t digitId, uint8_t val){ + DIAG(F("TM1638x displayVal(%d,%d)"),digitId,val); if ((digitId>7) | (val>15) | (val<0)) return; setDisplayMode(DISPLAY_TURN_ON | _pulse); setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_FIXED);