Compare commits
1 Commits
feature/le
...
feature/ov
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bfa52c1ca |
36
CLAUDE.md
36
CLAUDE.md
@@ -16,40 +16,6 @@ arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:mega Gaugecontroller.ino
|
|||||||
|
|
||||||
Serial monitor: 115200 baud (`Serial` is both CMD_PORT and DEBUG_PORT).
|
Serial monitor: 115200 baud (`Serial` is both CMD_PORT and DEBUG_PORT).
|
||||||
|
|
||||||
## Switching serial ports (debug → production)
|
|
||||||
|
|
||||||
Two `#define`s at the top of `Gaugecontroller.ino` control where commands and debug output go:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define CMD_PORT Serial // command channel (host sends SET, HOME, etc.)
|
|
||||||
#define DEBUG_PORT Serial // diagnostic prints (homing, boot messages)
|
|
||||||
```
|
|
||||||
|
|
||||||
**Debug / USB-only (default):** both point to `Serial` (the USB-CDC port). Connect via `minicom` or the Arduino IDE serial monitor at 115200 baud.
|
|
||||||
|
|
||||||
**Production (hardware UART):** change `CMD_PORT` to a hardware serial port so a host MCU or Raspberry Pi can drive it without occupying the USB port:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define CMD_PORT Serial1 // TX1=pin18, RX1=pin19
|
|
||||||
#define DEBUG_PORT Serial // keep USB for monitoring, or silence it (see below)
|
|
||||||
```
|
|
||||||
|
|
||||||
Arduino Mega hardware UARTs:
|
|
||||||
|
|
||||||
| Port | TX pin | RX pin |
|
|
||||||
|---------|--------|--------|
|
|
||||||
| Serial1 | 18 | 19 |
|
|
||||||
| Serial2 | 16 | 17 |
|
|
||||||
| Serial3 | 14 | 15 |
|
|
||||||
|
|
||||||
`setup()` calls `DEBUG_PORT.begin(115200)` only. If `CMD_PORT` differs from `DEBUG_PORT` you must also begin it — add a second `begin` call in `setup()`:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
CMD_PORT.begin(115200);
|
|
||||||
```
|
|
||||||
|
|
||||||
**Silencing debug output entirely:** point `DEBUG_PORT` at a null stream, or wrap all `DEBUG_PORT` calls in an `#ifdef DEBUG` guard. The simplest option is to replace the define with a no-op object, but the easiest production approach is just to leave `DEBUG_PORT Serial` and ignore the USB output.
|
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
The sketch controls `GAUGE_COUNT` stepper-motor gauges using a trapezoidal velocity profile and a simple text serial protocol.
|
The sketch controls `GAUGE_COUNT` stepper-motor gauges using a trapezoidal velocity profile and a simple text serial protocol.
|
||||||
@@ -90,7 +56,7 @@ Commands arrive as newline-terminated ASCII lines. Each `parse*` function in `pr
|
|||||||
| `HOME` | `HOME <id>` / `HOMEALL` | Run homing sequence |
|
| `HOME` | `HOME <id>` / `HOMEALL` | Run homing sequence |
|
||||||
| `SWEEP` | `SWEEP <id> <accel> <speed>` | Start sweep (0/0 stops) |
|
| `SWEEP` | `SWEEP <id> <accel> <speed>` | Start sweep (0/0 stops) |
|
||||||
| `POS?` | `POS?` | Query all gauges: `POS <id> <cur> <tgt> <homed> <homingState> <sweep>` |
|
| `POS?` | `POS?` | Query all gauges: `POS <id> <cur> <tgt> <homed> <homingState> <sweep>` |
|
||||||
| `LED` | `LED <id> <idx> <r> <g> <b>` | Set one LED (0-based index within gauge segment) to RGB colour (0–255 each); `<idx>` may be a range `N-M` to set LEDs N through M in one command |
|
| `LED` | `LED <id> <idx> <r> <g> <b>` | Set one LED (0-based index within gauge segment) to RGB colour (0–255 each) |
|
||||||
| `LED?` | `LED?` | Query all LEDs: one `LED <id> <idx> <r> <g> <b>` line per LED, then `OK` |
|
| `LED?` | `LED?` | Query all LEDs: one `LED <id> <idx> <r> <g> <b>` line per LED, then `OK` |
|
||||||
| `PING` | `PING` | Responds `PONG` |
|
| `PING` | `PING` | Responds `PONG` |
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ struct Gauge {
|
|||||||
long targetPos = 0;
|
long targetPos = 0;
|
||||||
|
|
||||||
long minPos = 0;
|
long minPos = 0;
|
||||||
long maxPos = 3610; // adjust to your usable travel
|
long maxPos = 3780; // adjust to your usable travel
|
||||||
long homingBackoffSteps = 3700; // should exceed reverse travel slightly
|
long homingBackoffSteps = 3700; // should exceed reverse travel slightly
|
||||||
|
|
||||||
float velocity = 0.0f;
|
float velocity = 0.0f;
|
||||||
@@ -520,19 +520,13 @@ bool parseLedQuery(const String& line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool parseLed(const String& line) {
|
bool parseLed(const String& line) {
|
||||||
int id, r, g, b;
|
int id, idx, r, g, b;
|
||||||
char idxToken[16];
|
if (sscanf(line.c_str(), "LED %d %d %d %d %d", &id, &idx, &r, &g, &b) == 5) {
|
||||||
if (sscanf(line.c_str(), "LED %d %15s %d %d %d", &id, idxToken, &r, &g, &b) == 5) {
|
|
||||||
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
||||||
char* dash = strchr(idxToken, '-');
|
if (idx < 0 || idx >= gaugePins[id].ledCount) { sendReply("ERR BAD_IDX"); return true; }
|
||||||
int idxFirst = atoi(idxToken);
|
leds[gaugeLedOffset[id] + idx] = CRGB(constrain(r, 0, 255),
|
||||||
int idxLast = dash ? atoi(dash + 1) : idxFirst;
|
constrain(g, 0, 255),
|
||||||
if (idxFirst < 0 || idxLast >= gaugePins[id].ledCount || idxFirst > idxLast) {
|
constrain(b, 0, 255));
|
||||||
sendReply("ERR BAD_IDX"); return true;
|
|
||||||
}
|
|
||||||
CRGB color(constrain(r, 0, 255), constrain(g, 0, 255), constrain(b, 0, 255));
|
|
||||||
for (int i = idxFirst; i <= idxLast; i++)
|
|
||||||
leds[gaugeLedOffset[id] + i] = color;
|
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
sendReply("OK");
|
sendReply("OK");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user