Mario Simaremare
/
g3_waterplay
Salinity and temperature sensors are implemented in classes.
Printer.cpp@14:6c24cab82ff0, 2016-06-24 (annotated)
- Committer:
- mariosimaremare
- Date:
- Fri Jun 24 13:46:52 2016 +0000
- Revision:
- 14:6c24cab82ff0
- Parent:
- 11:dcaaf1bb21ce
- Child:
- 15:e112bab9aa2f
Finished, ready for presentation.
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 | 3:7c648d1d8802 | 16 | _lcd_message("G3: WATERPLAY\n") |
mariosimaremare | 3:7c648d1d8802 | 17 | { |
mariosimaremare | 3:7c648d1d8802 | 18 | } |
mariosimaremare | 3:7c648d1d8802 | 19 | void Printer::toSerial(char *message) |
mariosimaremare | 3:7c648d1d8802 | 20 | { |
mariosimaremare | 3:7c648d1d8802 | 21 | this->_serial_message = message; |
mariosimaremare | 3:7c648d1d8802 | 22 | this->display(); |
mariosimaremare | 3:7c648d1d8802 | 23 | } |
mariosimaremare | 3:7c648d1d8802 | 24 | void Printer::toLCD(char *message) |
mariosimaremare | 3:7c648d1d8802 | 25 | { |
mariosimaremare | 3:7c648d1d8802 | 26 | this->_lcd_message = message; |
mariosimaremare | 3:7c648d1d8802 | 27 | this->display(); |
mariosimaremare | 3:7c648d1d8802 | 28 | } |
mariosimaremare | 3:7c648d1d8802 | 29 | void Printer::toBoth(char *message) |
mariosimaremare | 3:7c648d1d8802 | 30 | { |
mariosimaremare | 3:7c648d1d8802 | 31 | this->_serial_message = message; |
mariosimaremare | 3:7c648d1d8802 | 32 | this->_lcd_message = message; |
mariosimaremare | 3:7c648d1d8802 | 33 | this->display(); |
mariosimaremare | 3:7c648d1d8802 | 34 | } |
mariosimaremare | 5:4cbe44452889 | 35 | void Printer::toBothln(char *message) |
mariosimaremare | 5:4cbe44452889 | 36 | { |
mariosimaremare | 14:6c24cab82ff0 | 37 | char serial_buffer[48]; |
mariosimaremare | 14:6c24cab82ff0 | 38 | char lcd_buffer[48]; |
mariosimaremare | 5:4cbe44452889 | 39 | sprintf( |
mariosimaremare | 5:4cbe44452889 | 40 | serial_buffer, |
mariosimaremare | 5:4cbe44452889 | 41 | "%s\n\r", |
mariosimaremare | 5:4cbe44452889 | 42 | message |
mariosimaremare | 5:4cbe44452889 | 43 | ); |
mariosimaremare | 5:4cbe44452889 | 44 | |
mariosimaremare | 5:4cbe44452889 | 45 | sprintf( |
mariosimaremare | 5:4cbe44452889 | 46 | lcd_buffer, |
mariosimaremare | 5:4cbe44452889 | 47 | "%s\n", |
mariosimaremare | 5:4cbe44452889 | 48 | message |
mariosimaremare | 5:4cbe44452889 | 49 | ); |
mariosimaremare | 5:4cbe44452889 | 50 | |
mariosimaremare | 5:4cbe44452889 | 51 | this->_serial_message = serial_buffer; |
mariosimaremare | 5:4cbe44452889 | 52 | this->_lcd_message = lcd_buffer; |
mariosimaremare | 5:4cbe44452889 | 53 | this->display(); |
mariosimaremare | 5:4cbe44452889 | 54 | } |
mariosimaremare | 3:7c648d1d8802 | 55 | void Printer::display() |
mariosimaremare | 3:7c648d1d8802 | 56 | { |
mariosimaremare | 3:7c648d1d8802 | 57 | this->_serial.printf( |
mariosimaremare | 3:7c648d1d8802 | 58 | "%s", |
mariosimaremare | 3:7c648d1d8802 | 59 | this->_serial_message |
mariosimaremare | 3:7c648d1d8802 | 60 | ); |
mariosimaremare | 3:7c648d1d8802 | 61 | |
mariosimaremare | 3:7c648d1d8802 | 62 | this->_lcd.cls(); |
mariosimaremare | 3:7c648d1d8802 | 63 | this->_lcd.printf( |
mariosimaremare | 3:7c648d1d8802 | 64 | "%s", |
mariosimaremare | 3:7c648d1d8802 | 65 | this->_lcd_message |
mariosimaremare | 3:7c648d1d8802 | 66 | ); |
mariosimaremare | 3:7c648d1d8802 | 67 | } |
mariosimaremare | 3:7c648d1d8802 | 68 | void Printer::display(double salinity, char* salinityStatus, double temperature, char* temperatureStatus) |
mariosimaremare | 3:7c648d1d8802 | 69 | { |
mariosimaremare | 3:7c648d1d8802 | 70 | this->_serial.printf( |
mariosimaremare | 3:7c648d1d8802 | 71 | "salinity: %3.2F (%s) || temperature: %3.2F (%s)\n\r", |
mariosimaremare | 3:7c648d1d8802 | 72 | salinity, |
mariosimaremare | 3:7c648d1d8802 | 73 | salinityStatus, |
mariosimaremare | 3:7c648d1d8802 | 74 | temperature, |
mariosimaremare | 3:7c648d1d8802 | 75 | temperatureStatus |
mariosimaremare | 5:4cbe44452889 | 76 | |
mariosimaremare | 3:7c648d1d8802 | 77 | ); |
mariosimaremare | 3:7c648d1d8802 | 78 | |
mariosimaremare | 3:7c648d1d8802 | 79 | this->_lcd.cls(); |
mariosimaremare | 3:7c648d1d8802 | 80 | this->_lcd.printf( |
mariosimaremare | 3:7c648d1d8802 | 81 | "sal: %3.2F %s\ntmp: %3.2F %s\n", |
mariosimaremare | 3:7c648d1d8802 | 82 | salinity, |
mariosimaremare | 3:7c648d1d8802 | 83 | salinityStatus, |
mariosimaremare | 3:7c648d1d8802 | 84 | temperature, |
mariosimaremare | 3:7c648d1d8802 | 85 | temperatureStatus |
mariosimaremare | 3:7c648d1d8802 | 86 | ); |
mariosimaremare | 3:7c648d1d8802 | 87 | } |
mariosimaremare | 11:dcaaf1bb21ce | 88 | void Printer::display(char* salinityStrStatus, char* temperatureStrStatus){ |
mariosimaremare | 11:dcaaf1bb21ce | 89 | this->_serial.printf( |
mariosimaremare | 11:dcaaf1bb21ce | 90 | "%s || %s\n\r", |
mariosimaremare | 11:dcaaf1bb21ce | 91 | salinityStrStatus, |
mariosimaremare | 11:dcaaf1bb21ce | 92 | temperatureStrStatus |
mariosimaremare | 11:dcaaf1bb21ce | 93 | ); |
mariosimaremare | 11:dcaaf1bb21ce | 94 | |
mariosimaremare | 11:dcaaf1bb21ce | 95 | this->_lcd.cls(); |
mariosimaremare | 11:dcaaf1bb21ce | 96 | this->_lcd.printf( |
mariosimaremare | 11:dcaaf1bb21ce | 97 | "%s\n%s\n", |
mariosimaremare | 11:dcaaf1bb21ce | 98 | salinityStrStatus, |
mariosimaremare | 11:dcaaf1bb21ce | 99 | temperatureStrStatus |
mariosimaremare | 11:dcaaf1bb21ce | 100 | ); |
mariosimaremare | 11:dcaaf1bb21ce | 101 | } |