Initial commit for stepper controller
[radiotelescope.git] / stepper_controller / arduino / stepper / qm_code / ui.c
1 /*****************************************************************************
2 * Model: C:/Documents and Settings/Harry McNally/My Documents/project/arduino/stepper/arduino/stepper/stepper.qm
3 * File:  ./qm_code/ui.c
4 *
5 * This file has been generated automatically by QP Modeler (QM).
6 * DO NOT EDIT THIS FILE MANUALLY.
7 *
8 * Please visit www.state-machine.com/qm for more information.
9 *****************************************************************************/
10 //
11 // Product: Radiotelescope - Stepper Motor Controller
12 // Version: 0.1
13 // Date:    25 November 2010
14 //
15 //                      +-----------------------+
16 //                      |   d e c i s i o n s   |
17 //                      +-----------------------|
18 //                      | a n d   d e s i g n s |
19 //                      +-----------------------+
20 //
21 // Copyright (C) 2009 Decisions and Designs Pty Ltd. All rights reserved.
22 //
23 // This software may be distributed and modified under the terms of the GNU
24 // General Public License version 2 (GPL) as published by the Free Software
25 // Foundation and appearing in the file GPL.TXT included in the packaging of
26 // this file. Please note that GPL Section 2[b] requires that all works based
27 // on this software must also be made publicly available under the terms of
28 // the GPL ("Copyleft").
29 //
30 // Contact information:
31 // Decisions and Designs Web site: http://www.decisions-and-designs.com.au
32 // e-mail:                         [email protected]
33 //
34
35 #include "radiotelescope.h"
36 #include "signals.h"
37 #include "serial_command.h"
38 #include "ui.h"
39
40 extern Menu menu[];
41 extern MenuSignal menuSignal[];
42
43 #define UI_TX_BUFFER_LENGTH 80
44
45 /* encapsulated delcaration of the UI active object ------------------------*/ 
46 /* $(AOs::UI) ..............................................................*/
47 typedef struct UITag {
48 /* protected: */
49     QActive super;
50
51 /* private: */
52     SerialCommand serialCommand;
53     char txBuffer[UI_TX_BUFFER_LENGTH];
54 } UI;
55
56 /* public: */
57 void UI_ctor(void);
58
59 /* protected: */
60 QState UI_initial(UI *me);
61 QState UI_User(UI *me);
62
63
64 /* global objects ----------------------------------------------------------*/
65 UI AO_UI;
66
67 /* Active object definition ------------------------------------------------*/
68 /* $(AOs::UI) ..............................................................*/
69 /* $(AOs::UI::ctor) ........................................................*/
70 void UI_ctor(void) {
71     QActive_ctor((QActive *)&AO_UI, (QStateHandler)&UI_initial);
72     SerialCommand_ctor(&AO_UI.serialCommand, (QActive *)&AO_UI, menu, menuSignal, AO_UI.txBuffer, UI_TX_BUFFER_LENGTH, 0, 9600);
73     
74 }
75 /* $(AOs::UI::Statechart) ..................................................*/
76 /* @(/2/1/3/0) */
77 QState UI_initial(UI *me) {\r
78         SerialCommand_init(&AO_UI.serialCommand);
79     return Q_TRAN(&UI_User);
80 }
81 /* $(AOs::UI::Statechart::User) ............................................*/
82 QState UI_User(UI *me) {
83     switch (Q_SIG(me)) {
84         /* @(/2/1/3/1/0) */
85         case SERIAL_RX_DATA_SIG: {
86             serialDispatch(&me->serialCommand, SERIAL_RX_DATA_SIG, Q_PAR(me));
87             return Q_HANDLED();
88         }
89         /* @(/2/1/3/1/1) */
90         case SERIAL_TX_EMPTY_SIG: {
91             serialDispatch(&me->serialCommand, SERIAL_TX_EMPTY_SIG, Q_PAR(me));
92             return Q_HANDLED();
93         }
94         /* @(/2/1/3/1/2) */
95         case COMMAND_FAIL_SIG: {
96             serialNACK(&me->serialCommand, 0);
97             return Q_HANDLED();
98         }
99         /* @(/2/1/3/1/3) */
100         case COMMAND_AZIMUTH_SIG: {
101             QActive_post((QActive *)&AO_azimuth, SET_BASE_SPEED_SIG, Q_PAR(me));
102             QActive_post((QActive *)&AO_azimuth, SET_ACCELERATION_SIG,
103             me->serialCommand.vargs[1].v.param);
104             QActive_post((QActive *)&AO_azimuth, SET_SLEW_SPEED_SIG,
105             me->serialCommand.vargs[2].v.param);
106             QActive_post((QActive *)&AO_azimuth, SET_TOTAL_STEPS_SIG,
107             me->serialCommand.vargs[3].v.param);
108             serialReleaseVargs(&me->serialCommand);
109             serialACK(&me->serialCommand, 1);
110             return Q_HANDLED();
111         }
112         /* @(/2/1/3/1/4) */
113         case COMMAND_AZIMUTH_BASE_SIG: {
114             QActive_post((QActive *)&AO_azimuth, SET_BASE_SPEED_SIG, Q_PAR(me));
115             serialACK(&me->serialCommand, 1);
116             return Q_HANDLED();
117         }
118         /* @(/2/1/3/1/5) */
119         case COMMAND_AZIMUTH_SLEW_SIG: {
120             QActive_post((QActive *)&AO_azimuth, SET_SLEW_SPEED_SIG, Q_PAR(me));
121             serialACK(&me->serialCommand, 1);
122             return Q_HANDLED();
123         }
124         /* @(/2/1/3/1/6) */
125         case COMMAND_AZIMUTH_ACCELERATION_SIG: {
126             QActive_post((QActive *)&AO_azimuth, SET_ACCELERATION_SIG, Q_PAR(me));
127             serialACK(&me->serialCommand, 1);
128             return Q_HANDLED();
129         }
130         /* @(/2/1/3/1/7) */
131         case COMMAND_AZIMUTH_STEPS_SIG: {
132             QActive_post((QActive *)&AO_azimuth, SET_TOTAL_STEPS_SIG, Q_PAR(me));
133             serialACK(&me->serialCommand, 1);
134             return Q_HANDLED();
135         }
136         /* @(/2/1/3/1/8) */
137         case COMMAND_ELEVATION_SIG: {
138             QActive_post((QActive *)&AO_elevation, SET_BASE_SPEED_SIG, Q_PAR(me));
139             QActive_post((QActive *)&AO_elevation, SET_ACCELERATION_SIG,
140             me->serialCommand.vargs[1].v.param);
141             QActive_post((QActive *)&AO_elevation, SET_SLEW_SPEED_SIG,
142             me->serialCommand.vargs[2].v.param);
143             QActive_post((QActive *)&AO_elevation, SET_TOTAL_STEPS_SIG,
144             me->serialCommand.vargs[3].v.param);
145             serialReleaseVargs(&me->serialCommand);
146             serialACK(&me->serialCommand, 1);
147             return Q_HANDLED();
148         }
149         /* @(/2/1/3/1/9) */
150         case COMMAND_ELEVATION_BASE_SIG: {
151             QActive_post((QActive *)&AO_elevation, SET_BASE_SPEED_SIG, Q_PAR(me));
152             serialACK(&me->serialCommand, 1);
153             return Q_HANDLED();
154         }
155         /* @(/2/1/3/1/10) */
156         case COMMAND_ELEVATION_SLEW_SIG: {
157             QActive_post((QActive *)&AO_elevation, SET_SLEW_SPEED_SIG, Q_PAR(me));
158             serialACK(&me->serialCommand, 1);
159             return Q_HANDLED();
160         }
161         /* @(/2/1/3/1/11) */
162         case COMMAND_ELEVATION_ACCELERATION_SIG: {
163             QActive_post((QActive *)&AO_elevation, SET_ACCELERATION_SIG, Q_PAR(me));
164             serialACK(&me->serialCommand, 1);
165             return Q_HANDLED();
166         }
167         /* @(/2/1/3/1/12) */
168         case COMMAND_ELEVATION_STEPS_SIG: {
169             QActive_post((QActive *)&AO_elevation, SET_TOTAL_STEPS_SIG, Q_PAR(me));
170             serialACK(&me->serialCommand, 1);
171             return Q_HANDLED();
172         }
173         /* @(/2/1/3/1/13) */
174         case SERIAL_RX_ERROR_SIG: {
175             serialDispatch(&me->serialCommand, SERIAL_RX_ERROR_SIG, Q_PAR(me));
176             return Q_HANDLED();
177         }
178         /* @(/2/1/3/1/14) */
179         case SERIAL_TX_COMPLETE_SIG: {
180             serialDispatch(&me->serialCommand, SERIAL_TX_COMPLETE_SIG, Q_PAR(me));
181             return Q_HANDLED();
182         }
183         /* @(/2/1/3/1/15) */
184         case COMMAND_START_AZIMUTH_SIG: {
185             QActive_post((QActive *)&AO_azimuth, START_LINEAR_SLEW_SIG, 0);
186             serialACK(&me->serialCommand, 1);
187             return Q_HANDLED();
188         }
189         /* @(/2/1/3/1/16) */
190         case COMMAND_START_ELEVATION_SIG: {
191             QActive_post((QActive *)&AO_elevation, START_LINEAR_SLEW_SIG, 0);
192             serialACK(&me->serialCommand, 1);
193             return Q_HANDLED();
194         }
195         /* @(/2/1/3/1/17) */
196         case COMMAND_START_AZ_EL_SIG: {
197             QActive_post((QActive *)&AO_azimuth, START_LINEAR_SLEW_SIG, 0);
198             QActive_post((QActive *)&AO_elevation, START_LINEAR_SLEW_SIG, 0);
199             serialACK(&me->serialCommand, 1);
200             return Q_HANDLED();
201         }
202         /* @(/2/1/3/1/18) */
203         case COMMAND_AZIMUTH_CLOCKWISE_SIG: {
204             QActive_post((QActive *)&AO_azimuth, SET_DIRECTION_UP_CW_SIG, 0);
205             serialACK(&me->serialCommand, 1);
206             return Q_HANDLED();
207         }
208         /* @(/2/1/3/1/19) */
209         case COMMAND_AZIMUTH_CCW_SIG: {
210             QActive_post((QActive *)&AO_azimuth, SET_DIRECTION_DOWN_CCW_SIG, 0);
211             serialACK(&me->serialCommand, 1);
212             return Q_HANDLED();
213         }
214         /* @(/2/1/3/1/20) */
215         case COMMAND_ELEVATION_UP_SIG: {
216             QActive_post((QActive *)&AO_elevation, SET_DIRECTION_UP_CW_SIG, 0);
217             serialACK(&me->serialCommand, 1);
218             return Q_HANDLED();
219         }
220         /* @(/2/1/3/1/21) */
221         case COMMAND_ELEVATION_DOWN_SIG: {
222             QActive_post((QActive *)&AO_elevation, SET_DIRECTION_DOWN_CCW_SIG, 0);
223             serialACK(&me->serialCommand, 1);
224             return Q_HANDLED();
225         }
226     }
227     return Q_SUPER(&QHsm_top);
228 }

UCC git Repository :: git.ucc.asn.au