Implemented state "wait for connection".

Fixed LED heartbeat blink code.
Added button response commands for serial communication.
This commit is contained in:
jpunkt 2022-01-05 19:07:50 +01:00
parent 3bfe65f1f7
commit ef34adf75c
3 changed files with 25 additions and 19 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.vscode/c_cpp_properties.json .vscode/c_cpp_properties.json
.vscode/launch.json .vscode/launch.json
.vscode/ipch .vscode/ipch
workspace.code-workspace

View File

@ -11,6 +11,11 @@ enum Command {
FRONTLIGHT = 'F', FRONTLIGHT = 'F',
USER_INTERACT = 'U', USER_INTERACT = 'U',
RESP_BLUE = 'X',
RESP_RED = 'O',
RESP_YELLOW = 'Y',
RESP_GREEN = 'N',
RECORD = 'C', RECORD = 'C',
REWIND = 'R', REWIND = 'R',

View File

@ -81,9 +81,8 @@ State* SER = sm.addState(&state_error);
#define ERROR_OFF_MS 500 #define ERROR_OFF_MS 500
/*-------- Variables --------*/ /*-------- Variables --------*/
// Heartbeat blinker times // Heartbeat blinker timer
uint32_t on_time; elapsedMillis blink_time;
uint32_t off_time;
// Statemachine booleans // Statemachine booleans
bool handshake_complete; bool handshake_complete;
@ -153,17 +152,20 @@ void vert_count() {
* @param on_interval time LED stays on in millis * @param on_interval time LED stays on in millis
* @param off_interval time LED is off in millis * @param off_interval time LED is off in millis
*/ */
void blink_builtin(int on_interval, int off_interval) { void blink_builtin(uint32_t on_interval, uint32_t off_interval) {
uint32_t cur_time = millis();
if (digitalRead(LED_BUILTIN)) { if (digitalRead(LED_BUILTIN)) {
if (off_time < cur_time) { if (blink_time >= on_interval) {
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
on_time = cur_time + off_interval; blink_time = blink_time - on_interval;
// led_on = false;
// Serial.println("Turn LED off");
} }
} else { } else {
if (on_time < cur_time) { if (blink_time >= off_interval) {
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
off_time = cur_time + on_interval; blink_time = blink_time - off_interval;
// led_on = true;
// Serial.println("Turn LED on");
} }
} }
} }
@ -420,8 +422,7 @@ void setup() {
hor_pos = 0; hor_pos = 0;
vert_pos = 0; vert_pos = 0;
on_time = 0; blink_time = 0;
off_time = 0;
vert_up.setup(); vert_up.setup();
vert_down.setup(); vert_down.setup();
@ -490,8 +491,8 @@ void state_post() {
void state_zero() { void state_zero() {
Serial.println("State Zeroing."); Serial.println("State Zeroing.");
zero_motor(vert_up, vert_down, VERT_END_INNER, VERT_END_OUTER); // zero_motor(vert_up, vert_down, VERT_END_INNER, VERT_END_OUTER);
zero_motor(horz_left, horz_right, HORZ_END_OUTER, HORZ_END_INNER); // TODO check this // zero_motor(horz_left, horz_right, HORZ_END_OUTER, HORZ_END_INNER); // TODO check this
} }
/** /**
@ -516,14 +517,11 @@ void state_wait_serial() {
handshake_complete = false; handshake_complete = false;
Serial.println("State Waiting for Serial Handshake."); Serial.println("State Waiting for Serial Handshake.");
// digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
// off_time = millis() + WAIT_ON_MS;
// on_time = millis() + WAIT_OFF_MS;
} }
blink_builtin(WAIT_ON_MS, WAIT_OFF_MS); blink_builtin(WAIT_ON_MS, WAIT_OFF_MS);
ssp.loop();
// ssp.loop();
} }
/** /**
@ -532,8 +530,10 @@ void state_wait_serial() {
*/ */
void state_serial_com() { void state_serial_com() {
if (sm.executeOnce) { if (sm.executeOnce) {
digitalWrite(LED_BUILTIN, LOW);
Serial.println("State Serial Communication."); Serial.println("State Serial Communication.");
} }
ssp.loop(); ssp.loop();
} }
@ -583,6 +583,6 @@ bool transition_init_wait() {
* @return false * @return false
*/ */
bool transition_wait_sercom() { bool transition_wait_sercom() {
digitalWrite(LED_BUILTIN, LOW); // digitalWrite(LED_BUILTIN, LOW);
return handshake_complete; return handshake_complete;
} }