Rev 7 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7 | Rev 335 | ||
---|---|---|---|
1 | #include <stdio.h> |
1 | #include <stdio.h> |
2 | #include <string.h> |
2 | #include <string.h> |
3 | #include <unistd.h> |
3 | #include <unistd.h> |
4 | #include "libusmc.h" |
4 | #include "libusmc.h" |
5 | 5 | ||
6 | 6 | ||
7 | #define MENU_EXIT 0 |
7 | #define MENU_EXIT 0 |
8 | #define MENU_ERROR 1 |
8 | #define MENU_ERROR 1 |
9 | #define MENU_CONTINUE 2 |
9 | #define MENU_CONTINUE 2 |
10 | 10 | ||
11 | USMC_Devices devices; |
11 | USMC_Devices devices; |
12 | DWORD cur_dev; |
12 | DWORD cur_dev; |
13 | 13 | ||
14 | char str [105] = { 100 }; |
14 | char str [105] = { 100 }; |
15 | 15 | ||
16 | // Function that prints information about connected devices to console |
16 | // Function that prints information about connected devices to console |
17 | void print_devices ( USMC_Devices devices ) |
17 | void print_devices ( USMC_Devices devices ) |
18 | { |
18 | { |
19 | DWORD i; |
19 | DWORD i; |
20 | 20 | ||
21 | for ( i = 0 ; i < devices.NOD ; i++ ) |
21 | for ( i = 0 ; i < devices.NOD ; i++ ) |
22 | printf ( "Device# %d,\tSerial Number - %.16s,\tVersion - %.4s\n", i + 1, devices.Serial [i], devices.Version [i] ); |
22 | printf ( "Device# %d,\tSerial Number - %.16s,\tVersion - %.4s\n", i + 1, devices.Serial [i], devices.Version [i] ); |
23 | } |
23 | } |
24 | 24 | ||
25 | // Function that prints information about device state to console |
25 | // Function that prints information about device state to console |
26 | void print_state ( USMC_State state ) |
26 | void print_state ( USMC_State state ) |
27 | { |
27 | { |
28 | printf ( "The state is:\n" ); |
28 | printf ( "The state is:\n" ); |
29 | printf ( "- Current Position in microsteps - %d\n", state.CurPos ); |
29 | printf ( "- Current Position in microsteps - %d\n", state.CurPos ); |
30 | printf ( "- Temperature - %.2f\xf8\x43\n", state.Temp ); |
30 | printf ( "- Temperature - %.2f\xf8\x43\n", state.Temp ); |
31 | printf ( "- Step Divisor - %d\n", state.SDivisor ); |
31 | printf ( "- Step Divisor - %d\n", state.SDivisor ); |
32 | printf ( "- Loft state - %s\n", state.Loft?"Indefinite" : "Fixed" ); |
32 | printf ( "- Loft state - %s\n", state.Loft?"Indefinite" : "Fixed" ); |
33 | printf ( "- Power - %s\n", state.Power ? ( state.FullPower ? "Full" : "Half" ) : "Off" ); |
33 | printf ( "- Power - %s\n", state.Power ? ( state.FullPower ? "Full" : "Half" ) : "Off" ); |
34 | 34 | ||
35 | if ( state.RUN ) |
35 | if ( state.RUN ) |
36 | printf ( "- Step Motor is Running in %s Direction %s\n", |
36 | printf ( "- Step Motor is Running in %s Direction %s\n", |
37 | state.CW_CCW ? "CCW" : "CW", ( ( state.SDivisor == 1 ) && state.FullSpeed ) ? "at Full speed" : "" ); |
37 | state.CW_CCW ? "CCW" : "CW", ( ( state.SDivisor == 1 ) && state.FullSpeed ) ? "at Full speed" : "" ); |
38 | else |
38 | else |
39 | printf ( "- Step Motor is Not Running\n" ); |
39 | printf ( "- Step Motor is Not Running\n" ); |
40 | 40 | ||
41 | printf ( "- Device %s\n", state.AReset ? "is After Reset" : "Position Already Set" ); |
41 | printf ( "- Device %s\n", state.AReset ? "is After Reset" : "Position Already Set" ); |
42 | printf ( "- Input Synchronization Logical Pin state - %s\n", state.SyncIN ? "TRUE" : "FALSE" ); |
42 | printf ( "- Input Synchronization Logical Pin state - %s\n", state.SyncIN ? "TRUE" : "FALSE" ); |
43 | printf ( "- Output Synchronization Logical Pin state - %s\n", state.SyncOUT ? "TRUE" : "FALSE" ); |
43 | printf ( "- Output Synchronization Logical Pin state - %s\n", state.SyncOUT ? "TRUE" : "FALSE" ); |
44 | printf ( "- Rotary Transducer Logical Pin state - %s\n", state.RotTr ? "TRUE" : "FALSE" ); |
44 | printf ( "- Rotary Transducer Logical Pin state - %s\n", state.RotTr ? "TRUE" : "FALSE" ); |
45 | printf ( "- Rotary Transducer Error Flag - %s\n", state.RotTrErr ? "Error" : "Clear" ); |
45 | printf ( "- Rotary Transducer Error Flag - %s\n", state.RotTrErr ? "Error" : "Clear" ); |
46 | printf ( "- Emergency Disable Button - %s\n", state.EmReset ? "Pushed" : "Unpushed" ); |
46 | printf ( "- Emergency Disable Button - %s\n", state.EmReset ? "Pushed" : "Unpushed" ); |
47 | printf ( "- Trailer 1 Press state - %s\n", state.Trailer1 ? "Pushed" : "Unpushed" ); |
47 | printf ( "- Trailer 1 Press state - %s\n", state.Trailer1 ? "Pushed" : "Unpushed" ); |
48 | printf ( "- Trailer 2 Press state - %s\n", state.Trailer2 ? "Pushed" : "Unpushed" ); |
48 | printf ( "- Trailer 2 Press state - %s\n", state.Trailer2 ? "Pushed" : "Unpushed" ); |
49 | 49 | ||
50 | if ( state.Voltage == 0.0f ) |
50 | if ( state.Voltage == 0.0f ) |
51 | printf ( "- Input Voltage - Low\n" |
51 | printf ( "- Input Voltage - Low\n" ); |
52 | else |
52 | else |
53 | printf ( "- Input Voltage - %.1fV\n", state.Voltage ); |
53 | printf ( "- Input Voltage - %.1fV\n", state.Voltage ); |
54 | } |
54 | } |
55 | 55 | ||
56 | // Function that scans start parameters |
56 | // Function that scans start parameters |
57 | void scan_start_params ( int * dest_pos, float * speed, USMC_StartParameters * sp ) |
57 | void scan_start_params ( int * dest_pos, float * speed, USMC_StartParameters * sp ) |
58 | { |
58 | { |
59 | // Defaults |
59 | // Defaults |
60 | *speed = 2000.0f; |
60 | *speed = 2000.0f; |
61 | *dest_pos = 0; |
61 | *dest_pos = 0; |
62 | sp -> SDivisor = 8; |
62 | sp -> SDivisor = 8; |
63 | 63 | ||
64 | printf ( "Destination position:" ); |
64 | printf ( "Destination position:" ); |
65 | scanf ( "%d", dest_pos ); |
65 | scanf ( "%d", dest_pos ); |
66 | printf ( "\nSpeed (in tacts):" ); |
66 | printf ( "\nSpeed (in tacts):" ); |
67 | scanf ( "%f", speed ); |
67 | scanf ( "%f", speed ); |
68 | printf ( "\nSteps Divisor:" ); |
68 | printf ( "\nSteps Divisor:" ); |
69 | scanf ( " |
69 | scanf ( "%c", &( sp -> SDivisor ) ); |
70 | getchar (); |
70 | getchar (); |
71 | } |
71 | } |
72 | 72 | ||
73 | // Function that prints information about device start parameters to console |
73 | // Function that prints information about device start parameters to console |
74 | void print_start_params ( int dest_pos, float speed, const USMC_StartParameters sp ) |
74 | void print_start_params ( int dest_pos, float speed, const USMC_StartParameters sp ) |
75 | { |
75 | { |
76 | printf ( "Destination position - %d\n", dest_pos ); |
76 | printf ( "Destination position - %d\n", dest_pos ); |
77 | printf ( "speed - %.2ftacts/s\n", speed ); |
77 | printf ( "speed - %.2ftacts/s\n", speed ); |
78 | printf ( "Steps Divisor - %d\n", sp.SDivisor ); |
78 | printf ( "Steps Divisor - %d\n", sp.SDivisor ); |
79 | 79 | ||
80 | if ( sp.SDivisor == 1 ) |
80 | if ( sp.SDivisor == 1 ) |
81 | printf ( "Slow start/stop mode - %s\n", sp.SlStart ? "Enabled" : "Disabled" ); |
81 | printf ( "Slow start/stop mode - %s\n", sp.SlStart ? "Enabled" : "Disabled" ); |
82 | else if ( sp.LoftEn ) { |
82 | else if ( sp.LoftEn ) { |
83 | printf ( "Automatic backlash operation - Enabled\n" ); |
83 | printf ( "Automatic backlash operation - Enabled\n" ); |
84 | printf ( "Automatic backlash operation direction - %s\n", sp.DefDir ? "CCW" : "CW" ); |
84 | printf ( "Automatic backlash operation direction - %s\n", sp.DefDir ? "CCW" : "CW" ); |
85 | printf ( "Force automatic backlash operation - %s\n", sp.ForceLoft ? "TRUE" : "FALSE" ); |
85 | printf ( "Force automatic backlash operation - %s\n", sp.ForceLoft ? "TRUE" : "FALSE" ); |
86 | } else { |
86 | } else { |
87 | printf ( "Automatic backlash operation - Disabled\n" ); |
87 | printf ( "Automatic backlash operation - Disabled\n" ); |
88 | } |
88 | } |
89 | if ( sp.WSyncIN ) |
89 | if ( sp.WSyncIN ) |
90 | printf ( "Controller will wait for input synchronization signal to start\n" ); |
90 | printf ( "Controller will wait for input synchronization signal to start\n" ); |
91 | else |
91 | else |
92 | printf ( "Input synchronization signal ignored \n" ); |
92 | printf ( "Input synchronization signal ignored \n" ); |
93 | 93 | ||
94 | printf ( "Output synchronization counter will %sbe reset\n", sp.SyncOUTR ? "" : "not " ); |
94 | printf ( "Output synchronization counter will %sbe reset\n", sp.SyncOUTR ? "" : "not " ); |
95 | } |
95 | } |
96 | 96 | ||
97 | // Function that prints information about device parameters to console |
97 | // Function that prints information about device parameters to console |
98 | void print_params ( USMC_Parameters params ) |
98 | void print_params ( USMC_Parameters params ) |
99 | { |
99 | { |
100 | printf ( "The parameters are:\n" ); |
100 | printf ( "The parameters are:\n" ); |
101 | printf ( "Full acceleration time - %.0f ms\n", ( double ) params.AccelT ); |
101 | printf ( "Full acceleration time - %.0f ms\n", ( double ) params.AccelT ); |
102 | printf ( "Full deceleration time - %.0f ms\n", ( double ) params.DecelT ); |
102 | printf ( "Full deceleration time - %.0f ms\n", ( double ) params.DecelT ); |
103 | printf ( "Power reduction timeout - %.0f ms\n", ( double ) params.PTimeout ); |
103 | printf ( "Power reduction timeout - %.0f ms\n", ( double ) params.PTimeout ); |
104 | printf ( "Button speedup timeout 1 - %.0f ms\n", ( double ) params.BTimeout1 ); |
104 | printf ( "Button speedup timeout 1 - %.0f ms\n", ( double ) params.BTimeout1 ); |
105 | printf ( "Button speed after timeout 1 - %.2f steps/s\n", ( double ) params.BTO1P ); |
105 | printf ( "Button speed after timeout 1 - %.2f steps/s\n", ( double ) params.BTO1P ); |
106 | printf ( "Button speedup timeout 2 - %.0f ms\n", ( double ) params.BTimeout2 ); |
106 | printf ( "Button speedup timeout 2 - %.0f ms\n", ( double ) params.BTimeout2 ); |
107 | printf ( "Button speed after timeout 2 - %.2f steps/s\n", ( double ) params.BTO2P ); |
107 | printf ( "Button speed after timeout 2 - %.2f steps/s\n", ( double ) params.BTO2P ); |
108 | printf ( "Button speedup timeout 3 - %.0f ms\n", ( double ) params.BTimeout3 ); |
108 | printf ( "Button speedup timeout 3 - %.0f ms\n", ( double ) params.BTimeout3 ); |
109 | printf ( "Button speed after timeout 3 - %.2f steps/s\n", ( double ) params.BTO3P ); |
109 | printf ( "Button speed after timeout 3 - %.2f steps/s\n", ( double ) params.BTO3P ); |
110 | printf ( "Button speedup timeout 4 - %.0f ms\n", ( double ) params.BTimeout4 ); |
110 | printf ( "Button speedup timeout 4 - %.0f ms\n", ( double ) params.BTimeout4 ); |
111 | printf ( "Button speed after timeout 4 - %.2f steps/s\n", ( double ) params.BTO4P ); |
111 | printf ( "Button speed after timeout 4 - %.2f steps/s\n", ( double ) params.BTO4P ); |
112 | printf ( "Button reset timeout - %.0f ms\n", (double) params.BTimeoutR ); |
112 | printf ( "Button reset timeout - %.0f ms\n", (double) params.BTimeoutR ); |
113 | printf ( "Button reset operation speed - %.2f steps/s\n", ( double ) params.MinP ); |
113 | printf ( "Button reset operation speed - %.2f steps/s\n", ( double ) params.MinP ); |
114 | printf ( "Backlash operation distance - %d steps\n", ( int ) params.MaxLoft ); |
114 | printf ( "Backlash operation distance - %d steps\n", ( int ) params.MaxLoft ); |
115 | printf ( "Revolution distance - %d steps\n", ( int ) params.RTDelta ); |
115 | printf ( "Revolution distance - %d steps\n", ( int ) params.RTDelta ); |
116 | printf ( "Minimal revolution distance error - %d steps\n", ( int ) params.RTMinError ); |
116 | printf ( "Minimal revolution distance error - %d steps\n", ( int ) params.RTMinError ); |
117 | printf ( "Power off temperature - %.2f\xf8\x43\n", ( double ) params.MaxTemp ); |
117 | printf ( "Power off temperature - %.2f\xf8\x43\n", ( double ) params.MaxTemp ); |
118 | printf ( "Duration of the output synchronization pulse - " ); |
118 | printf ( "Duration of the output synchronization pulse - " ); |
119 | 119 | ||
120 | if ( params.SynOUTP == 0 ) |
120 | if ( params.SynOUTP == 0 ) |
121 | printf ( "minimal\n"); |
121 | printf ( "minimal\n"); |
122 | else |
122 | else |
123 | printf ( "%.1f * [Tact Period]\n", params.SynOUTP - 0.5 ); |
123 | printf ( "%.1f * [Tact Period]\n", params.SynOUTP - 0.5 ); |
124 | 124 | ||
125 | printf ( "speed of the last phase of the backlash operation - " ); |
125 | printf ( "speed of the last phase of the backlash operation - " ); |
126 | 126 | ||
127 | if ( params.LoftPeriod == 0.0f ) |
127 | if ( params.LoftPeriod == 0.0f ) |
128 | printf ( "normal\n" ); |
128 | printf ( "normal\n" ); |
129 | else |
129 | else |
130 | printf ( "%.2f steps/s\n", ( double ) params.LoftPeriod ); |
130 | printf ( "%.2f steps/s\n", ( double ) params.LoftPeriod ); |
131 | 131 | ||
132 | printf ( "<Angular Encoder Step> Equals <Angular Step Motor Step>/<%.2f>\n", params.EncMult ); |
132 | printf ( "<Angular Encoder Step> Equals <Angular Step Motor Step>/<%.2f>\n", params.EncMult ); |
133 | } |
133 | } |
134 | 134 | ||
135 | // Function that prints information about device "mode" parameters to console |
135 | // Function that prints information about device "mode" parameters to console |
136 | void print_mode ( USMC_Mode mode ) |
136 | void print_mode ( USMC_Mode mode ) |
137 | { |
137 | { |
138 | printf ( "mode parameters:\n" ); |
138 | printf ( "mode parameters:\n" ); |
139 | printf ( "Buttons - "); |
139 | printf ( "Buttons - "); |
140 | 140 | ||
141 | if ( mode.PMode ) |
141 | if ( mode.PMode ) |
142 | printf ( "Disabled\n" ); |
142 | printf ( "Disabled\n" ); |
143 | else { |
143 | else { |
144 | printf ( "Enabled\nButton 1 TRUE state - %s\n", mode.Butt1T ? "+3/+5 V" : "0 V(GND)" ); |
144 | printf ( "Enabled\nButton 1 TRUE state - %s\n", mode.Butt1T ? "+3/+5 V" : "0 V(GND)" ); |
145 | printf ( "Button 2 TRUE state - %s\n", mode.Butt2T ? "+3/+5 V" : "0 V(GND)" ); |
145 | printf ( "Button 2 TRUE state - %s\n", mode.Butt2T ? "+3/+5 V" : "0 V(GND)" ); |
146 | } |
146 | } |
147 | 147 | ||
148 | printf ( "Current reduction regime - %s\n", mode.PReg ? "Used" : "Not Used" ); |
148 | printf ( "Current reduction regime - %s\n", mode.PReg ? "Used" : "Not Used" ); |
149 | 149 | ||
150 | if ( mode.ResetD ) |
150 | if ( mode.ResetD ) |
151 | printf ( "Power - %s\n", mode.EMReset ? "Emerjency Off" : "Off" ); |
151 | printf ( "Power - %s\n", mode.EMReset ? "Emerjency Off" : "Off" ); |
152 | else |
152 | else |
153 | printf ( "Power - On\n" ); |
153 | printf ( "Power - On\n" ); |
154 | 154 | ||
155 | if ( mode.Tr1En || mode.Tr2En ) |
155 | if ( mode.Tr1En || mode.Tr2En ) |
156 | printf ( "Trailers are - %s\n", mode.TrSwap ? "Swapped" : "Direct" ); |
156 | printf ( "Trailers are - %s\n", mode.TrSwap ? "Swapped" : "Direct" ); |
157 | 157 | ||
158 | printf ( "Trailer 1 - "); |
158 | printf ( "Trailer 1 - "); |
159 | 159 | ||
160 | if ( mode.Tr1En ) |
160 | if ( mode.Tr1En ) |
161 | printf ( "Enabled\nTrailer 1 TRUE state - %s\n", mode.Tr1T ? "+3/+5 V" : "0 V(GND)" ); |
161 | printf ( "Enabled\nTrailer 1 TRUE state - %s\n", mode.Tr1T ? "+3/+5 V" : "0 V(GND)" ); |
162 | else |
162 | else |
163 | printf ( "Disabled\n" ); |
163 | printf ( "Disabled\n" ); |
164 | 164 | ||
165 | printf ( "Trailer 2 - " ); |
165 | printf ( "Trailer 2 - " ); |
166 | 166 | ||
167 | if ( mode.Tr2En ) |
167 | if ( mode.Tr2En ) |
168 | printf ( "Enabled\nTrailer 2 TRUE state - %s\n", mode.Tr2T ? "+3/+5 V" : "0 V(GND)" ); |
168 | printf ( "Enabled\nTrailer 2 TRUE state - %s\n", mode.Tr2T ? "+3/+5 V" : "0 V(GND)" ); |
169 | else |
169 | else |
170 | printf ( "Disabled\n" ); |
170 | printf ( "Disabled\n" ); |
171 | 171 | ||
172 | if ( mode.EncoderEn ) { |
172 | if ( mode.EncoderEn ) { |
173 | printf ( "Encoder - Enabled\n" ); |
173 | printf ( "Encoder - Enabled\n" ); |
174 | printf ( "Encoder Position Counter is %s\n", mode.EncoderInv ? "Inverted" : "Direct" ); |
174 | printf ( "Encoder Position Counter is %s\n", mode.EncoderInv ? "Inverted" : "Direct" ); |
175 | printf ( "Rotary Transducer and Input Syncronisation are\n" |
175 | printf ( "Rotary Transducer and Input Syncronisation are\n" |
176 | " Disabled Because of Encoder\n" ); |
176 | " Disabled Because of Encoder\n" ); |
177 | } else { |
177 | } else { |
178 | printf ( "Encoder - Disabled\n" ); |
178 | printf ( "Encoder - Disabled\n" ); |
179 | printf ( "Rotary Transducer - " ); |
179 | printf ( "Rotary Transducer - " ); |
180 | 180 | ||
181 | if ( mode.RotTeEn ) { |
181 | if ( mode.RotTeEn ) { |
182 | printf ( "Enabled\nRotary Transducer TRUE state - %s\n", mode.RotTrT ? "+3/+5 V" : "0 V(GND)" ); |
182 | printf ( "Enabled\nRotary Transducer TRUE state - %s\n", mode.RotTrT ? "+3/+5 V" : "0 V(GND)" ); |
183 | printf ( "Rotary Transducer Operation - %s\n", mode.RotTrOp ? "Stop on error" : "Check and ignore error" ); |
183 | printf ( "Rotary Transducer Operation - %s\n", mode.RotTrOp ? "Stop on error" : "Check and ignore error" ); |
184 | printf ( "Reset Rotary Transducer Check Positions - %s\n", mode.ResetRT ? "Initiated" : "No, why?" ); |
184 | printf ( "Reset Rotary Transducer Check Positions - %s\n", mode.ResetRT ? "Initiated" : "No, why?" ); |
185 | } else { |
185 | } else { |
186 | printf ( "Disabled\n" ); |
186 | printf ( "Disabled\n" ); |
187 | } |
187 | } |
188 | 188 | ||
189 | printf ( "Synchronization input mode:\n" ); |
189 | printf ( "Synchronization input mode:\n" ); |
190 | 190 | ||
191 | if ( mode.SyncINOp ) |
191 | if ( mode.SyncINOp ) |
192 | printf ( "Step motor will move one time to the destination position\n" ); |
192 | printf ( "Step motor will move one time to the destination position\n" ); |
193 | else |
193 | else |
194 | printf ( "Step motor will move multiple times by [destination position]\n" ); |
194 | printf ( "Step motor will move multiple times by [destination position]\n" ); |
195 | } |
195 | } |
196 | 196 | ||
197 | printf ( "Output Syncronization - " ); |
197 | printf ( "Output Syncronization - " ); |
198 | 198 | ||
199 | if ( mode.SyncOUTEn ) { |
199 | if ( mode.SyncOUTEn ) { |
200 | printf ( "Enabled\nReset Output Synchronization Counter - %s\n", mode.SyncOUTR ? "Initiated" : "No, why?" ); |
200 | printf ( "Enabled\nReset Output Synchronization Counter - %s\n", mode.SyncOUTR ? "Initiated" : "No, why?" ); |
201 | printf ( "Number of steps after which synchronization output sygnal occures - %u\n", mode.SyncCount ); |
201 | printf ( "Number of steps after which synchronization output sygnal occures - %u\n", mode.SyncCount ); |
202 | } else { |
202 | } else { |
203 | printf ( "Disabled\n" ); |
203 | printf ( "Disabled\n" ); |
204 | } |
204 | } |
205 | 205 | ||
206 | printf ( "Synchronization Output is " ); |
206 | printf ( "Synchronization Output is " ); |
207 | 207 | ||
208 | if ( mode.SyncInvert ) |
208 | if ( mode.SyncInvert ) |
209 | printf ( "INVERTED\n" ); |
209 | printf ( "INVERTED\n" ); |
210 | else |
210 | else |
211 | printf ( "NORMAL\n" ); |
211 | printf ( "NORMAL\n" ); |
212 | } |
212 | } |
213 | 213 | ||
214 | void print_enc_state ( USMC_EncoderState enc_state, USMC_Parameters up ) |
214 | void print_enc_state ( USMC_EncoderState enc_state, USMC_Parameters up ) |
215 | { |
215 | { |
216 | printf ( "The encoder state is:\n" ); |
216 | printf ( "The encoder state is:\n" ); |
217 | printf ( "- Current Position in microsteps - %.2f\n", enc_state.ECurPos/up.EncMult ); |
217 | printf ( "- Current Position in microsteps - %.2f\n", enc_state.ECurPos/up.EncMult ); |
218 | printf ( "- Encoder Position in microsteps - %.2f\n\n", enc_state.EncoderPos/up.EncMult ); |
218 | printf ( "- Encoder Position in microsteps - %.2f\n\n", enc_state.EncoderPos/up.EncMult ); |
219 | printf ( "- Current Position in \"Half of Encoder Step\"s - %d\n", enc_state.ECurPos ); |
219 | printf ( "- Current Position in \"Half of Encoder Step\"s - %d\n", enc_state.ECurPos ); |
220 | printf ( "- Encoder Position in \"Half of Encoder Step\"s - %d\n", enc_state.EncoderPos ); |
220 | printf ( "- Encoder Position in \"Half of Encoder Step\"s - %d\n", enc_state.EncoderPos ); |
221 | } |
221 | } |
222 | 222 | ||
223 | // Function that prints last error information |
223 | // Function that prints last error information |
224 | void print_error ( void ) |
224 | void print_error ( void ) |
225 | { |
225 | { |
226 | char er [256]; |
226 | char er [256]; |
227 | 227 | ||
228 | USMC_GetLastErr ( er, 255 ); |
228 | USMC_GetLastErr ( er, 255 ); |
229 | er [255] = '\0'; |
229 | er [255] = '\0'; |
230 | printf ( "\n%s", er ); |
230 | printf ( "\n%s", er ); |
231 | } |
231 | } |
232 | 232 | ||
233 | 233 | ||
234 | USMC_State state; |
234 | USMC_State state; |
235 | USMC_StartParameters start_params; |
235 | USMC_StartParameters start_params; |
236 | USMC_Parameters params; |
236 | USMC_Parameters params; |
237 | USMC_Mode mode; |
237 | USMC_Mode mode; |
238 | USMC_EncoderState enc_state; |
238 | USMC_EncoderState enc_state; |
239 | 239 | ||
240 | // Reference to Functions For Every Command (defined at the end of the file) |
240 | // Reference to Functions For Every Command (defined at the end of the file) |
241 | BOOL f1_get_dev_state ( void ); |
241 | BOOL f1_get_dev_state ( void ); |
242 | BOOL f2_start ( void ); |
242 | BOOL f2_start ( void ); |
243 | BOOL f3_stop ( void ); |
243 | BOOL f3_stop ( void ); |
244 | BOOL f4_set_params ( void ); |
244 | BOOL f4_set_params ( void ); |
245 | BOOL f5_set_mode ( void ); |
245 | BOOL f5_set_mode ( void ); |
246 | BOOL f6_set_cur_pos ( void ); |
246 | BOOL f6_set_cur_pos ( void ); |
247 | BOOL f7_turn_off_and_save_pos ( void ); |
247 | BOOL f7_turn_off_and_save_pos ( void ); |
248 | BOOL fs7_revert_sp_to_0 ( void ); |
248 | BOOL fs7_revert_sp_to_0 ( void ); |
249 | BOOL f8_get_enc_state ( void ); |
249 | BOOL f8_get_enc_state ( void ); |
250 | BOOL fp_change_power ( void ); |
250 | BOOL fp_change_power ( void ); |
251 | 251 | ||
252 | BOOL smpower = FALSE; |
252 | BOOL smpower = FALSE; |
253 | 253 | ||
254 | int menu ( void ) |
254 | int menu ( void ) |
255 | { |
255 | { |
256 | BOOL err = FALSE; |
256 | BOOL err = FALSE; |
257 | char menu_sel; |
257 | char menu_sel; |
258 | 258 | ||
259 | printf ( "menu :\n" |
259 | printf ( "menu :\n" |
260 | "1 - Get Device state\n" |
260 | "1 - Get Device state\n" |
261 | "2 - START\n" |
261 | "2 - START\n" |
262 | "3 - STOP\n" |
262 | "3 - STOP\n" |
263 | "4 - Set Parameters (can be changed only in c++ code)\n" |
263 | "4 - Set Parameters (can be changed only in c++ code)\n" |
264 | "5 - Set mode (can be changed only in c++ code)\n" |
264 | "5 - Set mode (can be changed only in c++ code)\n" |
265 | "6 - Set Current Position (can be changed only in c++ code)\n" |
265 | "6 - Set Current Position (can be changed only in c++ code)\n" |
266 | "7 - Turn Off and Save Current Position to Flash\n" |
266 | "7 - Turn Off and Save Current Position to Flash\n" |
267 | "SHIFT + 7 - Revert Start Position to 0\n" |
267 | "SHIFT + 7 - Revert Start Position to 0\n" |
268 | "8 - Get Encoder state\n" |
268 | "8 - Get Encoder state\n" |
269 | "\n" |
269 | "\n" |
270 | "p - Turn %s Power" |
270 | "p - Turn %s Power" |
271 | "\n" |
271 | "\n" |
272 | "9 - Select other device\n" |
272 | "9 - Select other device\n" |
273 | "0 - Exit program\n" |
273 | "0 - Exit program\n" |
274 | "Choose:", smpower ? "Off" : "On" ); |
274 | "Choose:", smpower ? "Off" : "On" ); |
275 | 275 | ||
276 | menu_sel = getchar (); |
276 | menu_sel = getchar (); |
277 | 277 | ||
278 | switch ( menu_sel ) |
278 | switch ( menu_sel ) |
279 | { |
279 | { |
280 | case '1': |
280 | case '1': |
281 | err = f1_get_dev_state (); |
281 | err = f1_get_dev_state (); |
282 | break; |
282 | break; |
283 | case '2': |
283 | case '2': |
284 | err = f2_start (); |
284 | err = f2_start (); |
285 | break; |
285 | break; |
286 | case '3': |
286 | case '3': |
287 | err = f3_stop (); |
287 | err = f3_stop (); |
288 | break; |
288 | break; |
289 | case '4': |
289 | case '4': |
290 | err = f4_set_params (); |
290 | err = f4_set_params (); |
291 | break; |
291 | break; |
292 | case '5': |
292 | case '5': |
293 | err = f5_set_mode (); |
293 | err = f5_set_mode (); |
294 | break; |
294 | break; |
295 | case '6': |
295 | case '6': |
296 | err = f6_set_cur_pos (); |
296 | err = f6_set_cur_pos (); |
297 | break; |
297 | break; |
298 | case '7': |
298 | case '7': |
299 | err = f7_turn_off_and_save_pos (); |
299 | err = f7_turn_off_and_save_pos (); |
300 | break; |
300 | break; |
301 | case '&': // 'SHIFT 7' on my keyboard |
301 | case '&': // 'SHIFT 7' on my keyboard |
302 | err = fs7_revert_sp_to_0 (); |
302 | err = fs7_revert_sp_to_0 (); |
303 | break; |
303 | break; |
304 | case '8': |
304 | case '8': |
305 | err = f8_get_enc_state (); |
305 | err = f8_get_enc_state (); |
306 | break; |
306 | break; |
307 | case 'p': |
307 | case 'p': |
308 | case 'P': |
308 | case 'P': |
309 | err = fp_change_power (); |
309 | err = fp_change_power (); |
310 | break; |
310 | break; |
311 | 311 | ||
312 | case '9': |
312 | case '9': |
313 | return MENU_ERROR; |
313 | return MENU_ERROR; |
314 | case '0': |
314 | case '0': |
315 | printf ( "\n" ); |
315 | printf ( "\n" ); |
316 | return MENU_EXIT; |
316 | return MENU_EXIT; |
317 | default: |
317 | default: |
318 | system ( "clear" ); |
318 | system ( "clear" ); |
319 | break; |
319 | break; |
320 | } |
320 | } |
321 | 321 | ||
322 | if ( err ) { |
322 | if ( err ) { |
323 | print_error (); |
323 | print_error (); |
324 | printf ( "\nPerforming Refressh..." ); |
324 | printf ( "\nPerforming Refressh..." ); |
325 | getchar (); |
325 | getchar (); |
326 | 326 | ||
327 | if ( USMC_Init ( &devices ) ) { |
327 | if ( USMC_Init ( &devices ) ) { |
328 | print_error (); |
328 | print_error (); |
329 | return MENU_EXIT; |
329 | return MENU_EXIT; |
330 | } |
330 | } |
331 | 331 | ||
332 | return MENU_ERROR; |
332 | return MENU_ERROR; |
333 | } |
333 | } |
334 | 334 | ||
335 | return MENU_CONTINUE; |
335 | return MENU_CONTINUE; |
336 | } |
336 | } |
337 | 337 | ||
338 | int select_menu ( void ) |
338 | int select_menu ( void ) |
339 | { |
339 | { |
340 | int ret; |
340 | int ret; |
341 | do { |
341 | do { |
342 | system ( "clear" ); |
342 | system ( "clear" ); |
343 | cur_dev = -1; |
343 | cur_dev = -1; |
344 | print_devices ( devices ); |
344 | print_devices ( devices ); |
345 | printf ( "\n\t0\tExit\n" ); |
345 | printf ( "\n\t0\tExit\n" ); |
346 | for ( ret=0;ret<devices.NOD;ret++) printf ( "\t%d\tDevice # %d\n",ret+1,ret+1 ); |
346 | for ( ret=0;ret<devices.NOD;ret++) printf ( "\t%d\tDevice # %d\n",ret+1,ret+1 ); |
347 | printf ( "\tx\tReInitialize\n" ); |
347 | printf ( "\tx\tReInitialize\n" ); |
348 | printf ( "\txx\tClose Driver Window and Exit Program\n" ); |
348 | printf ( "\txx\tClose Driver Window and Exit Program\n" ); |
349 | 349 | ||
350 | printf ( "Select:" ); |
350 | printf ( "Select:" ); |
351 | scanf ( "%s", str ); |
351 | scanf ( "%s", str ); |
352 | getchar (); |
352 | getchar (); |
353 | 353 | ||
354 | if ( strcmp ( str, "x" ) == 0 ) |
354 | if ( strcmp ( str, "x" ) == 0 ) |
355 | { |
355 | { |
356 | //// Perform "Refresh" of Driver |
356 | //// Perform "Refresh" of Driver |
357 | if ( USMC_Init ( &devices ) ) |
357 | if ( USMC_Init ( &devices ) ) |
358 | { |
358 | { |
359 | print_error (); |
359 | print_error (); |
360 | return MENU_EXIT; |
360 | return MENU_EXIT; |
361 | } |
361 | } |
362 | 362 | ||
363 | continue; |
363 | continue; |
364 | } else if ( strcmp ( str, "xx" ) == 0 ) { |
364 | } else if ( strcmp ( str, "xx" ) == 0 ) { |
365 | //// Close the MicroSMC.exe process |
365 | //// Close the MicroSMC.exe process |
366 | if ( USMC_Close () ) |
366 | if ( USMC_Close () ) |
367 | { |
367 | { |
368 | print_error (); |
368 | print_error (); |
369 | return MENU_EXIT; |
369 | return MENU_EXIT; |
370 | } |
370 | } |
371 | 371 | ||
372 | return MENU_EXIT; |
372 | return MENU_EXIT; |
373 | } |
373 | } |
374 | 374 | ||
375 | sscanf ( str, "%u", &cur_dev ); |
375 | sscanf ( str, "%u", &cur_dev ); |
376 | 376 | ||
377 | if ( cur_dev == 0 ) |
377 | if ( cur_dev == 0 ) |
378 | return MENU_EXIT; |
378 | return MENU_EXIT; |
379 | } while ( cur_dev > devices.NOD ); |
379 | } while ( cur_dev > devices.NOD ); |
380 | 380 | ||
381 | system ( "clear" ); |
381 | system ( "clear" ); |
382 | 382 | ||
383 | cur_dev--; // Decrement cur_dev by 1 ( we have zero-based device list, |
383 | cur_dev--; // Decrement cur_dev by 1 ( we have zero-based device list, |
384 | // but 1-based is user-friendly ) |
384 | // but 1-based is user-friendly ) |
385 | 385 | ||
386 | do { |
386 | do { |
387 | ret = menu (); |
387 | ret = menu (); |
388 | } while ( ret == MENU_CONTINUE ); |
388 | } while ( ret == MENU_CONTINUE ); |
389 | 389 | ||
390 | return ret; |
390 | return ret; |
391 | } |
391 | } |
392 | 392 | ||
393 | int exit_program ( void ) |
393 | int exit_program ( void ) |
394 | { |
394 | { |
395 | printf ( "\nPress any key to exit" ); |
395 | printf ( "\nPress any key to exit" ); |
396 | getchar (); |
396 | getchar (); |
397 | 397 | ||
398 | return MENU_EXIT; |
398 | return MENU_EXIT; |
399 | } |
399 | } |
400 | 400 | ||
401 | int main ( int argc, const char ** argv ) |
401 | int main ( int argc, const char ** argv ) |
402 | { |
402 | { |
403 | int res; |
403 | int res; |
404 | 404 | ||
405 | // change terminal mode to non-buffering |
405 | // change terminal mode to non-buffering |
406 | system ( "stty -icanon min 1" ); |
406 | system ( "stty -icanon min 1" ); |
407 | setbuf ( stdin, NULL ); |
407 | setbuf ( stdin, NULL ); |
408 | system ( "clear" ); |
408 | system ( "clear" ); |
409 | 409 | ||
410 | if ( USMC_Init ( &devices ) ) |
410 | if ( USMC_Init ( &devices ) ) |
411 | { |
411 | { |
412 | print_error (); |
412 | print_error (); |
413 | 413 | ||
414 | return exit_program (); |
414 | return exit_program (); |
415 | } |
415 | } |
416 | 416 | ||
417 | while ( select_menu () ); |
417 | while ( select_menu () ); |
418 | 418 | ||
419 | res = exit_program (); |
419 | res = exit_program (); |
420 | //restore terminal mode |
420 | //restore terminal mode |
421 | system ( "stty -icanon" ); |
421 | system ( "stty -icanon" ); |
422 | 422 | ||
423 | return res; |
423 | return res; |
424 | } |
424 | } |
425 | 425 | ||
426 | 426 | ||
427 | 427 | ||
428 | BOOL f1_get_dev_state ( void ) |
428 | BOOL f1_get_dev_state ( void ) |
429 | { |
429 | { |
430 | if ( USMC_GetState ( cur_dev, &state ) ) |
430 | if ( USMC_GetState ( cur_dev, &state ) ) |
431 | return TRUE; |
431 | return TRUE; |
432 | 432 | ||
433 | system ( "clear" ); |
433 | system ( "clear" ); |
434 | print_state ( state ); |
434 | print_state ( state ); |
435 | printf ( "\nPress any key to continue" ); |
435 | printf ( "\nPress any key to continue" ); |
436 | getchar (); |
436 | getchar (); |
437 | system ( "clear" ); |
437 | system ( "clear" ); |
438 | 438 | ||
439 | return FALSE; |
439 | return FALSE; |
440 | } |
440 | } |
441 | 441 | ||
442 | BOOL f2_start ( void ) |
442 | BOOL f2_start ( void ) |
443 | { |
443 | { |
444 | float speed = 2000.0f; |
444 | float speed = 2000.0f; |
445 | int dest_pos = 0; |
445 | int dest_pos = 0; |
446 | 446 | ||
447 | if ( USMC_GetStartParameters ( cur_dev, &start_params ) ) |
447 | if ( USMC_GetStartParameters ( cur_dev, &start_params ) ) |
448 | return TRUE; |
448 | return TRUE; |
449 | 449 | ||
450 | system ( "clear" ); |
450 | system ( "clear" ); |
451 | scan_start_params ( &dest_pos, &speed, &start_params ); |
451 | scan_start_params ( &dest_pos, &speed, &start_params ); |
452 | start_params.SlStart = TRUE; |
452 | start_params.SlStart = TRUE; |
453 | 453 | ||
454 | if ( USMC_Start ( cur_dev, dest_pos, &speed, &start_params ) ) |
454 | if ( USMC_Start ( cur_dev, dest_pos, &speed, &start_params ) ) |
455 | return TRUE; |
455 | return TRUE; |
456 | 456 | ||
457 | system ( "clear" ); |
457 | system ( "clear" ); |
458 | print_start_params ( dest_pos, speed, start_params ); |
458 | print_start_params ( dest_pos, speed, start_params ); |
459 | printf ( "\n" ); |
459 | printf ( "\n" ); |
460 | return FALSE; |
460 | return FALSE; |
461 | } |
461 | } |
462 | 462 | ||
463 | BOOL f3_stop ( void ) |
463 | BOOL f3_stop ( void ) |
464 | { |
464 | { |
465 | if ( USMC_Stop ( cur_dev ) ) |
465 | if ( USMC_Stop ( cur_dev ) ) |
466 | return TRUE; |
466 | return TRUE; |
467 | 467 | ||
468 | system ( "clear" ); |
468 | system ( "clear" ); |
469 | printf ( "Motor stopped\n\n" ); |
469 | printf ( "Motor stopped\n\n" ); |
470 | 470 | ||
471 | return FALSE; |
471 | return FALSE; |
472 | } |
472 | } |
473 | 473 | ||
474 | BOOL f4_set_params ( void ) |
474 | BOOL f4_set_params ( void ) |
475 | { |
475 | { |
476 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
476 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
477 | return TRUE; |
477 | return TRUE; |
478 | 478 | ||
479 | // Set anything you want here |
479 | // Set anything you want here |
480 | params.MaxTemp = 70.0f; |
480 | params.MaxTemp = 70.0f; |
481 | params.AccelT = 200.0f; |
481 | params.AccelT = 200.0f; |
482 | params.DecelT = 200.0f; |
482 | params.DecelT = 200.0f; |
483 | params.BTimeout1 = 5000.0f; |
483 | params.BTimeout1 = 5000.0f; |
484 | params.BTimeout2 = 5000.0f; |
484 | params.BTimeout2 = 5000.0f; |
485 | params.BTimeout3 = 5000.0f; |
485 | params.BTimeout3 = 5000.0f; |
486 | params.BTimeout4 = 5000.0f; |
486 | params.BTimeout4 = 5000.0f; |
487 | params.BTO1P = 625.0f; |
487 | params.BTO1P = 625.0f; |
488 | params.BTO2P = 16.0f; |
488 | params.BTO2P = 16.0f; |
489 | params.BTO3P = 625.0f; |
489 | params.BTO3P = 625.0f; |
490 | params.BTO4P = 16.0f;//500.0f; |
490 | params.BTO4P = 16.0f;//500.0f; |
491 | params.MinP = 500.0f; |
491 | params.MinP = 500.0f; |
492 | params.BTimeoutR = 500.0f; |
492 | params.BTimeoutR = 500.0f; |
493 | params.LoftPeriod = 500.0f; |
493 | params.LoftPeriod = 500.0f; |
494 | params.RTDelta = 200; |
494 | params.RTDelta = 200; |
495 | params.RTMinError = 15; |
495 | params.RTMinError = 15; |
496 | params.EncMult = 2.5f; |
496 | params.EncMult = 2.5f; |
497 | params.MaxLoft = 32; |
497 | params.MaxLoft = 32; |
498 | params.PTimeout = 100.0f; |
498 | params.PTimeout = 100.0f; |
499 | params.SynOUTP = 1; |
499 | params.SynOUTP = 1; |
500 | // |
500 | // |
501 | 501 | ||
502 | if ( USMC_SetParameters ( cur_dev, ¶ms ) ) |
502 | if ( USMC_SetParameters ( cur_dev, ¶ms ) ) |
503 | return TRUE; |
503 | return TRUE; |
504 | 504 | ||
505 | if ( USMC_SaveParametersToFlash ( cur_dev ) ) |
505 | if ( USMC_SaveParametersToFlash ( cur_dev ) ) |
506 | return TRUE; |
506 | return TRUE; |
507 | 507 | ||
508 | system ( "clear" ); |
508 | system ( "clear" ); |
509 | print_params ( params ); |
509 | print_params ( params ); |
510 | printf ( "\nThese Parameters are Saved to Flash" ); |
510 | printf ( "\nThese Parameters are Saved to Flash" ); |
511 | printf ( "\nPress any key to continue" ); |
511 | printf ( "\nPress any key to continue" ); |
512 | getchar (); |
512 | getchar (); |
513 | system ( "clear" ); |
513 | system ( "clear" ); |
514 | 514 | ||
515 | return FALSE; |
515 | return FALSE; |
516 | } |
516 | } |
517 | 517 | ||
518 | BOOL f5_set_mode ( void ) |
518 | BOOL f5_set_mode ( void ) |
519 | { |
519 | { |
520 | if ( USMC_GetMode ( cur_dev, &mode ) ) |
520 | if ( USMC_GetMode ( cur_dev, &mode ) ) |
521 | return TRUE; |
521 | return TRUE; |
522 | 522 | ||
523 | // Set anything you want here |
523 | // Set anything you want here |
524 | mode.SyncInvert = !mode.SyncInvert; |
524 | mode.SyncInvert = !mode.SyncInvert; |
525 | mode.EncoderEn = TRUE; |
525 | mode.EncoderEn = TRUE; |
526 | mode.RotTrOp = FALSE; |
526 | mode.RotTrOp = FALSE; |
527 | mode.ResetRT = TRUE; |
527 | mode.ResetRT = TRUE; |
528 | mode.ResBEnc = TRUE; |
528 | mode.ResBEnc = TRUE; |
529 | // Set anything you want here |
529 | // Set anything you want here |
530 | 530 | ||
531 | if ( USMC_SetMode ( cur_dev, &mode ) ) |
531 | if ( USMC_SetMode ( cur_dev, &mode ) ) |
532 | return TRUE; |
532 | return TRUE; |
533 | 533 | ||
534 | 534 | ||
535 | system ( "clear" ); |
535 | system ( "clear" ); |
536 | print_mode ( mode ); |
536 | print_mode ( mode ); |
537 | printf ( "\nPress any key to continue" ); |
537 | printf ( "\nPress any key to continue" ); |
538 | getchar (); |
538 | getchar (); |
539 | system ( "clear" ); |
539 | system ( "clear" ); |
540 | 540 | ||
541 | return FALSE; |
541 | return FALSE; |
542 | } |
542 | } |
543 | 543 | ||
544 | BOOL f6_set_cur_pos ( void ) |
544 | BOOL f6_set_cur_pos ( void ) |
545 | { |
545 | { |
546 | int newCurPos = 1000; |
546 | int newCurPos = 1000; |
547 | 547 | ||
548 | if ( USMC_SetCurrentPosition ( cur_dev, newCurPos ) ) |
548 | if ( USMC_SetCurrentPosition ( cur_dev, newCurPos ) ) |
549 | return TRUE; |
549 | return TRUE; |
550 | 550 | ||
551 | system ( "clear" ); |
551 | system ( "clear" ); |
552 | printf ( "\nSetCurrentPosition executed with argument %d", newCurPos ); |
552 | printf ( "\nSetCurrentPosition executed with argument %d", newCurPos ); |
553 | printf ( "\nPress any key to continue" ); |
553 | printf ( "\nPress any key to continue" ); |
554 | getchar (); |
554 | getchar (); |
555 | system ( "clear" ); |
555 | system ( "clear" ); |
556 | 556 | ||
557 | return FALSE; |
557 | return FALSE; |
558 | } |
558 | } |
559 | 559 | ||
560 | BOOL f7_turn_off_and_save_pos ( void ) |
560 | BOOL f7_turn_off_and_save_pos ( void ) |
561 | { |
561 | { |
562 | // Initialize structures (in case this function runs first) |
562 | // Initialize structures (in case this function runs first) |
563 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
563 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
564 | return TRUE; |
564 | return TRUE; |
565 | if ( USMC_GetMode ( cur_dev, &mode ) ) |
565 | if ( USMC_GetMode ( cur_dev, &mode ) ) |
566 | return TRUE; |
566 | return TRUE; |
567 | 567 | ||
568 | // Go to Full Step (automaticaly), then Turn Off |
568 | // Go to Full Step (automaticaly), then Turn Off |
569 | mode.ResetD = TRUE; |
569 | mode.ResetD = TRUE; |
570 | 570 | ||
571 | if ( USMC_SetMode ( cur_dev, &mode ) ) |
571 | if ( USMC_SetMode ( cur_dev, &mode ) ) |
572 | return TRUE; |
572 | return TRUE; |
573 | 573 | ||
574 | // Wait until Previous Comand is Done |
574 | // Wait until Previous Comand is Done |
575 | do { |
575 | do { |
576 | usleep ( 50 ); |
576 | usleep ( 50 ); |
577 | 577 | ||
578 | if ( USMC_GetState ( cur_dev, &state ) ) |
578 | if ( USMC_GetState ( cur_dev, &state ) ) |
579 | return TRUE; |
579 | return TRUE; |
580 | } while ( state.Power == TRUE ); |
580 | } while ( state.Power == TRUE ); |
581 | 581 | ||
582 | // Remember CurPos in Parameters Only While state.Power - FALSE |
582 | // Remember CurPos in Parameters Only While state.Power - FALSE |
583 | params.StartPos = state.CurPos; |
583 | params.StartPos = state.CurPos; |
584 | 584 | ||
585 | if ( USMC_SetParameters ( cur_dev, ¶ms ) ) |
585 | if ( USMC_SetParameters ( cur_dev, ¶ms ) ) |
586 | return TRUE; |
586 | return TRUE; |
587 | 587 | ||
588 | // Then of Course You Need to SaveToFlash |
588 | // Then of Course You Need to SaveToFlash |
589 | if ( USMC_SaveParametersToFlash ( cur_dev ) ) |
589 | if ( USMC_SaveParametersToFlash ( cur_dev ) ) |
590 | return TRUE; |
590 | return TRUE; |
591 | 591 | ||
592 | // Now You Can Unplug ME |
592 | // Now You Can Unplug ME |
593 | system ( "clear" ); |
593 | system ( "clear" ); |
594 | printf ( "\nThe Position \"%d\" is Saved to Flash\n", params.StartPos ); |
594 | printf ( "\nThe Position \"%d\" is Saved to Flash\n", params.StartPos ); |
595 | printf ( "\nWhen Controller is Powered Up Next Time\n" ); |
595 | printf ( "\nWhen Controller is Powered Up Next Time\n" ); |
596 | printf ( "\nIt Will Start From This Position\n" ); |
596 | printf ( "\nIt Will Start From This Position\n" ); |
597 | printf ( "\nPress any key to exit" ); |
597 | printf ( "\nPress any key to exit" ); |
598 | getchar (); |
598 | getchar (); |
599 | system ( "clear" ); |
599 | system ( "clear" ); |
600 | 600 | ||
601 | return FALSE; |
601 | return FALSE; |
602 | } |
602 | } |
603 | 603 | ||
604 | BOOL fs7_revert_sp_to_0 ( void ) |
604 | BOOL fs7_revert_sp_to_0 ( void ) |
605 | { |
605 | { |
606 | // Initialize structures (in case this function runs first) |
606 | // Initialize structures (in case this function runs first) |
607 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
607 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
608 | return TRUE; |
608 | return TRUE; |
609 | 609 | ||
610 | params.StartPos = 0; |
610 | params.StartPos = 0; |
611 | 611 | ||
612 | if ( USMC_SetParameters ( cur_dev, ¶ms ) ) |
612 | if ( USMC_SetParameters ( cur_dev, ¶ms ) ) |
613 | return TRUE; |
613 | return TRUE; |
614 | 614 | ||
615 | // Then of Course You Need to SaveToFlash |
615 | // Then of Course You Need to SaveToFlash |
616 | if ( USMC_SaveParametersToFlash ( cur_dev ) ) |
616 | if ( USMC_SaveParametersToFlash ( cur_dev ) ) |
617 | return TRUE; |
617 | return TRUE; |
618 | 618 | ||
619 | system ( "clear" ); |
619 | system ( "clear" ); |
620 | printf ( "\nStart Position is Reset to 0\n" ); |
620 | printf ( "\nStart Position is Reset to 0\n" ); |
621 | printf ( "\nPress any key to continue" ); |
621 | printf ( "\nPress any key to continue" ); |
622 | getchar (); |
622 | getchar (); |
623 | 623 | ||
624 | return FALSE; |
624 | return FALSE; |
625 | } |
625 | } |
626 | 626 | ||
627 | BOOL f8_get_enc_state ( void ) |
627 | BOOL f8_get_enc_state ( void ) |
628 | { |
628 | { |
629 | if ( USMC_GetEncoderState ( cur_dev, &enc_state ) ) |
629 | if ( USMC_GetEncoderState ( cur_dev, &enc_state ) ) |
630 | return TRUE; |
630 | return TRUE; |
631 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
631 | if ( USMC_GetParameters ( cur_dev, ¶ms ) ) |
632 | return TRUE; |
632 | return TRUE; |
633 | 633 | ||
634 | system ( "clear" ); |
634 | system ( "clear" ); |
635 | print_enc_state ( enc_state, params ); |
635 | print_enc_state ( enc_state, params ); |
636 | printf ( "\nPress any key to continue" ); |
636 | printf ( "\nPress any key to continue" ); |
637 | getchar (); |
637 | getchar (); |
638 | system ( "clear" ); |
638 | system ( "clear" ); |
639 | 639 | ||
640 | return FALSE; |
640 | return FALSE; |
641 | } |
641 | } |
642 | 642 | ||
643 | BOOL fp_change_power ( void ) |
643 | BOOL fp_change_power ( void ) |
644 | { |
644 | { |
645 | if ( USMC_GetMode ( cur_dev, &mode ) ) |
645 | if ( USMC_GetMode ( cur_dev, &mode ) ) |
646 | return TRUE; |
646 | return TRUE; |
647 | 647 | ||
648 | smpower = !smpower; |
648 | smpower = !smpower; |
649 | mode.ResetD = !smpower; |
649 | mode.ResetD = !smpower; |
650 | 650 | ||
651 | if ( USMC_SetMode ( cur_dev, &mode ) ) |
651 | if ( USMC_SetMode ( cur_dev, &mode ) ) |
652 | return TRUE; |
652 | return TRUE; |
653 | 653 | ||
654 | system ( "clear" ); |
654 | system ( "clear" ); |
655 | printf ( "Now, Power is %s\n", mode.ResetD ? "Off" : "On" ); |
655 | printf ( "Now, Power is %s\n", mode.ResetD ? "Off" : "On" ); |
656 | 656 | ||
657 | return FALSE; |
657 | return FALSE; |
658 | } |
658 | } |
659 | 659 |