#pragma once #include #include #include "Config.h" // 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 SetHeight, // value = 0..200, 100 = default standing height HeightUp, // serial console only HeightDown, // serial console only ZeroGyro, // capture the handset's current attitude as "level" CalStartSave, // stick sweep calibration: start, or save it if running CalCancel, 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') }; // 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; struct UiEvent { UiCmd cmd = UiCmd::None; uint8_t value = 0; }; // 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, }; // Everything the display shows. The remote is authoritative: the Nextion // only sends requests, and always renders what's in here. struct UiView { // Operator state (DRIVE page) 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; int16_t height = 0; // -1000..1000, 0 = default // Radio + robot telemetry bool link_ok = false; uint8_t link_pct = 0; 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 = ""; };