Skip to content

Commit a403085

Browse files
committed
iodpu
1 parent 8a0fa2e commit a403085

8 files changed

Lines changed: 95 additions & 70 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ v2.0 (pending)
66
* NEW: IFireStep interface implemented by: FireStepSerial, FireStepDuino
77
* NEW: IDuino interface implemented by: Mega2560, MockDuino
88

9+
v1.050
10+
------
11+
* NEW: "iod" now has "pu" boolean attribute for INPUT_PULLUP
12+
913
v1.040
1014
------
1115
* NEW: MTO_FPD: "movaa" moves all arms to given angle

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8)
33
project( firestep )
44

55
SET(PROJECT_VERSION_MAJOR 1)
6-
SET(PROJECT_VERSION_MINOR 4)
6+
SET(PROJECT_VERSION_MINOR 5)
77
set(PROJECT_VERSION_PATCH 0)
88
set(PROJECT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
99

FireStep/JsonController.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ Status JsonController::processEEPROM(JsonCommand& jcmd, JsonObject& jobj, const
834834
return status;
835835
}
836836

837-
Status JsonController::processIOPin(JsonCommand& jcmd, JsonObject& jobj, const char* key) {
837+
Status JsonController::processIOPin(JsonCommand& jcmd, JsonObject& jobj, const char* key, bool pullUp) {
838838
const char *pinStr = *key == 'd' || *key == 'a' ? key+1 : key+3;
839839
long pinLong = strtol(pinStr, NULL, 10);
840840
if (machine.isCorePin(pinLong)) {
@@ -848,10 +848,10 @@ Status JsonController::processIOPin(JsonCommand& jcmd, JsonObject& jobj, const c
848848
bool isAnalog = *key == 'a' || strncmp("ioa",key,3)==0;
849849
if (s && *s == 0) { // read
850850
if (isAnalog) {
851-
pinMode(pin+A0, INPUT);
851+
pinMode(pin+A0, pullUp ? INPUT_PULLUP : INPUT); // maybe INPUT_PULLUP should be error
852852
jobj[key] = analogRead(pin+A0);
853853
} else {
854-
pinMode(pin, INPUT);
854+
pinMode(pin, pullUp ? INPUT_PULLUP : INPUT);
855855
jobj[key] = (bool) digitalRead(pin);
856856
}
857857
} else if (isAnalog) {
@@ -909,20 +909,31 @@ Status JsonController::processProgram(JsonCommand& jcmd, JsonObject& jobj, const
909909
return status;
910910
}
911911

912-
Status JsonController::processIO(JsonCommand& jcmd, JsonObject& jobj, const char* key) {
913-
Status status = STATUS_NOT_IMPLEMENTED;
912+
Status JsonController::processIO(JsonCommand& jcmd, JsonObject& jobj, const char* key, bool pullUp) {
913+
Status status = STATUS_OK;
914914
if (strcmp_PS(OP_io, key) == 0) {
915915
JsonObject& kidObj = jobj[key];
916916
if (!kidObj.success()) {
917917
return jcmd.setError(STATUS_JSON_OBJECT, key);
918918
}
919+
char pu[10];
920+
strcpy_P(pu, OP_pu);
921+
if (kidObj.at(pu).success()) {
922+
pullUp = kidObj[pu];
923+
TESTCOUT1("iopu:", pullUp);
924+
}
919925
for (JsonObject::iterator it = kidObj.begin(); it != kidObj.end(); ++it) {
920-
status = processIO(jcmd, kidObj, it->key);
926+
status = processIO(jcmd, kidObj, it->key, pullUp);
927+
if (status < 0) {
928+
return status;
929+
}
921930
}
931+
} else if (strcmp_PS(OP_pu,key)==0) {
932+
// handled above
922933
} else if (strncmp("d",key,1)==0 || strncmp("iod",key,3)==0) {
923-
status = processIOPin(jcmd, jobj, key);
934+
status = processIOPin(jcmd, jobj, key, pullUp);
924935
} else if (strncmp("a",key,1)==0 || strncmp("ioa",key,3)==0) {
925-
status = processIOPin(jcmd, jobj, key);
936+
status = processIOPin(jcmd, jobj, key, pullUp);
926937
} else {
927938
return jcmd.setError(STATUS_UNRECOGNIZED_NAME, key);
928939
}

FireStep/JsonController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ typedef class JsonController {
3131
virtual Status processEEPROM(JsonCommand& jcmd, JsonObject& jobj, const char* key);
3232
virtual Status processEEPROMValue(JsonCommand& jcmd, JsonObject& jobj, const char* key, const char *addr);
3333
virtual Status processHome(JsonCommand& jcmd, JsonObject& jobj, const char* key) = 0;
34-
virtual Status processIO(JsonCommand& jcmd, JsonObject& jobj, const char* key);
35-
virtual Status processIOPin(JsonCommand& jcmd, JsonObject& jobj, const char* key);
34+
virtual Status processIO(JsonCommand& jcmd, JsonObject& jobj, const char* key, bool pullUp=false);
35+
virtual Status processIOPin(JsonCommand& jcmd, JsonObject& jobj, const char* key, bool pullUp);
3636
virtual Status processMark(JsonCommand& jcmd, JsonObject& jobj, const char* key);
3737
virtual Status processMotor(JsonCommand &jcmd, JsonObject& jobj, const char* key, char group);
3838
virtual Status processMove(JsonCommand& jcmd, JsonObject& jobj, const char* key) = 0;

FireStep/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern "C" {
99
//////////// GENERATED FILE (from version.h.in) /////////////////
1010

1111
#define VERSION_MAJOR 1
12-
#define VERSION_MINOR 4
12+
#define VERSION_MINOR 5
1313
#define VERSION_PATCH 0
1414

1515
//////////// GENERATED FILE (from version.h.in) /////////////////

src/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef uint8_t boolean;
2323
#define LOW 0
2424
#define INPUT 0
2525
#define OUTPUT 1
26+
#define INPUT_PULLUP 2
2627

2728
#define ADEN 7
2829
#define ADSC 6

src/MockDuino.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ int16_t digitalRead(int16_t pin) {
246246
void pinMode(int16_t pin, int16_t inout) {
247247
ASSERT(0 <= pin && pin < ARDUINO_PINS);
248248
arduino._pinMode[pin] = inout;
249+
if (inout == INPUT_PULLUP) {
250+
arduino.pin[pin] = HIGH;
251+
}
249252
}
250253

251254
int16_t MockDuino::getPinMode(int16_t pin) {

src/test.cpp

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3174
string 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-
50575063
void test_homz() {
50585064
cout << "TEST : test_homz() =====" << endl;
50595065

0 commit comments

Comments
 (0)