Team Alpha / Mbed 2 deprecated UserIntefaceLCD

Dependencies:   mbed mbed-rtos MLX90614

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Thermometer.cpp Source File

Thermometer.cpp

00001 #include "Thermometer.h"
00002 
00003 Thermometer::Thermometer(ST7565 *lcd, Item *back, DigitalOut *gyro, DigitalOut *thermo){
00004     this->title = " Thermometer";
00005     this->st7565 = lcd;
00006     this->back = back;
00007     this->gyro = gyro;
00008     this->thermo = thermo;
00009     tt = NULL;
00010 }
00011 
00012 void Thermometer::display(void){
00013     if(tt != NULL) return;
00014     gyro->write(0); thermo->write(1);
00015     tt = new Thread(&Thermometer::tt_start, this);
00016     tt->signal_set(START_THREAD);    
00017 }
00018 
00019 void Thermometer::tt_start(const void * args){
00020     Thermometer *t = (Thermometer*)args;
00021     t->display_temperature();
00022 }
00023 
00024 void Thermometer::display_temperature(){
00025     tt->signal_wait(START_THREAD);
00026     
00027     float temp;
00028     char temp_char[50];
00029     while(1){
00030         temp = get_temperature();
00031         //get temperature and display it
00032         sprintf(temp_char, "Temperature is: %0.2f", temp);
00033         st7565->drawstring(5, 3, temp_char);
00034         st7565->display();
00035         Thread::wait(15);
00036         st7565->clear();
00037     }
00038 }
00039 
00040 void Thermometer::update(char c){
00041     if(c == 'y'){
00042         tt->terminate();
00043         free(tt); tt = NULL;
00044         thermo->write(0);
00045         st7565->clear();
00046         this->setSelectedScreen(back);
00047     }
00048 }
00049 
00050 
00051