SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.
Dependencies: TSI USBDevice mbed-dev
Fork of SmartWheels by
StateMachine/StateManager.cpp@81:32bd7a25a699, 2017-04-18 (annotated)
- Committer:
- hazheng
- Date:
- Tue Apr 18 19:42:15 2017 +0000
- Branch:
- Drift
- Revision:
- 81:32bd7a25a699
- Parent:
- 80:c85cb93713b3
- Child:
- 82:992ba6f31e24
Added user interface for running state.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hazheng | 80:c85cb93713b3 | 1 | #include "StateManager.h" |
hazheng | 80:c85cb93713b3 | 2 | #include "States.h" |
hazheng | 80:c85cb93713b3 | 3 | #include "ArduTouch.h" |
hazheng | 80:c85cb93713b3 | 4 | |
hazheng | 80:c85cb93713b3 | 5 | #ifdef __cplusplus |
hazheng | 80:c85cb93713b3 | 6 | extern "C" { |
hazheng | 80:c85cb93713b3 | 7 | #endif |
hazheng | 80:c85cb93713b3 | 8 | |
hazheng | 80:c85cb93713b3 | 9 | static States* stat_manger_curr_stat = NULL; |
hazheng | 80:c85cb93713b3 | 10 | |
hazheng | 80:c85cb93713b3 | 11 | void state_manager_touch_pos(int16_t x, int16_t y) |
hazheng | 80:c85cb93713b3 | 12 | { |
hazheng | 80:c85cb93713b3 | 13 | stat_manger_curr_stat->TouchPosCallback(x, y); |
hazheng | 80:c85cb93713b3 | 14 | } |
hazheng | 80:c85cb93713b3 | 15 | |
hazheng | 80:c85cb93713b3 | 16 | void state_manager_touch_irq() |
hazheng | 80:c85cb93713b3 | 17 | { |
hazheng | 80:c85cb93713b3 | 18 | stat_manger_curr_stat->TouchIrqCallback(); |
hazheng | 80:c85cb93713b3 | 19 | } |
hazheng | 80:c85cb93713b3 | 20 | |
hazheng | 80:c85cb93713b3 | 21 | void state_manager_set_current_state(States* stat) |
hazheng | 80:c85cb93713b3 | 22 | { |
hazheng | 80:c85cb93713b3 | 23 | state_manager_clear_current_state(); |
hazheng | 80:c85cb93713b3 | 24 | |
hazheng | 80:c85cb93713b3 | 25 | stat_manger_curr_stat = stat; |
hazheng | 80:c85cb93713b3 | 26 | if(stat_manger_curr_stat) |
hazheng | 80:c85cb93713b3 | 27 | { |
hazheng | 80:c85cb93713b3 | 28 | if(stat_manger_curr_stat->HasTouchPosFunction()) |
hazheng | 80:c85cb93713b3 | 29 | { |
hazheng | 80:c85cb93713b3 | 30 | ardu_touch_set_pos_function(&state_manager_touch_pos); |
hazheng | 80:c85cb93713b3 | 31 | } |
hazheng | 80:c85cb93713b3 | 32 | |
hazheng | 80:c85cb93713b3 | 33 | if(stat_manger_curr_stat->HasTouchIrqFunction()) |
hazheng | 80:c85cb93713b3 | 34 | { |
hazheng | 80:c85cb93713b3 | 35 | ardu_touch_set_irq_function(&state_manager_touch_irq); |
hazheng | 80:c85cb93713b3 | 36 | } |
hazheng | 81:32bd7a25a699 | 37 | |
hazheng | 81:32bd7a25a699 | 38 | stat_manger_curr_stat->DrawUserInterface(); |
hazheng | 80:c85cb93713b3 | 39 | } |
hazheng | 80:c85cb93713b3 | 40 | } |
hazheng | 80:c85cb93713b3 | 41 | |
hazheng | 80:c85cb93713b3 | 42 | void state_manager_clear_current_state() |
hazheng | 80:c85cb93713b3 | 43 | { |
hazheng | 80:c85cb93713b3 | 44 | if(stat_manger_curr_stat) |
hazheng | 80:c85cb93713b3 | 45 | { |
hazheng | 80:c85cb93713b3 | 46 | delete stat_manger_curr_stat; |
hazheng | 80:c85cb93713b3 | 47 | stat_manger_curr_stat = NULL; |
hazheng | 80:c85cb93713b3 | 48 | } |
hazheng | 80:c85cb93713b3 | 49 | |
hazheng | 80:c85cb93713b3 | 50 | ardu_touch_set_irq_function(NULL); |
hazheng | 80:c85cb93713b3 | 51 | ardu_touch_set_pos_function(NULL); |
hazheng | 80:c85cb93713b3 | 52 | } |
hazheng | 80:c85cb93713b3 | 53 | |
hazheng | 80:c85cb93713b3 | 54 | void state_manager_update(float deltaTime) |
hazheng | 80:c85cb93713b3 | 55 | { |
hazheng | 80:c85cb93713b3 | 56 | if(stat_manger_curr_stat) |
hazheng | 80:c85cb93713b3 | 57 | { |
hazheng | 80:c85cb93713b3 | 58 | stat_manger_curr_stat->Update(deltaTime); |
hazheng | 80:c85cb93713b3 | 59 | } |
hazheng | 80:c85cb93713b3 | 60 | } |
hazheng | 80:c85cb93713b3 | 61 | |
hazheng | 80:c85cb93713b3 | 62 | #ifdef __cplusplus |
hazheng | 80:c85cb93713b3 | 63 | } |
hazheng | 80:c85cb93713b3 | 64 | #endif |