Files
hexapod-robot/2026-current/remote/NextionUI.h
T
mangavalkandClaude Opus 5.5 a961fa721b Remote: match the old remote's hardware; old remote code in LEGACY
- LEGACY/remote/teensy/: old remote sketch from
  https://mangavalk.com/Hexapod/remote.git @ 492dece (reference only).
- remote/Config.h: sticks on A0-A5, Nextion on Serial1 (0/1), as in the
  old sketch; MPU6050 moved to Wire2 (25/24) since A4/A5 are Wire's pins.
- NextionUI: controls on a vscope-global "control" page added to the
  old HMI; keeps the old t1 status texts; the old page-1 b2 button (and
  serial 'U') enter Nextion upload passthrough, following the PC's baud.
- Docs: NEXTION.md, remote README wiring, CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 15:29:21 +02:00

49 lines
1.8 KiB
C++

#pragma once
#include "UiTypes.h"
#include "Config.h"
// Nextion serial HMI driver. No Nextion library - the protocol is small:
//
// Nextion -> remote: custom frames the HMI's touch events send with printh:
// '#' <len> <cmd> [value] e.g. printh 23 01 41 (ToggleArm)
// printh 23 02 56 + prints hSpeed.val,1
// Command bytes are listed in NEXTION.md and in NextionUI.cpp.
// Native Nextion return frames (terminated FF FF FF) are also parsed: a
// display reset (0x88 "ready") triggers a full redraw, and the old HMI's
// upload button sends a standard touch event (0x65) that's recognized.
//
// remote -> Nextion: plain instructions ("bArm.txt=\"ARMED\"" + FF FF FF).
//
// The remote is authoritative: buttons are plain buttons (not dual-state),
// they only send requests, and render() repaints whatever the remote state
// actually is. A Nextion reboot or a dropped byte self-heals on the next
// periodic full refresh.
class NextionUI {
public:
void begin();
bool poll(UiEvent& out); // call every loop; returns one decoded event at a time
void render(const UiView& v, uint32_t now_ms);
// Nextion Editor upload through the remote's USB port. Never returns.
[[noreturn]] void runUploadPassthrough();
private:
enum class Rx : uint8_t { Idle, CustomLen, CustomBody, Native };
Rx rx_ = Rx::Idle;
uint8_t body_[4];
uint8_t body_len_ = 0, body_got_ = 0;
uint8_t native_buf_[8];
uint8_t native_len_ = 0, ff_run_ = 0;
UiView shown_;
bool force_full_ = true;
uint32_t last_full_ms_ = 0;
uint32_t last_link_ms_ = 0;
void cmd(const char* fmt, ...);
void pushState(const UiView& v, bool full);
void pushLink(const UiView& v);
bool decodeCustom(UiEvent& out);
bool decodeNative(UiEvent& out);
};