Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Printer.cpp
00001 /* 00002 * G3: WATERPLAY 00003 */ 00004 00005 #include "Printer.h" 00006 #include "TextLCD.h" 00007 #include "mbed.h" 00008 00009 Printer::Printer( 00010 mbed::Serial &serial, 00011 TextLCD &lcd 00012 ): 00013 _serial(serial), 00014 _lcd(lcd), 00015 _serial_message("G3: WATERPLAY\n\r"), 00016 _lcd_message("G3: WATERPLAY\n"), 00017 _display_status(true), 00018 _display_action(false) 00019 { 00020 } 00021 void Printer::switchStatus() 00022 { 00023 _display_status = !_display_status; 00024 } 00025 00026 void Printer::switchAction() 00027 { 00028 _display_action = !_display_action; 00029 } 00030 void Printer::toSerial(char *message) 00031 { 00032 this->_serial_message = message; 00033 this->display(); 00034 } 00035 void Printer::toLCD(char *message) 00036 { 00037 this->_lcd_message = message; 00038 this->display(); 00039 } 00040 void Printer::toBoth(char *message) 00041 { 00042 this->_serial_message = message; 00043 this->_lcd_message = message; 00044 this->display(); 00045 } 00046 void Printer::toBothln(char *message) 00047 { 00048 char serial_buffer[48]; 00049 char lcd_buffer[48]; 00050 sprintf( 00051 serial_buffer, 00052 "%s\n\r", 00053 message 00054 ); 00055 00056 sprintf( 00057 lcd_buffer, 00058 "%s\n", 00059 message 00060 ); 00061 00062 this->_serial_message = serial_buffer; 00063 this->_lcd_message = lcd_buffer; 00064 this->display(); 00065 } 00066 void Printer::display() 00067 { 00068 if(_display_action){ 00069 this->_serial.printf( 00070 "%s", 00071 this->_serial_message 00072 ); 00073 00074 this->_lcd.cls(); 00075 this->_lcd.printf( 00076 "%s", 00077 this->_lcd_message 00078 ); 00079 } 00080 } 00081 void Printer::display(double salinity, char* salinityStatus, double temperature, char* temperatureStatus) 00082 { 00083 if(_display_status){ 00084 this->_serial.printf( 00085 "salinity: %3.2F (%s) || temperature: %3.2F (%s)\n\r", 00086 salinity, 00087 salinityStatus, 00088 temperature, 00089 temperatureStatus 00090 00091 ); 00092 00093 this->_lcd.cls(); 00094 this->_lcd.printf( 00095 "sal: %3.2F %s\ntmp: %3.2F %s\n", 00096 salinity, 00097 salinityStatus, 00098 temperature, 00099 temperatureStatus 00100 ); 00101 } 00102 } 00103 void Printer::display(char* salinityStrStatus, char* temperatureStrStatus){ 00104 if(_display_status){ 00105 this->_serial.printf( 00106 "%s || %s\n\r", 00107 salinityStrStatus, 00108 temperatureStrStatus 00109 ); 00110 00111 this->_lcd.cls(); 00112 this->_lcd.printf( 00113 "%s\n%s\n", 00114 salinityStrStatus, 00115 temperatureStrStatus 00116 ); 00117 } 00118 }
Generated on Tue Jul 12 2022 19:11:49 by
1.7.2