( D6 E5 V2 q s9 \: S8 w- |void camera_aux4_on(), }* B5 a( `% l. ]- x2 R! X9 Q& R
{) a9 V1 i5 U4 d* L8 i8 P0 g. c( o
// turn aux relay 4 on % {3 @) t+ \& d0 l! }% L' l, _ digitalWrite(CAM_AUX_PIN4, HIGH); # k9 {+ H# @) [( [" i}' h# y5 c5 [! y7 D- M8 [, K1 w
: P/ |6 i" R0 I! @3 j# x; i
void camera_aux4_off()$ A2 V+ y) l. p0 n
{4 n. {" z1 \5 o9 F6 ^) B- T% v) |6 [
// turn aux relay 4 off $ `" {# _ A+ S0 t digitalWrite(CAM_AUX_PIN4, LOW);9 Q& i5 M. i4 f" }/ o: L, x; L
}作者: luxiang821 時(shí)間: 2014-5-10 09:54
樓主推薦的網(wǎng)址不錯(cuò)7 k' ^8 k+ D% B0 S
請(qǐng)問樓主是玩什么的,用樂高玩具嗎?作者: xmdesign 時(shí)間: 2014-5-10 09:55
// our point structure to make things nice.9 X0 }9 [/ ^% U- ?( i$ W6 X
struct LongPoint { : p" @0 H+ z! Y V- W! A# U8 W$ i long x;/ a# j/ E( _, J! b
long y; / C5 W* I5 I) [7 P9 y% p long z; 7 o4 ^5 R+ e( v! |- F5 {- x long u; 8 k+ w$ W& Z' l) I}; " a- |9 {1 }. D3 Q7 E2 O5 g% O+ L 8 ~1 X* J7 X9 M% |* D* Lstruct FloatPoint { ! D! c6 r$ Z; g) J( @( t float x; ) Z# J. B8 A! Q& h$ ?& e m6 ` float y; & z% x+ T. m0 r. ~7 d; | float z;2 b% X; i7 t4 l8 j1 Q1 _& z
float u; , `+ e% O0 a* ~) i* l};6 a5 v7 _ W9 ?% h% c1 q. m* t" v- `3 c0 @
: P; B b$ s( }FloatPoint current_units;) G! d6 e! s! n# |
FloatPoint target_units;: N7 m' @# i5 m; [4 h" Y) W
FloatPoint delta_units; ! B0 z1 f Y; Q# @ a; A; h! A5 Q9 x
FloatPoint current_steps; 0 y- R! M4 i' V9 CFloatPoint target_steps; + D, E- k( h. e$ o# ~4 k0 f' HFloatPoint delta_steps; # X; g3 ?; ]) t$ L+ d# ]1 k. G! H8 o* z" ~, [4 d/ i% N. u8 G
boolean abs_mode = false; //0 = 增量位置模式; 1 = 絕對(duì)位置模式& E3 p# [3 V/ z; q: ?
2 B N! w, W6 i- S//default to inches for units * t3 y- M: e1 C2 x' g& yfloat x_units = X_STEPS_PER_INCH;) d" r! ?* N! J1 W3 r5 t# T
float y_units = Y_STEPS_PER_INCH;% \. Y* G1 M" i. m0 g
float z_units = Z_STEPS_PER_INCH; ! O" g+ k- ~! `. Zfloat u_units = U_STEPS_PER_INCH; & ~2 |% u, F$ Rfloat curve_section = CURVE_SECTION_INCHES; * y- o0 m" O1 M5 y* d - Z8 s8 S4 I$ ] ~//our direction vars+ j( v; O) Q$ Z/ |) r
byte x_direction = 1;6 p8 j3 U, E, C9 k: b+ j
byte y_direction = 1; : G- {" V" s4 N9 Nbyte z_direction = 1; - P/ ?; u4 h' {: mbyte u_direction = 1; ! `! o a1 ]6 v6 O ) V0 u; ]" n' y2 ^# ?//初始化字符串處理9 s X$ V& y; B3 k6 \' B! B
void init_process_string()' v' Q- u7 w1 q
{( t3 z l0 t8 M( Q# e5 V
//init our command3 N k( V+ ]7 |7 [' l' ?6 V: a0 l
for (byte i=0; i<COMMAND_SIZE; i++)' M' F' P7 w& `; {3 b
word_old[i] = 0;2 Z7 ^" D" O! F( b5 r, _
serial_count = 0;& _) }" N# D5 i5 Q1 H" b/ e; D( M, k
} / i6 c, i6 ?! W2 `" P, J6 v , e3 P/ F' j# N4 s$ y//our feedrate variables.% j; w7 \, |0 R3 z. j7 N7 {
float feedrate = 0.0; F+ i; _3 q6 W* X
long feedrate_micros = 0; - K6 x9 A6 ` b- g9 } G$ H2 G, [: B7 P6 D
//讀取并執(zhí)行命令 $ H. T' G6 |& Y" Y) p. svoid process_string(char instruction[], int size) 3 l9 b: C$ d4 B{2 V1 [# g5 f1 S5 g: T5 q2 Z# S2 ]
//the character / means delete block... used for comments and stuff. " V* a- ?5 \1 L/ T7 ^" L if (instruction[0] == '/') / Z0 {, Z3 L+ A6 a2 _ {% c/ E ?) k7 K; f: Q$ u
// SerialUSB.print("ok");. o; j& e7 e2 D
// SerialUSB.print(byte(78)); : n5 H1 I7 M) O' W" n2 W! x8 b return;7 E6 ^- V/ ^* t8 Q) l
}" _' ^. l: m& j: T8 k. c
//init baby! - H- P7 [- `8 M* ]! b! z& Z" c FloatPoint fp;, H [' V8 e4 P# D. b% ~* z
fp.x = 0.0; 7 N; ?7 \: h% x& K fp.y = 0.0;/ C! i& T9 Z4 n C
fp.z = 0.0;! F: ^9 K/ h3 }5 j3 D# c
fp.u = 0.0;6 E; N& C; X- j* y8 \( l. O
+ _) u6 j) c& n8 p: D
byte code = 0;' e5 j A: ~3 i
7 d& @, H. z D& o3 [- S //顯示在處理的命令 & Z" B( W# X; [* o4 o#if (LCD_TYPE == 1604 ), G, N' i3 k& L+ K, O
// lcd.setCursor(0, 4);+ p4 U. z9 @" `, t& H" t, c
// lcd.print(word_old); ; y: n) ]: i G/ {6 I: i+ [+ t- v4 v0 c#endif + U( ?& V0 |; X3 u SerialUSB.println();1 T6 p% A. s2 p! F0 x t$ Y2 q0 V
SerialUSB.print(instruction);! M" d/ \5 w6 p( ^2 N: J, j
SerialUSB.print("\t");9 T" C' Z! m! n- v, b
1 O y+ J2 L1 k( y5 ~: s //what line are we at? 4 h7 X5 ^( F: b4 S1 u // long line = -1; # {9 a- m% s7 |0 X // if (has_command('N', instruction, size)) " t0 a% ?# f+ N0 e+ |9 H // line = (long)search_string('N', instruction, size); 9 K1 N' `- A; W# g - |4 h* r3 w9 ~ /*$ Y6 ~5 @$ o, b+ c: G7 N1 p1 E
Serial.print("line: "); , e$ C5 l0 [( Q6 Q Serial.println(line);2 T5 s* `4 I, C! f2 T9 b$ Q. m$ m! K
Serial.println(instruction); " o. d: c2 z8 K" ~4 g7 G */ - j4 J. h" _$ f1 s //判斷是否讀取了個(gè) G代碼? 4 n9 h! m- E$ {6 o if (' ]" x% p1 C7 N" e8 A& J
has_command('G', instruction, size) ||0 S B# w) t0 R' E, o; I7 Y* n
has_command('X', instruction, size) || 8 E2 f' _; E9 u" g' h0 q* \ has_command('Y', instruction, size) || - H5 u0 J1 H6 o has_command('Z', instruction, size) ||0 }# s- ?' }8 I8 m' s; Z
has_command('U', instruction, size) % P$ y0 W1 ]8 c& t% v; a' ^ ) ( ]) F; J4 v2 v8 D" f9 o$ }4 U { : R& O4 K3 t# T //which one? 9 F! Y* x9 D. ~" r. N$ n code = (int)search_string('G', instruction, size); l! i7 `. F' v Q4 x" I8 \; N
// Get co-ordinates if required by the code type given % Z$ @: R9 N5 K, A% r3 k! T switch (code)/ e1 i9 A+ n0 B
{ / U* {- a; k, L! v# Q case 0: ( x @* I& b1 E$ a# w x, n9 } h case 1: 6 V+ X' h o/ N( x* b6 Q case 2:1 c7 [: N* Z) U( R9 S$ k
case 3: - O3 q( V( D- e h4 b6 B4 q if(abs_mode)1 D0 m, z) n# u+ _. @) J9 L
{# |8 z$ E. N2 }- R1 S
//we do it like this to save time. makes curves better.% o) c9 z4 }% }7 M q
//eg. if only x and y are specified, we dont have to waste time looking up z.6 v& x- D, k. F0 x& h: k
if (has_command('X', instruction, size)) 7 R8 p- ~. p9 y7 Q/ `5 x$ S! j, K fp.x = search_string('X', instruction, size); 7 S) e/ }8 d$ x7 B else ! P* f* s7 P) n, O( X. H! A fp.x = current_units.x;% Y0 m* |, p# D, ~, {
! e! g/ D- R5 Q! `* |8 t if (has_command('Y', instruction, size)) 8 P& H0 {% y+ S) c* @ L9 u fp.y = search_string('Y', instruction, size);# h; a5 B7 {2 i- Z1 y
else $ m- A' _2 \" u# q8 N4 k fp.y = current_units.y;. c8 g. P7 T1 m) g, O; }
: i: P: t* G+ O" o# \& v! L
if (has_command('Z', instruction, size))( E. {+ A, i, X1 y4 B
fp.z = search_string('Z', instruction, size);- K" @+ r% Z+ R! E
else! c f( j' e% a# i+ p
fp.z = current_units.z; $ t+ m$ f: S) p) w " z n: l# i2 F: M! z$ K: r
if (has_command('U', instruction, size)) 9 P8 A+ S5 e2 J* A0 S* E fp.u = search_string('U', instruction, size); + W6 H g# a2 H _: Q5 x- ^% F% l* W else 4 j3 I3 A8 T! }* D fp.u = current_units.u;$ L4 D) P! L; z& U" l4 U' v: S
} 3 O, E9 h* i% I) I! y else- z; P" ?% [! n Y( C! u0 [$ P
{ , a3 f& Y% T0 s& |1 q/ S/ B1 l) J fp.x = search_string('X', instruction, size) + current_units.x; 0 k( A0 U) `/ d* S$ ~+ z, q/ o fp.y = search_string('Y', instruction, size) + current_units.y;5 i$ C; n2 d+ Q- h8 l
fp.z = search_string('Z', instruction, size) + current_units.z;1 z9 E; Z" L' c6 n }
fp.u = search_string('U', instruction, size) + current_units.u;: j# |( ]) |! Z' f
} 4 S& v" W$ S; v- f break; / j4 l9 q3 Z- s' Z! P/ C } ! R! f; D) i5 Q) S! Y //do something! 0 [% {9 ~' L- }/ L: u switch (code) , \+ G$ a5 [6 ^# u {: I* Y9 ^! x$ I3 k" ^2 l% k8 g& P( `
//Rapid Positioning, W2 B* l u. H& K) E: x! p
//Linear Interpolation& F. I: ?$ |+ k, z0 E
//these are basically the same thing.) {7 D. e# A9 q, p6 R
case 0:5 p5 ^6 O" P# m! M2 B
case 1:* I; q" b4 z: [% q+ r
//set our target. ( _, u# L2 j/ |7 k) r" } set_target(fp.x, fp.y, fp.z, fp.u);: \# V! ~) T: t9 i
//set_targeta( fp.a); 7 d$ E) b# s* L/ K: U$ v3 P7 q //do we have a set speed?( ?4 F: h9 c: Y1 i. e
if (has_command('G', instruction, size))1 e( \3 v4 P3 v. T2 c4 H: l
{ + w7 a" s# K+ p2 x6 Z0 z& t //adjust if we have a specific feedrate. ! C9 c- Q6 C8 r( V0 ~: u% f. t if (code == 1); W2 H* l6 F2 n# c( P) N" J# U6 A
{, _5 K w4 e) ? D+ F% _% f# ]
//how fast do we move? + p3 }+ H6 N' |1 M' N6 M feedrate = search_string('F', instruction, size); 1 G+ [" G8 m! s4 e- c4 p if (feedrate > 0)% U3 {" N. P. T0 d
feedrate_micros = calculate_feedrate_delay(feedrate); 2 f ^, W( Z* D/ H; x //nope, no feedrate8 e$ \3 I$ ~* p. K' T# t! B3 O
else ( B1 z t. S( r( Z' \+ }2 v feedrate_micros = getMaxSpeed(); ) ?0 e4 p( B6 | } C6 F& c/ t; |+ g2 o //use our max for normal moves. 0 o- p2 B4 K5 N else ! P, l( f% q5 e7 |9 v feedrate_micros = getMaxSpeed();: F+ Q( U G8 ~/ }
}' r: W; Q) }2 d w* T3 A6 ^! e
//nope, just coordinates!3 x! s, M; r8 T- R! r. z8 t( u
else! K w* g4 t) U, B( v! \3 O
{6 H2 E* Q9 P3 o1 R3 r% f1 C
//do we have a feedrate yet?, M2 e* ?; s- j* O# t" N0 A3 V6 G
if (feedrate > 0) 5 N8 g! M$ h7 C5 G feedrate_micros = calculate_feedrate_delay(feedrate); , x1 R" R4 g4 y6 [, S- X //nope, no feedrate! M: f1 ~$ n% [' \' n" r2 h1 q
else) R9 k {3 @4 c, Z: n+ O! k0 ^. {
feedrate_micros = getMaxSpeed(); : l# ?5 l- Y# |3 Z }+ K d0 D9 R5 y8 X
8 [0 r' e3 @+ k0 R //finally move.7 S" }* P. H4 S7 v/ ~3 d
dda_move(feedrate_micros);$ S: a3 G. e* v2 {6 }. z' ?
if(stop_flag) return; u9 N0 n2 }( h6 D. _1 }$ | break; . g, K/ p/ q) h, v' G, \$ K * |" v- U) k ]* u# G( F! N7 \" v. g //Clockwise arc! M' x* b: Z* Y/ x
case 2: - g0 @- t$ \/ h9 V# H8 _ //Counterclockwise arc7 p9 `$ J: y; [. ?1 p. Y
case 3:4 K1 r7 t, d* Q! P1 V) e1 T) e* |4 t4 A
FloatPoint cent;( |( \ q' g- N, y
// Centre coordinates are always relative% Y' l8 g' R/ R, l3 L0 Q
cent.x = search_string('I', instruction, size) + current_units.x; ! X4 U4 S" u$ u3 G3 H9 ? cent.y = search_string('J', instruction, size) + current_units.y; # p2 l) X' r6 F, A+ I& ?! d float angleA, angleB, angle, radius, length, aX, aY, bX, bY;6 p2 N+ Y& g9 s- g8 |- k7 f; \( r
/ _3 [" `5 c3 a* F
aX = (current_units.x - cent.x);0 z/ x8 H- p" [
aY = (current_units.y - cent.y);' P7 k0 a' ^* G1 q6 J g" r! t3 I6 X
bX = (fp.x - cent.x);: l( k/ ?$ P5 H' u: Q8 i
bY = (fp.y - cent.y); ' o8 F! C) O! L) t 3 @/ E" g' t& m. M if (code == 2) { // Clockwise 7 s4 Q, b* T5 P& n angleA = atan2(bY, bX); , ?! n' l: s& @# y* R6 }) Z angleB = atan2(aY, aX);0 j7 q, J' X( i" _1 Q5 T
} + y6 ?3 o* N4 Z3 V! ^1 X- m
else { // Counterclockwise/ [4 e3 W5 J% P, B1 \- _, [
angleA = atan2(aY, aX); % ~% o. N& }2 L1 g' h% h" { angleB = atan2(bY, bX); G7 R& G( \* x, `- j } ) o, z( {0 D8 v: j/ H6 ?: ~ // Make sure angleB is always greater than angleA* g1 Q$ @" D, x, `& e( B
// and if not add 2PI so that it is (this also takes& j; b6 h: v, j0 l
// care of the special case of angleA == angleB, 1 o' `2 ?/ `9 x. ~ // ie we want a complete circle)$ K- U. Z E% @
if (angleB <= angleA) angleB += 2 * M_PI; / l0 s! s) L- A3 Q: x angle = angleB - angleA; ) W& z6 U0 M# h! u8 `" i 6 C+ e9 i1 s7 t1 @ radius = sqrt(aX * aX + aY * aY); . x9 }) v3 k! `! W3 J( J0 A length = radius * angle;) t$ g& f2 }$ O0 d1 i3 L$ s
int steps, s, step;4 ~$ S9 C2 @0 w* w: Q- n
steps = (int) ceil(length / curve_section); ( Z& {* K [& b9 H4 J ' \6 T1 D2 y# y FloatPoint newPoint; . `. Q& @1 x% ^& { for (s = 1; s <= steps; s++) {8 G1 s7 m! [2 A. k
step = (code == 3) ? s : steps - s; // Work backwards for CW; d( y! c- [7 e; Z+ Z- ?6 i
newPoint.x = cent.x + radius * cos(angleA + angle * ((float) step / steps));: T* b2 {) j( L
newPoint.y = cent.y + radius * sin(angleA + angle * ((float) step / steps)); 3 P7 ?: A1 a, Z% J! K3 j set_target(newPoint.x, newPoint.y, fp.z, fp.u); 7 m$ b2 O3 z6 d6 ?3 v' X# } # S; v( m& ^9 E: }; W: N# U // Need to calculate rate for each section of curve8 ^1 v6 }1 C) [6 X( d2 s3 o
if (feedrate > 0) 6 j; `( s& G) x$ F6 a; T feedrate_micros = calculate_feedrate_delay(feedrate); / V' ?4 j& N- y( h else- }1 ?6 l9 S4 H6 H2 |
feedrate_micros = getMaxSpeed();4 _& X& J2 d9 b; ]
& D% f2 I A( r! [
// Make step) Q W z E5 B$ f: Z9 ^) x
dda_move(feedrate_micros); 4 _$ _0 `9 c! o% y# p# ~ if(stop_flag) return;# @1 N: }" j7 p- C! b w
} 6 c1 X4 N+ ]1 U7 G$ b: W& s , ^1 s$ Y6 l$ i: A! d$ f3 ] break;# n5 j: ]" h! T$ b
: V0 Z- F1 j9 O& L. H w) z //Dwell0 T& E- Q6 h; e
case 4: * W a, z1 X6 }% o7 {6 | delay((int)search_string('P', instruction, size));) o& k1 P) D3 z8 M) V$ Y4 v
break;$ X! E9 G I. @( g" d+ L
0 W! D# \: z8 c/ \% \6 K
//Inches for Units - W2 ~& D2 Z8 z$ L6 v9 t3 V! B case 20:; _% N7 ]; O& I" Y
x_units = X_STEPS_PER_INCH;6 L# _$ g: i! K( w6 |: r6 t' `
y_units = Y_STEPS_PER_INCH;& } v. q% f. n8 T1 H: c4 d. j
z_units = Z_STEPS_PER_INCH;% N& [) |% F V G* [: c
u_units = U_STEPS_PER_INCH;3 A! @. ?3 d5 f9 p
curve_section = CURVE_SECTION_INCHES; * J$ I+ Z# Y1 f) ?- c calculate_deltas();( A4 w) q2 K, h+ }
break;" l5 S# O+ m9 s
1 m# ?* Y. k0 O9 ]1 b8 w+ q" _
//mm for Units - A" p& g/ Z9 I$ [; p case 21: 4 b5 @" B; V; G, y, @ x_units = X_STEPS_PER_MM; 5 z4 {' Y# ^* M" P* r2 ~) I y_units = Y_STEPS_PER_MM;# I* z- x, r! O* B3 U ?) x
z_units = Z_STEPS_PER_MM;) E; w+ y5 r& L- n2 l8 y+ I) j
u_units = U_STEPS_PER_MM; 6 a7 i' { A6 r- C) W curve_section = CURVE_SECTION_MM; % g0 T7 o, _3 s. I! a calculate_deltas();9 @/ _, b/ V6 z" H
break;/ K0 n0 ` Y2 i: w
2 P1 j: O6 @$ |( ]3 t
//go home. 6 l( U" j- S4 g- X case 28:" V, x% ~6 j! F$ D
set_target(0.0, 0.0, 0.0, 0.0);1 C1 K" u" o7 O* M) |
dda_move(getMaxSpeed());: H2 w4 P V2 w5 d5 c2 ?
if(stop_flag) return; / l3 x5 `5 `9 K J8 ~* ^2 x( H break; 1 s/ M/ b$ p0 h2 [: n' w( }' U ! j/ U6 C* \! p; B4 ? //go home via an intermediate point. 6 H& R- M$ U& J' T case 30: ' x f7 t# {9 E9 C* { fp.x = search_string('X', instruction, size);& o4 V* x3 Z A7 L
fp.y = search_string('Y', instruction, size);& V7 j2 v! j a. Q
fp.z = search_string('Z', instruction, size);7 `5 m! f: y3 L9 Q$ o% D* p
fp.u = search_string('U', instruction, size);' X: `6 y' a3 S/ y7 ]* t; r6 F
//set our target. + {; K: ]( l2 e9 V" ? if(abs_mode)4 M2 u" k# g# v$ t7 l5 a* X4 F
{ ! _$ J5 J) m6 E6 E' \% b! o if (!has_command('X', instruction, size))# C- b$ W4 ^0 A+ t/ I4 x7 o9 K w( t
fp.x = current_units.x;5 e! ~' a( [# M/ `% |. f, W
if (!has_command('Y', instruction, size)), b# ]; c: ~" e, K! A, a0 ]9 C
fp.y = current_units.y; $ r* Y1 u& F5 ^8 f" ~3 o/ \ if (!has_command('Z', instruction, size)) 7 f4 }: h3 l2 D3 a6 _; E fp.z = current_units.z;0 L! E6 H; e8 W1 N8 T( |
if (!has_command('U', instruction, size)) 7 @( W2 x5 d: u" s+ t; l4 Z, R! U fp.u = current_units.u; 3 o6 g- I0 B' p! O- z set_target(fp.x, fp.y, fp.z, fp.u);7 u7 ~ u3 y0 ]/ Q7 c. z) M
1 x) @$ U9 _6 j! I, Y! Z } - Y/ `. C" ], p! }* d" \% p else / B3 H) A! K! H* Y! y$ t- N set_target(current_units.x + fp.x, current_units.y + fp.y, current_units.z + fp.z, current_units.u + fp.u );% X% g* z9 M1 w+ _9 |
) d4 N3 k8 X2 r9 Z& g4 F- } {
//go there.6 w2 w( Y2 B* s) B1 j6 G/ j9 {
dda_move(getMaxSpeed());% S/ ~2 k2 O& X& H( N5 r4 v8 }
if(stop_flag) return; 4 u$ B3 Y2 n) @3 F; Y: R $ Q; m6 w+ \' |( y //go home.$ T2 U7 ~9 ?) W2 S: N) E
set_target(0.0, 0.0, 0.0, 0.0 ); . h& H* h- F( r8 u: a 7 t7 x4 y6 u/ r! v
dda_move(getMaxSpeed());' y6 t6 [& t+ H: X; a$ s
if(stop_flag) return;. E3 V+ T, ]; n- ] }; h
break;( j5 C4 s) @5 t6 H: J9 @
! c" f0 Z) G. L9 X5 ^9 O
//Absolute Positioning8 h) d' }) i3 d! G& [+ `9 |5 O% i
case 90:# k* C6 X" ^+ D8 A0 R( v# c) S
abs_mode = true;# i4 a& I% E3 J' b- ?
break; ( a L3 P) U# ]6 ^/ \. [$ c2 g 1 |. _1 ^9 p. X6 R5 W* ] //Incremental Positioning : b' n0 G# J! j4 n% y" |2 K case 91:6 \# n# v8 B+ C1 R; h; {( e
abs_mode = false;% S b0 ]/ P6 @2 L5 E
break;: o3 |6 Q0 M2 m w l: d- f
% v& G0 Y/ I; n1 |) v //Set as home+ G, K0 `3 Z" |# ?9 F/ j, z s
case 92: $ P) u% J, }, J- a0 _. f! N" ` 6 m2 d8 b$ d" A+ { set_position(0.0, 0.0, 0.0, 0.0 ); % `7 M% P' G9 a# F/ P: W" E$ \: x 9 V* e4 U7 z5 f5 q+ W
break; # U6 w, ? D' a/ l/ I% F* g3 a( \, y/ r0 z, C% S1 U
/*+ f( l/ {, v5 J2 `/ o- N4 H
//Inverse Time Feed Mode8 `0 l v. i) X& N
case 93:+ i: G; v- Z5 T; r g' F) k
# r1 m, `' P2 L2 E& X
break; //TODO: add this0 G( b& x& m# R: g
! q1 ?, j. A5 Z
//Feed per Minute Mode ' r- p' b p. | case 94:$ d6 _! p4 O1 b* v1 P
* @) k; t! Q% U0 M" X) ^0 p3 b
break; //TODO: add this # ^- r3 a( f1 K; v2 A# _3 v$ \* f* x */4 r$ z' @$ L( Q0 \
7 k5 ~) ^- L8 x# D; Q- p
default:' ~9 q! w+ M5 b
SerialUSB.print("huh? G"); / i' C1 d" ~6 o SerialUSB.println(code,DEC); - T% x$ u0 ]1 x }/ r/ G: @) r) |% I( v# K" \* b
} : Q6 G7 m6 H2 F9 O, p t% M ! `0 | l" U+ V9 O+ `. D+ k' ] //find us an m code. ! p: H( n' D3 p if (has_command('M', instruction, size)) ' a& c- S; V- f0 w1 o0 k4 z {$ g6 z) J' X5 A' X- t+ a& c
code = search_string('M', instruction, size); ; @3 [: _2 Q0 s1 f switch (code) " O9 S& {/ ]- X1 M* x1 O q { 6 M W2 f; M! R, V0 x //TODO: this is a bug because search_string returns 0. gotta fix that.7 j! s' c. u% Z+ D
case 0: 2 v/ T6 q# F8 t- V$ o true;6 L& V5 O1 ^8 }* _- ?. h
break; ) E5 h; h4 X% P9 } " P. O5 j( j+ ^# p$ H7 @ case 100:& c. a7 T1 ~( m( _) V$ R
break; ' a7 h+ E; j" c+ e j- E1 B2 y5 W% j/ l5 V) S3 m
// fire camera relay $ l2 ^! v# j- |2 d case 101: # c, t, B: X( s) @0 U" {; X camera_shutter1(); 8 V) R1 K) p) [$ ? break; ! @; n6 h2 b9 v$ o" r- J5 A$ `' A1 q' y/ _( H
// fire camera relay2 o" A. u1 Q$ Q9 I/ A0 _ case 102: 6 C: z' `* n6 p! G @ camera_shutter2(); # o$ \: o2 B& Y( `$ K+ `3 ~ break;( Y. i1 ~* i5 ]- I
/* ! h2 f; ?( ~5 \$ t$ h // turn aux 1 relay on5 J+ E' c% B& W% I1 U7 e
case 103: $ o" A: O. D: Z4 a6 ^/ }+ d camera_aux1_on(); , x& B% R' j# z9 p* j; Q9 s break;9 B. z8 U2 i, j. [0 c/ r9 B
5 j l# o' _! R/ ~' ~, T% X
// turn aux 1 relay off5 @5 }" m' m* o& ^3 e
case 104: " x8 S# K! ?- ^ camera_aux1_off();$ g- J# k7 J- P3 J
break;0 m9 S" @5 g/ g4 j. Z( l& L
7 ?7 c2 d! M( ?1 y5 H& d9 [# ] // turn aux 2 relay on - n: J: e' M. p5 Y+ `2 T case 105:' X7 p! T; @: o
camera_aux2_on();8 V) y, _6 M. X3 a, u ^0 e
break; . s) Z- V5 K/ w# ^$ { ; ]( q5 V, r3 P( O6 d) ?9 W // turn aux 2 relay off; g0 d, Y& v$ N* ~
case 106:8 y: O: T* q: A- t: Z7 j
camera_aux2_off(); 9 h# C5 X8 A& v& I8 W6 a break; - s/ F+ I% u8 d- @9 Q' W * G n. V9 J/ i* h) {# b% M2 ] // turn aux 3 relay on 9 T4 t2 @- \2 K' R0 M% G case 107: / R* y: }6 ] f- k: N4 i6 W4 z camera_aux3_on();1 N$ b2 f6 x$ w% P- ]: H; t
break;" B7 N8 ?( }( }: C6 A
" b# j, I4 P( u) o' b
// turn aux 3 relay off& E8 @3 e% W4 j
case 108:4 T8 |& b& |# o' [! X
camera_aux3_off();+ u0 k: h, g2 J# I
break; * H, v% l' m$ @( y4 p: I ) G# V7 W* b2 s6 z // turn aux 4 relay on * x( ~! s R, U; A& G3 ^ case 109: 6 U- P$ y/ o! U0 e" v: U+ m( { camera_aux4_on(); # {- D8 a4 e' V break; : s+ l- |* Y; w( Q6 p- o: d! b& ]( d! Z; }8 B; j* d) h# |; s/ ^( ]
// turn aux 4 relay off * p8 a& C X5 [ D case 110: ( k# Q. E/ u+ ]0 \5 a2 }- p camera_aux4_off();$ a1 t1 c2 d! r: ], Z* m" Y
break; : r0 r! j* T& }9 T. [*/; _7 K3 P6 S* P0 f0 Y* m
default: # n) r3 I& z4 w 5 w1 s! x5 V1 \7 v SerialUSB.print("Huh? M");' U" M/ z9 z. J g3 `
SerialUSB.println(code); & S' @- q* R- {( u1 | } 6 k$ o4 ^) E( w ~- ? } ) W7 w: E- R( q$ W7 x 6 p |- ?1 A) X- K* n+ O //tell our host we're done.* p# p. ~, V( V7 @5 k. `/ r4 i
SerialUSB.print(byte(78));) v; m/ j! F- e w, @2 I. A
. i4 Q$ `. k# _4 w' e6 E) H% E; w
}, K; \& p4 ^( p+ ~3 X- \
7 m8 d# G( [$ a& _% U% U//look for the number that appears after the char key and return it 7 L- A. z7 I4 M6 r, c7 m: Xdouble search_string(char key, char instruction[], int string_size)3 z+ l# ` r r, I2 K$ q
{, Y3 a; M3 u% {, }% O) a- A
char temp[10] = " "; # u1 O. v4 k, ]; L x- m1 t for (byte i=0; i<string_size; i++) - `) M3 W+ T3 X5 c$ U { . g2 s, O, l! a4 b+ |& L+ H if (instruction[i] == key) 1 K% F( v/ E; E: p# \+ S8 V( K. N6 P( e { . \% u7 y5 E. T" \ i++; ' ?8 I* q2 n( C% ? int k = 0; - Q) N# M( L8 n while (i < string_size && k < 10)% X- n0 n- D3 w5 }3 @! t
{& e9 I% [, d, N& o/ y' n; z4 t; \2 E
if (instruction[i] == 0 || instruction[i] == ' ') 0 b" @' b: k2 e break; 0 X! r* A( M' t8 P; p : K1 s2 o4 O& g5 f temp[k] = instruction[i]; # T& f B0 l. N' Y- }6 |! g# \" J i++;( \( ~: C2 y# S4 e O
k++; & q9 m/ p( h1 I" x- _8 ?; l } & \' {. U% N1 A! h Q- J! g/ ^ return strtod(temp, NULL); : X: C1 |) B4 p+ [ v' T! H } 8 ^! X7 E) k7 f- v& Y1 g }: u' ?7 f% b1 x5 ~6 Q9 c
, v# ^, c9 ]4 e' J" Z, Y
return 0; % \3 E( w$ L8 `2 U8 p7 T/ A& b) m}! ?! P d. K3 } f; t
f' p+ n9 E$ z# L% r//look for the command if it exists. " C! R, z5 T3 R6 [! t6 jbool has_command(char key, char instruction[], int string_size) / [- q4 R- K- L8 |& M! R, s2 u3 ?{ ! s9 a! q; m% F5 |! U+ b for (byte i=0; i<string_size; i++) j; s. o9 h: E% V& `( g+ {5 ~
{( W$ i7 e/ K& s, V
if (instruction[i] == key){ ; } W$ \/ |. M3 f5 q# Q, f/ D8 L
return true; $ A) `- b e U } & j1 C& q7 F0 Q0 [7 `# R } ) j9 F/ y1 Q! Z: h" _, `4 ` 7 u. W* `. l* u return false;9 O4 S' W5 H3 `6 J2 \5 o7 m2 s% V% f
} " u, Y4 [5 j' F+ d9 M! l% M: I+ a$ A$ `: W" e7 O4 ^: S V
& E% j& u9 S" r, s8 T& i0 C