1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +01:00

peeled back

This commit is contained in:
Asbelos 2024-10-06 10:34:16 +01:00
parent aa2a6ad119
commit 3094074349
2 changed files with 8 additions and 24 deletions

View File

@ -48,7 +48,7 @@ const uint8_t HIGHFLASH _digits[16]={
}
void TM1638::_begin() {
tm->reset();
tm->displayClear();
tm->test();
_display();
}

View File

@ -27,25 +27,16 @@ uint8_t TM1638x::getButtons(){
return _buttons;
}
void TM1638x::reset(){
setDisplayMode(DISPLAY_TURN_ON | _pulse);
setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_AUTO);
ArduinoPins::fastWriteDigital(_stb_pin, LOW);
writeData(FIRST_DISPLAY_ADDRESS);
for(uint8_t i=0;i<16;i++)
writeData(0);
ArduinoPins::fastWriteDigital(_stb_pin, HIGH);
}
void TM1638x::displayDig(uint8_t digitId, uint8_t pgfedcba){
if (digitId>7) return;
setDisplayMode(DISPLAY_TURN_ON | _pulse);
setDataInstruction(DISPLAY_TURN_ON | _pulse);
setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_FIXED);
writeDataAt(FIRST_DISPLAY_ADDRESS+14-(digitId*2), pgfedcba);
}
void TM1638x::displayClear(){
setDisplayMode(DISPLAY_TURN_ON | _pulse);
setDataInstruction(DISPLAY_TURN_ON | _pulse);
setDataInstruction(INSTRUCTION_WRITE_DATA | INSTRUCTION_ADDRESS_FIXED);
for (uint8_t i=0;i<15;i+=2){
writeDataAt(FIRST_DISPLAY_ADDRESS+i,0x00);
@ -53,20 +44,19 @@ void TM1638x::displayClear(){
}
void TM1638x::writeLed(uint8_t num,bool state){
//DIAG(F("TM1638x writeLed(%d,%d)"),num,state);
if ((num<1) | (num>8)) return;
setDisplayMode(DISPLAY_TURN_ON | _pulse);
setDataInstruction(DISPLAY_TURN_ON | _pulse);
setDataInstruction(INSTRUCTION_WRITE_DATA | INSTRUCTION_ADDRESS_FIXED);
writeDataAt(FIRST_DISPLAY_ADDRESS + (num*2-1), state);
}
void TM1638x::displayTurnOn(){
setDisplayMode(DISPLAY_TURN_ON | _pulse);
setDataInstruction(DISPLAY_TURN_ON | _pulse);
_isOn = true;
}
void TM1638x::displayTurnOff(){
setDisplayMode(DISPLAY_TURN_OFF | _pulse);
setDataInstruction(DISPLAY_TURN_OFF | _pulse);
_isOn = false;
}
@ -75,7 +65,7 @@ void TM1638x::displaySetBrightness(pulse_t newpulse){
_pulse = newpulse;
uint8_t data = (_isOn) ? DISPLAY_TURN_ON : DISPLAY_TURN_OFF;
data |= _pulse;
setDisplayMode(data);
setDataInstruction(data);
}
void TM1638x::writeData(uint8_t data){
@ -95,12 +85,6 @@ void TM1638x::writeDataAt(uint8_t displayAddress, uint8_t data){
delayMicroseconds(1);
}
void TM1638x::setDisplayMode(uint8_t displayMode){
ArduinoPins::fastWriteDigital(_stb_pin, LOW);
writeData(displayMode);
ArduinoPins::fastWriteDigital(_stb_pin, HIGH);
delayMicroseconds(1);
}
void TM1638x::setDataInstruction(uint8_t dataInstruction){
ArduinoPins::fastWriteDigital(_stb_pin, LOW);
writeData(dataInstruction);
@ -112,7 +96,7 @@ void TM1638x::test(){
DIAG(F("TM1638x test"));
uint8_t val=0;
for(uint8_t i=0;i<5;i++){
//setDisplayMode(DISPLAY_TURN_ON | _pulse);
//setDataInstruction(DISPLAY_TURN_ON | _pulse);
displayTurnOn();
setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_AUTO);
ArduinoPins::fastWriteDigital(_stb_pin, LOW);