From fb8cca8d3507e5722ae7eed6b84c9a2ac4cfcdb2 Mon Sep 17 00:00:00 2001 From: FranziHH <45534937+FranziHH@users.noreply.github.com> Date: Wed, 30 Aug 2023 21:02:37 +0200 Subject: [PATCH 1/4] FastClock BUG serial is working I2C is wrong First, the initialization was incorrect. The FastClock was initialized before the I2C Manager was initialized Second: FastClock Functions are missing --- I2CManager.cpp | 6 +++++- IODevice.cpp | 12 +++++++++++- IO_EXFastclock.h | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/I2CManager.cpp b/I2CManager.cpp index d0d8550..a68d08d 100644 --- a/I2CManager.cpp +++ b/I2CManager.cpp @@ -48,6 +48,10 @@ static const FSH * guessI2CDeviceType(uint8_t address) { if (address >= 0x20 && address <= 0x26) return F("GPIO Expander"); +#ifdef FAST_CLOCK_I2C + else if (address == FAST_CLOCK_I2C) + return F("Fast Clock"); +#endif else if (address == 0x27) return F("GPIO Expander or LCD Display"); else if (address == 0x29) @@ -363,4 +367,4 @@ void I2CAddress::toHex(const uint8_t value, char *buffer) { /* static */ bool I2CAddress::_addressWarningDone = false; -#endif \ No newline at end of file +#endif diff --git a/IODevice.cpp b/IODevice.cpp index 2ed21b6..1155c85 100644 --- a/IODevice.cpp +++ b/IODevice.cpp @@ -27,6 +27,12 @@ #include "IO_MCP23017.h" #include "DCCTimer.h" +#if !defined(IO_NO_HAL) + #ifdef FAST_CLOCK_I2C + #include "IO_EXFastClock.h" // FastClock driver + #endif +#endif + #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) #define USE_FAST_IO #endif @@ -75,6 +81,11 @@ void IODevice::begin() { } else { DIAG(F("Default PCA9685 at I2C 0x41 disabled due to configured user device")); } + + #ifdef FAST_CLOCK_I2C + EXFastClock::create(FAST_CLOCK_I2C); + DIAG(F("EXFastClock::create")); + #endif // Predefine two MCP23017 module 0x20/0x21 if no conflicts // Allocates 32 pins 164-195 @@ -582,4 +593,3 @@ bool ArduinoPins::fastReadDigital(uint8_t pin) { #endif return result; } - diff --git a/IO_EXFastclock.h b/IO_EXFastclock.h index 5ed237e..06d546f 100644 --- a/IO_EXFastclock.h +++ b/IO_EXFastclock.h @@ -56,12 +56,12 @@ static void create(I2CAddress i2cAddress) { // XXXX change thistosave2 bytes if (_checkforclock == 0) { FAST_CLOCK_EXISTS = true; - //DIAG(F("I2C Fast Clock found at %s"), i2cAddress.toString()); + DIAG(F("I2C Fast Clock found at %s"), i2cAddress.toString()); new EXFastClock(i2cAddress); } else { FAST_CLOCK_EXISTS = false; - //DIAG(F("No Fast Clock found")); + DIAG(F("No Fast Clock found")); LCD(6,F("CLOCK NOT FOUND")); } From b8d1c682ea333a10a58abbcfe51014275f2d4b18 Mon Sep 17 00:00:00 2001 From: FranziHH <45534937+FranziHH@users.noreply.github.com> Date: Thu, 31 Aug 2023 10:08:23 +0200 Subject: [PATCH 2/4] FastClock is working for Me Fast Clock can be easily activated without complicated adjustments in config.h: Serial: simply comment out the required port: e.g. #define SERIAL1_COMMANDS OR for I2C //#define FAST_CLOCK_I2C 0x55 and define the address --- IO_EXFastclock.h | 5 +++-- config.example.h | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/IO_EXFastclock.h b/IO_EXFastclock.h index 06d546f..54d4cf1 100644 --- a/IO_EXFastclock.h +++ b/IO_EXFastclock.h @@ -95,7 +95,8 @@ void _loop(unsigned long currentMicros) override{ if (FAST_CLOCK_EXISTS==true) { uint8_t readBuffer[3]; byte a,b; - #ifdef EXRAIL_ACTIVE + // I would like to use the FastClock without EXRAIL + // #ifdef EXRAIL_ACTIVE I2CManager.read(_I2CAddress, readBuffer, 3); // XXXX change this to save a few bytes a = readBuffer[0]; @@ -110,7 +111,7 @@ void _loop(unsigned long currentMicros) override{ // Clock interval is 60/ clockspeed i.e 60/b seconds delayUntil(currentMicros + ((60/b) * 1000000)); - #endif + // #endif } } diff --git a/config.example.h b/config.example.h index 0f136f9..505d2b7 100644 --- a/config.example.h +++ b/config.example.h @@ -239,7 +239,10 @@ The configuration file for DCC-EX Command Station // SAMD/SAMC and STM32 have up to 6.) // To monitor a throttle on one or more serial ports, uncomment the defines below. // NOTE: do not define here the WiFi shield serial port or your wifi will not work. -// +// ------------------------------------- +// For Use with FastClock serial: uncomment the needed serial Port and +// FastClock will work, no further actions are needed +// ------------------------------------- //#define SERIAL1_COMMANDS //#define SERIAL2_COMMANDS //#define SERIAL3_COMMANDS @@ -247,6 +250,12 @@ The configuration file for DCC-EX Command Station //#define SERIAL5_COMMANDS //#define SERIAL6_COMMANDS // +// ------------------------------------- +// FastClock with I2C +// uncomment the following Line and Set the used I2C Address +//#define FAST_CLOCK_I2C 0x55 // default is 0x55 +// ------------------------------------- +// // BLUETOOTH SERIAL ON ESP32 // On ESP32 you have the possibility to use the builtin BT serial to connect to // the CS. From 4bdc4b7079dfd69ccec11292b1f15fe6f4d5d713 Mon Sep 17 00:00:00 2001 From: FranziHH <45534937+FranziHH@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:56:02 +0200 Subject: [PATCH 3/4] Update IODevice.cpp Debug Output adjusted --- IODevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IODevice.cpp b/IODevice.cpp index 1155c85..adefbf6 100644 --- a/IODevice.cpp +++ b/IODevice.cpp @@ -83,8 +83,8 @@ void IODevice::begin() { } #ifdef FAST_CLOCK_I2C - EXFastClock::create(FAST_CLOCK_I2C); DIAG(F("EXFastClock::create")); + EXFastClock::create(FAST_CLOCK_I2C); #endif // Predefine two MCP23017 module 0x20/0x21 if no conflicts From 7b5e2b41da918e76faeda6a074b37de6b25fde46 Mon Sep 17 00:00:00 2001 From: FranziHH <45534937+FranziHH@users.noreply.github.com> Date: Sun, 3 Sep 2023 16:09:26 +0200 Subject: [PATCH 4/4] new config options For Display Shows IP and Port in same Line: PRINT_IP_PORT_SINGLE_LINE Shows FastClock readable: FASTCLOCK_READABLE --- CommandDistributor.cpp | 15 ++++++++++++++- WifiInterface.cpp | 10 ++++++++-- config.example.h | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index ab6b52f..52169b5 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -181,7 +181,20 @@ void CommandDistributor::setClockTime(int16_t clocktime, int8_t clockrate, byte case 1: if (clocktime != lastclocktime){ // CAH. DIAG removed because LCD does it anyway. - LCD(6,F("Clk Time:%d Sp %d"), clocktime, clockrate); + + #ifndef FASTCLOCK_READABLE + LCD(6,F("Clk Time: %d Sp %d"), clocktime, clockrate); + #else + // Make Time readable + int hours = clocktime / 60; + int minutes = clocktime - (hours * 60); + int hoursH = hours / 10; + int hoursL = hours - (hoursH * 10); + int minutesH = minutes / 10; + int minutesL = minutes - (minutesH * 10); + LCD(6,F("Clk Time: %d%d:%d%d Sp %d"), hoursH, hoursL, minutesH, minutesL, clockrate); + #endif + // look for an event for this time RMFT2::clockEvent(clocktime,1); // Now tell everyone else what the time is. diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 7511af6..38a65c4 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -347,11 +347,17 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, } ipString[ipLen]=ipChar; } - LCD(4,F("%s"),ipString); // There is not enough room on some LCDs to put a title to this + #ifndef PRINT_IP_PORT_SINGLE_LINE + LCD(4,F("%s"),ipString); // There is not enough room on some LCDs to put a title to this + #else + LCD(4,F("%s:%d"),ipString,port); // *** Single IP:Port + #endif } // suck up anything after the IP. if (!checkForOK(1000, true, false)) return WIFI_DISCONNECTED; - LCD(5,F("PORT=%d"),port); + #ifndef PRINT_IP_PORT_SINGLE_LINE + LCD(5,F("PORT=%d"),port); + #endif return WIFI_CONNECTED; } diff --git a/config.example.h b/config.example.h index 505d2b7..1570139 100644 --- a/config.example.h +++ b/config.example.h @@ -167,6 +167,9 @@ The configuration file for DCC-EX Command Station // * #define SCROLLMODE 2 is by row (move up 1 row at a time). #define SCROLLMODE 1 +// Shows IP and Port on Display in a single line +// #define PRINT_IP_PORT_SINGLE_LINE + ///////////////////////////////////////////////////////////////////////////////////// // DISABLE EEPROM // @@ -256,6 +259,11 @@ The configuration file for DCC-EX Command Station //#define FAST_CLOCK_I2C 0x55 // default is 0x55 // ------------------------------------- // +// ------------------------------------- +// FastClock in HH:MM on Display +//#define FASTCLOCK_READABLE +// ------------------------------------- +// // BLUETOOTH SERIAL ON ESP32 // On ESP32 you have the possibility to use the builtin BT serial to connect to // the CS.