@@ -28,6 +28,49 @@ void replaceChar(string &s, char cmatch, char creplace) {
2828 }
2929}
3030
31+ string test_cmd (MachineThread &mt, int line, const char *cmd, int homeLoops=-1 , int probeLoops=-1 ) {
32+ TESTCOUT1 (" line:" , line);
33+ ASSERTEQUAL (STATUS_WAIT_IDLE, mt.status );
34+ ASSERTEQUALS (" " , Serial.output ().c_str ());
35+ Serial.push (cmd);
36+ mt.loop ();
37+ ASSERTEQUAL (STATUS_BUSY_PARSED, mt.status );
38+ arduino.setPin (PC2_X_MIN_PIN, LOW);
39+ arduino.setPin (PC2_Y_MIN_PIN, LOW);
40+ arduino.setPin (PC2_Z_MIN_PIN, LOW);
41+ arduino.setPin (PC2_PROBE_PIN, LOW);
42+ do {
43+ mt.loop ();
44+ } while (mt.status == STATUS_BUSY_PARSED);
45+ for (int i=0 ; i<5000 ; i++) {
46+ if (homeLoops >= 0 && i >= homeLoops) {
47+ arduino.setPin (PC2_X_MIN_PIN, HIGH); // trip home switch
48+ arduino.setPin (PC2_Y_MIN_PIN, HIGH); // trip home switch
49+ arduino.setPin (PC2_Z_MIN_PIN, HIGH); // trip home switch
50+ }
51+ if (probeLoops >= 0 && i >= probeLoops) {
52+ arduino.setPin (PC2_PROBE_PIN, HIGH); // no contact probe
53+ }
54+ if (mt.status == STATUS_BUSY_MOVING) {
55+ cerr << " ." ;
56+ mt.loop ();
57+ } else if (mt.status == STATUS_BUSY_CALIBRATING) {
58+ cerr << " *" ;
59+ mt.loop ();
60+ } else {
61+ cerr << endl;
62+ break ;
63+ }
64+ }
65+ if (mt.status != STATUS_OK) {
66+ cerr << Serial.output () << endl;
67+ }
68+ ASSERTEQUAL (STATUS_OK, mt.status );
69+ mt.loop ();
70+ ASSERTEQUAL (STATUS_WAIT_IDLE, mt.status );
71+ return Serial.output ();
72+ }
73+
3174string jsonTemplate (const char *jsonIn, string replace = " '\" " ) {
3275 string ji (jsonIn);
3376 for (int i = 0 ; i < replace.size (); i += 2 ) {
@@ -3394,26 +3437,32 @@ void test_io() {
33943437
33953438 MachineThread mt = test_setup ();
33963439 Machine &machine = mt.machine ;
3440+ string response;
33973441
3398- arduino.setPin (22 , HIGH);
3399- Serial.push (JT (" {'io':{'d22':''}} \n " ));
3400- test_ticks (1 );
3401- ASSERTEQUAL (STATUS_BUSY_PARSED, mt.status );
3402- test_ticks (1 );
3403- ASSERTEQUAL (STATUS_OK, mt.status );
3442+ arduino.setPin (22 , LOW); // without this input is indeterminate
3443+ response = test_cmd (mt, __LINE__, JT (" {'io':{'d22':''}}\n " ));
3444+ ASSERTEQUALS (JT (" {'s':0,'r':{'io':{'d22':false}},'t':0.000} \n " ), response.c_str ());
3445+ ASSERTEQUAL (INPUT, arduino.getPinMode (22 ));
3446+
3447+ // pu false is default
3448+ response = test_cmd (mt, __LINE__, JT (" {'io':{'d22':'','pu':false}}\n " ));
3449+ ASSERTEQUALS (JT (" {'s':0,'r':{'io':{'d22':false,'pu':false}},'t':0.000} \n " ), response.c_str ());
34043450 ASSERTEQUAL (INPUT, arduino.getPinMode (22 ));
3405- ASSERTEQUALS (JT (" {'s':0,'r':{'io':{'d22':true}},'t':0.000} \n " ), Serial.output ().c_str ());
3406- test_ticks (1 );
34073451
3452+ // INPUT_PULLUP
3453+ response = test_cmd (mt, __LINE__, JT (" {'io':{'d22':'','pu':true}}\n " ));
3454+ ASSERTEQUALS (JT (" {'s':0,'r':{'io':{'d22':true,'pu':true}},'t':0.000} \n " ), response.c_str ());
3455+ ASSERTEQUAL (INPUT_PULLUP, arduino.getPinMode (22 ));
3456+
3457+ // retest HIGH/LOW read
34083458 arduino.setPin (22 , LOW);
3409- Serial. push ( JT (" {'iod22':''} \n " ));
3410- test_ticks ( 1 );
3411- ASSERTEQUAL (STATUS_BUSY_PARSED, mt. status );
3412- test_ticks ( 1 );
3413- ASSERTEQUAL (STATUS_OK, mt. status );
3414- ASSERTEQUALS (JT (" {'s':0,'r':{'iod22':false} ,'t':0.000} \n " ), Serial. output () .c_str ());
3459+ response = test_cmd (mt, __LINE__, JT (" {'io':{'d22':''}} \n " ));
3460+ ASSERTEQUALS ( JT ( " {'s':0,'r':{'io':{'d22':false}},'t':0.000} \n " ), response. c_str () );
3461+ ASSERTEQUAL (INPUT, arduino. getPinMode ( 22 ) );
3462+ arduino. setPin ( 22 , HIGH );
3463+ response = test_cmd (mt, __LINE__, JT ( " {'io':{'d22':''}} \n " ) );
3464+ ASSERTEQUALS (JT (" {'s':0,'r':{'io':{'d22':true}} ,'t':0.000} \n " ), response .c_str ());
34153465 ASSERTEQUAL (INPUT, arduino.getPinMode (22 ));
3416- test_ticks (1 );
34173466
34183467 Serial.push (JT (" {'io':{'d220':''}} \n " ));
34193468 test_ticks (1 );
@@ -5011,49 +5060,6 @@ void test_ZPlane() {
50115060 cout << " TEST : test_ZPlane() OK " << endl;
50125061}
50135062
5014- string test_cmd (MachineThread &mt, int line, const char *cmd, int homeLoops=-1 , int probeLoops=-1 ) {
5015- TESTCOUT1 (" line:" , line);
5016- ASSERTEQUAL (STATUS_WAIT_IDLE, mt.status );
5017- ASSERTEQUALS (" " , Serial.output ().c_str ());
5018- Serial.push (cmd);
5019- mt.loop ();
5020- ASSERTEQUAL (STATUS_BUSY_PARSED, mt.status );
5021- arduino.setPin (PC2_X_MIN_PIN, LOW);
5022- arduino.setPin (PC2_Y_MIN_PIN, LOW);
5023- arduino.setPin (PC2_Z_MIN_PIN, LOW);
5024- arduino.setPin (PC2_PROBE_PIN, LOW);
5025- do {
5026- mt.loop ();
5027- } while (mt.status == STATUS_BUSY_PARSED);
5028- for (int i=0 ; i<5000 ; i++) {
5029- if (homeLoops >= 0 && i >= homeLoops) {
5030- arduino.setPin (PC2_X_MIN_PIN, HIGH); // trip home switch
5031- arduino.setPin (PC2_Y_MIN_PIN, HIGH); // trip home switch
5032- arduino.setPin (PC2_Z_MIN_PIN, HIGH); // trip home switch
5033- }
5034- if (probeLoops >= 0 && i >= probeLoops) {
5035- arduino.setPin (PC2_PROBE_PIN, HIGH); // no contact probe
5036- }
5037- if (mt.status == STATUS_BUSY_MOVING) {
5038- cerr << " ." ;
5039- mt.loop ();
5040- } else if (mt.status == STATUS_BUSY_CALIBRATING) {
5041- cerr << " *" ;
5042- mt.loop ();
5043- } else {
5044- cerr << endl;
5045- break ;
5046- }
5047- }
5048- if (mt.status != STATUS_OK) {
5049- cerr << Serial.output () << endl;
5050- }
5051- ASSERTEQUAL (STATUS_OK, mt.status );
5052- mt.loop ();
5053- ASSERTEQUAL (STATUS_WAIT_IDLE, mt.status );
5054- return Serial.output ();
5055- }
5056-
50575063void test_homz () {
50585064 cout << " TEST : test_homz() =====" << endl;
50595065
0 commit comments