Permalink
Browse files

Added Temperature/Humidity Sensor and Sharp PSD Sensors

  • Loading branch information...
1 parent 67993bf commit eaf423b154cc59930efef46b01528e63fcc1d516 @mmastria committed Feb 27, 2012
@@ -2,11 +2,11 @@
const char* command_name[] = {
"<shutter-event>", "Stop", "Open", "Close",
- "<shutter-state>", "Semi-Opened", "Closed", "Opened", "Closing", "Opening", "Error",
+ "<shutter-state>", "Semi-Opened", "Closed", "Opened", "Closing", "Opening", "Shutter-Error",
"<dome-event>", "Stop", "Go-Right", "Go-Left",
- "<dome-state>", "Stopped", "Going-Right", "Going-Left",
+ "<dome-state>", "Stopped", "Going-Right", "Going-Left", "Dome-Error",
"<scope-event>", "Get-TH",
- "<scope-state>", "Temp-Humid" };
+ "<scope-state>", "Temp-Humid", "Scope-Error" };
LabCommand::LabCommand() {
}
@@ -9,7 +9,7 @@ typedef enum {
DOME_EVENT, DOME_EVENT_STOP, DOME_EVENT_RIGHT, DOME_EVENT_LEFT,
DOME_STATE, DOME_STATE_STOPPED, DOME_STATE_RIGHT, DOME_STATE_LEFT, DOME_STATE_ERROR,
SCOPE_EVENT, SCOPE_EVENT_GETTH,
- SCOPE_STATE, SCOPE_STATE_TH}
+ SCOPE_STATE, SCOPE_STATE_TH, SCOPE_STATE_ERROR}
command_e;
class LabCommand {
@@ -20,6 +20,8 @@ class LabCommand {
volatile command_e cmd;
const char* getName();
+ volatile double humidity;
+ volatile double temperature;
};
@@ -15,21 +15,18 @@ void LabDome::stop() {
_motorPtr->off();
}
-command_e LabDome::checkRx() {
- command_e r = SHUTTER_STATE_ERROR;
+LabCommand *LabDome::checkRx() {
unsigned long started_waiting_at = millis();
bool timeout = false;
-// uint8_t pipe_num;
-// while (!_radioPtr->available(&pipe_num) && ! timeout )
+ LabCommand commandRx;
+ commandRx.cmd = DOME_STATE_ERROR;
while (!_radioPtr->available() && ! timeout )
if (millis() - started_waiting_at > 500 )
timeout = true;
if ( !timeout ) {
- LabCommand commandRx;
_radioPtr->read( &commandRx, sizeof(commandRx) );
- r = commandRx.cmd;
}
- return r;
+ return &commandRx;
}
void LabDome::setMotor(LabMotor *motorPtr) {
@@ -43,9 +40,7 @@ void LabDome::setRadio(RF24 *radioPtr) {
_radioPtr=radioPtr;
_radioPtr->begin();
_radioPtr->setRetries(15,15);
- //_radioPtr->openWritingPipe(pipesDomeShutter[0]);
_radioPtr->openReadingPipe(1,pipesDomeShutter[1]);
- //_radioPtr->openWritingPipe(pipesDomeScope[0]);
_radioPtr->openReadingPipe(2,pipesDomeScope[1]);
_radioPtr->startListening();
}
@@ -26,7 +26,7 @@ class LabDome {
void setMotor(LabMotor *motorPtr);
void setRadio(RF24 *radioPtr);
- command_e checkRx();
+ LabCommand *checkRx();
void shutterOpen();
void shutterStop();
@@ -78,7 +78,7 @@ void setup()
Serial.begin(57600);
printf_begin();
printf("\n\rLabDomeApp\n\r");
- printf("release 0.5 - 2012-feb-22\n\r");
+ printf("release 0.6 - 2012-feb-25\n\r");
printf("serial log 57600,n,8,1,p\n\r\n\r");
#ifdef __DEBUG__
printf("debug ON\r\n\r\n");
@@ -105,211 +105,137 @@ void setup()
_delay.wait(1000);
}
-void irCheck() {
+void check(unsigned long action) {
LabCommand commandRx;
- decode_results results;
- if(irrecv.decode(&results)) {
- if(results.decode_type == NEC) {
- switch(results.value) {
- case 0xFF22DD: // [<<] Dome Left
- beep.play();
+ switch(action) {
+ case 0xFF22DD: // [<<] Dome Left
+ case 0x4C: // [L] Dome Left
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: dome.left\n\r");
+ printf("> Call: dome.left\n\r");
#endif
- dome.left();
- commandRx.cmd = dome.getState();
+ dome.left();
+ commandRx.cmd = dome.getState();
#ifdef __DEBUG__
- printf(" St: %s\n\r", commandRx.getName());
+ printf(" St: %s\n\r", commandRx.getName());
#endif
- break;
- case 0xFF02FD: // [>>] Dome Right
- beep.play();
+ break;
+ case 0xFF02FD: // [>>] Dome Right
+ case 0x52: // [R] Dome Right
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: dome.right\n\r");
+ printf("> Call: dome.right\n\r");
#endif
- dome.right();
- commandRx.cmd = dome.getState();
+ dome.right();
+ commandRx.cmd = dome.getState();
#ifdef __DEBUG__
- printf(" St: %s\n\r", commandRx.getName());
+ printf(" St: %s\n\r", commandRx.getName());
#endif
- break;
- case 0xFFC23D: // [>||] Stop Dome
- beep.play();
+ break;
+ case 0xFFC23D: // [>||] Stop Dome
+ case 0x50: // [P] Stop Dome (Park)
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: dome.stop\n\r");
+ printf("> Call: dome.stop\n\r");
#endif
- dome.stop();
- commandRx.cmd = dome.getState();
+ dome.stop();
+ commandRx.cmd = dome.getState();
#ifdef __DEBUG__
- printf(" St: %s\n\r", commandRx.getName());
+ printf(" St: %s\n\r", commandRx.getName());
#endif
- break;
- case 0xFFE01F: // [-] Close Shutter
- beep.play();
+ break;
+ case 0xFFE01F: // [-] Close Shutter
+ case 0x44: // [-] Close Shutter (Down)
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: shutterClose\n\r");
+ printf("> Call: shutterClose\n\r");
#endif
- dome.shutterClose();
- commandRx.cmd = dome.checkRx();
+ dome.shutterClose();
+ commandRx = *dome.checkRx();
#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
+ printf(" Rx: %s\n\r", commandRx.getName());
#endif
- break;
- case 0xFFA857: // [+] Open Shutter
- beep.play();
+ break;
+ case 0xFFA857: // [+] Open Shutter
+ case 0x55: // [+] Open Shutter (Up)
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: shutterOpen\n\r");
+ printf("> Call: shutterOpen\n\r");
#endif
- dome.shutterOpen();
- commandRx.cmd = dome.checkRx();
+ dome.shutterOpen();
+ commandRx = *dome.checkRx();
#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
+ printf(" Rx: %s\n\r", commandRx.getName());
#endif
- break;
- case 0xFF906F: // [EQ] Stop Shutter
- beep.play();
+ break;
+ case 0xFF906F: // [EQ] Stop Shutter
+ case 0x53: // [EQ] Stop Shutter (Stop)
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: shutterStop\n\r");
+ printf("> Call: shutterStop\n\r");
#endif
- dome.shutterStop();
- commandRx.cmd = dome.checkRx();
+ dome.shutterStop();
+ commandRx = *dome.checkRx();
#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
+ printf(" Rx: %s\n\r", commandRx.getName());
#endif
- break;
- case 0xFFA25D: // [CH-] Get Temperature/Humidity
- beep.play();
+ break;
+ case 0xFFA25D: // [CH-] Get Temperature/Humidity
+ case 0x54: // [CH-] Get Temperature/Humidity (Temp)
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: getTH\n\r");
+ printf("> Call: getTH\n\r");
#endif
- dome.getTH();
- commandRx.cmd = dome.checkRx();
+ dome.getTH();
+ commandRx = *dome.checkRx();
#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
+ if(commandRx.cmd==SCOPE_STATE_TH) {
+ char humidityBuffer[10];
+ char temperatureBuffer[10];
+ dtostrf(commandRx.humidity, 6, 2,humidityBuffer);
+ dtostrf(commandRx.temperature, 6, 2, temperatureBuffer);
+ printf(" Rx: %s - Temperature: %s / Humidity: %s\n\r", commandRx.getName(), temperatureBuffer, humidityBuffer);
+ }
+ else {
+ printf(" Rx: %s\n\r", commandRx.getName());
+ }
#endif
- break;
- case 0xFFFFFFFF: // discard
- break;
- default:
+ break;
+ case 0xFFFFFFFF: // discard
+ break;
+ default:
#ifdef __DEBUG__
- printf("\n\rCode: %X\n\r", results.value);
+ printf("\n\rCode: %X\n\r", action);
#endif
- beep.play();
- _delay.wait(10);
- beep.play();
+ beep.play();
+ _delay.wait(10);
+ beep.play();
#ifdef __DEBUG__
- printf("> Call: shutterState\n\r");
+ printf("> Call: shutterState\n\r");
#endif
- dome.shutterState();
- commandRx.cmd = dome.checkRx();
+ dome.shutterState();
+ commandRx = *dome.checkRx();
#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
+ printf(" Rx: %s\n\r", commandRx.getName());
#endif
- }
+ }
+}
+
+void irCheck() {
+ decode_results results;
+ if(irrecv.decode(&results)) {
+ if(results.decode_type == NEC) {
+ check(results.value);
}
irrecv.resume();
}
}
void serialCheck() {
- LabCommand commandRx;
int inByte = 0;
if(Serial.available() > 0) {
- inByte = Serial.read();
- switch(inByte) {
- case 0x4C: // [L] Dome Left
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: dome.left\n\r");
-#endif
- dome.left();
- commandRx.cmd = dome.getState();
-#ifdef __DEBUG__
- printf(" St: %s\n\r", commandRx.getName());
-#endif
- break;
- case 0x52: // [R] Dome Right
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: dome.right\n\r");
-#endif
- dome.right();
- commandRx.cmd = dome.getState();
-#ifdef __DEBUG__
- printf(" St: %s\n\r", commandRx.getName());
-#endif
- break;
- case 0x50: // [P] Stop Dome (Park)
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: dome.stop\n\r");
-#endif
- dome.stop();
- commandRx.cmd = dome.getState();
-#ifdef __DEBUG__
- printf(" St: %s\n\r", commandRx.getName());
-#endif
- break;
- case 0x44: // [-] Close Shutter (Down)
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: shutterClose\n\r");
-#endif
- dome.shutterClose();
- commandRx.cmd = dome.checkRx();
-#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
-#endif
- break;
- case 0x55: // [+] Open Shutter (Up)
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: shutterOpen\n\r");
-#endif
- dome.shutterOpen();
- commandRx.cmd = dome.checkRx();
-#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
-#endif
- break;
- case 0x53: // [EQ] Stop Shutter (Stop)
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: shutterStop\n\r");
-#endif
- dome.shutterStop();
- commandRx.cmd = dome.checkRx();
-#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
-#endif
- break;
- case 0x54: // [CH-] Get Temperature/Humidity (Temp)
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: getTH\n\r");
-#endif
- dome.getTH();
- commandRx.cmd = dome.checkRx();
-#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
-#endif
- break;
- default:
-#ifdef __DEBUG__
- printf("\n\rCode: %X\n\r", inByte);
-#endif
- beep.play();
- _delay.wait(10);
- beep.play();
-#ifdef __DEBUG__
- printf("> Call: shutterState\n\r");
-#endif
- dome.shutterState();
- commandRx.cmd = dome.checkRx();
-#ifdef __DEBUG__
- printf(" Rx: %s\n\r", commandRx.getName());
-#endif
- }
+ inByte = Serial.read();
+ check(inByte);
}
}
Oops, something went wrong.

0 comments on commit eaf423b

Please sign in to comment.