Nýtt branch og kóðar plús breytingar á fyrri kóðum fyrir part 4
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#include "pre_operational_state.h"
|
||||
#include "motor_controller.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
PreOperationalState::PreOperationalState()
|
||||
: previous_time(0),
|
||||
led_state(false)
|
||||
{
|
||||
}
|
||||
|
||||
void PreOperationalState::enter()
|
||||
{
|
||||
Serial.println("State: Pre-operational");
|
||||
|
||||
context->stop_motor();
|
||||
|
||||
context->led_off();
|
||||
|
||||
led_state = false;
|
||||
|
||||
previous_time = millis();
|
||||
}
|
||||
|
||||
void PreOperationalState::update()
|
||||
{
|
||||
unsigned long current_time = millis();
|
||||
|
||||
if (current_time - previous_time >= 500)
|
||||
{
|
||||
previous_time = current_time;
|
||||
|
||||
led_state = !led_state;
|
||||
|
||||
if (led_state)
|
||||
{
|
||||
context->led_on();
|
||||
}
|
||||
else
|
||||
{
|
||||
context->led_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PreOperationalState::command(char c)
|
||||
{
|
||||
if (c == 'o' || c == 'O')
|
||||
{
|
||||
Serial.println("Command: set operational");
|
||||
|
||||
context->to_operational();
|
||||
}
|
||||
|
||||
else if (c == 'r' || c == 'R')
|
||||
{
|
||||
Serial.println("Command: reset");
|
||||
|
||||
context->to_initialization();
|
||||
}
|
||||
}
|
||||
|
||||
void PreOperationalState::exit()
|
||||
{
|
||||
context->led_off();
|
||||
}
|
||||
Reference in New Issue
Block a user