Skip to content
Snippets Groups Projects
Commit 7713ca81 authored by jp7g21's avatar jp7g21
Browse files

Merge remote-tracking branch 'refs/remotes/origin/master'

parents 82cec962 19e45fbd
No related branches found
No related tags found
No related merge requests found
#include <avr/io.h>
#include "servos.hpp"
#include "uart.hpp"
#include "command.h"
#include "state-controller.hpp"
#include "time.hpp"
int main()
{
initTime();
initServos();
initUart();
while (1)
{
updateState();
}
}
#include "servos.hpp"
#include "command.h"
#include "time.hpp"
#include <avr/interrupt.h>
enum State
{
STATE_DELAY, STATE_READY
};
static State state = STATE_READY;
static uint32_t delayEnd = 0;
void parseCommand(command *comm)
{
switch (comm->comm_ch)
{
case 's':
setServoAngle(comm->arg[0] - 1, comm->arg[1] * 60);
updateServos();
break;
case 'd':
delayEnd = getCurrentMillis() + comm->arg[0];
state = STATE_DELAY;
break;
}
}
void updateState()
{
switch (state)
{
case STATE_READY:
{
cli();
command *tmp = get_command();
command comm = *tmp;
sei();
if (tmp != nullptr)
parseCommand(&comm);
break;
}
case STATE_DELAY:
if (getCurrentMillis() > delayEnd)
state = STATE_READY;
break;
}
}
#ifndef STATE_CONTROLLER_H
#define STATE_CONTROLLER_H
#include "command.h"
/**
* Updates command the state.
* Should be called periodically.
*/
void updateState();
#endif /* STATE_CONTROLLER_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment