Test session

Dependencies:   FatFileSystem MCP23017 WattBob_TextLCD mbed

Fork of Assignment_2_herpe by Xavier Herpe

Committer:
xouf2114
Date:
Tue Mar 14 14:46:43 2017 +0000
Revision:
4:48761259552a
Test of Assignment 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xouf2114 4:48761259552a 1 /**
xouf2114 4:48761259552a 2 * Mostly just a wrapper around the LCD display.
xouf2114 4:48761259552a 3 *
xouf2114 4:48761259552a 4 * Author: Jacob Baungard Hansen
xouf2114 4:48761259552a 5 */
xouf2114 4:48761259552a 6
xouf2114 4:48761259552a 7 #include "lcd_helper.h"
xouf2114 4:48761259552a 8
xouf2114 4:48761259552a 9 /**
xouf2114 4:48761259552a 10 * Constructor setups the LCD Display
xouf2114 4:48761259552a 11 * and writes initial values needed for this project.
xouf2114 4:48761259552a 12 */
xouf2114 4:48761259552a 13 LCDHelper::LCDHelper() {
xouf2114 4:48761259552a 14
xouf2114 4:48761259552a 15 this->par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip
xouf2114 4:48761259552a 16 this->lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display
xouf2114 4:48761259552a 17 par_port->write_bit(1,BL_BIT); // turn LCD backlight ON
xouf2114 4:48761259552a 18
xouf2114 4:48761259552a 19 lcd->cls(); // clear display
xouf2114 4:48761259552a 20
xouf2114 4:48761259552a 21 this->print("Fr d1 d2 ", "a1 a2 e ");
xouf2114 4:48761259552a 22
xouf2114 4:48761259552a 23 }
xouf2114 4:48761259552a 24
xouf2114 4:48761259552a 25 LCDHelper::~LCDHelper() {
xouf2114 4:48761259552a 26 delete this->par_port;
xouf2114 4:48761259552a 27 delete this->lcd;
xouf2114 4:48761259552a 28 }
xouf2114 4:48761259552a 29
xouf2114 4:48761259552a 30 /**
xouf2114 4:48761259552a 31 * Clears the display and prints one line
xouf2114 4:48761259552a 32 */
xouf2114 4:48761259552a 33 void LCDHelper::print(std::string line1) {
xouf2114 4:48761259552a 34 this->print(line1, std::string());
xouf2114 4:48761259552a 35 }
xouf2114 4:48761259552a 36
xouf2114 4:48761259552a 37 /**
xouf2114 4:48761259552a 38 * Clears the display and prints two lines
xouf2114 4:48761259552a 39 */
xouf2114 4:48761259552a 40 void LCDHelper::print(std::string line1, std::string line2) {
xouf2114 4:48761259552a 41 lcd->cls(); // clear display
xouf2114 4:48761259552a 42
xouf2114 4:48761259552a 43 lcd->locate(0,0); // set cursor to location (0,0) - top left corner
xouf2114 4:48761259552a 44 lcd->printf(line1.c_str());
xouf2114 4:48761259552a 45
xouf2114 4:48761259552a 46 // only print line2 if it contains data
xouf2114 4:48761259552a 47 if (!line2.empty()) {
xouf2114 4:48761259552a 48 lcd->locate(1,0); // set cursor to location (1,0) - bottom left corner
xouf2114 4:48761259552a 49 lcd->printf(line2.c_str());
xouf2114 4:48761259552a 50 }
xouf2114 4:48761259552a 51 }
xouf2114 4:48761259552a 52
xouf2114 4:48761259552a 53 void LCDHelper::clear() {
xouf2114 4:48761259552a 54 lcd->cls(); // clear display
xouf2114 4:48761259552a 55 }
xouf2114 4:48761259552a 56
xouf2114 4:48761259552a 57 /**
xouf2114 4:48761259552a 58 *
xouf2114 4:48761259552a 59 *
xouf2114 4:48761259552a 60 * @Param state pointer to state object
xouf2114 4:48761259552a 61 */
xouf2114 4:48761259552a 62 void LCDHelper::print_state(State * state) {
xouf2114 4:48761259552a 63 lcd->locate(0,3);
xouf2114 4:48761259552a 64 lcd->printf("%d", state->get_freq());
xouf2114 4:48761259552a 65
xouf2114 4:48761259552a 66 lcd->locate(0,10);
xouf2114 4:48761259552a 67 lcd->printf("%d", state->get_digital_1());
xouf2114 4:48761259552a 68
xouf2114 4:48761259552a 69 lcd->locate(0,15);
xouf2114 4:48761259552a 70 lcd->printf("%d", state->get_digital_2());
xouf2114 4:48761259552a 71
xouf2114 4:48761259552a 72 lcd->locate(1,3);
xouf2114 4:48761259552a 73 // printf is very slow at converting from float to int
xouf2114 4:48761259552a 74 int avg_analog_1 = (int) floor( state->get_avg_analog_1() + 0.5);
xouf2114 4:48761259552a 75 lcd->printf("%d", avg_analog_1);
xouf2114 4:48761259552a 76
xouf2114 4:48761259552a 77 lcd->locate(1,8);
xouf2114 4:48761259552a 78 // printf is very slow at converting from float to int
xouf2114 4:48761259552a 79 int avg_analog_2 = (int) floor( state->get_avg_analog_2() + 0.5);
xouf2114 4:48761259552a 80 lcd->printf("%d", avg_analog_2);
xouf2114 4:48761259552a 81
xouf2114 4:48761259552a 82 lcd->locate(1,12);
xouf2114 4:48761259552a 83 lcd->printf("%d", state->get_error() );
xouf2114 4:48761259552a 84
xouf2114 4:48761259552a 85 }