mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
Working
This commit is contained in:
parent
fc4df87848
commit
7e7c00594b
44
IO_TM1638.h
44
IO_TM1638.h
|
@ -1,6 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* © 2024, Henk Kruisbrink & Chris Harlow. All rights reserved.
|
* © 2024, Chris Harlow. All rights reserved.
|
||||||
* © 2023, Neil McKechnie. All rights reserved.
|
|
||||||
*
|
*
|
||||||
* This file is part of DCC++EX API
|
* This file is part of DCC++EX API
|
||||||
*
|
*
|
||||||
|
@ -22,9 +21,9 @@
|
||||||
#define IO_TM1638_h
|
#define IO_TM1638_h
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "IODevice.h"
|
#include "IODevice.h"
|
||||||
#include "I2CManager.h"
|
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
#include "TM1638x.h"
|
#include "TM1638x.h"
|
||||||
|
|
||||||
class TM1638 : public IODevice {
|
class TM1638 : public IODevice {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -81,8 +80,47 @@ int _read(VPIN vpin) override {
|
||||||
|
|
||||||
// digital write sets led state
|
// digital write sets led state
|
||||||
void _write(VPIN vpin, int value) override {
|
void _write(VPIN vpin, int value) override {
|
||||||
|
// TODO.. skip if no state change
|
||||||
tm->writeLed(vpin - _firstVpin + 1,value!=0);
|
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
|
#endif // IO_TM1638_h
|
||||||
|
|
0
Release - Architecture Doc/TM1638.md
Normal file
0
Release - Architecture Doc/TM1638.md
Normal file
|
@ -39,6 +39,7 @@ void TM1638x::reset(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638x::displayVal(uint8_t digitId, uint8_t val){
|
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;
|
if ((digitId>7) | (val>15) | (val<0)) return;
|
||||||
setDisplayMode(DISPLAY_TURN_ON | _pulse);
|
setDisplayMode(DISPLAY_TURN_ON | _pulse);
|
||||||
setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_FIXED);
|
setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_FIXED);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user