Dave Lu / Mbed 2 deprecated FYDP

Dependencies:   mbed

Fork of FYDP_Final2 by Dave Lu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers State.cpp Source File

State.cpp

00001 #include "State.hpp"
00002 
00003 typedef void (*Void2Void)(void);
00004 
00005 void noop(void) {}
00006 
00007 int State::currentState(int prevState, float pitch) {
00008    switch(prevState) {
00009       case UNCALIBRATED:
00010          return UNCALIBRATED;
00011       case STOP:
00012          if(pitch > 7) {
00013             onStopToSwing();
00014             return SWING;
00015          } else if(pitch < -13) {
00016             onStopToMaybe();
00017             return MAYBESTOP;
00018          }
00019          return STOP;
00020       case SWING:
00021          if(pitch < -7) {
00022             return MAYBESTOP;
00023          }
00024          return SWING;
00025       case MAYBESTOP:
00026          if(pitch > -5) {
00027             return STOP;
00028          }
00029          return MAYBESTOP;
00030       default:
00031          return UNCALIBRATED;
00032    }
00033 }
00034 
00035 State::State() {
00036    onStopToSwing = &noop;
00037    onStopToMaybe = &noop;
00038    state = UNCALIBRATED;
00039 }
00040 
00041 void State::onSwing(Void2Void handler) {
00042    onStopToSwing = handler;
00043 }
00044 
00045 void State::onMaybe(Void2Void handler) {
00046    onStopToMaybe = handler;
00047 }
00048 
00049 void State::next(float thigh) {
00050    state = currentState(state, thigh);
00051 }