Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station

Dependencies:   BMP180 ConfigFile N5110 PowerControl beep mbed

Committer:
OHstin
Date:
Mon May 11 15:25:52 2015 +0000
Revision:
0:da2b8c7a1ec1
Completed Weather Station

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OHstin 0:da2b8c7a1ec1 1 /**
OHstin 0:da2b8c7a1ec1 2 @file BaterryStatusScreen.h
OHstin 0:da2b8c7a1ec1 3
OHstin 0:da2b8c7a1ec1 4
OHstin 0:da2b8c7a1ec1 5 */
OHstin 0:da2b8c7a1ec1 6
OHstin 0:da2b8c7a1ec1 7 #ifndef BATTERYSTATUSSCREEN_H
OHstin 0:da2b8c7a1ec1 8 #define BATTERYSTATUSSCREEN_H
OHstin 0:da2b8c7a1ec1 9
OHstin 0:da2b8c7a1ec1 10 #include "ParameterController.h"
OHstin 0:da2b8c7a1ec1 11 #include "Inputs.h"
OHstin 0:da2b8c7a1ec1 12 #include "Sensors.h"
OHstin 0:da2b8c7a1ec1 13
OHstin 0:da2b8c7a1ec1 14 /**
OHstin 0:da2b8c7a1ec1 15
OHstin 0:da2b8c7a1ec1 16 @brief Displays the current battery voltage along with it's sentiment on the LCD screen \n
OHstin 0:da2b8c7a1ec1 17 @brief It consists of a parameter controller\n
OHstin 0:da2b8c7a1ec1 18 @brief battery voltage is shown in Volts\n
OHstin 0:da2b8c7a1ec1 19 @author Augustine Kizito K\n
OHstin 0:da2b8c7a1ec1 20 @date April 2015
OHstin 0:da2b8c7a1ec1 21
OHstin 0:da2b8c7a1ec1 22 */
OHstin 0:da2b8c7a1ec1 23
OHstin 0:da2b8c7a1ec1 24
OHstin 0:da2b8c7a1ec1 25
OHstin 0:da2b8c7a1ec1 26 class BatteryStatusScreen : public ParameterController // inherit ParameterController Properties
OHstin 0:da2b8c7a1ec1 27 {
OHstin 0:da2b8c7a1ec1 28
OHstin 0:da2b8c7a1ec1 29 public:
OHstin 0:da2b8c7a1ec1 30 /**
OHstin 0:da2b8c7a1ec1 31 This functions manages the execution of the battery status screen
OHstin 0:da2b8c7a1ec1 32 @returns
OHstin 0:da2b8c7a1ec1 33 -1 - Navigate to previous screen
OHstin 0:da2b8c7a1ec1 34 */
OHstin 0:da2b8c7a1ec1 35 int start();
OHstin 0:da2b8c7a1ec1 36 /**
OHstin 0:da2b8c7a1ec1 37 Creates an instance of the battery status screen
OHstin 0:da2b8c7a1ec1 38
OHstin 0:da2b8c7a1ec1 39 */
OHstin 0:da2b8c7a1ec1 40 BatteryStatusScreen()
OHstin 0:da2b8c7a1ec1 41 :ParameterController( "Voltage", // Parameter
OHstin 0:da2b8c7a1ec1 42 "Volts") // Units
OHstin 0:da2b8c7a1ec1 43 {} // initialises parameter controller
OHstin 0:da2b8c7a1ec1 44
OHstin 0:da2b8c7a1ec1 45 private:
OHstin 0:da2b8c7a1ec1 46
OHstin 0:da2b8c7a1ec1 47 void setVoltageSentiment( float temperature); // get temperature sentiment
OHstin 0:da2b8c7a1ec1 48 void voltageUpdate(); // update the voltage
OHstin 0:da2b8c7a1ec1 49 float getCurrentVoltage(); // get the current voltage
OHstin 0:da2b8c7a1ec1 50 void onBack(); // user pressed the back button
OHstin 0:da2b8c7a1ec1 51 void onEnter(); // user pressed the enter button
OHstin 0:da2b8c7a1ec1 52
OHstin 0:da2b8c7a1ec1 53 bool changeScreen; // tracks if the user pressed a button that changes screen
OHstin 0:da2b8c7a1ec1 54 int nextScreen; // tracks whether the user wants to go to
OHstin 0:da2b8c7a1ec1 55 //the previous screen or next screen
OHstin 0:da2b8c7a1ec1 56 Ticker voltTicker; // create ticker object
OHstin 0:da2b8c7a1ec1 57
OHstin 0:da2b8c7a1ec1 58
OHstin 0:da2b8c7a1ec1 59 };
OHstin 0:da2b8c7a1ec1 60
OHstin 0:da2b8c7a1ec1 61 int BatteryStatusScreen::start()
OHstin 0:da2b8c7a1ec1 62 {
OHstin 0:da2b8c7a1ec1 63
OHstin 0:da2b8c7a1ec1 64 changeScreen = false;
OHstin 0:da2b8c7a1ec1 65
OHstin 0:da2b8c7a1ec1 66 float currentVoltage = getCurrentVoltage(); // get current temperature
OHstin 0:da2b8c7a1ec1 67
OHstin 0:da2b8c7a1ec1 68 backButton.mode(PullDown); // activate pullDown resistor
OHstin 0:da2b8c7a1ec1 69 enterButton.mode(PullDown); // activate pullDown resistor
OHstin 0:da2b8c7a1ec1 70
OHstin 0:da2b8c7a1ec1 71 backButton.rise(this,&BatteryStatusScreen::onBack); // call onBack when the back button is pressed
OHstin 0:da2b8c7a1ec1 72
OHstin 0:da2b8c7a1ec1 73 debounce.start(); // start the debouncing timer
OHstin 0:da2b8c7a1ec1 74
OHstin 0:da2b8c7a1ec1 75 voltTicker.attach(this, &BatteryStatusScreen::voltageUpdate, 10); // update parameter every 10 seconds
OHstin 0:da2b8c7a1ec1 76
OHstin 0:da2b8c7a1ec1 77 // initialise the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 78 ParameterController::setValue(currentVoltage);
OHstin 0:da2b8c7a1ec1 79 setVoltageSentiment(currentVoltage);
OHstin 0:da2b8c7a1ec1 80
OHstin 0:da2b8c7a1ec1 81 // Launch the Parameter Controller
OHstin 0:da2b8c7a1ec1 82 ParameterController::showInfo();
OHstin 0:da2b8c7a1ec1 83
OHstin 0:da2b8c7a1ec1 84 while(changeScreen == false) { // shows the screen until the user presses the back button
OHstin 0:da2b8c7a1ec1 85 // mbed goes to sleep to save power
OHstin 0:da2b8c7a1ec1 86 Sleep();
OHstin 0:da2b8c7a1ec1 87 }
OHstin 0:da2b8c7a1ec1 88
OHstin 0:da2b8c7a1ec1 89 // detach interrupts
OHstin 0:da2b8c7a1ec1 90 backButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 91 voltTicker.detach();
OHstin 0:da2b8c7a1ec1 92
OHstin 0:da2b8c7a1ec1 93 return nextScreen;
OHstin 0:da2b8c7a1ec1 94 }
OHstin 0:da2b8c7a1ec1 95
OHstin 0:da2b8c7a1ec1 96 void BatteryStatusScreen::voltageUpdate()
OHstin 0:da2b8c7a1ec1 97 {
OHstin 0:da2b8c7a1ec1 98
OHstin 0:da2b8c7a1ec1 99 float currentVoltage = getCurrentVoltage(); // get current voltage
OHstin 0:da2b8c7a1ec1 100 // update the voltage sentiment
OHstin 0:da2b8c7a1ec1 101 setVoltageSentiment(currentVoltage);
OHstin 0:da2b8c7a1ec1 102
OHstin 0:da2b8c7a1ec1 103 // initialise the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 104 ParameterController::setValue(currentVoltage);
OHstin 0:da2b8c7a1ec1 105 ParameterController::updateInfo();
OHstin 0:da2b8c7a1ec1 106
OHstin 0:da2b8c7a1ec1 107 }
OHstin 0:da2b8c7a1ec1 108
OHstin 0:da2b8c7a1ec1 109
OHstin 0:da2b8c7a1ec1 110 void BatteryStatusScreen::setVoltageSentiment(float batteryVoltage)
OHstin 0:da2b8c7a1ec1 111 {
OHstin 0:da2b8c7a1ec1 112 if (batteryVoltage > 7.92) { // battery voltage is greater than 2.6V
OHstin 0:da2b8c7a1ec1 113 // battery has three bars
OHstin 0:da2b8c7a1ec1 114 ParameterController::setSentiment("Battery Full ");
OHstin 0:da2b8c7a1ec1 115
OHstin 0:da2b8c7a1ec1 116 } else if ( (batteryVoltage < 7.92 )&& (batteryVoltage > 6.5)) { // battery voltage is between 2.64V and 1.65V
OHstin 0:da2b8c7a1ec1 117 // battery has two bars
OHstin 0:da2b8c7a1ec1 118 ParameterController::setSentiment("Sufficient ");
OHstin 0:da2b8c7a1ec1 119
OHstin 0:da2b8c7a1ec1 120 } else if ((batteryVoltage < 6.5) && (batteryVoltage > 6)) { // battery voltage is between 1.65V and 0.66V
OHstin 0:da2b8c7a1ec1 121 // battery has one bar
OHstin 0:da2b8c7a1ec1 122 ParameterController::setSentiment("Battery Low ");
OHstin 0:da2b8c7a1ec1 123 } else { // battery voltage is less than 0.66V
OHstin 0:da2b8c7a1ec1 124 // empty battery
OHstin 0:da2b8c7a1ec1 125 ParameterController::setSentiment("Change Battery");
OHstin 0:da2b8c7a1ec1 126 }
OHstin 0:da2b8c7a1ec1 127
OHstin 0:da2b8c7a1ec1 128 }
OHstin 0:da2b8c7a1ec1 129
OHstin 0:da2b8c7a1ec1 130 float BatteryStatusScreen::getCurrentVoltage()
OHstin 0:da2b8c7a1ec1 131 {
OHstin 0:da2b8c7a1ec1 132 float voltage = getVoltage(); // read voltage
OHstin 0:da2b8c7a1ec1 133 return voltage;
OHstin 0:da2b8c7a1ec1 134 }
OHstin 0:da2b8c7a1ec1 135
OHstin 0:da2b8c7a1ec1 136 void BatteryStatusScreen::onBack()
OHstin 0:da2b8c7a1ec1 137 {
OHstin 0:da2b8c7a1ec1 138 if (debounceSuccess()) {
OHstin 0:da2b8c7a1ec1 139 playSound(); // play sound from buzzer
OHstin 0:da2b8c7a1ec1 140 nextScreen = -1;
OHstin 0:da2b8c7a1ec1 141 changeScreen = true; // user wants to view a different screen
OHstin 0:da2b8c7a1ec1 142 debounce.reset(); // reset the timer
OHstin 0:da2b8c7a1ec1 143 }
OHstin 0:da2b8c7a1ec1 144
OHstin 0:da2b8c7a1ec1 145
OHstin 0:da2b8c7a1ec1 146 }
OHstin 0:da2b8c7a1ec1 147
OHstin 0:da2b8c7a1ec1 148
OHstin 0:da2b8c7a1ec1 149
OHstin 0:da2b8c7a1ec1 150
OHstin 0:da2b8c7a1ec1 151
OHstin 0:da2b8c7a1ec1 152 #endif