OSDN Git Service

状態遷移に関連するクラスを追加
authorkouichi <kkoba@kirari-kobayashi.(none)>
Mon, 2 Sep 2013 13:57:33 +0000 (22:57 +0900)
committerkouichi <kkoba@kirari-kobayashi.(none)>
Mon, 2 Sep 2013 13:57:33 +0000 (22:57 +0900)
context.cpp [new file with mode: 0644]
context.h [new file with mode: 0644]
exceptionstate.cpp [new file with mode: 0644]
exceptionstate.h [new file with mode: 0644]
runstate.cpp [new file with mode: 0644]
runstate.h [new file with mode: 0644]
systemstate.h [new file with mode: 0644]

diff --git a/context.cpp b/context.cpp
new file mode 100644 (file)
index 0000000..c23de2d
--- /dev/null
@@ -0,0 +1,17 @@
+#include "context.h"\r
+\r
+void ContextStuff::Context::Display(ecrobot::Lcd& lcd)\r
+{\r
+       state_array[current_state]->Display(lcd);\r
+}\r
+\r
+void ContextStuff::Context::CyclicExcute()\r
+{\r
+       state_array[current_state]->CyclicExcute();\r
+}\r
+\r
+void ContextStuff::Context::SetETLineTracer(ETLineTracer* value)\r
+{\r
+    run_state.SetETLineTracer(value);\r
+}\r
+\r
diff --git a/context.h b/context.h
new file mode 100644 (file)
index 0000000..71e1b5a
--- /dev/null
+++ b/context.h
@@ -0,0 +1,28 @@
+#ifndef CONTEXT_H\r
+#define CONTEXT_H\r
+\r
+#include "systemstate.h"\r
+#include "exceptionstate.h"\r
+#include "runstate.h"\r
+\r
+class ETLineTracer;\r
+namespace ContextStuff{\r
+       class Context\r
+       {\r
+               int current_state;\r
+               SystemStateStuff::ExceptionState exception_state;\r
+               SystemStateStuff::RunState run_state;\r
+               SystemStateStuff::SystemState* state_array[2];\r
+       public:\r
+               enum{EXCEPTION_STATE,RUN_STATE};\r
+               Context():current_state(RUN_STATE),exception_state(),run_state()\r
+                       {state_array[EXCEPTION_STATE] = &exception_state;state_array[RUN_STATE] = &run_state;}\r
+               ~Context(){;}\r
+               void ChangeState(const int value){current_state = value;}\r
+               void CyclicExcute();\r
+               void Display(ecrobot::Lcd& lcd);\r
+        void SetETLineTracer(ETLineTracer* value);\r
+       };\r
+};\r
+\r
+#endif /* CONTEXT_H */\r
diff --git a/exceptionstate.cpp b/exceptionstate.cpp
new file mode 100644 (file)
index 0000000..c99c939
--- /dev/null
@@ -0,0 +1,10 @@
+#include "exceptionstate.h"\r
+#include "context.h"\r
+#include "kernel.h"\r
+#include "kernel_id.h"\r
+#include "ecrobot_interface.h"\r
+\r
+using namespace SystemStateStuff;\r
+void ExceptionState::Display(ecrobot::Lcd& lcd)\r
+{\r
+}\r
diff --git a/exceptionstate.h b/exceptionstate.h
new file mode 100644 (file)
index 0000000..5abeed4
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef ExceptionSTATE_H\r
+#define ExceptionSTATE_H\r
+\r
+#include "systemstate.h"\r
+\r
+namespace SystemStateStuff{\r
+       class ExceptionState : public SystemState{\r
+       public:\r
+               ExceptionState(){;}\r
+               ~ExceptionState(){;}\r
+               void CyclicExcute(){;}\r
+               void Display(ecrobot::Lcd& lcd);\r
+       };\r
+};\r
+#endif /* ExceptionSTATE_H */\r
diff --git a/runstate.cpp b/runstate.cpp
new file mode 100644 (file)
index 0000000..27807b4
--- /dev/null
@@ -0,0 +1,20 @@
+#include "runstate.h"\r
+#include "tsprintf.h"\r
+#include "Lcd.h"\r
+\r
+\r
+using namespace SystemStateStuff;\r
+void RunState::Display(ecrobot::Lcd& lcd)\r
+{\r
+       static int cnt = 0;\r
+       char str[16+1];\r
+       lcd.clear();\r
+       tsprintf(str,"cnt = %d",cnt++); // tsprintf 使用例\r
+       lcd.putf("s",str);\r
+       lcd.disp();\r
+}\r
+\r
+void RunState::CyclicExcute()\r
+{\r
+       m_tracer->RunTrace(100);\r
+}\r
diff --git a/runstate.h b/runstate.h
new file mode 100644 (file)
index 0000000..cca8abe
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef RUNSTATE_H\r
+#define RUNSTATE_H\r
+#include "systemstate.h"\r
+#include "ETLineTracer.h"\r
+\r
+namespace SystemStateStuff{\r
+       class RunState : public SystemState{\r
+        ETLineTracer* m_tracer;\r
+       public:\r
+               RunState() : m_tracer(0){;}\r
+               ~RunState(){;}\r
+               void CyclicExcute();\r
+               void Display(ecrobot::Lcd& lcd);\r
+        void SetETLineTracer(ETLineTracer* value){m_tracer = value;}\r
+       };\r
+};\r
+#endif /* RUNSTATE_H */\r
+\r
diff --git a/systemstate.h b/systemstate.h
new file mode 100644 (file)
index 0000000..ed0c3be
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef SYSTEMSTATE_H\r
+#define SYSTEMSTATE_H\r
+\r
+namespace ecrobot{\r
+       class Lcd;\r
+};\r
+\r
+namespace SystemStateStuff{\r
+\r
+       class SystemState{\r
+       public:\r
+               SystemState(){;}\r
+               virtual ~SystemState(){;}\r
+               virtual void Display(ecrobot::Lcd& lcd) = 0;\r
+               virtual void CyclicExcute() = 0;\r
+       };\r
+};\r
+\r
+#endif /* SYSTEMSTATE_H */\r