diff --git a/include/motor.h b/include/motor.h index 467c22c..5932bb7 100644 --- a/include/motor.h +++ b/include/motor.h @@ -26,15 +26,6 @@ public: void setStallCallback(StallCallback callback); void resetStallDetection(); - // Pingpong mode (time-based only) - void startPingpong(int speed, int timeMs, int speedRandomPercent, int timeRandomPercent); - void stopPingpong(); - bool isPingpongActive(); - int getPingpongSpeed(); - int getPingpongTime(); - int getPingpongSpeedRandom(); - int getPingpongTimeRandom(); - private: int _speed = 0; int _direction = 0; @@ -45,17 +36,6 @@ private: int _adcOffsetRight = 0; int _adcOffsetLeft = 0; - // Pingpong state - bool _pingpongActive = false; - int _pingpongBaseSpeed = 50; - int _pingpongBaseTime = 2000; - int _pingpongSpeedRandomPercent = 0; - int _pingpongTimeRandomPercent = 0; - int _pingpongCurrentSpeed = 50; - int _pingpongCurrentTime = 2000; - unsigned long _pingpongLastSwitch = 0; - int _pingpongDirection = 1; - // Stall detection state bool _stalled = false; int _stallConfirmCount = 0; @@ -65,8 +45,6 @@ private: void applyMotorState(); float readCurrentSense(int pin); void calibrateCurrentOffset(); - void updatePingpong(); - int applyRandomness(int baseValue, int randomPercent); void checkStall(); }; diff --git a/src/main.cpp b/src/main.cpp index 4ece2de..640e767 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,6 @@ void onMotorStall() { Serial.println("Stall callback triggered - stopping motor!"); motor.stop(); - motor.stopPingpong(); } void setupWiFi() { diff --git a/src/motor.cpp b/src/motor.cpp index 76b2364..8bc3066 100644 --- a/src/motor.cpp +++ b/src/motor.cpp @@ -86,9 +86,6 @@ void MotorController::update() { // Check for stall condition checkStall(); #endif - - // Update pingpong mode - updatePingpong(); } int MotorController::getSpeed() { @@ -245,88 +242,3 @@ void MotorController::calibrateCurrentOffset() { _adcOffsetRight, _adcOffsetLeft); #endif } - -// Pingpong mode implementation (time-based only) -void MotorController::startPingpong(int speed, int timeMs, int speedRandomPercent, int timeRandomPercent) { - _pingpongBaseSpeed = constrain(speed, 0, 100); - _pingpongBaseTime = constrain(timeMs, 100, 30000); - _pingpongSpeedRandomPercent = constrain(speedRandomPercent, 0, 100); - _pingpongTimeRandomPercent = constrain(timeRandomPercent, 0, 100); - - _pingpongDirection = 1; - _pingpongCurrentSpeed = applyRandomness(_pingpongBaseSpeed, _pingpongSpeedRandomPercent); - _pingpongCurrentTime = applyRandomness(_pingpongBaseTime, _pingpongTimeRandomPercent); - _pingpongLastSwitch = millis(); - _pingpongActive = true; - - // Apply initial state - _speed = _pingpongCurrentSpeed; - _direction = _pingpongDirection; - applyMotorState(); - - Serial.printf("Pingpong started: speed=%d%% (base=%d, rand=%d%%), time=%dms (base=%d, rand=%d%%)\n", - _pingpongCurrentSpeed, _pingpongBaseSpeed, _pingpongSpeedRandomPercent, - _pingpongCurrentTime, _pingpongBaseTime, _pingpongTimeRandomPercent); -} - -void MotorController::stopPingpong() { - _pingpongActive = false; - stop(); - Serial.println("Pingpong stopped"); -} - -bool MotorController::isPingpongActive() { - return _pingpongActive; -} - -int MotorController::getPingpongSpeed() { - return _pingpongBaseSpeed; -} - -int MotorController::getPingpongTime() { - return _pingpongBaseTime; -} - -int MotorController::getPingpongSpeedRandom() { - return _pingpongSpeedRandomPercent; -} - -int MotorController::getPingpongTimeRandom() { - return _pingpongTimeRandomPercent; -} - -void MotorController::updatePingpong() { - if (!_pingpongActive) return; - - unsigned long now = millis(); - - // Time-based switching - if ((now - _pingpongLastSwitch) >= (unsigned long)_pingpongCurrentTime) { - // Switch direction - _pingpongDirection = -_pingpongDirection; - - // Apply randomness for next cycle - _pingpongCurrentSpeed = applyRandomness(_pingpongBaseSpeed, _pingpongSpeedRandomPercent); - _pingpongCurrentTime = applyRandomness(_pingpongBaseTime, _pingpongTimeRandomPercent); - _pingpongLastSwitch = now; - - // Apply new state - _speed = _pingpongCurrentSpeed; - _direction = _pingpongDirection; - applyMotorState(); - - Serial.printf("Pingpong switch: dir=%d, speed=%d%%, next_time=%dms\n", - _pingpongDirection, _pingpongCurrentSpeed, _pingpongCurrentTime); - } -} - -int MotorController::applyRandomness(int baseValue, int randomPercent) { - if (randomPercent == 0) return baseValue; - - int maxVariation = (baseValue * randomPercent) / 100; - int variation = random(-maxVariation, maxVariation + 1); - int result = baseValue + variation; - - // Ensure result stays positive and reasonable - return max(1, result); -} diff --git a/src/webserver.cpp b/src/webserver.cpp index a3088db..2464c5d 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -122,60 +122,6 @@ const char index_html[] PROGMEM = R"rawliteral( .stall-warning.active { display: block; } - .pingpong-section { - background: #16213e; - padding: 20px; - border-radius: 10px; - margin-bottom: 20px; - } - .pingpong-status { - padding: 10px; - border-radius: 5px; - margin-bottom: 15px; - font-weight: bold; - } - .pingpong-status.active { - background: #00c853; - color: white; - } - .pingpong-status.inactive { - background: #444; - color: #aaa; - } - .setting-row { - display: flex; - justify-content: space-between; - align-items: center; - margin-bottom: 10px; - } - .setting-row label { - text-align: left; - flex: 1; - } - .setting-row .value { - color: #00d9ff; - font-weight: bold; - min-width: 60px; - } - .setting-slider { - width: 100%; - height: 20px; - -webkit-appearance: none; - background: #0f3460; - border-radius: 10px; - outline: none; - margin-top: 5px; - } - .setting-slider::-webkit-slider-thumb { - -webkit-appearance: none; - width: 25px; - height: 25px; - background: #00d9ff; - border-radius: 50%; - cursor: pointer; - } - .btn-pingpong-start { background: #9c27b0; color: white; } - .btn-pingpong-stop { background: #607d8b; color: white; } @@ -210,43 +156,6 @@ const char index_html[] PROGMEM = R"rawliteral( - -
- -

🏓 Pingpong Mode

- -
-
INACTIVE
- -
- - 50% -
- - -
- - 2.0s -
- - -
- - 0% -
- - -
- - 0% -
- -
- -
- - -