diff --git a/arduino_proto_threads/tp_dragon/dragon.dot b/arduino_proto_threads/tp_dragon/dragon.dot new file mode 100644 index 0000000..930c4c0 --- /dev/null +++ b/arduino_proto_threads/tp_dragon/dragon.dot @@ -0,0 +1,71 @@ +digraph finite_state_machine { +overlap=false +fontname="Arial" +fontsize=50; +label="\nÉtats pour l'animation du dragon." +rankdir=LR; // bgcolor="#C6CFD532"; // transparent +edge[style="filled,setlinewidth(4)",fontsize=30]; +node[style="setlinewidth(4)",color="#000000",fontsize=30]; +pad=0.2 // margins / clusters +nodesep=1.2 +ranksep=2.2 +//center=true + +subgraph clusterInternal { + fontsize=40; + label="\nVue interne du sous ensemble { Attente - Animations }\n\n" + style=filled color = "#FFC0A0" +// margin=10 # in points + TMD [label="\nMode Dégradé\n?",fillcolor="#DDDDDD",shape=diamond,style=filled] + ABP [label="Attente\nde l'appui\nbouton\n",fillcolor="#A0FFFF",shape=circle,style=filled] + node [shape=circle,style=filled]; + R1 [label="Attente\nfin\nanimation",fillcolor="red:#FD4030",style=radial] // lightred + J1 [label="Attente\nfin\nanimation",fillcolor="#FFF030"] ; // lightyellow + B1 [label="Attente\nfin\nanimation",fillcolor="#70A0FF"] ; // lightblue + VMN [label="Affiche\nluminosité\ncourante",fillcolor="#80ff80:green"]; + VMD [label="Clignote\nà\n1 Hertz",fillcolor="#80ff80:black",style=radial]; + FB [style=invis] + { rank = min ABP VMD } + { rank = max J1 } + { rank = same B1 VMN } + { rank = same R1 FB TMD } + +// n e s w for top right bottom left + ABP -> TMD:n [label="Vérification du mode"]; // n for nord (top), + ABP -> R1 [label="Animation Led Rouge"]; + TMD:w -> VMD [label="Active clignotement Led Verte",taillabel="Oui"]; + TMD:ne -> B1 [label="Animation Led Bleue",taillabel="Non"]; + TMD:e -> J1 [label="Animation Led Jaune",taillabel="Non"]; + TMD:se -> VMN [label="Baisse luminosité Led Verte",taillabel="Non"]; +// TMD:nw -> ABP [label="Mode dégradé",decorate=true,taillabel="Oui"]; + + R1 -> ABP [label = "Fin animation"]; + J1 -> ABP [label = "Fin animation"]; + B1 -> ABP [label = "Fin animation"]; +// R1 -> J1 [style=invis] //,constraint=false] +B1 -> J1 [style=invis] //,constraint=false] + +// TMD:s -> FB // [style=invis] //,constraint=false] +} // clusterD + +subgraph clusterGlobal { + fontsize=40; label="\nVue synthétique\n\n" style=filled color = "#A0FFFF" + node [shape = doublecircle, style = filled, fillcolor="#000000"]; On Off ; +# node [shape = doublecircle, style = filled, fillcolor="#E890F0"]; On Off ; + node [shape = circle, style = filled, fillcolor="#FFC0A0"]; Wait Show ; + Off [label="\nOff\n\n",fontname="Arial",fontsize="30",fillcolor="#E890F0"] + // On [label="\nOn\n\n",fontname="Arial",fontsize="30"] + { rank = min On } + { rank = max Off } + + Wait [ label = "Attente\nd'un appui\nbouton\nCycle=Faux" ]; + Show [ label = "Attente\nfin des\nanimations\nCycle=vrai" ]; + On -> Wait [ label = "Mise\nsous\ntension"]; + Wait -> Show [ label = "Animation"]; + Show -> Wait [ label = "Fin animation"]; + Show -> Off [ label = "Mise\nhors\ntension"]; + Show -> Wait [ label = "Ré-initialisation"]; + Wait -> Wait [ label = "Ré-initialisation"]; + Wait -> Off [ label = "Mise\nhors\ntension"]; + } // clusterGlobal +} //finite_state_machine diff --git a/arduino_proto_threads/tp_dragon/dragon.svg b/arduino_proto_threads/tp_dragon/dragon.svg new file mode 100644 index 0000000..72a6e45 --- /dev/null +++ b/arduino_proto_threads/tp_dragon/dragon.svg @@ -0,0 +1,253 @@ + + + + + + +finite_state_machine + +États pour l'animation du dragon. + +clusterInternal + +Vue interne du sous ensemble { Attente - Animations } + + +clusterGlobal + +Vue synthétique + + + +TMD + +Mode Dégradé +? + + + +J1 + +Attente +fin +animation + + + +TMD:e->J1 + + +Animation Led Jaune +Non + + + +B1 + +Attente +fin +animation + + + +TMD:ne->B1 + + +Animation Led Bleue +Non + + + +VMN + + + + + + + +Affiche +luminosité +courante + + + +TMD:se->VMN + + +Baisse luminosité Led Verte +Non + + + +VMD + + + + + + + +Clignote +à +1 Hertz + + + +TMD:w->VMD + + +Active clignotement Led Verte +Oui + + + +ABP + +Attente +de l'appui +bouton + + + +ABP->TMD:n + + +Vérification du mode + + + +R1 + + + + + + + +Attente +fin +animation + + + +ABP->R1 + + +Animation Led Rouge + + + +R1->ABP + + +Fin animation + + + +J1->ABP + + +Fin animation + + + +B1->ABP + + +Fin animation + + + + + +On + + +On + + + +Wait + +Attente +d'un appui +bouton +Cycle=Faux + + + +On->Wait + + +Mise +sous +tension + + + +Off + + +Off + + + +Wait->Off + + +Mise +hors +tension + + + +Wait->Wait + + +Ré-initialisation + + + +Show + +Attente +fin des +animations +Cycle=vrai + + + +Wait->Show + + +Animation + + + +Show->Off + + +Mise +hors +tension + + + +Show->Wait + + +Fin animation + + + +Show->Wait + + +Ré-initialisation + + + diff --git a/arduino_proto_threads/tp_dragon/dragon_etats.dot b/arduino_proto_threads/tp_dragon/dragon_etats.dot new file mode 100644 index 0000000..71864b8 --- /dev/null +++ b/arduino_proto_threads/tp_dragon/dragon_etats.dot @@ -0,0 +1,68 @@ +digraph finite_state_machine { +overlap=false +fontname="Arial" +fontsize=50; +label="\nÉtats pour l'animation du dragon." +rankdir=LR; // bgcolor="#C6CFD532"; // transparent +edge[style="filled,setlinewidth(4)",fontsize=30]; +node[style="setlinewidth(4)",color="#000000",fontsize=30]; +pad=0.2 // margins / clusters //center=true +nodesep=1.2 +ranksep=2.2 + +subgraph clusterInternal { + fontsize=40; + label="\nVue interne du sous ensemble { Attente - Animations }\n\n" + style=filled color = "#FFC0A0" +// margin=10 # in points + TMD [label="\nMode Dégradé\n?",fillcolor="#DDDDDD",shape=diamond,style=filled] + ABP [label="Attente\nde l'appui\nbouton\n",fillcolor="#A0FFFF",shape=circle,style=filled] + node [shape=circle,style=filled]; + R1 [label="Attente\nfin\nanimation",fillcolor="red:#FD4030",style=radial] // lightred + J1 [label="Attente\nfin\nanimation",fillcolor="#FFF030"] ; // lightyellow + B1 [label="Attente\nfin\nanimation",fillcolor="#70A0FF"] ; // lightblue + VMN [label="Affiche\nluminosité\ncourante",fillcolor="#80ff80:green"]; + VMD [label="Clignote\nà\n1 Hertz",fillcolor="#80ff80:black",style=radial]; + FB [style=invis] + { rank = min ABP VMD } + { rank = max J1 } + { rank = same B1 VMN } + { rank = same R1 FB TMD } + +// n e s w for top right bottom left + ABP -> TMD:n [label="Vérification du mode"]; // n for nord (top), + ABP -> R1 [label="Animation Led Rouge"]; + TMD:w -> VMD [label="Active clignotement Led Verte",taillabel="Oui"]; + TMD:ne -> B1 [label="Animation Led Bleue",taillabel="Non"]; + TMD:e -> J1 [label="Animation Led Jaune",taillabel="Non"]; + TMD:se -> VMN [label="Baisse luminosité Led Verte",taillabel="Non"]; +// TMD:nw -> ABP [label="Mode dégradé",decorate=true,taillabel="Oui"]; + + R1 -> ABP [label = "Fin animation"]; + J1 -> ABP [label = "Fin animation"]; + B1 -> ABP [label = "Fin animation"]; +// R1 -> J1 [style=invis] //,constraint=false] +B1 -> J1 [style=invis] //,constraint=false] + +// TMD:s -> FB // [style=invis] //,constraint=false] +} // clusterD + +subgraph clusterGlobal { + fontsize=40; label="\nVue synthétique\n\n" style=filled color = "#A0FFFF" + Off [shape = doublecircle, style = filled, fillcolor="#000000"] +// On [shape = circle, style = filled, fillcolor="#000000"] + node [shape = circle, style = filled, fillcolor="#FFC0A0"]; Wait Show ; + { rank = min On } + { rank = max Off } + + Wait [ label = "Attente\nd'un appui\nbouton\nCycle=Faux" ]; + Show [ label = "Attente\nfin des\nanimations\nCycle=vrai" ]; +// On -> Wait [ label = "Mise\nsous\ntension"]; + Wait -> Show [ label = "Animation"]; + Show -> Wait [ label = "Fin animation"]; + Show -> Off [ label = "Mise\nhors\ntension"]; + Show -> Wait [ label = "Ré-initialisation"]; + Wait -> Wait [ label = "Ré-initialisation"]; + Wait -> Off [ label = "Mise\nhors\ntension"]; + } // clusterGlobal +} //finite_state_machine diff --git a/arduino_proto_threads/tp_dragon/pt.h b/arduino_proto_threads/tp_dragon/pt.h new file mode 100644 index 0000000..ef90636 --- /dev/null +++ b/arduino_proto_threads/tp_dragon/pt.h @@ -0,0 +1,76 @@ +#ifndef __PT_H__ +#define __PT_H__ + +typedef unsigned short lc_t; +#define LC_INIT(s) s = 0; // LC_INIT +#define LC_RESUME(s) switch(s) { case 0: // LC_RESUME +#define LC_SET(s) s = __LINE__; case __LINE__: // LC_SET line +#define LC_END(s) } // LC_END + +struct pt { lc_t lc; }; + +#define PT_WAITING 0 +#define PT_YIELDED 1 +#define PT_EXITED 2 +#define PT_ENDED 3 +#define PT_INIT(pt) LC_INIT((pt)->lc) // INIT +#define PT_THREAD(name_args) char name_args // THREAD +#define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc) // BEGIN +#define PT_END(pt) LC_END((pt)->lc); \ + PT_YIELD_FLAG = 0; \ + PT_INIT(pt); return PT_ENDED; } // END +#define PT_WAIT_UNTIL(pt, condition) \ + do { \ + LC_SET((pt)->lc); \ + if(!(condition)) { \ + return PT_WAITING; \ + } \ + } while(0) // WAIT_UNTIL +#define PT_WAIT_WHILE(pt, cond) \ + PT_WAIT_UNTIL((pt), !(cond)) // WAIT_WHILE +#define PT_WAIT_THREAD(pt, thread) \ + PT_WAIT_WHILE((pt), PT_SCHEDULE(thread)) // WAIT_THREAD +#define PT_SPAWN(pt, child, thread) \ + do { \ + PT_INIT((child)); \ + PT_WAIT_THREAD((pt), (thread)); \ + } while(0) // SPAWN +#define PT_RESTART(pt) \ + do { \ + PT_INIT(pt); \ + return PT_WAITING; \ + } while(0) // RESTART +#define PT_EXIT(pt) \ + do { \ + PT_INIT(pt); \ + return PT_EXITED; \ + } while(0) // EXIT +#define PT_SCHEDULE(f) ((f) < PT_EXITED) // SCHEDULE +#define PT_YIELD(pt) \ + do { \ + PT_YIELD_FLAG = 0; \ + LC_SET((pt)->lc); \ + if(PT_YIELD_FLAG == 0) { \ + return PT_YIELDED; \ + } \ + } while(0) // YIELD +#define PT_YIELD_UNTIL(pt, cond) \ + do { \ + PT_YIELD_FLAG = 0; \ + LC_SET((pt)->lc); \ + if((PT_YIELD_FLAG == 0) || !(cond)) { \ + return PT_YIELDED; \ + } \ + } while(0) // YIELD_UNTIL +// checked for n calls in a thread : seems OK +#define PT_DELAY(pt, ms) \ + do { \ + static unsigned long _PTTTL_ ; \ + _PTTTL_ = millis() + (unsigned int)(ms); \ + PT_WAIT_UNTIL((pt), (millis() > _PTTTL_)); \ + } while(0) // DELAY +#define PT_SYNC(pt, mark, ms) \ + do { \ + PT_WAIT_UNTIL((pt), (millis() - (mark) > (ms) )); \ + } while(0) // SYNC +#endif /* __PT_H__ */