School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
main_functions.h@16:296d68305630, 2021-01-20 (annotated)
- Committer:
- tuxx0046
- Date:
- Wed Jan 20 08:11:46 2021 +0000
- Revision:
- 16:296d68305630
- Parent:
- 15:638e65c37d58
Some functions have been changed, renamed and refactored.; Minor changes to comments/documentation.; Fully working build.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 14:3ac7c08dbc52 | 1 | /** |
tuxx0046 | 14:3ac7c08dbc52 | 2 | @file main_functions.h |
tuxx0046 | 14:3ac7c08dbc52 | 3 | @author Tu Tri Huynh |
tuxx0046 | 14:3ac7c08dbc52 | 4 | @date January 18, 2021 |
tuxx0046 | 16:296d68305630 | 5 | @brief Functions to be envoked in main function. Uses global variables. |
tuxx0046 | 14:3ac7c08dbc52 | 6 | */ |
tuxx0046 | 14:3ac7c08dbc52 | 7 | |
tuxx0046 | 14:3ac7c08dbc52 | 8 | /** |
tuxx0046 | 14:3ac7c08dbc52 | 9 | This function will update the sensor readings. |
tuxx0046 | 15:638e65c37d58 | 10 | 1/18/2021 |
tuxx0046 | 14:3ac7c08dbc52 | 11 | */ |
tuxx0046 | 16:296d68305630 | 12 | void main_update_readings() |
tuxx0046 | 14:3ac7c08dbc52 | 13 | { |
tuxx0046 | 15:638e65c37d58 | 14 | light_sensor_reading = light_sensor.read(); |
tuxx0046 | 14:3ac7c08dbc52 | 15 | light_intensity = helper_get_sensor_read_in_percent(light_sensor_reading); |
tuxx0046 | 14:3ac7c08dbc52 | 16 | rotary_reading = rotary.read(); |
tuxx0046 | 14:3ac7c08dbc52 | 17 | rotary_setting = helper_get_sensor_read_in_percent(rotary_reading); |
tuxx0046 | 15:638e65c37d58 | 18 | } |
tuxx0046 | 15:638e65c37d58 | 19 | |
tuxx0046 | 15:638e65c37d58 | 20 | /** |
tuxx0046 | 15:638e65c37d58 | 21 | This function will check which sensor controls the light, allowing the rotary or the light sensor to determine blink rate, |
tuxx0046 | 15:638e65c37d58 | 22 | and updates the lcd display accordingly |
tuxx0046 | 15:638e65c37d58 | 23 | 1/19/2021 |
tuxx0046 | 15:638e65c37d58 | 24 | */ |
tuxx0046 | 16:296d68305630 | 25 | void main_check_light_control() |
tuxx0046 | 15:638e65c37d58 | 26 | { |
tuxx0046 | 15:638e65c37d58 | 27 | if (rotary_is_on(rotary)) |
tuxx0046 | 15:638e65c37d58 | 28 | { |
tuxx0046 | 15:638e65c37d58 | 29 | led_set_blink_rate(rotary_reverse_read(rotary_reading)); |
tuxx0046 | 15:638e65c37d58 | 30 | } |
tuxx0046 | 15:638e65c37d58 | 31 | else |
tuxx0046 | 15:638e65c37d58 | 32 | { |
tuxx0046 | 15:638e65c37d58 | 33 | led_set_blink_rate(light_sensor_reading); |
tuxx0046 | 15:638e65c37d58 | 34 | } |
tuxx0046 | 15:638e65c37d58 | 35 | |
tuxx0046 | 15:638e65c37d58 | 36 | lcd_update_upper_right(light_intensity, rotary_setting); |
tuxx0046 | 15:638e65c37d58 | 37 | } |
tuxx0046 | 15:638e65c37d58 | 38 | |
tuxx0046 | 15:638e65c37d58 | 39 | /** |
tuxx0046 | 15:638e65c37d58 | 40 | Reads the temperature and updates the display if temperature has changed. |
tuxx0046 | 15:638e65c37d58 | 41 | 1/19/2021 |
tuxx0046 | 15:638e65c37d58 | 42 | */ |
tuxx0046 | 16:296d68305630 | 43 | void main_update_temperature(bool switch_temp) |
tuxx0046 | 15:638e65c37d58 | 44 | { |
tuxx0046 | 15:638e65c37d58 | 45 | int new_temp = (int)temp.getTemperature(); |
tuxx0046 | 15:638e65c37d58 | 46 | /// Update if change in temperature |
tuxx0046 | 15:638e65c37d58 | 47 | if (current_temp != new_temp) |
tuxx0046 | 15:638e65c37d58 | 48 | { |
tuxx0046 | 15:638e65c37d58 | 49 | current_temp = new_temp; |
tuxx0046 | 15:638e65c37d58 | 50 | lcd_update_lower_right(temp.getTemperature(), is_fahrenheit); |
tuxx0046 | 15:638e65c37d58 | 51 | } |
tuxx0046 | 16:296d68305630 | 52 | /// Check if change temperature unit wanted |
tuxx0046 | 15:638e65c37d58 | 53 | else if (switch_temp == true) |
tuxx0046 | 15:638e65c37d58 | 54 | { |
tuxx0046 | 15:638e65c37d58 | 55 | lcd_update_lower_right(temp.getTemperature(), is_fahrenheit); |
tuxx0046 | 15:638e65c37d58 | 56 | } |
tuxx0046 | 15:638e65c37d58 | 57 | } |
tuxx0046 | 16:296d68305630 | 58 | |
tuxx0046 | 16:296d68305630 | 59 | /** |
tuxx0046 | 16:296d68305630 | 60 | Runs a while loop that checks for button presses |
tuxx0046 | 16:296d68305630 | 61 | 1/19/2021 |
tuxx0046 | 16:296d68305630 | 62 | */ |
tuxx0046 | 16:296d68305630 | 63 | void main_run_button_check() |
tuxx0046 | 16:296d68305630 | 64 | { |
tuxx0046 | 16:296d68305630 | 65 | while(1) |
tuxx0046 | 16:296d68305630 | 66 | { |
tuxx0046 | 16:296d68305630 | 67 | switch_temp = button_switch_temp_unit(button, is_fahrenheit); |
tuxx0046 | 16:296d68305630 | 68 | main_update_temperature(switch_temp); |
tuxx0046 | 16:296d68305630 | 69 | switch_temp = false; |
tuxx0046 | 16:296d68305630 | 70 | wait_us(250000); |
tuxx0046 | 16:296d68305630 | 71 | } |
tuxx0046 | 16:296d68305630 | 72 | } |
tuxx0046 | 16:296d68305630 | 73 | |
tuxx0046 | 16:296d68305630 | 74 | /** |
tuxx0046 | 16:296d68305630 | 75 | Runs the setup menu |
tuxx0046 | 16:296d68305630 | 76 | 1/19/2021 |
tuxx0046 | 16:296d68305630 | 77 | */ |
tuxx0046 | 16:296d68305630 | 78 | void main_run_setup() |
tuxx0046 | 16:296d68305630 | 79 | { |
tuxx0046 | 16:296d68305630 | 80 | lcd_initialize(); |
tuxx0046 | 16:296d68305630 | 81 | lcd_show_setup_screen(); |
tuxx0046 | 16:296d68305630 | 82 | setup_run_setup(); |
tuxx0046 | 16:296d68305630 | 83 | } |
tuxx0046 | 16:296d68305630 | 84 | |
tuxx0046 | 16:296d68305630 | 85 | /** |
tuxx0046 | 16:296d68305630 | 86 | Starts the main screen on LCD display |
tuxx0046 | 16:296d68305630 | 87 | 1/19/2021 |
tuxx0046 | 16:296d68305630 | 88 | */ |
tuxx0046 | 16:296d68305630 | 89 | void main_run_main_screen() |
tuxx0046 | 16:296d68305630 | 90 | { |
tuxx0046 | 16:296d68305630 | 91 | lcd_show_main_screen(); |
tuxx0046 | 16:296d68305630 | 92 | lcd_update_lower_left(building, room); |
tuxx0046 | 16:296d68305630 | 93 | } |
tuxx0046 | 16:296d68305630 | 94 |