This program is an advanced "IoT" thermometer using LM75B component library. It displays the current value to the Serial host in Celcius or Fahrenheit (possible to change using a switch). It also stores an historic and displays it to the user using the LCD screen. Moreover, you can change the orientation of the screen by turning the device, just like a smartphone.
Dependencies: C12832 FXOS8700CQ LM75B mbed
ThermalDisplayer.cpp@8:6f30f477fa23, 2016-02-23 (annotated)
- Committer:
- co838_gtvl2
- Date:
- Tue Feb 23 18:13:35 2016 +0000
- Revision:
- 8:6f30f477fa23
- Parent:
- 6:6c61186c8739
V1.0.1; Updated init of variables and LEDs; Removed unused file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
co838_gtvl2 | 1:06713d1b69cf | 1 | #include "ThermalDisplayer.h" |
co838_gtvl2 | 1:06713d1b69cf | 2 | |
co838_gtvl2 | 6:6c61186c8739 | 3 | /** |
co838_gtvl2 | 2:5d0c209e5c61 | 4 | * Constructor, initialize Potentiometer, LCD and variables |
co838_gtvl2 | 2:5d0c209e5c61 | 5 | */ |
co838_gtvl2 | 6:6c61186c8739 | 6 | ThermalDisplayer::ThermalDisplayer() |
co838_gtvl2 | 6:6c61186c8739 | 7 | : pot(A1), |
co838_gtvl2 | 6:6c61186c8739 | 8 | accel(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1) |
co838_gtvl2 | 2:5d0c209e5c61 | 9 | { |
co838_gtvl2 | 2:5d0c209e5c61 | 10 | this->lcd = new C12832(D11, D13, D12, D7, D10); |
co838_gtvl2 | 4:5bf99eb2d740 | 11 | this->lcd->set_auto_up(0); |
co838_gtvl2 | 2:5d0c209e5c61 | 12 | this->temperatures = std::list<float>(MAX_SIZE); |
co838_gtvl2 | 2:5d0c209e5c61 | 13 | this->minScale = MIN_MIN_SCALE; |
co838_gtvl2 | 2:5d0c209e5c61 | 14 | this->maxScale = MAX_MAX_SCALE; |
co838_gtvl2 | 4:5bf99eb2d740 | 15 | this->screenOrientation = true; |
co838_gtvl2 | 4:5bf99eb2d740 | 16 | this->accel.enable(); |
co838_gtvl2 | 1:06713d1b69cf | 17 | } |
co838_gtvl2 | 1:06713d1b69cf | 18 | |
co838_gtvl2 | 6:6c61186c8739 | 19 | /** |
co838_gtvl2 | 2:5d0c209e5c61 | 20 | * Add record to temperature historic |
co838_gtvl2 | 6:6c61186c8739 | 21 | * @param const float &temp, the record to add. |
co838_gtvl2 | 2:5d0c209e5c61 | 22 | */ |
co838_gtvl2 | 2:5d0c209e5c61 | 23 | void ThermalDisplayer::addTemp(const float &temp) |
co838_gtvl2 | 2:5d0c209e5c61 | 24 | { |
co838_gtvl2 | 1:06713d1b69cf | 25 | this->temperatures.pop_front(); |
co838_gtvl2 | 1:06713d1b69cf | 26 | this->temperatures.push_back(temp); |
co838_gtvl2 | 1:06713d1b69cf | 27 | } |
co838_gtvl2 | 1:06713d1b69cf | 28 | |
co838_gtvl2 | 6:6c61186c8739 | 29 | /** |
co838_gtvl2 | 2:5d0c209e5c61 | 30 | * Display informations to the LCD screen |
co838_gtvl2 | 3:a4dac093a968 | 31 | * Screen isn't even flusing ! |
co838_gtvl2 | 6:6c61186c8739 | 32 | * For each temperature record, it draw a white rectangle to erase previous data |
co838_gtvl2 | 6:6c61186c8739 | 33 | * then draw on top of it the new data. |
co838_gtvl2 | 2:5d0c209e5c61 | 34 | */ |
co838_gtvl2 | 2:5d0c209e5c61 | 35 | void ThermalDisplayer::display() |
co838_gtvl2 | 2:5d0c209e5c61 | 36 | { |
co838_gtvl2 | 6:6c61186c8739 | 37 | std::list<float>::const_iterator it; |
co838_gtvl2 | 2:5d0c209e5c61 | 38 | |
co838_gtvl2 | 1:06713d1b69cf | 39 | int pos = 0; |
co838_gtvl2 | 1:06713d1b69cf | 40 | for (it = this->temperatures.begin(); it != this->temperatures.end(); it++, pos++) { |
co838_gtvl2 | 2:5d0c209e5c61 | 41 | int height = (int) (32 * ((*it) - this->minScale) / (this->maxScale - this->minScale)); |
co838_gtvl2 | 4:5bf99eb2d740 | 42 | height = height > DISPLAY_Y ? DISPLAY_Y : (height < 0 ? 0 : height); |
co838_gtvl2 | 4:5bf99eb2d740 | 43 | if (this->screenOrientation) { |
co838_gtvl2 | 4:5bf99eb2d740 | 44 | this->lcd->rect(pos * 2, 0, pos * 2 + 1, DISPLAY_Y, 0); |
co838_gtvl2 | 4:5bf99eb2d740 | 45 | this->lcd->rect(pos * 2, DISPLAY_Y - height, pos * 2 + 1, DISPLAY_Y, 1); |
co838_gtvl2 | 4:5bf99eb2d740 | 46 | } else { |
co838_gtvl2 | 4:5bf99eb2d740 | 47 | this->lcd->rect(DISPLAY_X - (pos * 2), 0, DISPLAY_X - (pos * 2 + 1), DISPLAY_Y, 0); |
co838_gtvl2 | 4:5bf99eb2d740 | 48 | this->lcd->rect(DISPLAY_X - (pos * 2), 0, DISPLAY_X - (pos * 2 + 1), height, 1); |
co838_gtvl2 | 4:5bf99eb2d740 | 49 | } |
co838_gtvl2 | 1:06713d1b69cf | 50 | } |
co838_gtvl2 | 4:5bf99eb2d740 | 51 | this->lcd->copy_to_lcd(); |
co838_gtvl2 | 2:5d0c209e5c61 | 52 | } |
co838_gtvl2 | 2:5d0c209e5c61 | 53 | |
co838_gtvl2 | 6:6c61186c8739 | 54 | /** |
co838_gtvl2 | 2:5d0c209e5c61 | 55 | * Adjust scale of the display according to POT2 |
co838_gtvl2 | 4:5bf99eb2d740 | 56 | * Also adjust the screen orientation accodring to FXOS8700CQ accelerometer |
co838_gtvl2 | 2:5d0c209e5c61 | 57 | */ |
co838_gtvl2 | 6:6c61186c8739 | 58 | void ThermalDisplayer::adjustScale() |
co838_gtvl2 | 2:5d0c209e5c61 | 59 | { |
co838_gtvl2 | 2:5d0c209e5c61 | 60 | float potValue = this->pot; |
co838_gtvl2 | 2:5d0c209e5c61 | 61 | |
co838_gtvl2 | 2:5d0c209e5c61 | 62 | this->minScale = MIN_MIN_SCALE + potValue * (MAX_MIN_SCALE - MIN_MIN_SCALE); |
co838_gtvl2 | 2:5d0c209e5c61 | 63 | this->maxScale = MIN_MAX_SCALE + (1.0f - potValue) * (MAX_MAX_SCALE - MIN_MAX_SCALE); |
co838_gtvl2 | 4:5bf99eb2d740 | 64 | |
co838_gtvl2 | 4:5bf99eb2d740 | 65 | SRAWDATA accel_data; |
co838_gtvl2 | 4:5bf99eb2d740 | 66 | SRAWDATA magn_data; |
co838_gtvl2 | 4:5bf99eb2d740 | 67 | uint8_t data = this->accel.get_data(&accel_data, &magn_data); |
co838_gtvl2 | 4:5bf99eb2d740 | 68 | if (accel_data.y <= -100) { |
co838_gtvl2 | 4:5bf99eb2d740 | 69 | this->screenOrientation = false; |
co838_gtvl2 | 4:5bf99eb2d740 | 70 | } else { |
co838_gtvl2 | 4:5bf99eb2d740 | 71 | this->screenOrientation = true; |
co838_gtvl2 | 4:5bf99eb2d740 | 72 | } |
co838_gtvl2 | 1:06713d1b69cf | 73 | } |