School project.

Dependencies:   Timezone NTPClient BSP_DISCO_F746NG Grove_temperature

Committer:
tuxx0046
Date:
Wed Jan 13 10:36:30 2021 +0000
Revision:
1:1ee11539cc43
Parent:
0:ed4063a0a4d5
Child:
2:90d31841523a
Comments have been added.; Initial setup process functionality has a bug where it does not continue the program after confirming "yes" at the end.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tuxx0046 1:1ee11539cc43 1 /**
tuxx0046 0:ed4063a0a4d5 2 @file main.cpp
tuxx0046 0:ed4063a0a4d5 3 @brief Light Control System to automatically dimmer or increase light levels depending on registered light intensity.
tuxx0046 0:ed4063a0a4d5 4
tuxx0046 0:ed4063a0a4d5 5 @author Tu Tri Huynh
tuxx0046 0:ed4063a0a4d5 6
tuxx0046 0:ed4063a0a4d5 7 @date 1/13/2021
tuxx0046 0:ed4063a0a4d5 8 */
tuxx0046 0:ed4063a0a4d5 9
tuxx0046 0:ed4063a0a4d5 10 #include "mbed.h"
tuxx0046 0:ed4063a0a4d5 11
tuxx0046 0:ed4063a0a4d5 12
tuxx0046 0:ed4063a0a4d5 13 char building[31];
tuxx0046 0:ed4063a0a4d5 14 char room[31];
tuxx0046 0:ed4063a0a4d5 15 //bool is_set = false;
tuxx0046 0:ed4063a0a4d5 16
tuxx0046 1:1ee11539cc43 17 /**
tuxx0046 1:1ee11539cc43 18 Declaration of the function (prototype)
tuxx0046 1:1ee11539cc43 19 @date 1/13/2021
tuxx0046 1:1ee11539cc43 20 */
tuxx0046 0:ed4063a0a4d5 21 void setup_set_room_and_building();
tuxx0046 0:ed4063a0a4d5 22
tuxx0046 1:1ee11539cc43 23 /**
tuxx0046 1:1ee11539cc43 24 Confirm if happy with inputted information
tuxx0046 1:1ee11539cc43 25 @date 1/13/2021
tuxx0046 1:1ee11539cc43 26 */
tuxx0046 0:ed4063a0a4d5 27 void setup_confirm()
tuxx0046 0:ed4063a0a4d5 28 {
tuxx0046 0:ed4063a0a4d5 29 char answer;
tuxx0046 0:ed4063a0a4d5 30 printf("Type y for Yes, n for no: ");
tuxx0046 0:ed4063a0a4d5 31 scanf("%1s",&answer);
tuxx0046 0:ed4063a0a4d5 32 if (answer == 'y' || answer == 'Y')
tuxx0046 0:ed4063a0a4d5 33 {
tuxx0046 0:ed4063a0a4d5 34 //is_set = true;
tuxx0046 0:ed4063a0a4d5 35 printf("Setup successfully completed.\n");
tuxx0046 0:ed4063a0a4d5 36 }
tuxx0046 0:ed4063a0a4d5 37 else
tuxx0046 0:ed4063a0a4d5 38 {
tuxx0046 0:ed4063a0a4d5 39 setup_set_room_and_building();
tuxx0046 0:ed4063a0a4d5 40 }
tuxx0046 0:ed4063a0a4d5 41 printf("setup_confirm function end\n");
tuxx0046 0:ed4063a0a4d5 42 }
tuxx0046 0:ed4063a0a4d5 43
tuxx0046 1:1ee11539cc43 44 /**
tuxx0046 1:1ee11539cc43 45 Show inputted information, and call setup_confirm to ask for confirmation.
tuxx0046 1:1ee11539cc43 46 @date 1/13/2021
tuxx0046 1:1ee11539cc43 47 */
tuxx0046 0:ed4063a0a4d5 48 void setup_show_settings()
tuxx0046 0:ed4063a0a4d5 49 {
tuxx0046 0:ed4063a0a4d5 50 printf("Is this correct?\n");
tuxx0046 0:ed4063a0a4d5 51 printf("Building: %s\n", building);
tuxx0046 0:ed4063a0a4d5 52 printf("Room: %s\n", room);
tuxx0046 0:ed4063a0a4d5 53 setup_confirm();
tuxx0046 0:ed4063a0a4d5 54 }
tuxx0046 0:ed4063a0a4d5 55
tuxx0046 1:1ee11539cc43 56 /**
tuxx0046 1:1ee11539cc43 57 Function to set building and room. Will call setup_show_settings to show what has been inputted.
tuxx0046 1:1ee11539cc43 58 @date 1/13/2021
tuxx0046 1:1ee11539cc43 59 */
tuxx0046 0:ed4063a0a4d5 60 void setup_set_room_and_building()
tuxx0046 0:ed4063a0a4d5 61 {
tuxx0046 0:ed4063a0a4d5 62 printf("Please set the building (maximum 30 characters): ");
tuxx0046 0:ed4063a0a4d5 63 scanf("%30s", building);
tuxx0046 0:ed4063a0a4d5 64 printf("Please set the room (maximum 30 characters): ");
tuxx0046 0:ed4063a0a4d5 65 scanf("%30s", room);
tuxx0046 0:ed4063a0a4d5 66 setup_show_settings();
tuxx0046 0:ed4063a0a4d5 67 }
tuxx0046 0:ed4063a0a4d5 68
tuxx0046 1:1ee11539cc43 69 /**
tuxx0046 1:1ee11539cc43 70 Function to run the initial setup process.
tuxx0046 1:1ee11539cc43 71 @date 1/13/2021
tuxx0046 1:1ee11539cc43 72 */
tuxx0046 0:ed4063a0a4d5 73 void setup_run_setup()
tuxx0046 0:ed4063a0a4d5 74 {
tuxx0046 0:ed4063a0a4d5 75 printf("Welcome to the Light Control System initial setup process\n");
tuxx0046 0:ed4063a0a4d5 76 printf("Please set the units' location...\n\n");
tuxx0046 0:ed4063a0a4d5 77 setup_set_room_and_building();
tuxx0046 0:ed4063a0a4d5 78 }
tuxx0046 0:ed4063a0a4d5 79
tuxx0046 0:ed4063a0a4d5 80 int main(){
tuxx0046 0:ed4063a0a4d5 81 /*
tuxx0046 0:ed4063a0a4d5 82 printf("Mbed OS version: %d,%d,%d\n\n",MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
tuxx0046 0:ed4063a0a4d5 83 */
tuxx0046 0:ed4063a0a4d5 84
tuxx0046 0:ed4063a0a4d5 85 setup_run_setup();
tuxx0046 0:ed4063a0a4d5 86 printf("Setup done.");
tuxx0046 0:ed4063a0a4d5 87 }