2026-09-28 18:14:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include <Arduino.h>
|
2026-11-17 14:42:37 +01:00
|
|
|
#include <HexapodProtocol.h>
|
|
|
|
|
#include "Config.h"
|
2026-09-28 18:14:00 +02:00
|
|
|
|
|
|
|
|
// Operator commands. Produced by the Nextion touchscreen (NextionUI) and by
|
|
|
|
|
// the USB serial console (SerialConsole) through the same path, so the
|
|
|
|
|
// remote can be fully exercised on the bench without the display attached.
|
|
|
|
|
enum class UiCmd : uint8_t {
|
|
|
|
|
None = 0,
|
|
|
|
|
ToggleArm,
|
|
|
|
|
Disarm, // unconditional - the big red button
|
|
|
|
|
ToggleStand,
|
|
|
|
|
ToggleGait, // tripod <-> wave
|
|
|
|
|
ToggleWalkMode, // direct (A) <-> heading-hold (B)
|
|
|
|
|
ToggleRStickXlate, // right stick: rotation <-> translation
|
|
|
|
|
ToggleRemoteGyro,
|
|
|
|
|
ToggleRobotGyro,
|
|
|
|
|
SetSpeed, // value = 0..255
|
|
|
|
|
SpeedUp, // serial console only
|
|
|
|
|
SpeedDown, // serial console only
|
2026-09-29 00:37:12 +02:00
|
|
|
SetHeight, // value = 0..200, 100 = default standing height
|
|
|
|
|
HeightUp, // serial console only
|
|
|
|
|
HeightDown, // serial console only
|
2026-09-28 18:14:00 +02:00
|
|
|
ZeroGyro, // capture the handset's current attitude as "level"
|
2026-11-17 14:42:37 +01:00
|
|
|
CalStartSave, // stick sweep calibration: start, or save it if running
|
2026-09-28 18:14:00 +02:00
|
|
|
CalCancel,
|
2026-11-17 14:42:37 +01:00
|
|
|
PageShown, // value = Nextion page id (UiPage); the display just showed it
|
|
|
|
|
ServoCalToggle, // servo centre calibration on/off (robot holds the centre pose)
|
|
|
|
|
ServoCalLeg, // value = leg 0..5
|
|
|
|
|
ServoCalJoint, // value = joint 0..2 (coxa, femur, tibia)
|
|
|
|
|
ServoCalNext, // serial console only: next servo
|
|
|
|
|
ServoCalTrim, // value = SERVO_TRIM_* step code
|
|
|
|
|
ServoCalSave, // store the trims in the robot's EEPROM
|
|
|
|
|
ServoCalRevert, // reload the trims from the robot's EEPROM
|
|
|
|
|
UploadRequest, // display update mode from the touchscreen: needs a second tap
|
|
|
|
|
NextionUpload, // display update mode right away (serial console 'U')
|
2026-09-28 18:14:00 +02:00
|
|
|
};
|
|
|
|
|
|
2026-11-17 14:42:37 +01:00
|
|
|
// ServoCalTrim values.
|
|
|
|
|
constexpr uint8_t SERVO_TRIM_MINUS_BIG = 0;
|
|
|
|
|
constexpr uint8_t SERVO_TRIM_MINUS_SMALL = 1;
|
|
|
|
|
constexpr uint8_t SERVO_TRIM_PLUS_SMALL = 2;
|
|
|
|
|
constexpr uint8_t SERVO_TRIM_PLUS_BIG = 3;
|
|
|
|
|
constexpr uint8_t SERVO_TRIM_ZERO = 4;
|
|
|
|
|
|
2026-09-28 18:14:00 +02:00
|
|
|
struct UiEvent {
|
|
|
|
|
UiCmd cmd = UiCmd::None;
|
|
|
|
|
uint8_t value = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-17 14:42:37 +01:00
|
|
|
// The HMI's pages (remote/remote.HMI, page id = position in the Editor's
|
|
|
|
|
// page list). Each page reports itself with a 'P' frame when it opens.
|
|
|
|
|
enum UiPage : uint8_t {
|
|
|
|
|
PAGE_SPLASH = 0, PAGE_DRIVE, PAGE_STATUS, PAGE_SERVOS, PAGE_CAL, PAGE_SETUP, PAGE_UPLOAD,
|
|
|
|
|
PAGE_UNKNOWN = 0xFF,
|
|
|
|
|
};
|
|
|
|
|
|
2026-09-28 18:14:00 +02:00
|
|
|
// Everything the display shows. The remote is authoritative: the Nextion
|
|
|
|
|
// only sends requests, and always renders what's in here.
|
|
|
|
|
struct UiView {
|
2026-11-17 14:42:37 +01:00
|
|
|
// Operator state (DRIVE page)
|
2026-09-28 18:14:00 +02:00
|
|
|
bool armed = false;
|
|
|
|
|
bool stand = false;
|
|
|
|
|
bool gait_wave = false;
|
|
|
|
|
bool mode_b = false;
|
|
|
|
|
bool rstick_xlate = false;
|
|
|
|
|
bool remote_gyro = false;
|
|
|
|
|
bool robot_gyro = false;
|
|
|
|
|
uint8_t speed_target = 0;
|
2026-09-29 00:37:12 +02:00
|
|
|
int16_t height = 0; // -1000..1000, 0 = default
|
2026-11-17 14:42:37 +01:00
|
|
|
|
|
|
|
|
// Radio + robot telemetry
|
2026-09-28 18:14:00 +02:00
|
|
|
bool link_ok = false;
|
|
|
|
|
uint8_t link_pct = 0;
|
2026-11-17 14:42:37 +01:00
|
|
|
bool tele_ok = false; // fresh telemetry from the robot
|
|
|
|
|
Telemetry tele;
|
|
|
|
|
|
|
|
|
|
// Handset (STATUS page)
|
|
|
|
|
bool imu_ok = false;
|
|
|
|
|
float imu_roll = 0, imu_pitch = 0; // degrees, vs the zeroed level
|
|
|
|
|
int16_t sticks[NUM_AXES] = {};
|
|
|
|
|
uint16_t battery_mv = 0; // 0 = not measured
|
|
|
|
|
|
|
|
|
|
// SETUP page
|
|
|
|
|
bool stick_calibrating = false;
|
|
|
|
|
bool upload_confirm = false; // UPDATE DISPLAY tapped once, waiting for the second tap
|
|
|
|
|
|
|
|
|
|
// CAL page (servo centre calibration)
|
|
|
|
|
bool servo_cal = false;
|
|
|
|
|
uint8_t servo_sel = 0; // leg * 3 + joint
|
|
|
|
|
bool trim_synced = false; // trim below is known (read back from the robot)
|
|
|
|
|
int16_t trim_us = 0;
|
|
|
|
|
|
|
|
|
|
const char* message = "";
|
2026-09-28 18:14:00 +02:00
|
|
|
};
|