Run servo movement on different core
This commit is contained in:
@ -64,7 +64,6 @@ void SesameController::configure(ServoConfiguration servoConfig, ServerConfigura
|
||||
void SesameController::loop(uint32_t millis) {
|
||||
currentTime = millis;
|
||||
server.loop(millis);
|
||||
servo.loop(millis);
|
||||
}
|
||||
|
||||
// MARK: Local
|
||||
|
@ -4,7 +4,28 @@
|
||||
|
||||
ServoController::ServoController() { }
|
||||
|
||||
void performReset(void * pvParameters) {
|
||||
ServoController* servo = (ServoController *) pvParameters;
|
||||
for(;;){
|
||||
servo->loop(millis());
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
void ServoController::configure(ServoConfiguration configuration) {
|
||||
|
||||
// Create a task that runs on a different core,
|
||||
// So that it's always executed
|
||||
xTaskCreatePinnedToCore(
|
||||
performReset, /* Task function. */
|
||||
"Servo", /* name of task. */
|
||||
1000, /* Stack size of task */
|
||||
this, /* parameter of the task */
|
||||
1, /* priority of the task */
|
||||
&servoResetTask,
|
||||
1); /* pin task to core 1 */
|
||||
|
||||
|
||||
openDuration = configuration.openDuration;
|
||||
pressedValue = configuration.pressedValue;
|
||||
releasedValue = configuration.releasedValue;
|
||||
@ -15,9 +36,7 @@ void ServoController::configure(ServoConfiguration configuration) {
|
||||
}
|
||||
|
||||
void ServoController::pressButton() {
|
||||
servo.write(pressedValue);
|
||||
buttonIsPressed = true;
|
||||
openingEndTime = millis() + openDuration;
|
||||
shouldPressButton = true;
|
||||
}
|
||||
|
||||
void ServoController::releaseButton() {
|
||||
@ -26,7 +45,12 @@ void ServoController::releaseButton() {
|
||||
}
|
||||
|
||||
void ServoController::loop(uint32_t millis) {
|
||||
if (buttonIsPressed && millis > openingEndTime) {
|
||||
if (shouldPressButton) {
|
||||
servo.write(pressedValue);
|
||||
openingEndTime = millis + openDuration;
|
||||
buttonIsPressed = true;
|
||||
shouldPressButton = false;
|
||||
} else if (buttonIsPressed && millis > openingEndTime) {
|
||||
releaseButton();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user