Test session
Dependencies: FatFileSystem MCP23017 WattBob_TextLCD mbed
Fork of Assignment_2_herpe by
lcd_helper.cpp
00001 /** 00002 * Mostly just a wrapper around the LCD display. 00003 * 00004 * Author: Jacob Baungard Hansen 00005 */ 00006 00007 #include "lcd_helper.h" 00008 00009 /** 00010 * Constructor setups the LCD Display 00011 * and writes initial values needed for this project. 00012 */ 00013 LCDHelper::LCDHelper() { 00014 00015 this->par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip 00016 this->lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display 00017 par_port->write_bit(1,BL_BIT); // turn LCD backlight ON 00018 00019 lcd->cls(); // clear display 00020 00021 this->print("Fr d1 d2 ", "a1 a2 e "); 00022 00023 } 00024 00025 LCDHelper::~LCDHelper() { 00026 delete this->par_port; 00027 delete this->lcd; 00028 } 00029 00030 /** 00031 * Clears the display and prints one line 00032 */ 00033 void LCDHelper::print(std::string line1) { 00034 this->print(line1, std::string()); 00035 } 00036 00037 /** 00038 * Clears the display and prints two lines 00039 */ 00040 void LCDHelper::print(std::string line1, std::string line2) { 00041 lcd->cls(); // clear display 00042 00043 lcd->locate(0,0); // set cursor to location (0,0) - top left corner 00044 lcd->printf(line1.c_str()); 00045 00046 // only print line2 if it contains data 00047 if (!line2.empty()) { 00048 lcd->locate(1,0); // set cursor to location (1,0) - bottom left corner 00049 lcd->printf(line2.c_str()); 00050 } 00051 } 00052 00053 void LCDHelper::clear() { 00054 lcd->cls(); // clear display 00055 } 00056 00057 /** 00058 * 00059 * 00060 * @Param state pointer to state object 00061 */ 00062 void LCDHelper::print_state(State * state) { 00063 lcd->locate(0,3); 00064 lcd->printf("%d", state->get_freq()); 00065 00066 lcd->locate(0,10); 00067 lcd->printf("%d", state->get_digital_1()); 00068 00069 lcd->locate(0,15); 00070 lcd->printf("%d", state->get_digital_2()); 00071 00072 lcd->locate(1,3); 00073 // printf is very slow at converting from float to int 00074 int avg_analog_1 = (int) floor( state->get_avg_analog_1() + 0.5); 00075 lcd->printf("%d", avg_analog_1); 00076 00077 lcd->locate(1,8); 00078 // printf is very slow at converting from float to int 00079 int avg_analog_2 = (int) floor( state->get_avg_analog_2() + 0.5); 00080 lcd->printf("%d", avg_analog_2); 00081 00082 lcd->locate(1,12); 00083 lcd->printf("%d", state->get_error() ); 00084 00085 }
Generated on Thu Jul 14 2022 10:33:15 by
1.7.2
