Mario Simaremare
/
g3_waterplay
Salinity and temperature sensors are implemented in classes.
Printer.cpp@15:e112bab9aa2f, 2016-06-28 (annotated)
- Committer:
- mariosimaremare
- Date:
- Tue Jun 28 12:30:40 2016 +0000
- Revision:
- 15:e112bab9aa2f
- Parent:
- 14:6c24cab82ff0
Using new boxes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mariosimaremare | 3:7c648d1d8802 | 1 | /* |
mariosimaremare | 3:7c648d1d8802 | 2 | * G3: WATERPLAY |
mariosimaremare | 3:7c648d1d8802 | 3 | */ |
mariosimaremare | 3:7c648d1d8802 | 4 | |
mariosimaremare | 3:7c648d1d8802 | 5 | #include "Printer.h" |
mariosimaremare | 3:7c648d1d8802 | 6 | #include "TextLCD.h" |
mariosimaremare | 3:7c648d1d8802 | 7 | #include "mbed.h" |
mariosimaremare | 3:7c648d1d8802 | 8 | |
mariosimaremare | 3:7c648d1d8802 | 9 | Printer::Printer( |
mariosimaremare | 3:7c648d1d8802 | 10 | mbed::Serial &serial, |
mariosimaremare | 3:7c648d1d8802 | 11 | TextLCD &lcd |
mariosimaremare | 3:7c648d1d8802 | 12 | ): |
mariosimaremare | 3:7c648d1d8802 | 13 | _serial(serial), |
mariosimaremare | 3:7c648d1d8802 | 14 | _lcd(lcd), |
mariosimaremare | 3:7c648d1d8802 | 15 | _serial_message("G3: WATERPLAY\n\r"), |
mariosimaremare | 15:e112bab9aa2f | 16 | _lcd_message("G3: WATERPLAY\n"), |
mariosimaremare | 15:e112bab9aa2f | 17 | _display_status(true), |
mariosimaremare | 15:e112bab9aa2f | 18 | _display_action(false) |
mariosimaremare | 15:e112bab9aa2f | 19 | { |
mariosimaremare | 15:e112bab9aa2f | 20 | } |
mariosimaremare | 15:e112bab9aa2f | 21 | void Printer::switchStatus() |
mariosimaremare | 3:7c648d1d8802 | 22 | { |
mariosimaremare | 15:e112bab9aa2f | 23 | _display_status = !_display_status; |
mariosimaremare | 15:e112bab9aa2f | 24 | } |
mariosimaremare | 15:e112bab9aa2f | 25 | |
mariosimaremare | 15:e112bab9aa2f | 26 | void Printer::switchAction() |
mariosimaremare | 15:e112bab9aa2f | 27 | { |
mariosimaremare | 15:e112bab9aa2f | 28 | _display_action = !_display_action; |
mariosimaremare | 3:7c648d1d8802 | 29 | } |
mariosimaremare | 3:7c648d1d8802 | 30 | void Printer::toSerial(char *message) |
mariosimaremare | 3:7c648d1d8802 | 31 | { |
mariosimaremare | 3:7c648d1d8802 | 32 | this->_serial_message = message; |
mariosimaremare | 3:7c648d1d8802 | 33 | this->display(); |
mariosimaremare | 3:7c648d1d8802 | 34 | } |
mariosimaremare | 3:7c648d1d8802 | 35 | void Printer::toLCD(char *message) |
mariosimaremare | 3:7c648d1d8802 | 36 | { |
mariosimaremare | 3:7c648d1d8802 | 37 | this->_lcd_message = message; |
mariosimaremare | 3:7c648d1d8802 | 38 | this->display(); |
mariosimaremare | 3:7c648d1d8802 | 39 | } |
mariosimaremare | 3:7c648d1d8802 | 40 | void Printer::toBoth(char *message) |
mariosimaremare | 3:7c648d1d8802 | 41 | { |
mariosimaremare | 3:7c648d1d8802 | 42 | this->_serial_message = message; |
mariosimaremare | 3:7c648d1d8802 | 43 | this->_lcd_message = message; |
mariosimaremare | 3:7c648d1d8802 | 44 | this->display(); |
mariosimaremare | 3:7c648d1d8802 | 45 | } |
mariosimaremare | 5:4cbe44452889 | 46 | void Printer::toBothln(char *message) |
mariosimaremare | 5:4cbe44452889 | 47 | { |
mariosimaremare | 14:6c24cab82ff0 | 48 | char serial_buffer[48]; |
mariosimaremare | 14:6c24cab82ff0 | 49 | char lcd_buffer[48]; |
mariosimaremare | 5:4cbe44452889 | 50 | sprintf( |
mariosimaremare | 5:4cbe44452889 | 51 | serial_buffer, |
mariosimaremare | 5:4cbe44452889 | 52 | "%s\n\r", |
mariosimaremare | 5:4cbe44452889 | 53 | message |
mariosimaremare | 5:4cbe44452889 | 54 | ); |
mariosimaremare | 5:4cbe44452889 | 55 | |
mariosimaremare | 5:4cbe44452889 | 56 | sprintf( |
mariosimaremare | 5:4cbe44452889 | 57 | lcd_buffer, |
mariosimaremare | 5:4cbe44452889 | 58 | "%s\n", |
mariosimaremare | 5:4cbe44452889 | 59 | message |
mariosimaremare | 5:4cbe44452889 | 60 | ); |
mariosimaremare | 5:4cbe44452889 | 61 | |
mariosimaremare | 5:4cbe44452889 | 62 | this->_serial_message = serial_buffer; |
mariosimaremare | 5:4cbe44452889 | 63 | this->_lcd_message = lcd_buffer; |
mariosimaremare | 5:4cbe44452889 | 64 | this->display(); |
mariosimaremare | 5:4cbe44452889 | 65 | } |
mariosimaremare | 3:7c648d1d8802 | 66 | void Printer::display() |
mariosimaremare | 3:7c648d1d8802 | 67 | { |
mariosimaremare | 15:e112bab9aa2f | 68 | if(_display_action){ |
mariosimaremare | 15:e112bab9aa2f | 69 | this->_serial.printf( |
mariosimaremare | 15:e112bab9aa2f | 70 | "%s", |
mariosimaremare | 15:e112bab9aa2f | 71 | this->_serial_message |
mariosimaremare | 15:e112bab9aa2f | 72 | ); |
mariosimaremare | 15:e112bab9aa2f | 73 | |
mariosimaremare | 15:e112bab9aa2f | 74 | this->_lcd.cls(); |
mariosimaremare | 15:e112bab9aa2f | 75 | this->_lcd.printf( |
mariosimaremare | 15:e112bab9aa2f | 76 | "%s", |
mariosimaremare | 15:e112bab9aa2f | 77 | this->_lcd_message |
mariosimaremare | 15:e112bab9aa2f | 78 | ); |
mariosimaremare | 15:e112bab9aa2f | 79 | } |
mariosimaremare | 3:7c648d1d8802 | 80 | } |
mariosimaremare | 3:7c648d1d8802 | 81 | void Printer::display(double salinity, char* salinityStatus, double temperature, char* temperatureStatus) |
mariosimaremare | 3:7c648d1d8802 | 82 | { |
mariosimaremare | 15:e112bab9aa2f | 83 | if(_display_status){ |
mariosimaremare | 15:e112bab9aa2f | 84 | this->_serial.printf( |
mariosimaremare | 15:e112bab9aa2f | 85 | "salinity: %3.2F (%s) || temperature: %3.2F (%s)\n\r", |
mariosimaremare | 15:e112bab9aa2f | 86 | salinity, |
mariosimaremare | 15:e112bab9aa2f | 87 | salinityStatus, |
mariosimaremare | 15:e112bab9aa2f | 88 | temperature, |
mariosimaremare | 15:e112bab9aa2f | 89 | temperatureStatus |
mariosimaremare | 15:e112bab9aa2f | 90 | |
mariosimaremare | 15:e112bab9aa2f | 91 | ); |
mariosimaremare | 15:e112bab9aa2f | 92 | |
mariosimaremare | 15:e112bab9aa2f | 93 | this->_lcd.cls(); |
mariosimaremare | 15:e112bab9aa2f | 94 | this->_lcd.printf( |
mariosimaremare | 15:e112bab9aa2f | 95 | "sal: %3.2F %s\ntmp: %3.2F %s\n", |
mariosimaremare | 15:e112bab9aa2f | 96 | salinity, |
mariosimaremare | 15:e112bab9aa2f | 97 | salinityStatus, |
mariosimaremare | 15:e112bab9aa2f | 98 | temperature, |
mariosimaremare | 15:e112bab9aa2f | 99 | temperatureStatus |
mariosimaremare | 15:e112bab9aa2f | 100 | ); |
mariosimaremare | 15:e112bab9aa2f | 101 | } |
mariosimaremare | 3:7c648d1d8802 | 102 | } |
mariosimaremare | 11:dcaaf1bb21ce | 103 | void Printer::display(char* salinityStrStatus, char* temperatureStrStatus){ |
mariosimaremare | 15:e112bab9aa2f | 104 | if(_display_status){ |
mariosimaremare | 15:e112bab9aa2f | 105 | this->_serial.printf( |
mariosimaremare | 15:e112bab9aa2f | 106 | "%s || %s\n\r", |
mariosimaremare | 15:e112bab9aa2f | 107 | salinityStrStatus, |
mariosimaremare | 15:e112bab9aa2f | 108 | temperatureStrStatus |
mariosimaremare | 15:e112bab9aa2f | 109 | ); |
mariosimaremare | 15:e112bab9aa2f | 110 | |
mariosimaremare | 15:e112bab9aa2f | 111 | this->_lcd.cls(); |
mariosimaremare | 15:e112bab9aa2f | 112 | this->_lcd.printf( |
mariosimaremare | 15:e112bab9aa2f | 113 | "%s\n%s\n", |
mariosimaremare | 15:e112bab9aa2f | 114 | salinityStrStatus, |
mariosimaremare | 15:e112bab9aa2f | 115 | temperatureStrStatus |
mariosimaremare | 15:e112bab9aa2f | 116 | ); |
mariosimaremare | 15:e112bab9aa2f | 117 | } |
mariosimaremare | 11:dcaaf1bb21ce | 118 | } |