summaryrefslogtreecommitdiffstats
path: root/test/src/test-c-inline.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/test-c-inline.c')
-rw-r--r--test/src/test-c-inline.c201
1 files changed, 166 insertions, 35 deletions
diff --git a/test/src/test-c-inline.c b/test/src/test-c-inline.c
index 659fcdf..7b375a9 100644
--- a/test/src/test-c-inline.c
+++ b/test/src/test-c-inline.c
@@ -1,60 +1,191 @@
-#include <stdlib.h> // EXIT_SUCCESS
-#include <stdio.h> // printf
+//#include <stdlib.h> // EXIT_SUCCESS
+//#include <stdio.h> // printf
#include <string.h> // memset
+#undef ON_AVR
+
/**
* Preprocess:
- * uscxml-transform -tc -i ./test-c-inline.c -o ./test-c-inline.c.scxml.c
+ * uscxml-transform -tc -i ./gadget-inline-avr.c -o ./gadget-inline-avr.c.scxml.c
*/
/** INLINE SCXML BEGIN
-<scxml name="test-inline" datamodel="native">
- <state id="foo">
- <transition target="done" cond="UD->foo == 3" />
- <onentry>
- enteredFoo();
- </onentry>
- </state>
- <final id="done">
- <onentry>
- enteredDone();
- </onentry>
- </final>
+
+<scxml>
+ <parallel>
+ <onentry>
+ <raise event="blueHigh" />
+ </onentry>
+ <!--
+ 1 X X X X
+ ^ ^^^ ^^^
+ | | |
+ | | Action
+ | Color
+ Here comes the signal!
+
+ Colors:
+ blue 1,1
+ red 1,0
+ green 0,1
+ ESC! 0,0
+
+ Actions:
+ dimUp: 0,1
+ dimDown: 0,0
+ turnOn: 1,1
+ turnDown: 1,0
+
+ ESC!:
+ 0,0 All off
+ 1,1 All on
+
+ IR emitter is either Color + Action or Special
+ -->
+ <state id="interaction">
+ <transition event="blueHigh">
+ <!-- Receiver beware, here it comes -->
+ <raise event="IROn" />
+
+ <!-- color blue -->
+ <raise event="IROn" />
+ <raise event="IROn" />
+
+ <!-- action dimUp -->
+ <raise event="IROff" />
+ <raise event="IROn" />
+
+ <!-- make sure to turn LED off -->
+ <raise event="IROff" />
+
+ </transition>
+ </state>
+
+ <state id="periphery">
+ <transition event="IROn" target="IRLedOn" type="internal" />
+ <transition event="IROff" target="IRLedOff" type="internal" />
+
+ <!-- These are the lines we will connect to the IR emitter -->
+ <state id="IRLedOff">
+ <onentry>ledOff();</onentry>
+ </state>
+ <state id="IRLedOn">
+ <onentry>ledOn();</onentry>
+ </state>
+ </state>
+ </parallel>
</scxml>
INLINE SCXML END */
-/**
- * These function can be called from within executable content
- */
-void enteredFoo() {
- printf("Entered Foo!\n");
-}
+#define IQ_LENGTH 10
+#define EQ_LENGTH 10
+
+const char* iQ[IQ_LENGTH];
+size_t iwPtr = 0;
+size_t irPtr = 0;
+
+const char* eQ[EQ_LENGTH];
+size_t ewPtr = 0;
+size_t erPtr = 0;
+
-void enteredDone() {
- printf("Entered Done!\n");
+void ledOn() {
+ printf("Turned on LED!\n");
}
-struct userData {
- int foo;
-};
+void ledOff() {
+ printf("Turned off LED!\n");
+}
-#define UD ((struct userData*)ctx->user_data)
#include "test-c-inline.c.scxml.c"
+void* dequeue_internal(const uscxml_ctx* ctx) {
+ if (iwPtr != irPtr) {
+ size_t tmp = irPtr;
+ irPtr = (irPtr + 1 >= IQ_LENGTH ? 0 : irPtr + 1);
+ return iQ[tmp];
+ }
+ return NULL;
+}
+
+void* dequeue_external(const uscxml_ctx* ctx) {
+ if (ewPtr != erPtr) {
+ size_t tmp = erPtr;
+ irPtr = (erPtr + 1 >= EQ_LENGTH ? 0 : erPtr + 1);
+ return eQ[tmp];
+ }
+ return NULL;
+}
+
+int is_matched(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event) {
+ char* tPtr1 = (char*)event;
+ char* tPtr2 = (char*)transition->event;
+ while(*tPtr1 && *tPtr2) {
+ if (tPtr1 != tPtr2)
+ return 0;
+ tPtr1++;
+ tPtr2++;
+ }
+ return 1;
+}
+
+int raise(const uscxml_ctx* ctx, const char* event) {
+ iQ[iwPtr] = event;
+ iwPtr = (iwPtr + 1 >= IQ_LENGTH ? 0 : iwPtr + 1);
+ return USCXML_ERR_OK;
+}
+
+int send(const uscxml_ctx* ctx, const char* event) {
+ eQ[ewPtr] = event;
+ ewPtr = (ewPtr + 1 >= IQ_LENGTH ? 0 : ewPtr + 1);
+ return USCXML_ERR_OK;
+}
int main(int argc, char** argv) {
- struct userData ud;
- uscxml_ctx ctx;
- int err = USCXML_ERR_OK;
+
+#ifdef ON_AVR
+ int ir_led = 9;
+ int blue_touch = 1;
+ int red_touch = 2;
+ int yellow_touch = 3;
+ pinMode(ir_led, OUTPUT);
+ pinMode(blue_touch, INPUT);
+ pinMode(red_touch, INPUT);
+ pinMode(yellow_touch, INPUT);
+
+#endif
+
+
+ uscxml_ctx ctx;
+ int err = USCXML_ERR_OK;
+
memset(&ctx, 0, sizeof(uscxml_ctx));
- ctx.machine = &USCXML_MACHINE_TEST_INLINE;
- ctx.user_data = &ud;
- ud.foo = 3;
+ ctx.machine = &USCXML_MACHINE;
+
+ ctx.exec_content_raise = raise;
+ ctx.dequeue_internal = dequeue_internal;
+ ctx.dequeue_external = dequeue_external;
+ ctx.is_matched = is_matched;
while(err != USCXML_ERR_DONE) {
+
err = uscxml_step(&ctx);
+#ifdef ON_AVR
+ if (err == USCXML_IDLE) {
+ if (digitalRead(blue) == HIGH) {
+ send(ctx, "blueHigh");
+ }
+ if (digitalRead(blue) == HIGH) {
+ send(ctx, "redHigh");
+ }
+ if (digitalRead(blue) == HIGH) {
+ send(ctx, "greenHigh");
+ }
+ }
+ delay(20);
+#endif
}
- return EXIT_SUCCESS;
-} \ No newline at end of file
+ return 0;
+}