|
7#
樓主 |
發(fā)表于 2014-5-10 09:55:02
|
只看該作者
// our point structure to make things nice.
p/ Y; H8 i. W! o! M9 L3 ]9 Tstruct LongPoint {
" d6 Z, E$ @/ ] p9 x long x;
( M$ N" T; ~ ~& d% Q long y;
! [9 W$ k3 @- x; E! j% o long z;
- |) o2 a' D. i5 c& o long u;3 ~+ N. [; a1 G a* x
};
7 l1 M; z' R. n2 w$ E# p; J8 o8 L% W6 \# T4 X. c
struct FloatPoint {
2 |8 r- e5 c# ^# W6 G9 }7 ?+ V float x;
7 l: g" Y- J ?4 P0 J float y;
5 G# }+ X) `# Q; ^: g7 C float z;
5 p! B0 a) d! r3 x& ?) [/ ]" ~$ P float u;
& E% L: n O% d2 x) ?' }};
+ A4 ]" q& m7 {. I6 u
& f5 A* s6 V' T* @! kFloatPoint current_units;, j- l+ _1 g( g U+ p* B
FloatPoint target_units;0 R6 L4 p1 V2 M, g* w7 T2 n
FloatPoint delta_units;
0 X# m/ ~8 n/ c: M$ S. `) M# X- f1 n0 ^3 f- D2 L# [: _$ K
FloatPoint current_steps;
: W' G2 w: u& ]; kFloatPoint target_steps;1 m) \ o4 }0 B4 L& k
FloatPoint delta_steps;6 Q; O! } O- t' b
: d5 @, x" P* cboolean abs_mode = false; //0 = 增量位置模式; 1 = 絕對位置模式
! A* Q6 |/ W! I4 d8 h' M' l" U# @5 X9 @# }* e
//default to inches for units0 L% a7 Y' I# j% ^ v6 r# U! b
float x_units = X_STEPS_PER_INCH;
$ M& X# M) f }float y_units = Y_STEPS_PER_INCH;2 x' E$ p) c% a |) A* ]
float z_units = Z_STEPS_PER_INCH;
5 v2 v/ {$ m# ]& g O2 ]' }, ufloat u_units = U_STEPS_PER_INCH;
- B- s5 i+ k. g8 b! `% y rfloat curve_section = CURVE_SECTION_INCHES;
3 H) T0 v9 h6 F% Y0 B
# B; v+ T# b& r+ O% z% W//our direction vars
& G: ^/ |$ a0 u% Nbyte x_direction = 1;3 ?! Y( F }) N$ @
byte y_direction = 1;
6 l* f- a ^4 p1 L2 ubyte z_direction = 1;
! A2 r6 s6 I0 Tbyte u_direction = 1;# U& Z: Q( g+ U8 _0 x6 c' P7 F0 ^% Z( K
( L5 L! z: B2 D! r; Z
//初始化字符串處理 _. ^/ k2 l# Z
void init_process_string()
. q: C/ _1 ^6 q8 c( Q{8 V# } `1 f, S% g' W" t& t# X
//init our command
! d: V4 R; n: `2 v, l for (byte i=0; i<COMMAND_SIZE; i++). q9 i& U! W, L* k* d' E H8 l
word_old[i] = 0;
- }5 D1 m" Y- }( S: _! g0 l$ g! a serial_count = 0;
; ]% p' @" U/ A8 C1 X2 j, C+ `: q( a}3 n7 i6 _& x: @ l- }6 ~* u) Y' q
$ l8 ~4 M7 V; J1 Q% Y, I+ h
//our feedrate variables.& t F7 S% Q$ y" D
float feedrate = 0.0;
5 X3 ~! Y1 J% W* A+ [long feedrate_micros = 0;/ z r0 H' S4 N7 K4 J
, J. i3 |4 P, ?& u, P//讀取并執(zhí)行命令
4 H: U) p3 [! X/ W9 m2 \' ]+ Avoid process_string(char instruction[], int size)
% l' G* _. U. z1 l% N& m) t1 R& j& P{0 f, V" s' }/ [) n% y
//the character / means delete block... used for comments and stuff.1 A) p1 i5 ]& [+ c
if (instruction[0] == '/')
- ?) Z6 @. b0 B8 ?* c {
) ?0 |3 S5 [7 i. b. }- A // SerialUSB.print("ok");$ |0 a+ m: Y% T; H4 P! Q
// SerialUSB.print(byte(78));
+ t" ~/ ?+ R" o7 M" T, Q8 z return;
1 G, E: _- _" a P9 r! `7 V0 s! k* ` }- ]7 {9 ~) I* g: r
//init baby!
M; s' J5 @7 r0 M, r7 u- w5 s FloatPoint fp;
& m; f9 I1 Z" t% K! e/ K fp.x = 0.0;! ?) @2 x$ M( v6 ~7 a4 |
fp.y = 0.0;
- H3 s! R' ^% J5 k- c0 k4 s5 s fp.z = 0.0;7 ~- u; s: Y% A
fp.u = 0.0;! r! @+ j+ c' Y. F1 e( L
: J5 h9 s+ C9 z% |& I) I
byte code = 0;0 j7 n, z: `0 S% u _5 ^
- Q) w ~0 E6 q% i" m! T8 x* l: ^
//顯示在處理的命令/ L* v: w6 \& r1 E C0 V
#if (LCD_TYPE == 1604 )
) T/ Z; Z' `2 W1 z4 C6 A // lcd.setCursor(0, 4);" K# z# J0 S- F" ]' W
// lcd.print(word_old);
) F7 N9 C# Q% _. F2 w0 q#endif' S; ~- b; E0 F7 {
SerialUSB.println();* p- j A5 E k% f- k" u, \* L
SerialUSB.print(instruction);
8 {* {. B3 U6 }% N, {' K' }. p4 l/ y SerialUSB.print("\t");
9 a, ?3 u0 D8 q) z# W% Z; H" l# ~, U
//what line are we at?2 n: V, G/ Q! c6 U# Y
// long line = -1;8 q, Q& ^# g }7 {
// if (has_command('N', instruction, size)), I5 x v3 i- X: [7 z- r
// line = (long)search_string('N', instruction, size);5 O' S& |0 R( d p
4 G4 Z- H& u6 }9 J, L
/*' H1 i* N' }0 }" E( w6 G
Serial.print("line: "); u6 r7 n E: H2 Y+ h" E
Serial.println(line);
; ?5 Q9 B9 ~! V: V: {, F Serial.println(instruction);
$ r4 S; c' k( x# Z */# D8 ]* L4 J8 b" f
//判斷是否讀取了個 G代碼?: X. l( W$ G3 Z0 q' |
if (
q' h. ?) ]( Z' z+ m- A: b has_command('G', instruction, size) ||
s; ?, {7 t9 n4 H! x8 E! C+ a has_command('X', instruction, size) ||" Q; k7 \1 \: a+ P; |
has_command('Y', instruction, size) ||
7 A5 h4 c" }, L* d+ p% O Y has_command('Z', instruction, size) ||
0 x% r2 n, S ?, k has_command('U', instruction, size)
4 u" W. y9 w, z2 {+ m )6 l9 i0 W; T" Z: K K' s# x
{
: q: X8 s4 u- j* O7 e# Q //which one?5 l/ \8 ^- I: v9 E( M
code = (int)search_string('G', instruction, size);
7 t4 r2 e4 T' ~ X, g. e // Get co-ordinates if required by the code type given. h- P) h) A! S* ^- N
switch (code)
8 i$ j7 j, _4 } Z" w {
( }1 o7 } n3 K! X ^ case 0:
! u! v- e. m; P case 1:" Z# E! X$ b& d+ U5 L
case 2:
( w( g& y& Z3 s case 3:; k- X: `% [# u: q( O. Q% w
if(abs_mode)( E; k8 _* o% a: D. g
{
3 n6 \) p3 c; J' a( \. x, d9 ` //we do it like this to save time. makes curves better.
, M; n8 B# y- l- {# F //eg. if only x and y are specified, we dont have to waste time looking up z.
. r9 x+ V8 z/ C `2 U6 N Z if (has_command('X', instruction, size)); N, x8 F! \% d$ k
fp.x = search_string('X', instruction, size);
# l: c+ e) `3 r; {, e% m+ o: t else# c! i# v) u. ]- b+ ?9 v
fp.x = current_units.x;
5 _0 M+ }/ P& p1 v% c
$ s }" m- K# i( _1 X if (has_command('Y', instruction, size))# a* R, h2 M. ]7 F! p" z# n/ \
fp.y = search_string('Y', instruction, size);
3 x& Z) b. j$ I else
/ O( z2 _2 w8 q& |$ g& H: W4 D fp.y = current_units.y;
, r* i+ d' W/ x. I" G/ T# K2 Y7 ~4 {1 s. \+ k
if (has_command('Z', instruction, size))
3 k; e! V& t; [2 }0 e; w" n fp.z = search_string('Z', instruction, size);
* z1 b8 j7 R3 l! ^5 { else
) R: f, W" K4 |: U0 ^# ? v1 W* e fp.z = current_units.z;- _2 d& _& r* V$ _: T
6 K* W- _- E# W: u8 E
if (has_command('U', instruction, size)): ?4 \9 w* V% F. X _4 u
fp.u = search_string('U', instruction, size);
. }/ g* J" T% G- f( I4 p( A7 ~ else( ~( J. {1 M" \3 W( Y- Q
fp.u = current_units.u;
. ^2 p8 x& C7 ?: @ Y0 V3 a }& E5 x. k$ e5 P; ^4 Y. k. n
else! }( x7 M( o y" u4 p
{
) |: [% g7 [0 } fp.x = search_string('X', instruction, size) + current_units.x;% e) G" H K+ o& H- q8 V* Y% {
fp.y = search_string('Y', instruction, size) + current_units.y;. w5 o1 A' }: H. C
fp.z = search_string('Z', instruction, size) + current_units.z;, W! B9 e4 z; v6 {
fp.u = search_string('U', instruction, size) + current_units.u;+ Z2 ]6 Z- e0 e7 ]
}
; v5 ~! f7 f9 h% y# t$ P/ _ break;
, X4 z' x5 L" w7 r }; L/ k5 ~. N# _! m
//do something!+ i% q( d3 m' M* g1 b0 [5 d4 ]+ O
switch (code)% E& o& c& ]. w! u! a9 S0 F% n; ?
{
5 _+ f: l4 u/ {: Y! p //Rapid Positioning
, |. R; A: f0 o( V/ t //Linear Interpolation( |- a) {, a6 z
//these are basically the same thing.
+ P6 T: X9 D: m( y8 w$ k case 0:
% ^) ~2 g& ~- e3 a9 G; s+ ? case 1:# V/ W# A. J8 }4 T+ T/ ]
//set our target.- r: D% w% L i
set_target(fp.x, fp.y, fp.z, fp.u);
/ |# i+ h$ A7 f9 C //set_targeta( fp.a);
; _- {6 O) O N0 d- }- e! R2 S* d //do we have a set speed?
# K2 l; _: i+ b3 C1 @; h if (has_command('G', instruction, size)) F$ k- v" e# A# e" ^( R
{
9 ]0 y8 d& p+ q //adjust if we have a specific feedrate.
! Y: A \& a/ \' M) E1 h5 U6 r6 j3 y if (code == 1)6 `$ ]9 `. W9 u# c
{8 K3 W* ~0 B3 E3 @7 G H
//how fast do we move?
5 x) v6 Q3 N1 W8 ]8 T1 t% Q feedrate = search_string('F', instruction, size);
: }6 w! W6 A% j if (feedrate > 0)
) h7 r9 o0 ^5 j3 t feedrate_micros = calculate_feedrate_delay(feedrate);
) Q9 c4 a o: a# ]! F" S! b //nope, no feedrate
d# d6 r4 {. Y% I$ O; t" @ else
: L2 c# H0 [4 k/ T u* _8 j# E feedrate_micros = getMaxSpeed();9 o. N6 X+ e5 o/ n! T
}' X3 t+ p3 N+ Y1 o, M/ `: x8 m
//use our max for normal moves.- y9 W5 a' m9 y. A. J
else
$ D0 H4 ]0 j2 A feedrate_micros = getMaxSpeed();
1 s0 z* c4 q; E, W4 K }
) i! z1 W. p, Q9 B //nope, just coordinates!$ u# t5 r/ d/ ?
else
) s5 Y& Z1 ^$ i* z5 @1 e- ~/ i {
% Z1 p" n& V5 s1 R+ ~- G //do we have a feedrate yet?% t! S# }# s# V0 [: c2 v* q
if (feedrate > 0)
( h4 X8 u0 X8 u% d1 v feedrate_micros = calculate_feedrate_delay(feedrate);
2 G: K6 o) m; g0 q! d: O; `. l //nope, no feedrate V+ X3 d2 h. o! n- s
else
+ W" O' g5 Z4 O* g feedrate_micros = getMaxSpeed();
0 H: J0 L# n& b }, f$ m* J% y% V& b
' P C! O* W2 }; l: S& [; F0 C. O
//finally move.- [) d {5 \. g2 ]/ `1 o. V1 g
dda_move(feedrate_micros);5 }% M# {) B& q9 | h
if(stop_flag) return;
6 q' \" H; N, j9 Y break;* b; E$ d% ?5 ~1 c8 B7 {
" Y& o" B( G$ L, k
//Clockwise arc
- K6 ]' u% h7 Q( I9 ] case 2:8 W* V( i [" ~% e! `. G5 r
//Counterclockwise arc
0 I" { R3 H6 T! Q3 Y2 [ case 3:
/ W1 [4 p" M- ~: r4 x FloatPoint cent;1 N. h# `/ A8 E/ X% e3 k7 |
// Centre coordinates are always relative$ ]+ v1 ~8 _1 f4 \2 T" }; m
cent.x = search_string('I', instruction, size) + current_units.x;
) J( q% ?) |! H& {9 Z cent.y = search_string('J', instruction, size) + current_units.y;
9 k2 b0 j5 W: H( `3 G$ d) L float angleA, angleB, angle, radius, length, aX, aY, bX, bY;
6 v2 t7 H9 L& b$ \7 z" P& l0 W" _+ @; G& d! [" y0 _4 ?7 g- Z; k
aX = (current_units.x - cent.x);
1 `. ?: T+ G+ ?0 l aY = (current_units.y - cent.y); K9 D% s6 F& g( f! Q
bX = (fp.x - cent.x);
: h7 s& f: o; i5 _5 C* T bY = (fp.y - cent.y);
7 b. b+ u$ z8 D' ~7 s
( T0 ^- d6 T! K6 }1 ~ if (code == 2) { // Clockwise
0 c1 W' }! H5 Q9 ]" e angleA = atan2(bY, bX);5 g# u( O; y- ?; C
angleB = atan2(aY, aX);% @/ l* a* b$ Y" t3 x
} - d" N, g4 x- B+ c: U1 \5 j
else { // Counterclockwise
7 N: A' f& {4 P2 M2 W$ T( w angleA = atan2(aY, aX);
! O$ u; _. V) ? Q% }# i angleB = atan2(bY, bX);
$ N( e3 k6 n- |# p; r }$ c' g9 l# }8 L! q
// Make sure angleB is always greater than angleA. c6 w) X% q2 S. ~6 d9 |3 ?5 P
// and if not add 2PI so that it is (this also takes
2 s) [' J! {, D& K // care of the special case of angleA == angleB,, r l" a. R0 k8 O; w
// ie we want a complete circle)- N3 \. a- P- p; M1 u9 }" q' o' ^ k2 \
if (angleB <= angleA) angleB += 2 * M_PI;
0 n+ a9 `' L: E, N' T angle = angleB - angleA;
' d3 [/ b! n+ n. s+ M* t# o2 c" W2 k
radius = sqrt(aX * aX + aY * aY);. O I; ^' x$ W E! I
length = radius * angle;
8 w5 g3 \# L5 L7 i' a, B9 l int steps, s, step;
+ x4 Y5 @5 ?: \/ s; X* ?) t steps = (int) ceil(length / curve_section);0 h9 V& R% G) e; e
7 s. s8 a b8 ] d! i FloatPoint newPoint;* g0 e3 w0 E1 u
for (s = 1; s <= steps; s++) {+ x/ f6 f, C3 f
step = (code == 3) ? s : steps - s; // Work backwards for CW- b. `) r, C- }; J5 K
newPoint.x = cent.x + radius * cos(angleA + angle * ((float) step / steps));
, Q. w" P7 G+ g newPoint.y = cent.y + radius * sin(angleA + angle * ((float) step / steps));
, @/ _1 j7 n% ^' U' s0 M set_target(newPoint.x, newPoint.y, fp.z, fp.u);! ?) z, n8 s' w! M. }
$ F4 O. i1 @- u" Q- m C9 h" t* K8 E* I // Need to calculate rate for each section of curve. _0 S6 {# p# u* b
if (feedrate > 0)- Q, _ X8 N8 S
feedrate_micros = calculate_feedrate_delay(feedrate);
* Z6 }+ M, @7 w: W% h9 |6 o else: T- S0 J( L# F2 h1 C
feedrate_micros = getMaxSpeed();( }$ R! y6 I) m8 {
" }( Z' r* V7 w/ Z( e {& b* f
// Make step
+ b' W& d" \- I dda_move(feedrate_micros);
6 C o% w5 b, m, F- U. F if(stop_flag) return;1 k9 R* `+ Q7 v2 R$ E! {3 E% j+ T
}
% i1 Q/ {) D6 V5 w' {% k
# {' L6 [7 f7 F g9 j/ D break;
; U1 Y& x/ s& E1 A* E
. O" B$ n+ F2 s" U, n1 T //Dwell4 ], i" i1 i8 K4 s( t. N
case 4:9 f( q e( Y& ]% B/ Q4 w
delay((int)search_string('P', instruction, size));" O- C' n# L) l. O( B
break;
3 ^3 m+ o, _$ D# y0 F" i0 r) s
H3 } q& n) H, k- q //Inches for Units
8 l% }- D, z( h; [$ f case 20:; E5 q; s: P0 B4 p
x_units = X_STEPS_PER_INCH;
( t) q e; f! `6 W y_units = Y_STEPS_PER_INCH;. C' \3 |/ V G# p
z_units = Z_STEPS_PER_INCH;
. j* {' Q' U0 p8 J7 {3 L u_units = U_STEPS_PER_INCH;
5 D& f. D3 ^- x1 Y6 u# D/ h curve_section = CURVE_SECTION_INCHES;, m8 _' ~; b/ K& \; }
calculate_deltas();
+ Y0 e/ e) G; _ b# g7 L1 d break;
, y5 ^: y7 [! Y! N" i# l) q. d9 I: [0 P+ G3 l; o3 @% c# n E
//mm for Units
9 C# \0 \% O6 i# a+ E case 21:% |% C5 r6 x$ o( Z0 [
x_units = X_STEPS_PER_MM;1 n8 d+ M1 F# \# J- O4 J
y_units = Y_STEPS_PER_MM;
0 h9 A" Q( @; i; h( l+ E0 l z_units = Z_STEPS_PER_MM;1 a' m7 p* o2 V9 d# E# p
u_units = U_STEPS_PER_MM;; j9 v( Y4 ]' u( N' R. |% A7 Y
curve_section = CURVE_SECTION_MM;
0 j5 d' B- `5 M- ^ \' j calculate_deltas();6 b5 K1 \* Z# q K5 C# V& B
break;
+ i# f! N: o A7 w# L: H/ \) O4 C- F) A
//go home.$ ?4 Z' R9 ^3 _- ~
case 28:
8 J4 q: q( J# c |0 u5 H set_target(0.0, 0.0, 0.0, 0.0);% {' @3 A+ [- c7 @$ f" _2 W" K! J% b
dda_move(getMaxSpeed());/ `# f% p3 |. b, y" b# O( c" C
if(stop_flag) return;4 f* l7 w, F( Y" }/ o8 o4 M
break;7 \$ T, l6 I: z% l$ y& o
* j! x; l/ K, d* s* e
//go home via an intermediate point.9 N, `/ |- d/ D+ y3 I0 U9 l3 |
case 30:' m4 k' c) o! v/ a7 O
fp.x = search_string('X', instruction, size);9 d+ Y3 a" S _
fp.y = search_string('Y', instruction, size);9 p5 R0 @: c8 ?2 O+ s$ l" d9 i
fp.z = search_string('Z', instruction, size);
. q! G1 m0 l2 w) a* h7 t fp.u = search_string('U', instruction, size);
7 P9 {. U$ ] I0 u% I //set our target.5 T: \- _3 S/ _
if(abs_mode)* z1 R8 [: E' p0 C" h2 a3 N
{
& m2 E& B+ Y; u+ `7 [9 U if (!has_command('X', instruction, size))
% m- M" K9 x2 R. k2 ~6 D fp.x = current_units.x;6 z( E6 \- c: n- i$ c P
if (!has_command('Y', instruction, size))( ?! m4 H( [ H# T q |
fp.y = current_units.y;! b; h ]: t/ Q' k" {
if (!has_command('Z', instruction, size)); x' [0 W0 r# L+ X
fp.z = current_units.z;0 h ^ R! b4 Q n# O8 @7 E) ?
if (!has_command('U', instruction, size))
! u/ z. L5 |, [ fp.u = current_units.u;
4 x3 o! o) y4 F, F6 c+ \: ^ set_target(fp.x, fp.y, fp.z, fp.u);" e8 P. a: H+ b3 F
+ n5 ^9 l# C+ O7 |- Q9 S }- \6 u5 q* a0 a3 w+ N! G4 M& ?9 V+ y
else* k5 k$ ~9 l% [; D
set_target(current_units.x + fp.x, current_units.y + fp.y, current_units.z + fp.z, current_units.u + fp.u );2 `$ A( S" y7 v' \- d! x; @9 N2 _
+ j" Q6 U# w' a7 K3 Z3 L( L //go there.3 [6 l- V: M+ f: e$ D( r+ ^
dda_move(getMaxSpeed());
+ b. t% _; @8 b3 H& ] if(stop_flag) return;
& _1 d6 ^$ S* z3 X. V3 g0 j8 e& e$ a
3 w# T9 @9 k8 P+ x5 \& F //go home., B8 L6 n9 a! h* } y
set_target(0.0, 0.0, 0.0, 0.0 );
: {, c. x2 U9 [3 X5 E% c; w
4 I/ y: w% T/ B$ T: B. ] dda_move(getMaxSpeed());
( l0 T" O: ~ L) A if(stop_flag) return;5 A- `/ x! @/ e5 k' @; O
break;
9 w3 I. A: d/ T* B: J, H! W$ y9 J" c! F9 j
//Absolute Positioning: R8 G* R6 s+ u; D d
case 90:
6 @9 ?8 I* @4 } abs_mode = true;
) J+ o9 o+ j1 [7 T. e- H) v break;# e4 X$ M/ {" Y+ q9 s
8 z. m8 e* o" Y4 X2 F3 M5 S' @ //Incremental Positioning
3 g7 I; U/ T$ t; L M$ `) v u case 91:8 f* l1 M8 X8 f7 I% ^/ X
abs_mode = false;- T3 g+ u- N8 R) }# N3 I
break;
% @9 i- ~ _! g0 X6 @. y/ }1 C3 E- G& L% u
//Set as home
. h7 U' z) E7 j' A' Z case 92:# R. d: g2 e" {6 a0 m
9 [4 u. N8 g" Y$ ~/ `* `2 O
set_position(0.0, 0.0, 0.0, 0.0 );+ E* T; l, t) ^# m' j
; }; L w: H! V+ w1 w
break;
( D4 d+ s" H( {9 h7 Z2 ~2 s- c
1 `7 `, G! k" a) ~; D. {9 T /*
; Y1 ~4 w, s$ X //Inverse Time Feed Mode. ]3 R& a& W# i* v( U
case 93:
3 l! C6 N" A& o* ] * p y- ~. Y$ ]* \. x9 E- [, n+ H
break; //TODO: add this0 p1 q3 e& i/ C6 ~. B2 X8 Z
* C) T' ~# T& N3 y, d
//Feed per Minute Mode( q! `0 K! j" C6 `
case 94:- A; k8 }9 @( X+ b1 O& Z e
4 t, V0 r5 d* V& n break; //TODO: add this1 S0 U! \- S4 s0 u1 j }6 e4 g
*/
& {. i! P2 @6 C2 q! M- ^& t
- q. I C4 n/ v& u. f3 [% G7 D default:2 P' d3 q4 r v j1 |& m/ N
SerialUSB.print("huh? G");- a( c n. d' t( f* @* J# @
SerialUSB.println(code,DEC);9 T' C! X# p! t8 p
}
& A) |4 p" M4 u+ u9 b4 w7 W5 D }
{9 @% q: d7 V6 I* p! i) r; S, h% {& b) m9 |2 s; s) I
//find us an m code.
- B E8 a5 \9 m+ T/ @! ` if (has_command('M', instruction, size))& {' k* f9 Z4 @1 A
{1 o0 }/ |7 D& v& ~$ [4 f# a
code = search_string('M', instruction, size);
5 x# i0 b7 S6 I3 c switch (code)
# [, V+ ~8 P2 r: p {. @5 n b3 V' D0 }
//TODO: this is a bug because search_string returns 0. gotta fix that.
9 P$ k& v1 n- i2 B/ O" @ case 0:
/ m- B1 l" | |0 q) \5 F; ~ true;
. g' ]* Y; L) c$ m break;
' p2 E" t' z# T" ~0 I' a6 T. Y u3 B4 f& N
case 100:
) z% z1 D) @' @0 \8 y break;+ {9 G8 Q$ X+ j! C
% H$ w7 A* r7 J3 J" ~9 w: G
// fire camera relay
, i3 A( G- S& Z4 K case 101:
1 z. w4 s0 p$ H+ \) j camera_shutter1();
5 i/ X* j; j5 r break;! R0 j5 Y/ M% ?5 I
?1 s& o2 P% O. v
// fire camera relay2
, `" x( U5 ^7 Q: o0 Y case 102:$ t+ d+ S2 j- U" Y7 n* i
camera_shutter2();
* K4 X! X* ~( ]7 t- k! j break;9 @" s8 A( H. Z1 H
/*
2 E8 O) A9 [$ D; `0 Y // turn aux 1 relay on
8 O$ w$ C6 i) z3 t case 103:
: j+ |0 A$ p; m1 o& t+ ]& G& G camera_aux1_on();
6 G3 ^% i) P; ]; v% R, i break;# r- x: {# F, i
1 G; k0 R9 }# _. b$ E
// turn aux 1 relay off
3 S3 j' z2 @: s& t+ s: ? case 104:; m7 V' d5 X) r `
camera_aux1_off();& C5 b, }7 A6 {
break;
7 i- v9 H) H4 L
: d7 x* W7 @5 G // turn aux 2 relay on$ r, |3 z, Y6 K$ _3 _# o
case 105:
, D3 ^4 q# ~( z8 h$ t* B camera_aux2_on();: b% v8 H/ E9 ^' L/ h0 @1 J! z8 }
break;! \1 A! T! O( L7 B
0 j( p7 q# w# f3 b. p1 H // turn aux 2 relay off' d0 S: B* }- b, K! {
case 106:5 q: s3 `: T1 F, @, |, a
camera_aux2_off();- A% `: @8 L0 ]
break;
, w! C2 S1 L1 L4 w. D2 P a. m1 H* T3 M
// turn aux 3 relay on, t. P# _6 _9 j8 `' ^, v# c
case 107:' w, z; M4 L# `# l6 P0 k5 m
camera_aux3_on();
& b/ `) v5 P+ P5 E" |6 w break;" o) z# o8 Y$ T) t" T
" L1 A; o: r$ u1 w, A- I
// turn aux 3 relay off! P) p+ ^! S$ q$ u
case 108:$ ~2 r$ U6 }$ D' G. r% o
camera_aux3_off();
9 F0 P" e( V% ] break;
) C* u& o: N2 b/ g7 Q7 v
% Q/ l6 L4 D$ B: t; a1 x$ F // turn aux 4 relay on
" Z; M7 f, c& z4 [' e' X7 P case 109:
) [/ S0 s" }2 M) l, b4 K8 O camera_aux4_on();; j5 m" w! q! u, [
break;/ p: s6 \# p1 E! r+ o9 o' i: a7 ]' p
6 V. v' Q0 Q, }) Z* D // turn aux 4 relay off
( d$ z9 L3 t" L5 P+ B case 110:5 K+ @( |6 ^" w. y3 i
camera_aux4_off();
. S2 x! B$ p+ T( ? break;
0 R4 x+ r2 u2 c8 t*/8 m$ T2 h0 C+ w9 S
default:
* L6 A+ p; W2 q4 z# ^7 e) p# w
w1 p1 i% G. | f: H+ a* K SerialUSB.print("Huh? M");% g1 J8 N2 l, H- c
SerialUSB.println(code);
& ]' y- a# x7 G0 n2 l3 }! f }7 C4 u `) Z) B8 d
}
3 A6 }+ m- g" v( G: m$ s f3 R8 B$ r! F+ e! Q V
//tell our host we're done.$ e8 R4 i8 S3 r, H& d) L
SerialUSB.print(byte(78));
1 y( ~# O( m* v( J: J7 ^! |& ]* }8 X) Y9 q n/ B
}8 D+ f0 Y) G: S! \; g# R- p
4 x& G( m T& k. \//look for the number that appears after the char key and return it. D* }: G6 C3 m! b6 _3 L# M
double search_string(char key, char instruction[], int string_size)
' V% Y0 W5 u( R" }1 Y{# Z0 j! x1 @7 R3 ?' \6 U* q
char temp[10] = " ";
* T8 Z' S5 L0 T; q5 I for (byte i=0; i<string_size; i++)
+ f7 t7 S+ {% X) G6 R {; S3 K+ H( ?0 t' m
if (instruction[i] == key)3 r6 J" @; h" D2 `# O
{
2 Z; v* g: [8 {' a. x9 F i++;
4 f( R" u9 n' w- x) H- M int k = 0;
O# H, Y' J4 w. s. W/ a* ~; e' m while (i < string_size && k < 10)
+ |$ C2 _# q/ [2 ] {
" a. {" B9 p' b% L# v7 x* ^# P6 i if (instruction[i] == 0 || instruction[i] == ' ')& g' b1 @2 l- g3 w5 J* ]. _
break;( k* u+ @0 m7 g/ s4 d
: P& }" p" n5 x) C
temp[k] = instruction[i];3 y0 W. N% z5 J8 M: z
i++;( a: E# Y1 @- Y4 @* T
k++;7 n u4 W& l0 H" w$ g
}8 i" x8 M) s: J- s4 A4 h% n0 s
return strtod(temp, NULL);
8 Q" L9 \9 B6 V6 |. W+ b }% h& e& j# L% j- ~0 v5 b
}) Q+ C* y- E/ D4 w5 j ]! u
" `' f$ l+ u4 \; [1 f$ x return 0;/ a* K5 C+ J' u: X) c- X. j' h
}0 z. S5 m& T% a6 D0 _ D
) `7 F8 N$ G% ~8 c3 h, _$ `) Q
//look for the command if it exists.. t8 V" [' K! r' ~: o
bool has_command(char key, char instruction[], int string_size)
$ ^# g# L9 e( x7 X6 k+ O! @; I{4 O- Q0 q9 {- w7 L; H" o: R r+ }
for (byte i=0; i<string_size; i++)
* Q7 J+ C$ K+ Q7 |; w {1 M5 Y: X& J; J4 V
if (instruction[i] == key){
6 l! k, ~( r' p! d. R A" m# j9 e' D$ x2 y% V* W
return true;
) q- b% N! j- c }! P, }+ E; `( p2 D) Q
}1 V; Y2 _, V5 ^0 }9 e
4 j1 [4 M5 `" m( V: k+ i
return false;8 `" Q) w: B8 k2 W! D
}
" V3 s' ^/ \; r+ D" ?5 e! n Y- ^. d. E, ]) [7 ^# Y
, M& \/ B6 |0 B$ b) | |
+ ?4 j% N$ r, e! ?( n
|
|