Mario Simaremare
/
g3_waterplay
Salinity and temperature sensors are implemented in classes.
Revision 15:e112bab9aa2f, committed 2016-06-28
- Comitter:
- mariosimaremare
- Date:
- Tue Jun 28 12:30:40 2016 +0000
- Parent:
- 14:6c24cab82ff0
- Commit message:
- Using new boxes.
Changed in this revision
--- a/Printer.cpp Fri Jun 24 13:46:52 2016 +0000 +++ b/Printer.cpp Tue Jun 28 12:30:40 2016 +0000 @@ -13,8 +13,19 @@ _serial(serial), _lcd(lcd), _serial_message("G3: WATERPLAY\n\r"), - _lcd_message("G3: WATERPLAY\n") + _lcd_message("G3: WATERPLAY\n"), + _display_status(true), + _display_action(false) +{ +} +void Printer::switchStatus() { + _display_status = !_display_status; +} + +void Printer::switchAction() +{ + _display_action = !_display_action; } void Printer::toSerial(char *message) { @@ -54,48 +65,54 @@ } void Printer::display() { - this->_serial.printf( - "%s", - this->_serial_message - ); - - this->_lcd.cls(); - this->_lcd.printf( - "%s", - this->_lcd_message - ); + if(_display_action){ + this->_serial.printf( + "%s", + this->_serial_message + ); + + this->_lcd.cls(); + this->_lcd.printf( + "%s", + this->_lcd_message + ); + } } void Printer::display(double salinity, char* salinityStatus, double temperature, char* temperatureStatus) { - this->_serial.printf( - "salinity: %3.2F (%s) || temperature: %3.2F (%s)\n\r", - salinity, - salinityStatus, - temperature, - temperatureStatus - - ); - - this->_lcd.cls(); - this->_lcd.printf( - "sal: %3.2F %s\ntmp: %3.2F %s\n", - salinity, - salinityStatus, - temperature, - temperatureStatus - ); + if(_display_status){ + this->_serial.printf( + "salinity: %3.2F (%s) || temperature: %3.2F (%s)\n\r", + salinity, + salinityStatus, + temperature, + temperatureStatus + + ); + + this->_lcd.cls(); + this->_lcd.printf( + "sal: %3.2F %s\ntmp: %3.2F %s\n", + salinity, + salinityStatus, + temperature, + temperatureStatus + ); + } } void Printer::display(char* salinityStrStatus, char* temperatureStrStatus){ - this->_serial.printf( - "%s || %s\n\r", - salinityStrStatus, - temperatureStrStatus - ); - - this->_lcd.cls(); - this->_lcd.printf( - "%s\n%s\n", - salinityStrStatus, - temperatureStrStatus - ); + if(_display_status){ + this->_serial.printf( + "%s || %s\n\r", + salinityStrStatus, + temperatureStrStatus + ); + + this->_lcd.cls(); + this->_lcd.printf( + "%s\n%s\n", + salinityStrStatus, + temperatureStrStatus + ); + } }
--- a/Printer.h Fri Jun 24 13:46:52 2016 +0000 +++ b/Printer.h Tue Jun 28 12:30:40 2016 +0000 @@ -22,12 +22,16 @@ void display(); void display(double salinity, char* salinityStatus, double temperature, char* temperatureStatus); void display(char* salinityStrStatus, char* temperatureStrStatus); + void switchStatus(); + void switchAction(); private: Serial &_serial; TextLCD &_lcd; char* _serial_message; char* _lcd_message; + bool _display_status; + bool _display_action; }; #endif \ No newline at end of file
--- a/Procedure.cpp Fri Jun 24 13:46:52 2016 +0000 +++ b/Procedure.cpp Tue Jun 28 12:30:40 2016 +0000 @@ -35,7 +35,7 @@ for(int counter = 0; counter < number_of_procedure;){ _printer.toBothln(procedures[counter]); - if (_button == 1){ + if (_button == 0){ counter++; } wait(1);
--- a/SalinitySensor.cpp Fri Jun 24 13:46:52 2016 +0000 +++ b/SalinitySensor.cpp Tue Jun 28 12:30:40 2016 +0000 @@ -17,7 +17,9 @@ _voltage(0.0), _salinity(0.0), _status(0.0), - _strStatus("OK") + _strStatus("OK"), + _in_boundary(false), + _in_danger(false) { this->reload(); } @@ -46,8 +48,10 @@ MULTIPLIER; - if(this->_salinity > 0.0){ - this->_salinity += VARIANCE; + this->_in_boundary = false; + if(this->_salinity > 0.25){ + this->_salinity += VARIANCE; + this->_in_boundary = true; } this->_status = 0.0; this->_strStatus = "OK"; @@ -83,4 +87,18 @@ char* SalinitySensor::getStrStatus() { return(this->_strStatus); +} + +bool SalinitySensor::inBoundary() +{ + return(this->_in_boundary); +} + +bool SalinitySensor::inDanger() +{ + bool in_danger = false; + if(this->_in_boundary && this->_salinity != 0.0){ + in_danger = true; + } + return(in_danger); } \ No newline at end of file
--- a/SalinitySensor.h Fri Jun 24 13:46:52 2016 +0000 +++ b/SalinitySensor.h Tue Jun 28 12:30:40 2016 +0000 @@ -28,6 +28,8 @@ double getSalinity(); double getStatus(); char* getStrStatus(); + bool inBoundary(); + bool inDanger(); private: Printer &_printer; @@ -37,6 +39,8 @@ double _salinity; double _status; char* _strStatus; + bool _in_boundary; + bool _in_danger; }; #endif \ No newline at end of file
--- a/TemperatureSensor.cpp Fri Jun 24 13:46:52 2016 +0000 +++ b/TemperatureSensor.cpp Tue Jun 28 12:30:40 2016 +0000 @@ -16,7 +16,8 @@ _voltage(0.0), _temperature(0.0), _status(0.0), - _strStatus("OK") + _strStatus("OK"), + _in_boundary(false) { this->reload(); } @@ -45,6 +46,11 @@ this->_temperature += 0.21*this->_temperature - 6.09; } + this->_in_boundary = false; + if(this->_temperature > 0.0 && this->_temperature < 100.0){ + this->_in_boundary = true; + } + this->_status = 0.0; this->_strStatus = "OK"; if(this->_temperature < LOWER_BOUNDARY){ @@ -89,4 +95,12 @@ bool TemperatureSensor::inBoundary(){ return(this->_in_boundary); +} + +bool TemperatureSensor::inDanger(){ + bool in_danger = false; + if(this->_in_boundary && this->_status != 0.0){ + in_danger = true; + } + return(in_danger); } \ No newline at end of file
--- a/TemperatureSensor.h Fri Jun 24 13:46:52 2016 +0000 +++ b/TemperatureSensor.h Tue Jun 28 12:30:40 2016 +0000 @@ -18,12 +18,12 @@ Printer &printer, PinName pin ); - static const double VIN = 4.85; - static const double CONVERTER = 1.6667; + static const double VIN = 3.3; + static const double CONVERTER = 1.142; static const double LOWER_BOUNDARY = 28.0; static const double UPPER_BOUNDARY = 31.9; - static const double VARIANCE = 5.0; - static const double RESISTANCE = 15000.0; + static const double VARIANCE = 0.0; + static const double RESISTANCE = 20000.0; static const int SAMPLING_NUMBER = 100; static const double K0 = 0.00102119; static const double K1 = 0.000222468; @@ -36,6 +36,7 @@ double getStatus(); char* getStrStatus(); bool inBoundary(); + bool inDanger(); private: Printer &_printer;
--- a/Waterplay.cpp Fri Jun 24 13:46:52 2016 +0000 +++ b/Waterplay.cpp Tue Jun 28 12:30:40 2016 +0000 @@ -29,7 +29,7 @@ int retVal = 1; _temperatureSensor.reload(); _salinitySensor.reload(); - _flasher.flash(1); + _flasher.flash(0.1); _printer.display( _salinitySensor.getSalinity(), @@ -38,38 +38,36 @@ _temperatureSensor.getStrStatus() ); _flasher.flash(2); - + if( - _temperatureSensor.getTemperature() > 0.0 - && _temperatureSensor.getTemperature() < 100.0 - ) { - if(_temperatureSensor.getStatus() < 0.0) { - _alarm.danger_flash(); + !_temperatureSensor.inBoundary() + || !_salinitySensor.inBoundary() + || !_tank.is_proximity_ok() + ){ + if(!_temperatureSensor.inBoundary()){ + _printer.toBothln("check the temperature sensor"); } + + if(_salinitySensor.inBoundary()){ + _printer.toBothln("check the salinity sensor"); + } + + if(!_tank.is_proximity_ok()){ + _printer.toBothln("check the salinity sensor"); + } + _alarm.danger_flash_long(); + } + + if(_temperatureSensor.inDanger()) { _thermostat.react( _temperatureSensor.getStatus() ); - } else { - _printer.toBothln("check the temperature sensor"); - _alarm.danger_flash_long(); - //wait(10.0); } - if( - _salinitySensor.getSalinity() > 0.25 // avoid interferences. - ) { - if(_salinitySensor.getStatus() != 0.0){ - _alarm.danger_flash(); - } + if(_salinitySensor.inDanger()) { _tank.react( _salinitySensor.getStatus() ); - - - } else { - _printer.toBothln("check the salinity sensor"); - _alarm.danger_flash_long(); - //wait(10.0); } _printer.display(
--- a/main.cpp Fri Jun 24 13:46:52 2016 +0000 +++ b/main.cpp Tue Jun 28 12:30:40 2016 +0000 @@ -28,6 +28,8 @@ Serial serial(USBTX, USBRX); Flasher led1(LED1); Flasher alarm(p17); +InterruptIn statusSwitch(p8); +InterruptIn actionSwitch(p9); Printer printer(serial, lcd); SalinitySensor salinitySensor( @@ -47,7 +49,7 @@ ); Ping pinger(p30); - + Tank tank( printer, salinitySyringe, @@ -55,7 +57,7 @@ pinger, alarm ); - + Waterplay waterplay( printer, temperatureSensor, @@ -72,13 +74,24 @@ printer, button ); + +void switchStatus(){ + printer.switchStatus(); +} + +void switchAction(){ + printer.switchAction(); +} int main() { + statusSwitch.rise(switchStatus); + actionSwitch.rise(switchAction); + printer.display(); led1.flash(1); - procedure.proceed(); - tank.initialize(); + //procedure.proceed(); + //tank.initialize(); while(keep_running) { waterplay.control();