Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Nextion.h>
- #include <ESP32Servo.h>
- // Define serial communication for Nextion
- #define nexSerial Serial2
- // Create Nextion objects (Page, ID, NAME)
- NexButton minusLeftBT = NexButton(4, 5, "MinusLeft");
- NexButton plusLeftBT = NexButton(4, 6, "PlusLeft");
- NexButton minusRightBT = NexButton(4, 7, "MinusRight");
- NexButton plusRightBT = NexButton(4, 8, "PlusRight");
- NexButton sAxisBT = NexButton(3, 2, "S_AXIS");
- NexButton fAxisBT = NexButton(3, 3, "F_AXIS");
- NexButton startSessionBT = NexButton(1, 5, "StartSesion");
- NexButton pauseBT = NexButton(7, 4, "PAUSE");
- NexButton endBT = NexButton(8, 3, "END");
- NexButton resumeBT = NexButton(8, 4, "RESUME");
- NexButton minusSpeedBT = NexButton(5, 5, "MinusSpeed");
- NexButton plusSpeedBT = NexButton(5, 6, "PlusSpeed");
- NexText minAngleTX = NexText(4, 11, "MinAngleTX");
- NexText maxAngleTX = NexText(4, 12, "MaxAngleTX");
- NexText speedTX = NexText(5, 7, "SpeedTX");
- NexButton speedBT = NexButton(0, 6, "SPEED");
- NexButton plusRepsBT = NexButton(6, 6, "PlusReps");
- NexButton minusRepsBT = NexButton(6, 5, "MinusReps");
- NexText repsMinTX = NexText(6, 9, "RepsMinTX");
- NexText repsMaxTX = NexText(6, 8, "RepsMaxTX");
- NexText repetitionTX = NexText(6, 7, "RepetitionTX");
- NexButton repetitionBT = NexButton(0, 7, "REPETITION");
- NexText HandTX = NexText(1, 9, "HandTX");
- NexText MovementsTX = NexText(1, 10, "MovementsTX");
- NexText SpeedTX = NexText(1, 11, "SpeedTX");
- NexText RepetitionTX = NexText(1, 12, "RepetitionTX");
- NexButton startBT = NexButton(0, 3, "START");
- NexButton LeftHandDual = NexButton(2, 5, "LeftHandDual");
- NexButton RightHandDual = NexButton(2, 6, "RightHandDual");
- Servo servoSide;
- Servo servoTop;
- int neutralAngleSide = 132; // Neutral position for servoSide
- int neutralAngleTop = 137; // Neutral position for servoTop
- // Variables for pause at extremes, repetitions, and speed
- int extremePause = 1000; // Pause duration at extremes (in milliseconds)
- // Servo specifications
- const float maxSpeed = 0.14; // Time per 60° at 6V (seconds)
- const float maxAnglePerSec = 60.0 / maxSpeed; // Maximum angle per second at max speed
- // Homecoming speed
- int homeComingSpeed = 30; // Default homecoming speed set to 30%
- // Constants for limits of each axis
- const int S_AXIS_MAX_LEFT = 0;
- const int S_AXIS_MIN_LEFT = -20;
- const int S_AXIS_MAX_RIGHT = 40;
- const int S_AXIS_MIN_RIGHT = 0;
- const int F_AXIS_MAX_LEFT = 0;
- const int F_AXIS_MIN_LEFT = -5;
- const int F_AXIS_MAX_RIGHT = 20;
- const int F_AXIS_MIN_RIGHT = 0;
- const int SPEED_MAX = 100;
- const int SPEED_MIN = 0;
- const int REPS_MAX = 50;
- const int REPS_MIN = 1;
- // Variables to store the current angles, speed, and repetitions
- int s_axis_left = -20;
- int s_axis_right = 20;
- int f_axis_left = -5;
- int f_axis_right = 5;
- int currentSpeed = 50;
- int currentReps = 10;
- int remainingReps;
- // Variables to store the current button states
- bool minusLeftBTPressed = false;
- bool plusLeftBTPressed = false;
- bool minusRightBTPressed = false;
- bool plusRightBTPressed = false;
- bool minusSpeedBTPressed = false;
- bool plusSpeedBTPressed = false;
- bool plusRepsBTPressed = false;
- bool minusRepsBTPressed = false;
- unsigned long minusLeftBTPressTime = 0;
- unsigned long plusLeftBTPressTime = 0;
- unsigned long minusRightBTPressTime = 0;
- unsigned long plusRightBTPressTime = 0;
- unsigned long minusSpeedBTPressTime = 0;
- unsigned long plusSpeedBTPressTime = 0;
- unsigned long plusRepsBTPressTime = 0;
- unsigned long minusRepsBTPressTime = 0;
- const unsigned long SHORT_PRESS_DURATION = 300;
- const unsigned long LONG_PRESS_DURATION = 1000;
- const unsigned long REPEAT_RATE = 100;
- bool isSAxis = true;
- bool isRightHand = true; // Default to right hand
- bool sessionPaused = false; // Tracks whether the session is paused
- bool endSession = false; // Tracks whether the session is canceled
- // Constants for Serial Communication Pins
- const int RX_PIN = 16;
- const int TX_PIN = 17;
- NexTouch *nex_listen_list[] = {
- &minusLeftBT,
- &plusLeftBT,
- &minusRightBT,
- &plusRightBT,
- &sAxisBT,
- &fAxisBT,
- &startSessionBT,
- &pauseBT,
- &endBT,
- &resumeBT,
- &minusSpeedBT,
- &plusSpeedBT,
- &speedBT,
- &plusRepsBT,
- &minusRepsBT,
- &repetitionBT,
- &startBT,
- &LeftHandDual,
- &RightHandDual,
- NULL
- };
- // Function declarations
- void minusLeftBTPressCallback(void *ptr);
- void minusLeftBTReleaseCallback(void *ptr);
- void plusLeftBTPressCallback(void *ptr);
- void plusLeftBTReleaseCallback(void *ptr);
- void minusRightBTPressCallback(void *ptr);
- void minusRightBTReleaseCallback(void *ptr);
- void plusRightBTPressCallback(void *ptr);
- void plusRightBTReleaseCallback(void *ptr);
- void minusSpeedBTPressCallback(void *ptr);
- void minusSpeedBTReleaseCallback(void *ptr);
- void plusSpeedBTPressCallback(void *ptr);
- void plusSpeedBTReleaseCallback(void *ptr);
- void plusRepsBTPressCallback(void *ptr);
- void plusRepsBTReleaseCallback(void *ptr);
- void minusRepsBTPressCallback(void *ptr);
- void minusRepsBTReleaseCallback(void *ptr);
- void sAxisBTCallback(void *ptr);
- void fAxisBTCallback(void *ptr);
- void startSessionBTCallback(void *ptr);
- void pauseBTCallback(void *ptr);
- void endBTCallback(void *ptr);
- void resumeBTCallback(void *ptr);
- void repetitionBTCallback(void *ptr);
- void speedBTCallback(void *ptr); // Added speedBTCallback declaration
- void setup() {
- Serial.begin(115200);
- nexSerial.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
- nexInit();
- // Update the SUMMARY page
- updateSummaryPage();
- servoSide.attach(25);
- servoTop.attach(27);
- servoSide.write(neutralAngleSide);
- servoTop.write(neutralAngleTop);
- delay(500);
- Serial.println("Ready to receive commands.");
- minusLeftBT.attachPush(minusLeftBTPressCallback, &minusLeftBT);
- minusLeftBT.attachPop(minusLeftBTReleaseCallback, &minusLeftBT);
- plusLeftBT.attachPush(plusLeftBTPressCallback, &plusLeftBT);
- plusLeftBT.attachPop(plusLeftBTReleaseCallback, &plusLeftBT);
- minusRightBT.attachPush(minusRightBTPressCallback, &minusRightBT);
- minusRightBT.attachPop(minusRightBTReleaseCallback, &minusRightBT);
- plusRightBT.attachPush(plusRightBTPressCallback, &plusRightBT);
- plusRightBT.attachPop(plusRightBTReleaseCallback, &plusRightBT);
- sAxisBT.attachPop(sAxisBTCallback, &sAxisBT);
- fAxisBT.attachPop(fAxisBTCallback, &fAxisBT);
- startSessionBT.attachPop(startSessionBTCallback, &startSessionBT);
- pauseBT.attachPush(pauseBTCallback, &pauseBT);
- endBT.attachPop(endBTCallback, &endBT);
- resumeBT.attachPop(resumeBTCallback, &resumeBT);
- minusSpeedBT.attachPush(minusSpeedBTPressCallback, &minusSpeedBT);
- minusSpeedBT.attachPop(minusSpeedBTReleaseCallback, &minusSpeedBT);
- plusSpeedBT.attachPush(plusSpeedBTPressCallback, &plusSpeedBT);
- plusSpeedBT.attachPop(plusSpeedBTReleaseCallback, &plusSpeedBT);
- speedBT.attachPop(speedBTCallback, &speedBT); // Added speedBTCallback
- plusRepsBT.attachPush(plusRepsBTPressCallback, &plusRepsBT);
- plusRepsBT.attachPop(plusRepsBTReleaseCallback, &plusRepsBT);
- minusRepsBT.attachPush(minusRepsBTPressCallback, &minusRepsBT);
- minusRepsBT.attachPop(minusRepsBTReleaseCallback, &minusRepsBT);
- repetitionBT.attachPop(repetitionBTCallback, &repetitionBT);
- startBT.attachPop(startBTCallback, &startBT);
- LeftHandDual.attachPop(LeftHandDualCallback, &LeftHandDual);
- RightHandDual.attachPop(RightHandDualCallback, &RightHandDual);
- updateDisplay();
- updateMinMaxDisplay();
- updatespeedTX();
- }
- void loop() {
- nexLoop(nex_listen_list);
- if (sessionPaused) return;
- unsigned long currentTime = millis();
- if (minusLeftBTPressed && currentTime - minusLeftBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- if (isSAxis) {
- s_axis_left = max(s_axis_left - 1, S_AXIS_MIN_LEFT);
- } else {
- f_axis_left = max(f_axis_left - 1, F_AXIS_MIN_LEFT);
- }
- updateDisplay();
- lastUpdateTime = currentTime;
- }
- }
- if (plusLeftBTPressed && currentTime - plusLeftBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- if (isSAxis) {
- s_axis_left = min(s_axis_left + 1, S_AXIS_MAX_LEFT);
- } else {
- f_axis_left = min(f_axis_left + 1, F_AXIS_MAX_LEFT);
- }
- updateDisplay();
- lastUpdateTime = currentTime;
- }
- }
- if (minusRightBTPressed && currentTime - minusRightBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- if (isSAxis) {
- s_axis_right = max(s_axis_right - 1, S_AXIS_MIN_RIGHT);
- } else {
- f_axis_right = max(f_axis_right - 1, F_AXIS_MIN_RIGHT);
- }
- updateDisplay();
- lastUpdateTime = currentTime;
- }
- }
- if (plusRightBTPressed && currentTime - plusRightBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- if (isSAxis) {
- s_axis_right = min(s_axis_right + 1, S_AXIS_MAX_RIGHT);
- } else {
- f_axis_right = min(f_axis_right + 1, F_AXIS_MAX_RIGHT);
- }
- updateDisplay();
- lastUpdateTime = currentTime;
- }
- }
- if (minusSpeedBTPressed && currentTime - minusSpeedBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- currentSpeed = max(currentSpeed - 1, SPEED_MIN);
- updatespeedTX();
- lastUpdateTime = currentTime;
- }
- }
- if (plusSpeedBTPressed && currentTime - plusSpeedBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- currentSpeed = min(currentSpeed + 1, SPEED_MAX);
- updatespeedTX();
- lastUpdateTime = currentTime;
- }
- }
- // Logic for repetition increment
- if (plusRepsBTPressed && currentTime - plusRepsBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- currentReps = min(currentReps + 1, REPS_MAX);
- updateRepetitionTX();
- lastUpdateTime = currentTime;
- }
- }
- // Logic for repetition decrement
- if (minusRepsBTPressed && currentTime - minusRepsBTPressTime > LONG_PRESS_DURATION) {
- static unsigned long lastUpdateTime = 0;
- if (currentTime - lastUpdateTime >= REPEAT_RATE) {
- currentReps = max(currentReps - 1, REPS_MIN);
- updateRepetitionTX();
- lastUpdateTime = currentTime;
- }
- }
- }
- void updateDisplay() {
- nexSerial.print("LeftAngleTX.txt=\"");
- if (isSAxis) {
- nexSerial.print(s_axis_left);
- } else {
- nexSerial.print(f_axis_left);
- }
- nexSerial.write(0xB0); // Degree symbol
- nexSerial.print("\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.print("RightAngleTX.txt=\"");
- if (isSAxis) {
- nexSerial.print(s_axis_right);
- } else {
- nexSerial.print(f_axis_right);
- }
- nexSerial.write(0xB0); // Degree symbol
- nexSerial.print("\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- }
- void updatespeedTX() {
- nexSerial.print("SpeedTX.txt=\"");
- nexSerial.print(currentSpeed);
- nexSerial.print("%\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- }
- void updateRepetitionTX() {
- nexSerial.print("RepetitionTX.txt=\"");
- nexSerial.print(currentReps);
- nexSerial.print("x\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- }
- void updateMinMaxDisplay() {
- char minAngleTXStr[10];
- char maxAngleTXStr[10];
- if (isSAxis) {
- sprintf(minAngleTXStr, "%d", S_AXIS_MIN_LEFT);
- sprintf(maxAngleTXStr, "%d", S_AXIS_MAX_RIGHT);
- } else {
- sprintf(minAngleTXStr, "%d", F_AXIS_MIN_LEFT);
- sprintf(maxAngleTXStr, "%d", F_AXIS_MAX_RIGHT);
- }
- minAngleTX.setText(minAngleTXStr);
- maxAngleTX.setText(maxAngleTXStr);
- char minRepsTXStr[10];
- char maxRepsTXStr[10];
- sprintf(minRepsTXStr, "%d", REPS_MIN);
- sprintf(maxRepsTXStr, "%d", REPS_MAX);
- repsMinTX.setText(minRepsTXStr);
- repsMaxTX.setText(maxRepsTXStr);
- updateDisplay();
- updatespeedTX();
- updateRepetitionTX();
- }
- void updateRepsAfterPress(unsigned long pressTime, int *reps, int minValue, int maxValue, bool increment) {
- unsigned long pressDuration = millis() - pressTime;
- if (pressDuration < LONG_PRESS_DURATION) {
- if (increment) {
- *reps = min(*reps + 1, maxValue);
- } else {
- *reps = max(*reps - 1, minValue);
- }
- updateRepetitionTX();
- }
- }
- void updateNumberAfterPress(unsigned long pressTime, int *number, int minValue, int maxValue, bool increment) {
- unsigned long pressDuration = millis() - pressTime;
- if (pressDuration < LONG_PRESS_DURATION) {
- if (increment) {
- *number = min(*number + 1, maxValue);
- } else {
- *number = max(*number - 1, minValue);
- }
- updateDisplay();
- updatespeedTX();
- }
- }
- void updateSummaryPage() {
- // Update hand information
- nexSerial.print("SUMMARY.HandTX.txt=\"");
- nexSerial.print(isRightHand ? "Right" : "Left");
- nexSerial.print("\"");
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- // Update MovementsTX
- nexSerial.print("SUMMARY.MovementsTX.txt=\"");
- if (isSAxis) {
- nexSerial.print("S: ");
- nexSerial.print(s_axis_left);
- nexSerial.write(0xB0); // Degree symbol
- nexSerial.print(" / ");
- nexSerial.print(s_axis_right);
- nexSerial.write(0xB0); // Degree symbol
- } else {
- nexSerial.print("F: ");
- nexSerial.print(f_axis_left);
- nexSerial.write(0xB0); // Degree symbol
- nexSerial.print(" / ");
- nexSerial.print(f_axis_right);
- nexSerial.write(0xB0); // Degree symbol
- }
- nexSerial.print("\"");
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- // Update SpeedTX
- nexSerial.print("SUMMARY.SpeedTX.txt=\"");
- nexSerial.print(currentSpeed);
- nexSerial.print("%\"");
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- // Update RepetitionTX
- nexSerial.print("SUMMARY.RepetitionTX.txt=\"");
- nexSerial.print(currentReps);
- nexSerial.print("x\"");
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- }
- void moveServo() {
- int minAngle = isSAxis ? s_axis_left : f_axis_left; // Determine the minimum angle based on the active axis
- int maxAngle = isSAxis ? s_axis_right : f_axis_right; // Determine the maximum angle based on the active axis
- Servo &activeServo = isSAxis ? servoSide : servoTop; // Select the active servo (servoSide or servoTop)
- int lastDisplayedSpeed = -1; // Track the last displayed speed to avoid redundant updates
- remainingReps = currentReps; // Initialize the remaining repetitions
- for (int i = 1; i <= currentReps; i++) {
- remainingReps = currentReps - i + 1; // Update remaining reps count
- // Check if session is paused or canceled
- if (sessionPaused) {
- homeComing(activeServo, isSAxis); // Move to neutral position
- while (sessionPaused) {
- // Wait here until resumed (pauseBT toggles sessionPaused to false)
- if (endSession) {
- Serial.println("Session canceled by end button.");
- return; // Exit the loop entirely
- }
- delay(100); // Small delay to avoid busy-waiting
- }
- }
- if (endSession) {
- Serial.println("Session canceled by end button.");
- return; // Exit the loop entirely
- }
- // Display remaining repetitions
- char remainingRepsStr[10];
- sprintf(remainingRepsStr, "%dx", remainingReps);
- nexSerial.print("ActiveRepsTX.txt=\"");
- nexSerial.print(remainingRepsStr);
- nexSerial.print("\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- // Display the current speed
- if (currentSpeed != lastDisplayedSpeed) {
- char activeSpeedStr[10];
- sprintf(activeSpeedStr, "%d%%", currentSpeed);
- nexSerial.print("ActiveSpeedTX.txt=\"");
- nexSerial.print(activeSpeedStr);
- nexSerial.print("\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- lastDisplayedSpeed = currentSpeed;
- }
- // Move to minimum angle
- nexSerial.print("ActiveAngleTX.txt=\"");
- nexSerial.print(minAngle);
- nexSerial.write(0xB0); // Degree symbol
- nexSerial.print("\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- moveToAngle(activeServo, minAngle, isSAxis); // Move servo
- delay(extremePause); // Pause at extreme
- // Move to maximum angle
- nexSerial.print("ActiveAngleTX.txt=\"");
- nexSerial.print(maxAngle);
- nexSerial.write(0xB0); // Degree symbol
- nexSerial.print("\"");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- moveToAngle(activeServo, maxAngle, isSAxis); // Move servo
- delay(extremePause); // Pause at extreme
- }
- // Move servo to neutral position after finishing
- homeComing(activeServo, isSAxis);
- // Navigate to page 0
- nexSerial.print("page 0");
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- Serial.println("Servo movement complete. Navigated to page 0.");
- }
- void moveToAngle(Servo &servo, int targetUserAngle, bool isSideServo) {
- int targetAngle = convertToServoAngle(targetUserAngle, isSideServo);
- int currentAngle = servo.read();
- Serial.print("Moving servo to: ");
- Serial.println(targetAngle);
- int step = (currentAngle < targetAngle) ? 1 : -1;
- while (currentAngle != targetAngle) {
- currentAngle += step;
- servo.write(currentAngle);
- // Speed-adjusted delay
- float speedFactor = currentSpeed / 100.0; // Convert percentage to a factor (0.0 to 1.0)
- int dynamicDelay = (int)(10 / speedFactor); // Scale the delay inversely with speed
- delay(dynamicDelay);
- }
- servo.write(targetAngle);
- }
- void homeComing(Servo &servo, bool isSideServo) {
- int neutralAngle = isSideServo ? neutralAngleSide : neutralAngleTop; // Determine neutral angle
- int currentAngle = servo.read(); // Get the current servo angle
- Serial.println("Returning servo to neutral position...");
- // Determine the direction of movement
- int step = (currentAngle < neutralAngle) ? 1 : -1;
- // Adjust speed based on homeComingSpeed (scale delay inversely)
- float speedFactor = homeComingSpeed / 100.0; // Convert speed percentage to a factor (0.0 to 1.0)
- int dynamicDelay = (int)(10 / speedFactor); // Scale delay inversely with speed factor
- // Gradually move servo to neutral position
- while (currentAngle != neutralAngle) {
- currentAngle += step;
- servo.write(currentAngle);
- delay(dynamicDelay); // Apply speed-controlled delay
- }
- // Ensure servo is precisely at the neutral position
- servo.write(neutralAngle);
- Serial.println("Servo returned to neutral position.");
- }
- float calculateSpeed() {
- return maxAnglePerSec * (currentSpeed / 100.0);
- }
- int convertToServoAngle(int userAngle, bool isSideServo) {
- if (isSideServo) {
- return neutralAngleSide + userAngle;
- } else {
- return neutralAngleTop + userAngle;
- }
- }
- // Button press and release callbacks
- void minusLeftBTPressCallback(void *ptr) {
- minusLeftBTPressed = true;
- minusLeftBTPressTime = millis();
- }
- void minusLeftBTReleaseCallback(void *ptr) {
- minusLeftBTPressed = false;
- if (isSAxis) {
- updateNumberAfterPress(minusLeftBTPressTime, &s_axis_left, S_AXIS_MIN_LEFT, S_AXIS_MAX_LEFT, false);
- } else {
- updateNumberAfterPress(minusLeftBTPressTime, &f_axis_left, F_AXIS_MIN_LEFT, F_AXIS_MAX_LEFT, false);
- }
- updateSummaryPage();
- }
- void plusLeftBTPressCallback(void *ptr) {
- plusLeftBTPressed = true;
- plusLeftBTPressTime = millis();
- }
- void plusLeftBTReleaseCallback(void *ptr) {
- plusLeftBTPressed = false;
- if (isSAxis) {
- updateNumberAfterPress(plusLeftBTPressTime, &s_axis_left, S_AXIS_MIN_LEFT, S_AXIS_MAX_LEFT, true);
- } else {
- updateNumberAfterPress(plusLeftBTPressTime, &f_axis_left, F_AXIS_MIN_LEFT, F_AXIS_MAX_LEFT, true);
- }
- updateSummaryPage();
- }
- void minusRightBTPressCallback(void *ptr) {
- minusRightBTPressed = true;
- minusRightBTPressTime = millis();
- }
- void minusRightBTReleaseCallback(void *ptr) {
- minusRightBTPressed = false;
- if (isSAxis) {
- updateNumberAfterPress(minusRightBTPressTime, &s_axis_right, S_AXIS_MIN_RIGHT, S_AXIS_MAX_RIGHT, false);
- } else {
- updateNumberAfterPress(minusRightBTPressTime, &f_axis_right, F_AXIS_MIN_RIGHT, F_AXIS_MAX_RIGHT, false);
- }
- updateSummaryPage();
- }
- void plusRightBTPressCallback(void *ptr) {
- plusRightBTPressed = true;
- plusRightBTPressTime = millis();
- }
- void plusRightBTReleaseCallback(void *ptr) {
- plusRightBTPressed = false;
- if (isSAxis) {
- updateNumberAfterPress(plusRightBTPressTime, &s_axis_right, S_AXIS_MIN_RIGHT, S_AXIS_MAX_RIGHT, true);
- } else {
- updateNumberAfterPress(plusRightBTPressTime, &f_axis_right, F_AXIS_MIN_RIGHT, F_AXIS_MAX_RIGHT, true);
- }
- updateSummaryPage();
- }
- void minusSpeedBTPressCallback(void *ptr) {
- minusSpeedBTPressed = true;
- minusSpeedBTPressTime = millis();
- }
- void minusSpeedBTReleaseCallback(void *ptr) {
- minusSpeedBTPressed = false;
- updateNumberAfterPress(minusSpeedBTPressTime, ¤tSpeed, SPEED_MIN, SPEED_MAX, false);
- updateSummaryPage(); // Update SUMMARY page
- }
- void plusSpeedBTReleaseCallback(void *ptr) {
- plusSpeedBTPressed = false;
- updateNumberAfterPress(plusSpeedBTPressTime, ¤tSpeed, SPEED_MIN, SPEED_MAX, true);
- updateSummaryPage(); // Update SUMMARY page
- }
- void plusSpeedBTPressCallback(void *ptr) {
- plusSpeedBTPressed = true;
- plusSpeedBTPressTime = millis();
- }
- void plusRepsBTPressCallback(void *ptr) {
- plusRepsBTPressed = true;
- plusRepsBTPressTime = millis();
- }
- void plusRepsBTReleaseCallback(void *ptr) {
- plusRepsBTPressed = false;
- updateRepsAfterPress(plusRepsBTPressTime, ¤tReps, REPS_MIN, REPS_MAX, true);
- updateSummaryPage(); // Update SUMMARY page
- }
- void minusRepsBTReleaseCallback(void *ptr) {
- minusRepsBTPressed = false;
- updateRepsAfterPress(minusRepsBTPressTime, ¤tReps, REPS_MIN, REPS_MAX, false);
- updateSummaryPage(); // Update SUMMARY page
- }
- void minusRepsBTPressCallback(void *ptr) {
- minusRepsBTPressed = true;
- minusRepsBTPressTime = millis();
- }
- void sAxisBTCallback(void *ptr) {
- isSAxis = true;
- updateMinMaxDisplay();
- updateSummaryPage(); // Update SUMMARY page
- }
- void fAxisBTCallback(void *ptr) {
- isSAxis = false;
- updateMinMaxDisplay();
- updateSummaryPage(); // Update SUMMARY page
- }
- void startSessionBTCallback(void *ptr) {
- Serial.println("Starting servo movement...");
- moveServo();
- }
- void pauseBTCallback(void *ptr) {
- sessionPaused = !sessionPaused; // Toggle pause state
- if (sessionPaused) {
- Serial.println("Session paused.");
- homeComing(isSAxis ? servoSide : servoTop, isSAxis); // Move to neutral
- } else {
- Serial.println("Session resumed.");
- }
- }
- void endBTCallback(void *ptr) {
- endSession = true; // Set the session cancel flag
- Serial.println("Session canceled. Moving servos to neutral...");
- // Move servos to neutral position
- if (isSAxis) {
- homeComing(servoSide, true); // Neutral for s-axis servo
- } else {
- homeComing(servoTop, false); // Neutral for f-axis servo
- }
- Serial.println("Servos moved to neutral position. Session ended.");
- }
- void resumeBTCallback(void *ptr) {
- sessionPaused = false;
- Serial.println("Session resumed.");
- }
- void speedBTCallback(void *ptr) {
- updatespeedTX();
- }
- void repetitionBTCallback(void *ptr) {
- updateMinMaxDisplay();
- }
- void startBTCallback(void *ptr) {
- Serial.println("START button pressed.F");
- }
- void LeftHandDualCallback(void *ptr) {
- isRightHand = false; // Set to left hand
- Serial.println("Left hand selected.");
- // Update Nextion display states
- nexSerial.print("HAND.LeftHandDual.val=1"); // Turn LeftHandDual ON
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.print("HAND.RightHandDual.val=0"); // Turn RightHandDual OFF
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- // Update HandDual button value
- nexSerial.print("HOME.HandDual.val=1"); // Left hand (value 1)
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- updateSummaryPage(); // Reflect changes on SUMMARY page
- }
- void RightHandDualCallback(void *ptr) {
- isRightHand = true; // Set to right hand
- Serial.println("Right hand selected.");
- // Update Nextion display states
- nexSerial.print("HAND.RightHandDual.val=1"); // Turn RightHandDual ON
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.print("HAND.LeftHandDual.val=0"); // Turn LeftHandDual OFF
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- // Update HandDual button value
- nexSerial.print("HOME.HandDual.val=0"); // Right hand (value 0)
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- nexSerial.write(0xFF);
- updateSummaryPage(); // Reflect changes on SUMMARY page
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement