From 11916dcb45ac43fbd3c0e1c83b28cc4f73f4fd62 Mon Sep 17 00:00:00 2001 From: Trusty77 Date: Sun, 11 Feb 2024 11:13:49 +0100 Subject: [PATCH] 2.4.3 --- CommandStation-EX-LaBox.ino | 3 +- Z21Throttle.cpp | 62 +++++++++++++++++++++++++++++++++---- version_labox.h | 14 +++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 version_labox.h diff --git a/CommandStation-EX-LaBox.ino b/CommandStation-EX-LaBox.ino index 02fc725e..eec895ec 100644 --- a/CommandStation-EX-LaBox.ino +++ b/CommandStation-EX-LaBox.ino @@ -51,6 +51,7 @@ #include "DCCEX.h" #include "EEPROM.h" +#include "version_labox.h" #ifdef CPU_TYPE_ERROR #error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH THE ARCHITECTURES LISTED IN defines.h @@ -91,7 +92,7 @@ void setup() ADCee::begin(); DIAG(F("License GPLv3 fsf.org (c) Locoduino.org")); - DIAG(F("LaBox : 2.4.2")); + DIAG(F("LaBox : %s"), VERSION_LABOX); DISPLAY_START ( // This block is still executed for DIAGS if display not in use diff --git a/Z21Throttle.cpp b/Z21Throttle.cpp index 3a830df2..8132c85b 100644 --- a/Z21Throttle.cpp +++ b/Z21Throttle.cpp @@ -445,7 +445,12 @@ void Z21Throttle::notifyLocoInfo(byte inMSB, byte inLSB) { void Z21Throttle::notifyTurnoutInfo(byte inMSB, byte inLSB) { Z21Throttle::replyBuffer[0] = inMSB; // turnout address msb Z21Throttle::replyBuffer[1] = inLSB; // turnout address lsb - Z21Throttle::replyBuffer[2] = B00000000; // 000000ZZ ZZ : 00 not switched 01 pos1 10 pos2 11 invalid + int id = (inMSB << 8) + inLSB; + + if (Turnout::isClosed(id)) + Z21Throttle::replyBuffer[2] = B00000000; // 000000ZZ ZZ : 00 not switched 01 pos1 10 pos2 11 invalid + else + Z21Throttle::replyBuffer[2] = B00000001; // 000000ZZ ZZ : 00 not switched 01 pos1 10 pos2 11 invalid notify(HEADER_LAN_XPRESS_NET, LAN_X_HEADER_TURNOUT_INFO, Z21Throttle::replyBuffer, 3, false); } @@ -731,14 +736,17 @@ bool Z21Throttle::parse() { if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d LOCO INFO: "), this->clientid); notifyLocoInfo(DB[2], DB[3]); done = true; - break; + case LAN_X_HEADER_GET_TURNOUT_INFO: - if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d TURNOUT INFO "), this->clientid); + { + int id = (DB[1] << 8) + DB[2]; + if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d TURNOUT %d INFO"), this->clientid, id); notifyTurnoutInfo(DB[1], DB[2]); done = true; - + } break; + case LAN_X_HEADER_GET_FIRMWARE_VERSION: if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d FIRMWARE VERSION "), this->clientid); notifyFirmwareVersion(); @@ -770,11 +778,53 @@ bool Z21Throttle::parse() { break; case LAN_X_HEADER_CV_WRITE: if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d CV WRITE "), this->clientid); - notifyFirmwareVersion(); + cvWriteProg(DB[2], DB[3], DB[4]); done = true; break; case LAN_X_HEADER_SET_TURNOUT: - if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d TURNOUT "), this->clientid); + { + int id = (DB[1] << 8) + DB[2]; + bool activate = DB[3] & 0b00001000; + bool IsOutput1 = DB[3] & 0b00000001; + if (activate) { + if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d TURNOUT %d %s output%s"), this->clientid, id + 1, activate?"active":"inactive", IsOutput1?"1":"2"); + } + else { + if (Diag::Z21THROTTLEVERBOSE) DIAG(F("%d TURNOUT %d %s"), this->clientid, id + 1, activate?"active":"inactive"); + } + if (!Turnout::exists(id)) { + // If turnout does not exist, create it + int addr = (id / 4) + 1; + int subaddr = id % 4; + DCCTurnout::create(id,addr,subaddr); + if (Diag::Z21THROTTLEVERBOSE) DIAG(F("TURNOUT %d created"), id); + //StringFormatter::send(stream, F("HmTurnout %d created\n"),id); + } + + if (activate) { + Turnout::setClosed(id, !IsOutput1); + } + else { + this->notifyTurnoutInfo(DB[1], DB[2]); + } + + /* + switch (DB[2] & 0b0001000) { + // T and C according to RCN-213 where 0 is Stop, Red, Thrown, Diverging. + case 'T': + Turnout::setClosed(id,false); + break; + case 'C': + Turnout::setClosed(id,true); + break; + case '2': + Turnout::setClosed(id,!Turnout::isClosed(id)); + break; + default : + Turnout::setClosed(id,true); + break; + }*/ + } //done = true; break; case 0x22: diff --git a/version_labox.h b/version_labox.h new file mode 100644 index 00000000..63db2dd1 --- /dev/null +++ b/version_labox.h @@ -0,0 +1,14 @@ +#ifndef version_labox_h +#define version_labox_h + +#define VERSION_LABOX "2.4.3" +// 2.4.3 - Fix CV write on Z21 app. +// - First try to implement turnout setting by Z21 app. Not yet fonctionnal ! +// - Creation of this file ! +// 2.4.2 - Merge with CommandStation-EX 5.0.9 +// - Fix long address reading with 16384... +// 2.4.1 - Fix use of define USE_HMI for compilation. +// - Fix value of HMI_deltaCurrent to 0 +// 2.4.0 - First operationnal version on ESP32. + +#endif