LCD implementation of our project.
Dependencies: mbed mbed-rtos MLX90614
Revision 8:81ed1135ba02, committed 2015-06-03
- Comitter:
- ovidiup13
- Date:
- Wed Jun 03 16:37:21 2015 +0000
- Parent:
- 7:11675c1dce4f
- Child:
- 9:4bed81856c2f
- Commit message:
- done something, idk what
Changed in this revision
--- a/Compass.cpp Wed Jun 03 12:22:46 2015 +0000 +++ b/Compass.cpp Wed Jun 03 16:37:21 2015 +0000 @@ -1,11 +1,14 @@ #include "Compass.h" //constructor -Compass::Compass(ST7565 * lcd, Item * back) +Compass::Compass(ST7565 * lcd, Item * back, DigitalOut *gyro, DigitalOut *thermo) { this->title = " Compass"; this->st7565= lcd; this->back = back; + this->gyro = gyro; + this->thermo = thermo; + ct = NULL; } @@ -14,6 +17,7 @@ { //create a new thread to get and update compass - do later if(ct != NULL) return; //thread is already running + thermo->write(0); gyro->write(1); ct = new Thread(&Compass::ct_start, this); ct->signal_set(START_THREAD); } @@ -37,7 +41,7 @@ #ifdef LSM303_on LSM303(&state); #endif - draw_compass(state.heading - 33 + 90); //offset + draw_compass(state.heading - 33); //add offset Thread::wait(30); st7565->clear(); } @@ -50,8 +54,8 @@ //kill thread and go back if(c == 'y') { ct->terminate(); - free(ct); - ct = NULL; + free(ct); ct = NULL; + gyro->write(0); st7565->clear();//clear everything this->setSelectedScreen(back); } else @@ -84,7 +88,7 @@ { //variables int x_temp, y_temp; - double rad = degrees * M_PI / 180; //radians + double rad = (degrees + 90) * M_PI / 180; //radians //calculate coordinates to point x_temp = X_CENTER + (int) (POINTER_LENGTH * cos(rad)); @@ -109,13 +113,13 @@ //display pointing direction st7565->drawstring(0, 2, "Pointing:"); - char * pointer = get_direction(degrees); + char * pointer = get_direction(degrees + 90); st7565->drawstring(0, 4, pointer); //display degrees and radians in bottom left corner char s_deg[10], s_rad[10]; - sprintf(s_deg, "DEG:%0.2g", degrees); - sprintf(s_rad, "RAD:%.2g", rad); + sprintf(s_deg, "DEG:%d", (int)degrees % 360); + sprintf(s_rad, "RAD:%0.2f", (int)degrees % 360 * M_PI / 180.0); st7565->drawstring(1, 6, s_deg); st7565->drawstring(1, 7, s_rad);
--- a/Compass.h Wed Jun 03 12:22:46 2015 +0000 +++ b/Compass.h Wed Jun 03 16:37:21 2015 +0000 @@ -22,12 +22,13 @@ virtual void update(char c); //constructor - Compass(ST7565 *lcd, Item *back); + Compass(ST7565 *lcd, Item *back, DigitalOut *gyro, DigitalOut *thermo); private: Thread *ct; //compass update thread //helper functions + DigitalOut *gyro, *thermo; void draw_compass(double degrees); static void ct_start(void const *args); void compass_update(void);
--- a/Item.h Wed Jun 03 12:22:46 2015 +0000 +++ b/Item.h Wed Jun 03 16:37:21 2015 +0000 @@ -4,6 +4,7 @@ #include "st7565LCD.h" #include "rtos.h" #include "gyro.h" +#include "mbed.h" //screen configuration #define LEFT_MARGIN 5
--- a/LevelMeter.cpp Wed Jun 03 12:22:46 2015 +0000 +++ b/LevelMeter.cpp Wed Jun 03 16:37:21 2015 +0000 @@ -1,10 +1,12 @@ #include "LevelMeter.h" -LevelMeter::LevelMeter(ST7565 *lcd, Item * back) +LevelMeter::LevelMeter(ST7565 *lcd, Item * back, DigitalOut *gyro, DigitalOut *thermo) { this->st7565 = lcd; this->title = " Level meter"; this->back = back; + this->gyro = gyro; + this->thermo = thermo; lt = NULL; } @@ -12,6 +14,7 @@ { //create a new thread to get and update compass - do later if(lt != NULL) return;//thread is already running + thermo->write(0); gyro->write(1); lt = new Thread(&LevelMeter::lt_start, this); lt->signal_set(START_THREAD); } @@ -33,7 +36,7 @@ while(true) { calc_avrg_or(&result,2); draw_elements(result.x, result.y); - //printf("%0.0f, %0.0f\n", result.x, result.y); + printf("%0.0f, %0.0f\n", result.x, result.y); Thread::wait(15); st7565->clear(); } @@ -73,6 +76,8 @@ //display st7565->display(); + free(rsx); + free(rsy); } void LevelMeter::update(char c) @@ -80,6 +85,7 @@ if(c == 'y') { lt->terminate(); free(lt); lt = NULL; + gyro->write(0); st7565->clear(); this->setSelectedScreen(back); }
--- a/LevelMeter.h Wed Jun 03 12:22:46 2015 +0000 +++ b/LevelMeter.h Wed Jun 03 16:37:21 2015 +0000 @@ -1,4 +1,5 @@ #include "Item.h" +#include "mbed.h" //define coordinates #define X0 63 //center @@ -9,7 +10,7 @@ class LevelMeter: public Item { public: //constructors - LevelMeter(ST7565 *lcd, Item * back); + LevelMeter(ST7565 *lcd, Item * back, DigitalOut *gyro, DigitalOut *thermo); //inherited functions virtual void display(void); @@ -18,6 +19,7 @@ private: Thread *lt; + DigitalOut *gyro, *thermo; void draw_elements(double rx, double ry); static void lt_start(void const *args); void update_cross(void);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MLX90614.lib Wed Jun 03 16:37:21 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/aquahika/code/MLX90614/#dcd4fe76bd13
--- a/Measure.cpp Wed Jun 03 12:22:46 2015 +0000 +++ b/Measure.cpp Wed Jun 03 16:37:21 2015 +0000 @@ -2,6 +2,7 @@ void Measure::display(void){ this->display_items(); + laser->write(1); } void Measure::update(char c){ @@ -20,11 +21,13 @@ //go to next screen else if(c == 'y'){ if(selected == 1) - this->setSelectedScreen(next); - else if(selected == 2) this->setSelectedScreen(back); + else if(selected == 2){ + this->setSelectedScreen(back); + } else return; + laser->write(0); } //display items display_items();
--- a/Measure.h Wed Jun 03 12:22:46 2015 +0000 +++ b/Measure.h Wed Jun 03 16:37:21 2015 +0000 @@ -4,13 +4,8 @@ class Measure: public Item { public: - //menu items - only 2 -> start and back - Item **items[2]; - Item *next; //screen to go next - bool hasResult; - - //constructors - Measure(char * title, ST7565 *lcd, Item *back){ + //constructor for thermometer + Measure(char * title, ST7565 *lcd, Item *back, DigitalOut *laser){ this->title = title; this->st7565 = lcd; this->back = back; @@ -18,8 +13,14 @@ hasResult = false; selected = 1; current_line = 6; + isOn = false; + this->laser = laser; }; + //Measure(char *title, ST7565, *lcd, Item *back, DigitalOut *laser); + //Measure(char * title, ST7565 *lcd, Item *back); + //constructor for thermometer + //Measure(char *title, ST7565 *lcd, Item *back, DigitalOut *gyro, DigitalOut *thermo); Measure(); //inherited functions @@ -43,6 +44,16 @@ } private: + //digital outputs for controlling stuff + DigitalOut *laser; + + //menu items - only 2 -> start and back + Item **items[2]; + Item *next; //screen to go next + + + bool hasResult, isOn; + int selected, current_line; char * description, *nextName, *backName; void display_description(char *r);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Thermometer.cpp Wed Jun 03 16:37:21 2015 +0000 @@ -0,0 +1,51 @@ +#include "Thermometer.h" + +Thermometer::Thermometer(ST7565 *lcd, Item *back, DigitalOut *gyro, DigitalOut *thermo){ + this->title = " Thermometer"; + this->st7565 = lcd; + this->back = back; + this->gyro = gyro; + this->thermo = thermo; + tt = NULL; +} + +void Thermometer::display(void){ + if(tt != NULL) return; + gyro->write(0); thermo->write(1); + tt = new Thread(&Thermometer::tt_start, this); + tt->signal_set(START_THREAD); +} + +void Thermometer::tt_start(const void * args){ + Thermometer *t = (Thermometer*)args; + t->display_temperature(); +} + +void Thermometer::display_temperature(){ + tt->signal_wait(START_THREAD); + + float temp; + char temp_char[50]; + while(1){ + temp = get_temperature(); + //get temperature and display it + sprintf(temp_char, "Temperature is: %0.2f", temp); + st7565->drawstring(5, 3, temp_char); + st7565->display(); + Thread::wait(15); + st7565->clear(); + } +} + +void Thermometer::update(char c){ + if(c == 'y'){ + tt->terminate(); + free(tt); tt = NULL; + thermo->write(0); + st7565->clear(); + this->setSelectedScreen(back); + } +} + + + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Thermometer.h Wed Jun 03 16:37:21 2015 +0000 @@ -0,0 +1,19 @@ +#include "Item.h" + + +class Thermometer: public Item { + public: + Thermometer(ST7565 *lcd, Item *back, DigitalOut *gyro, DigitalOut *thermo); + + //inherited functions + virtual void display(void); + virtual void update(char c); + + private: + Thread *tt; + + DigitalOut *gyro, *thermo; + char * title; + static void tt_start(const void *args); + void display_temperature(); +}; \ No newline at end of file
--- a/UserInterface.h Wed Jun 03 12:22:46 2015 +0000 +++ b/UserInterface.h Wed Jun 03 16:37:21 2015 +0000 @@ -9,6 +9,7 @@ #include "Compass.h" #include "LevelMeter.h" #include "Measure.h" +#include "Thermometer.h" //include libs #include <string.h>
--- a/gyro.cpp Wed Jun 03 12:22:46 2015 +0000 +++ b/gyro.cpp Wed Jun 03 16:37:21 2015 +0000 @@ -2,7 +2,7 @@ //DigitalOut myled(LED1); //Serial pc(USBTX, USBRX); // tx, rx for USB debug printf to terminal console -I2C i2c(p28, p27); // LPC1768 I2C pin allocation +I2C i2c(p9, p10); // LPC1768 I2C pin allocation //DigitalIn din(p23); // used as a test button // Globals @@ -10,6 +10,13 @@ int16_t const Offset_mY=-115.0; float const RadtoDeg=(180.0/3.141592654); +MLX90614 IR_thermometer(&i2c); + +float get_temperature(void){ + float temp; + IR_thermometer.getTemp(&temp); + return temp; +} char readByte(char address, char reg) // Reads one byte from an I2C address
--- a/gyro.h Wed Jun 03 12:22:46 2015 +0000 +++ b/gyro.h Wed Jun 03 16:37:21 2015 +0000 @@ -11,6 +11,9 @@ #include "mbed.h" #include "MKI124V1.h" #include "math.h" +#include "mlx90614.h" + +float get_temperature(void); char readByte(char address, char reg);
--- a/main.cpp Wed Jun 03 12:22:46 2015 +0000 +++ b/main.cpp Wed Jun 03 16:37:21 2015 +0000 @@ -11,6 +11,13 @@ DigitalIn select(p22); DigitalIn up(p20); +//laser +DigitalOut laser_mod(p21, 0); + +//gyro and thermo digital out +DigitalOut gyro(P0_29, 0); //pin31 +DigitalOut thermo(P0_30, 0); //pin32 + int main(){ //create god UI object UI * ui = new UI(&st7565); @@ -20,19 +27,11 @@ //create distance screens - Measure *distance = new Measure(" Distance", &st7565, main_menu); - distance->setDescription("Select Start from the menu below to start laser."); - Measure *distance2 = new Measure(" Distance", &st7565, distance); - distance2->setDescription("Press select button to fix target."); - Measure *distance3 = new Measure(" Distance", &st7565, main_menu); - distance3->setDescription("Distance to target is:"); - distance3->setResult(true); - - distance->setNext(" Start", distance2); - distance2->setNext(" Select", distance3); - distance3->setNext(" Start again", distance); + Measure *distance = new Measure(" Distance", &st7565, main_menu, &laser_mod); + distance->setDescription("Select Start from the menu below to start laser."); main_menu->addItem(distance); + /* //create point-to-point screens Measure *p2p = new Measure(" Point-to-Point", &st7565, main_menu); p2p->setDescription("Select Start from the menu to start laser for #1 target."); @@ -49,16 +48,21 @@ p2p3->setNext(" Select", p2p4); p2p4->setNext(" Start again", p2p); main_menu->addItem(p2p); + */ //create level meter screen - LevelMeter *lvl = new LevelMeter(&st7565, main_menu); + LevelMeter *lvl = new LevelMeter(&st7565, main_menu, &gyro, &thermo); main_menu->addItem(lvl); //create compass screen - Compass *compass = new Compass(&st7565, main_menu); + Compass *compass = new Compass(&st7565, main_menu, &gyro, &thermo); main_menu->addItem(compass); //create thermo screen + Thermometer *thermo_screen = new Thermometer(&st7565, main_menu, &gyro, &thermo); + main_menu->addItem(thermo_screen); + + /* Measure *thermo = new Measure(" Thermometer", &st7565, main_menu); thermo->setDescription("Press Start from the menu to start laser."); Measure *thermo2 = new Measure(" Thermometer", &st7565, thermo); @@ -70,7 +74,7 @@ thermo->setNext(" Start", thermo2); thermo2->setNext(" Start", thermo3); thermo3->setNext(" Start", thermo); - main_menu->addItem(thermo); + */ //create header object Header * header = new Header("", &st7565); @@ -83,19 +87,19 @@ while(1) { if(select){ wait(0.1); - printf("select\n"); + //printf("select\n"); ui->update('y'); //ascii 121 wait(WAIT_TIME); } else if(up){ wait(0.1); - printf("up\n"); + //printf("up\n"); ui->update('w'); //ascii 119 wait(WAIT_TIME); } else if(down){ wait(0.1); - printf("down\n"); + //printf("down\n"); ui->update('s'); //ascii 115 wait(WAIT_TIME); }