-
Notifications
You must be signed in to change notification settings - Fork 11
Added support for grab sampler from comeadhra repository. #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,9 +350,68 @@ char * AtlasPH::name(){ | |
} | ||
|
||
bool AtlasPH::set(const char* param, const char* value){ | ||
if (strncmp(param, "temp", 4) == 0){ | ||
this->setTemp(atof(value)); | ||
return true; | ||
if (strncmp(param, "t", 1) == 0){ | ||
if ( value != NULL ) | ||
{ | ||
this->setTemp(atof(value)); | ||
return true; | ||
} | ||
//Send temperature compensation value | ||
else | ||
{ | ||
char output_str[DEFAULT_BUFFER_SIZE + 3]; | ||
snprintf(output_str, DEFAULT_BUFFER_SIZE, | ||
"{" | ||
"\"s%u\":{" | ||
"\"type\":\"%s\"," | ||
"\"data\":\t,%f\"" | ||
"}" | ||
"}", | ||
channel_, | ||
this->name(), | ||
temperature | ||
); | ||
send(output_str); | ||
|
||
} | ||
} else if (strncmp(param, "c", 1) == 0){ | ||
//Get calibration status | ||
if (value == NULL) | ||
{ | ||
char output_str[DEFAULT_BUFFER_SIZE + 3]; | ||
snprintf(output_str, DEFAULT_BUFFER_SIZE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indent on this block. |
||
"{" | ||
"\"s%u\":{" | ||
"\"type\":\"%s\"," | ||
"\"data\":\"c,%f\"" | ||
"}" | ||
"}", | ||
channel_, | ||
this->name(), | ||
calibrationStatus | ||
); | ||
send(output_str); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove whitespace, fix indent (this might be a spaces/tabs mix-- if so, convert everything to spaces). |
||
} | ||
//Calibrate PH lowpoint | ||
else if(strncmp(value, "low", 3) == 0) | ||
{ | ||
this->calibrate(-1); | ||
return true; | ||
} | ||
//Calibrate PH midpoint | ||
else if(strncmp(value, "mid", 3) == 0) | ||
{ | ||
this->calibrate(0); | ||
return true; | ||
} | ||
//Calibrate PH highpoint | ||
else if(strncmp(value, "high", 4) == 0) | ||
{ | ||
this->calibrate(1); | ||
return true; | ||
} | ||
//Serial.println("trigger calibrate method"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this unless we regularly use it for testing. |
||
} | ||
return false; | ||
} | ||
|
@@ -571,21 +630,93 @@ char * AtlasDO::name(){ | |
} | ||
|
||
bool AtlasDO::set(const char* param, const char* value){ | ||
if (strncmp(param, "ec", 2) == 0){ | ||
this->setEC(atof(value)); | ||
return true; | ||
} else if (strncmp(param, "temp", 4) == 0){ | ||
this->setTemp(atof(value)); | ||
return true; | ||
} else if (strncmp(param, "cal", 3) == 0){ | ||
//Serial.println("trigger calibrate method"); | ||
if (strncmp(param, "e", 1) == 0){ | ||
if ( value != NULL ) | ||
{ | ||
this->setEC(atof(value)); | ||
return true; | ||
} | ||
else | ||
{ | ||
char output_str[DEFAULT_BUFFER_SIZE + 3]; | ||
snprintf(output_str, DEFAULT_BUFFER_SIZE, | ||
"{" | ||
"\"s%u\":{" | ||
"\"type\":\"%s\"," | ||
"\"data\":\e,%f\"" | ||
"}" | ||
"}", | ||
channel_, | ||
this->name(), | ||
ec | ||
); | ||
send(output_str); | ||
} | ||
} else if (strncmp(param, "t", 1) == 0){ | ||
if ( value != NULL ) | ||
{ | ||
this->setTemp(atof(value)); | ||
return true; | ||
} | ||
//Send temperature compensation value | ||
else | ||
{ | ||
char output_str[DEFAULT_BUFFER_SIZE + 3]; | ||
snprintf(output_str, DEFAULT_BUFFER_SIZE, | ||
"{" | ||
"\"s%u\":{" | ||
"\"type\":\"%s\"," | ||
"\"data\":\t,%f\"" | ||
"}" | ||
"}", | ||
channel_, | ||
this->name(), | ||
temperature | ||
); | ||
send(output_str); | ||
|
||
} | ||
} else if (strncmp(param, "c", 1) == 0){ | ||
//Get calibration status | ||
if (value == NULL) | ||
{ | ||
char output_str[DEFAULT_BUFFER_SIZE + 3]; | ||
snprintf(output_str, DEFAULT_BUFFER_SIZE, | ||
"{" | ||
"\"s%u\":{" | ||
"\"type\":\"%s\"," | ||
"\"data\":\"c,%f\"" | ||
"}" | ||
"}", | ||
channel_, | ||
this->name(), | ||
calibrationStatus | ||
); | ||
send(output_str); | ||
|
||
} | ||
//Zero DO sensor | ||
else if(strncmp(value, "zero", 4) == 0) | ||
{ | ||
this->calibrate(0); | ||
return true; | ||
} | ||
//Calibrate DO sensor to atmospheric pressure | ||
else if(strncmp(value, "atm", 3) == 0) | ||
{ | ||
this->calibrate(1); | ||
return true; | ||
} | ||
|
||
//Serial.println("trigger calibrate method"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented print unless regularly used for debugging. |
||
} | ||
return false; | ||
} | ||
|
||
//Clamp temperature to range 0,100.0 | ||
void AtlasDO::setTemp(double temp) { | ||
if (temp > 0.0){ | ||
this->temperature = temp; | ||
this->temperature = min(temp, 100.0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason to clamp this? Is there some out-of-range issue we are worried about? Seems bad to not know we are out of range. |
||
lastCommand = SET_TEMP; | ||
this->sendCommand(); | ||
} | ||
|
@@ -908,3 +1039,97 @@ uint32_t Winch::encoder(bool *valid) | |
return enc1; | ||
} | ||
|
||
|
||
GrabSampler::GrabSampler(int channel):Sensor(channel), PoweredSensor(channel, true), channel_(channel) | ||
{ | ||
// init_time = millis(); | ||
|
||
pinMode(board::SENSOR[channel_].GPIO[board::RX_POS], OUTPUT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More indent fixes. |
||
pinMode(board::SENSOR[channel_].GPIO[board::TX_POS], OUTPUT); | ||
pinMode(board::SENSOR[channel_].GPIO[board::RX_NEG], OUTPUT); | ||
pinMode(board::SENSOR[channel_].GPIO[board::TX_NEG], OUTPUT); | ||
disable(0); | ||
disable(2); | ||
|
||
} | ||
|
||
/*void GrabSampler::loop() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code block unless we plan to use it. |
||
{ | ||
if( millis() - init_time > wait_time && !isActive) | ||
{ | ||
//start_time = millis(); | ||
//isActive = true; | ||
powerOn(); | ||
pinMode(board::SENSOR[channel_].GPIO[board::RX_POS], HIGH); | ||
pinMode(board::SENSOR[channel_].GPIO[board::RX_NEG], HIGH); | ||
pinMode(board::SENSOR[channel_].GPIO[board::TX_POS], HIGH); | ||
pinMode(board::SENSOR[channel_].GPIO[board::TX_NEG], HIGH); | ||
} | ||
else if( isActive && millis() - start_time > pump_time ) | ||
{ | ||
powerOff(); | ||
pinMode(board::SENSOR[channel_].GPIO[board::RX_POS], LOW); | ||
pinMode(board::SENSOR[channel_].GPIO[board::RX_NEG], LOW); | ||
pinMode(board::SENSOR[channel_].GPIO[board::TX_POS], LOW); | ||
pinMode(board::SENSOR[channel_].GPIO[board::TX_NEG], LOW); | ||
start_time = millis()*100; | ||
} | ||
|
||
|
||
}*/ | ||
char * GrabSampler::name() | ||
{ | ||
return "GrabSampler"; | ||
|
||
} | ||
|
||
void GrabSampler::enable(int pump_num) | ||
{ | ||
|
||
switch(pump_num) | ||
{ | ||
case 0: case 1: digitalWrite(board::SENSOR[channel_].GPIO[board::RX_POS], HIGH); analogWrite(board::SENSOR[channel_].GPIO[board::RX_NEG], pump_num == 0 ? 255 : 0); break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indenting/newlines here to look like a normal switch case. |
||
case 2: case 3: digitalWrite(board::SENSOR[channel_].GPIO[board::TX_POS], HIGH); analogWrite(board::SENSOR[channel_].GPIO[board::TX_NEG], pump_num == 2 ? 255 : 0); break; | ||
default: break; | ||
}; | ||
} | ||
|
||
|
||
void GrabSampler::disable(int pump_num) | ||
{ | ||
digitalWrite(board::SENSOR[channel_].GPIO[pump_num < 2 ? board::RX_POS: board::TX_POS], LOW); | ||
} | ||
|
||
bool GrabSampler::set(const char* param, const char* value) | ||
{ | ||
// Turn pumps on or off depending on command | ||
if (!strncmp("e", param, 2)) | ||
{ | ||
int pump_num = atol(value); | ||
active[pump_num] = true; | ||
enable(pump_num); | ||
powerOn(); | ||
return true; | ||
} | ||
else if (!strncmp("d", param, 2)) | ||
{ | ||
int pump_num = atol(value); | ||
active[pump_num] = false; | ||
disable(pump_num); | ||
|
||
//Check if any pump is still enabled | ||
for(int i = 0; i < 4; i++) if (active[i]) return true; | ||
|
||
powerOff(); | ||
return true; | ||
} | ||
// Return false for unknown command. | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline this brace.