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 haofan Zheng

Branch:
Drift
Revision:
80:c85cb93713b3
Child:
81:32bd7a25a699
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/StateMachine/StateManager.cpp	Tue Apr 18 19:26:33 2017 +0000
@@ -0,0 +1,62 @@
+#include "StateManager.h"
+#include "States.h"
+#include "ArduTouch.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static States* stat_manger_curr_stat = NULL;
+
+void state_manager_touch_pos(int16_t x, int16_t y)
+{
+    stat_manger_curr_stat->TouchPosCallback(x, y);
+}
+
+void state_manager_touch_irq()
+{
+    stat_manger_curr_stat->TouchIrqCallback();
+}
+
+void state_manager_set_current_state(States* stat)
+{
+    state_manager_clear_current_state();
+    
+    stat_manger_curr_stat = stat;
+    if(stat_manger_curr_stat)
+    {
+        if(stat_manger_curr_stat->HasTouchPosFunction())
+        {
+            ardu_touch_set_pos_function(&state_manager_touch_pos);
+        }
+        
+        if(stat_manger_curr_stat->HasTouchIrqFunction())
+        {
+            ardu_touch_set_irq_function(&state_manager_touch_irq);
+        }
+    }
+}
+
+void state_manager_clear_current_state()
+{
+    if(stat_manger_curr_stat)
+    {
+        delete stat_manger_curr_stat;
+        stat_manger_curr_stat = NULL;
+    }
+    
+    ardu_touch_set_irq_function(NULL);
+    ardu_touch_set_pos_function(NULL);
+}
+
+void state_manager_update(float deltaTime)
+{
+    if(stat_manger_curr_stat)
+    {
+        stat_manger_curr_stat->Update(deltaTime);
+    }
+}
+
+#ifdef __cplusplus
+}
+#endif
\ No newline at end of file