From d78e04366f98d6f060f6b6a6e68a5f47bbe7db81 Mon Sep 17 00:00:00 2001 From: Serge NOEL Date: Fri, 13 Feb 2026 09:28:40 +0100 Subject: [PATCH] Ajout desc --- .../Platformio/Arduino.old/XPT2046.ino | 66 ++++++++++++- .../Platformio/Arduino.old/events.ino | 26 +++++ PacoMouseCYD/Platformio/Arduino.old/file.ino | 36 +++++++ PacoMouseCYD/Platformio/Arduino.old/gui.ino | 54 ++++++++++- PacoMouseCYD/Platformio/Arduino.old/lnet.ino | 53 +++++++++-- PacoMouseCYD/Platformio/Arduino.old/main.ino | 58 ++++++----- PacoMouseCYD/Platformio/Arduino.old/play.ino | 68 +++++++++++++ PacoMouseCYD/Platformio/Arduino.old/steam.ino | 31 ++++++ .../Platformio/Arduino.old/system.ino | 51 ++++++++++ .../Platformio/Arduino.old/window.ino | 27 ++++++ PacoMouseCYD/Platformio/Arduino.old/xnet.ino | 59 ++++++++++-- PacoMouseCYD/Platformio/Arduino.old/z21.ino | 39 +++++++- PacoMouseCYD/Platformio/src/README.md | 95 +++++++++++++++++++ 13 files changed, 619 insertions(+), 44 deletions(-) create mode 100644 PacoMouseCYD/Platformio/src/README.md diff --git a/PacoMouseCYD/Platformio/Arduino.old/XPT2046.ino b/PacoMouseCYD/Platformio/Arduino.old/XPT2046.ino index 652ff98..a541115 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/XPT2046.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/XPT2046.ino @@ -1,5 +1,69 @@ + +/** + * @file XPT2046.ino + * @brief XPT2046 SPI/Bitbang touchscreen interface for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains the implementation of the XPT2046 touchscreen interface, + * including initialization, calibration, and touch detection for the PacoMouseCYD throttle. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief XPT2046 touchscreen class constructor. + * @param mosiPin MOSI pin number. + * @param misoPin MISO pin number. + * @param clkPin Clock pin number. + * @param csPin Chip select pin number. + */ +XPT2046_TS::XPT2046_TS(uint8_t mosiPin, uint8_t misoPin, uint8_t clkPin, uint8_t csPin); + +/** + * @brief Initializes the touchscreen with given width and height. + * @param width Screen width. + * @param height Screen height. + */ +void XPT2046_TS::begin(uint16_t width, uint16_t height); + +/** + * @brief Sets the touchscreen calibration values. + * @param xMin Minimum X value. + * @param xMax Maximum X value. + * @param yMin Minimum Y value. + * @param yMax Maximum Y value. + */ +void XPT2046_TS::setCalibration(uint16_t xMin, uint16_t xMax, uint16_t yMin, uint16_t yMax); + +/** + * @brief Gets the current touchscreen calibration values. + * @return The current TouchCalibration struct. + */ +TouchCalibration XPT2046_TS::getCalibration(); + +/** + * @brief Sets the touchscreen rotation. + * @param n Rotation value (0-3). + */ +void XPT2046_TS::setRotation(uint8_t n); + +/** + * @brief Checks if the touchscreen is currently being touched. + * @return True if touched, false otherwise. + */ +bool XPT2046_TS::touched(); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ - Simple XPT2046 SPI/Bitbang interface for PacoMouseCYD + Simple XPT2046 SPI/Bitbang interface for PacoMouseCYD */ #include "config.h" diff --git a/PacoMouseCYD/Platformio/Arduino.old/events.ino b/PacoMouseCYD/Platformio/Arduino.old/events.ino index 8607110..7b4a1a0 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/events.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/events.ino @@ -1,3 +1,29 @@ + +/** + * @file events.ino + * @brief Event processing and handling for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for processing system and user events, managing timers, + * and handling event-driven actions in the PacoMouseCYD throttle firmware. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Processes the next event in the event queue. + */ +void eventProcess(); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ */ diff --git a/PacoMouseCYD/Platformio/Arduino.old/file.ino b/PacoMouseCYD/Platformio/Arduino.old/file.ino index e7d1878..9ac4bf5 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/file.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/file.ino @@ -1,3 +1,39 @@ + +/** + * @file file.ino + * @brief File handling and storage for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for managing locomotive data files, checking file names, + * saving and loading data to and from the SD card or internal filesystem, and related utilities. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Checks if a file name has a .csv extension. + * @param fileName The file name to check. + * @return True if the file name ends with .csv, false otherwise. + */ +bool checkName(char *fileName); + +/** + * @brief Saves locomotive data to a .csv file. + * @param fs The filesystem object. + * @param pos The position in the locomotive data array. + * @return True if the data was saved successfully, false otherwise. + */ +bool saveLocoData(fs::FS &fs, uint16_t pos); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ */ diff --git a/PacoMouseCYD/Platformio/Arduino.old/gui.ino b/PacoMouseCYD/Platformio/Arduino.old/gui.ino index ba447e5..76d88e0 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/gui.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/gui.ino @@ -1,6 +1,56 @@ + +/** + * @file gui.ino + * @brief Graphical User Interface (GUI) for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for initializing and managing the graphical user interface, + * including timers, drawing routines, and event handling for the PacoMouseCYD throttle. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Initializes the GUI, timers, and object stacks. + */ +void initGUI(); + +/** + * @brief Clears all system timers. + */ +void clearTimers(); + +/** + * @brief Sets a timer with the specified parameters. + * @param id Timer ID. + * @param count Timer count value. + * @param type Timer type (oneshot, periodic, etc). + */ +void setTimer(uint16_t id, uint16_t count, uint16_t type); + +/** + * @brief Stops a timer by ID. + * @param id Timer ID. + */ +void stopTimer(uint16_t id); + +/** + * @brief Processes all timers, triggering events as needed. + */ +void timerProcess(); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ - Very basic Graphical User Interface (GUI) for PacoMouseCYD - All data in absolute coordinates + Very basic Graphical User Interface (GUI) for PacoMouseCYD + All data in absolute coordinates */ //////////////////////////////////////////////////////////// diff --git a/PacoMouseCYD/Platformio/Arduino.old/lnet.ino b/PacoMouseCYD/Platformio/Arduino.old/lnet.ino index f231226..d7c67e6 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/lnet.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/lnet.ino @@ -1,13 +1,54 @@ + +/** + * @file lnet.ino + * @brief Loconet over TCP support for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for sending and receiving Loconet messages over TCP, + * handling Loconet protocol details, and managing communication with Loconet command stations. + * + * This software and associated files are a DIY project that is not intended for commercial use. + * This software uses libraries with different licenses, follow all their different terms included. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. + * + * Sources are only provided for building and uploading to the device. + * You are not allowed to modify the source code or fork/publish this project. + * Commercial use is forbidden. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Sends a Loconet message over TCP. + * @param Msg Pointer to the Loconet message structure. + */ +void lnetSend(lnMsg *Msg); + +/** + * @brief Receives and processes Loconet messages from TCP. + */ +void lnetReceive(); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ - This software and associated files are a DIY project that is not intended for commercial use. - This software uses libraries with different licenses, follow all their different terms included. + This software and associated files are a DIY project that is not intended for commercial use. + This software uses libraries with different licenses, follow all their different terms included. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. - Sources are only provided for building and uploading to the device. - You are not allowed to modify the source code or fork/publish this project. - Commercial use is forbidden. + Sources are only provided for building and uploading to the device. + You are not allowed to modify the source code or fork/publish this project. + Commercial use is forbidden. */ //////////////////////////////////////////////////////////// diff --git a/PacoMouseCYD/Platformio/Arduino.old/main.ino b/PacoMouseCYD/Platformio/Arduino.old/main.ino index a60ee37..c77122a 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/main.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/main.ino @@ -1,39 +1,47 @@ + /** - * PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ + * @file main.ino + * @brief Main entry point and core logic for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ * - * This software and associated files are a DIY project that is not intended for commercial use. - * This software uses libraries with different licenses, follow all their different terms included. + * This file contains the main setup and loop functions, version history, and + * overall initialization for the PacoMouseCYD throttle firmware. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. + * This software and associated files are a DIY project that is not intended for commercial use. + * This software uses libraries with different licenses, follow all their different terms included. * - * Sources are only provided for building and uploading to the device. - * You are not allowed to modify the source code or fork/publish this project. - * Commercial use is forbidden. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. * - * -------------------------------------------------------------------------------------------------- + * Sources are only provided for building and uploading to the device. + * You are not allowed to modify the source code or fork/publish this project. + * Commercial use is forbidden. * - * Use 2.8" Cheap Yellow Display ESP32-2432S028 (CYD) - * - ILI9341 driver chip (320x240) - * - XPT2046 chip for touch screen + * -------------------------------------------------------------------------------------------------- * - * CYD Also available in 2.4" and 3.2" (Use Resistive touch) + * Use 2.8" Cheap Yellow Display ESP32-2432S028 (CYD) + * - ILI9341 driver chip (320x240) + * - XPT2046 chip for touch screen * - * Select ESP32 Dev Module in Arduino IDE + * CYD Also available in 2.4" and 3.2" (Use Resistive touch) * - * SD Card. IMPORTANT!!!: use FAT32 SD card (max. 32GB) + * Select ESP32 Dev Module in Arduino IDE * - * -------------------------------------------------------------------------------------------------- + * SD Card. IMPORTANT!!!: use FAT32 SD card (max. 32GB) * - * v0.1 24feb25 Start writting code - * v0.2 07mar25 GUI, SD Pictures, Wifi configuration and loco throttle on Z21 working - * v0.3 21mar25 Added loco list sorting and loco image selection. Added internal file system for loco data. - * v0.4 19apr25 Added configuration menu screen. Corrected touch rotation for CYD 2.4". Changed translations files. Added programming CV. Added speedometer. - * v0.5 02jun25 Added steam loco throttle. Adding more function icons. Added Xpressnet LAN and Loconet over TCP protocols. Added experimental identify command station for Loconet. - * v0.6 08oct25 Added Loconet programming. New LocoEditor for browser on SD. - * v0.7 23nov25 Corrected bugs on loconet steam direction. Added accessory panels. Added WiFi analyzer. - * v0.8 15dec25 Added ECoS/CS1 protocol. Updated user defined CYDs. Changes in modal windows. - * v0.9 03jan26 Added Station Run for kids. Corrected minor bugs on loconet -*/ + * -------------------------------------------------------------------------------------------------- + * + * v0.1 24feb25 Start writing code + * v0.2 07mar25 GUI, SD Pictures, Wifi configuration and loco throttle on Z21 working + * v0.3 21mar25 Added loco list sorting and loco image selection. Added internal file system for loco data. + * v0.4 19apr25 Added configuration menu screen. Corrected touch rotation for CYD 2.4". Changed translations files. Added programming CV. Added speedometer. + * v0.5 02jun25 Added steam loco throttle. Adding more function icons. Added Xpressnet LAN and Loconet over TCP protocols. Added experimental identify command station for Loconet. + * v0.6 08oct25 Added Loconet programming. New LocoEditor for browser on SD. + * v0.7 23nov25 Corrected bugs on loconet steam direction. Added accessory panels. Added WiFi analyzer. + * v0.8 15dec25 Added ECoS/CS1 protocol. Updated user defined CYDs. Changes in modal windows. + * v0.9 03jan26 Added Station Run for kids. Corrected minor bugs on loconet + */ // PacoMouseCYD program version #define VER_H "0" diff --git a/PacoMouseCYD/Platformio/Arduino.old/play.ino b/PacoMouseCYD/Platformio/Arduino.old/play.ino index dfe010f..703d637 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/play.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/play.ino @@ -1,3 +1,71 @@ + +/** + * @file play.ino + * @brief Station Run - Model Train Game for Kids for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for the Station Run game, including station time updates, + * level and target management, and game logic for the PacoMouseCYD throttle. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Updates the station time display. + * @param seconds The number of seconds to display. + */ +void updateStationTime(uint16_t seconds); + +/** + * @brief Updates the target number of stations for the current level. + */ +void updateStationTarget(); + +/** + * @brief Initializes or resets station counters for the game. + * @param ini If true, initializes counters; otherwise, resets for new round. + */ +void newStationCounters(bool ini); + +/** + * @brief Generates a new station number, avoiding repetition of the last. + * @param last The last station number used. + * @return The new station number. + */ +uint8_t newStation(byte last); + +/** + * @brief Updates the display for the target number of stations. + */ +void updateTargetStations(); + +/** + * @brief Updates the display for the current count of stations. + */ +void updateCountStations(); + +/** + * @brief Updates the display for the current game level. + */ +void updateStationLevel(); + +/** + * @brief Updates the display for the number of stars earned. + */ +void updateStationStars(); + +/** + * @brief Sets a new target station and updates icon positions. + */ +void setNewTarget(); + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ */ diff --git a/PacoMouseCYD/Platformio/Arduino.old/steam.ino b/PacoMouseCYD/Platformio/Arduino.old/steam.ino index ae17eeb..e06c291 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/steam.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/steam.ino @@ -1,3 +1,34 @@ + +/** + * @file steam.ino + * @brief Steam throttle control for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for managing the steam locomotive throttle, + * including pressure, water, and speed control for the PacoMouseCYD throttle. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Initializes the steam throttle and related variables. + */ +void initSteamThrottle(); + +/** + * @brief Updates the steam throttle state and encoder value. + */ +void updateSteamThrottle(); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ */ diff --git a/PacoMouseCYD/Platformio/Arduino.old/system.ino b/PacoMouseCYD/Platformio/Arduino.old/system.ino index 3688664..ab17077 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/system.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/system.ino @@ -1,3 +1,54 @@ + +/** + * @file system.ino + * @brief System support functions for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for hardware initialization, backlight control, + * display rotation, and system-level utilities for the PacoMouseCYD throttle. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Initializes all hardware pins and peripherals. + */ +void initPins(); + +/** + * @brief Sets the PWM backlight value. + * @param value The backlight intensity value. + */ +void setBacklight(uint8_t value); + +/** + * @brief Rotates the display and touchscreen. + * @param pos The rotation position. + */ +void setRotationDisplay(uint8_t pos); + +/** + * @brief Resets the inactivity timer and restores backlight if needed. + */ +void aliveAndKicking(); + +#if (USE_RGB_LED == PRESENT) +/** + * @brief Sets the color of the RGB LED. + * @param color The color value. + */ +void setColorRGB(uint16_t color); +#endif + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ */ diff --git a/PacoMouseCYD/Platformio/Arduino.old/window.ino b/PacoMouseCYD/Platformio/Arduino.old/window.ino index 8066c54..0004a87 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/window.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/window.ino @@ -1,3 +1,30 @@ + +/** + * @file window.ino + * @brief Window object and UI management for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for creating, opening, and managing window objects, + * drawing UI elements, and handling window-related events for the PacoMouseCYD throttle. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Opens a window by its ID and initializes its objects. + * @param id The window ID to open. + */ +void openWindow(uint16_t id); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ */ diff --git a/PacoMouseCYD/Platformio/Arduino.old/xnet.ino b/PacoMouseCYD/Platformio/Arduino.old/xnet.ino index 6ff5a10..7d796e4 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/xnet.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/xnet.ino @@ -1,13 +1,60 @@ + +/** + * @file xnet.ino + * @brief XpressNet LAN protocol support for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for handling XpressNet LAN protocol operations, + * error handling, and communication with command stations for the PacoMouseCYD throttle. + * + * This software and associated files are a DIY project that is not intended for commercial use. + * This software uses libraries with different licenses, follow all their different terms included. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. + * + * Sources are only provided for building and uploading to the device. + * You are not allowed to modify the source code or fork/publish this project. + * Commercial use is forbidden. + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Shows error states for XpressNet LAN and updates UI accordingly. + */ +void showErrorXnet(); + +/** + * @brief Shows normal operation state for XpressNet LAN and updates UI accordingly. + */ +void showNormalOpsXnet(); + +/** + * @brief Computes the XpressNet address, handling long addresses. + * @param adr The input address. + * @return The computed XpressNet address. + */ +uint16_t addrXnet(uint16_t adr); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// + /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ - This software and associated files are a DIY project that is not intended for commercial use. - This software uses libraries with different licenses, follow all their different terms included. + This software and associated files are a DIY project that is not intended for commercial use. + This software uses libraries with different licenses, follow all their different terms included. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. - Sources are only provided for building and uploading to the device. - You are not allowed to modify the source code or fork/publish this project. - Commercial use is forbidden. + Sources are only provided for building and uploading to the device. + You are not allowed to modify the source code or fork/publish this project. + Commercial use is forbidden. */ diff --git a/PacoMouseCYD/Platformio/Arduino.old/z21.ino b/PacoMouseCYD/Platformio/Arduino.old/z21.ino index 72456c9..d107f4a 100644 --- a/PacoMouseCYD/Platformio/Arduino.old/z21.ino +++ b/PacoMouseCYD/Platformio/Arduino.old/z21.ino @@ -1,6 +1,14 @@ + /** - * PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/ - * + * @file z21.ino + * @brief Z21 protocol support for PacoMouseCYD throttle. + * @author F. Cañada + * @date 2025-2026 + * @copyright https://usuaris.tinet.cat/fmco/ + * + * This file contains functions for Z21 protocol operations, including reading and writing CVs, + * sending commands, and handling Z21-specific communication for the PacoMouseCYD throttle. + * * This software and associated files are a DIY project that is not intended for commercial use. * This software uses libraries with different licenses, follow all their different terms included. * @@ -9,8 +17,31 @@ * Sources are only provided for building and uploading to the device. * You are not allowed to modify the source code or fork/publish this project. * Commercial use is forbidden. - * - **/ + */ + +//////////////////////////////////////////////////////////// +// API Documentation +//////////////////////////////////////////////////////////// +/** + * @brief Reads a CV value from the Z21 command station. + * @param adr The CV address to read. + * @param stepPrg Programming step. + */ +void readCVZ21(unsigned int adr, byte stepPrg); + +/** + * @brief Writes a CV value to the Z21 command station. + * @param adr The CV address to write. + * @param data The data to write. + * @param stepPrg Programming step. + */ +void writeCVZ21(unsigned int adr, unsigned int data, byte stepPrg); + +// Add further function documentation here as needed for each public function. + +//////////////////////////////////////////////////////////// +// End API Documentation +//////////////////////////////////////////////////////////// diff --git a/PacoMouseCYD/Platformio/src/README.md b/PacoMouseCYD/Platformio/src/README.md new file mode 100644 index 0000000..81a9f24 --- /dev/null +++ b/PacoMouseCYD/Platformio/src/README.md @@ -0,0 +1,95 @@ +# Introduction + +This is the source files folder for the EasyDccMouse. + +EasyDccMouse is a system to remote control DCC scale locomotive, it is based on a ESP32 with tft display, touch screen, encoder and battery. + +EasyDccMouse sends actions to a DCC centrale station. + + +``` ++------------------------------------------------------+ +| [O] [⇄] [ID] [⚡] | <-- Header with 4 icons: +| ON Dir DCC Power | [O] Status (ON/OFF) +| | [⇄] Direction (Forward/Reverse) +| [================== Train ===================] | [ID] DCC id +| | [⚡] Power/Connection +| |██████████████████████████████████████████| | <-- Model picture (190x40 px) +| | +| ___ | +| .-' '-. | +| .' '. | +| / \ | +| | /\ /\ | | <-- Speedometer (arc + needle) +| | / \ / \ | | +| | / \_/ \ | | +| |/ \| | +| '---------------' | +| | | | +| | | | +| Needle | +| | +| [F1] [F2] [F3] [F4] [F5] [F6] [F7] [F8] | <-- Function pad (row 1) +| [F9] [F10][F11][F12][F13][F14][F15][F16] | <-- Function pad (row 2) ++------------------------------------------------------+ +``` + +# Implementation + + +## How to draw speedometer with arc and needle on my TFT display? + +To draw an arc-style speedometer with a moving needle on your TFT display (e.g., ILI9341), you can use the TFT_eSPI library. Here’s a step-by-step example: + +1. **Draw the arc:** + - Use `drawArc()` or draw multiple short lines to approximate an arc. + - Example: Draw an arc from 135° to 45° (like a semicircle at the bottom). + +2. **Draw the needle:** + - Calculate the angle for the needle based on the speed value. + - Use `drawLine()` from the center of the arc to the edge at the calculated angle. + +3. **Display the speed value:** + - Use `setCursor()` and `print()` to show the numeric speed. + +**Example code:** +```cpp +#include +#include + +TFT_eSPI tft = TFT_eSPI(); + +void drawSpeedometer(int speed) { + int cx = 120, cy = 120, r = 80; // Center and radius + int minAngle = 135, maxAngle = 45; // Degrees + int minSpeed = 0, maxSpeed = 100; + + // Draw arc (approximate with lines) + for (int a = minAngle; a >= maxAngle; a -= 3) { + float rad = a * 3.14159 / 180.0; + int x1 = cx + (r - 10) * cos(rad); + int y1 = cy + (r - 10) * sin(rad); + int x2 = cx + r * cos(rad); + int y2 = cy + r * sin(rad); + tft.drawLine(x1, y1, x2, y2, TFT_WHITE); + } + + // Draw needle + float angle = minAngle - (float)(speed - minSpeed) / (maxSpeed - minSpeed) * (minAngle - maxAngle); + float rad = angle * 3.14159 / 180.0; + int nx = cx + (r - 20) * cos(rad); + int ny = cy + (r - 20) * sin(rad); + tft.drawLine(cx, cy, nx, ny, TFT_RED); + + // Draw speed value + tft.setCursor(cx - 20, cy + 30); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + tft.setTextSize(2); + tft.printf("%d", speed); +} +``` + +**Tips:** +- Clear the previous needle before drawing a new one for smooth animation. +- Adjust `cx`, `cy`, and `r` for your display size. +- You can enhance the arc with tick marks and labels for a more realistic look. \ No newline at end of file