Ajout desc

This commit is contained in:
Serge NOEL
2026-02-13 09:28:40 +01:00
parent 758f73bc0e
commit d78e04366f
13 changed files with 619 additions and 44 deletions

View File

@@ -1,3 +1,67 @@
/**
* @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/ /* 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
*/ */

View File

@@ -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/ /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/
*/ */

View File

@@ -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/ /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/
*/ */

View File

@@ -1,3 +1,53 @@
/**
* @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/ /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/
Very basic Graphical User Interface (GUI) for PacoMouseCYD Very basic Graphical User Interface (GUI) for PacoMouseCYD
All data in absolute coordinates All data in absolute coordinates

View File

@@ -1,3 +1,44 @@
/**
* @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/ /* 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 and associated files are a DIY project that is not intended for commercial use.

View File

@@ -1,5 +1,13 @@
/** /**
* 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 file contains the main setup and loop functions, version history, and
* overall initialization for the PacoMouseCYD throttle firmware.
* *
* This software and associated files are a DIY project that is not intended for commercial use. * 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 uses libraries with different licenses, follow all their different terms included.
@@ -24,7 +32,7 @@
* *
* -------------------------------------------------------------------------------------------------- * --------------------------------------------------------------------------------------------------
* *
* v0.1 24feb25 Start writting code * v0.1 24feb25 Start writing code
* v0.2 07mar25 GUI, SD Pictures, Wifi configuration and loco throttle on Z21 working * 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.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.4 19apr25 Added configuration menu screen. Corrected touch rotation for CYD 2.4". Changed translations files. Added programming CV. Added speedometer.
@@ -33,7 +41,7 @@
* v0.7 23nov25 Corrected bugs on loconet steam direction. Added accessory panels. Added WiFi analyzer. * 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.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.9 03jan26 Added Station Run for kids. Corrected minor bugs on loconet
*/ */
// PacoMouseCYD program version // PacoMouseCYD program version
#define VER_H "0" #define VER_H "0"

View File

@@ -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/ /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/
*/ */

View File

@@ -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/ /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/
*/ */

View File

@@ -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/ /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/
*/ */

View File

@@ -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/ /* PacoMouseCYD throttle -- F. Cañada 2025-2026 -- https://usuaris.tinet.cat/fmco/
*/ */

View File

@@ -1,3 +1,50 @@
/**
* @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/ /* 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 and associated files are a DIY project that is not intended for commercial use.

View File

@@ -1,5 +1,13 @@
/** /**
* 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 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 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. * 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. * You are not allowed to modify the source code or fork/publish this project.
* Commercial use is forbidden. * 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
////////////////////////////////////////////////////////////

View File

@@ -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. Heres 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 <TFT_eSPI.h>
#include <math.h>
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.