School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
setup_functions.h@20:9d4450357ce7, 2021-01-21 (annotated)
- Committer:
- tuxx0046
- Date:
- Thu Jan 21 12:43:03 2021 +0000
- Revision:
- 20:9d4450357ce7
- Parent:
- 14:3ac7c08dbc52
Updated libraries used section in comments in main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 3:02e7aac23ff9 | 1 | /** |
tuxx0046 | 10:137cf2c92871 | 2 | @file setup_functions.h |
tuxx0046 | 10:137cf2c92871 | 3 | @author Tu Tri Huynh |
tuxx0046 | 10:137cf2c92871 | 4 | @date January 13, 2021 |
tuxx0046 | 10:137cf2c92871 | 5 | @brief Functions used for initial setup of the unit, specifically to set the building and room where unit installation is planned. |
tuxx0046 | 3:02e7aac23ff9 | 6 | */ |
tuxx0046 | 3:02e7aac23ff9 | 7 | |
tuxx0046 | 3:02e7aac23ff9 | 8 | /** |
tuxx0046 | 3:02e7aac23ff9 | 9 | Declaration of the function (prototype) to allow other functions to call it |
tuxx0046 | 3:02e7aac23ff9 | 10 | @date 1/13/2021 |
tuxx0046 | 3:02e7aac23ff9 | 11 | */ |
tuxx0046 | 3:02e7aac23ff9 | 12 | void setup_set_room_and_building(); |
tuxx0046 | 3:02e7aac23ff9 | 13 | |
tuxx0046 | 3:02e7aac23ff9 | 14 | /** |
tuxx0046 | 3:02e7aac23ff9 | 15 | Prompt user for confirmation if happy with inputted information |
tuxx0046 | 14:3ac7c08dbc52 | 16 | 1/13/2021 |
tuxx0046 | 3:02e7aac23ff9 | 17 | */ |
tuxx0046 | 3:02e7aac23ff9 | 18 | void setup_confirm() |
tuxx0046 | 3:02e7aac23ff9 | 19 | { |
tuxx0046 | 3:02e7aac23ff9 | 20 | char answer; |
tuxx0046 | 5:9a9cc43f3c2c | 21 | printf("Type y for Yes, n to redo: "); |
tuxx0046 | 3:02e7aac23ff9 | 22 | scanf("%1s",&answer); |
tuxx0046 | 3:02e7aac23ff9 | 23 | if (answer == 'y' || answer == 'Y') |
tuxx0046 | 3:02e7aac23ff9 | 24 | { |
tuxx0046 | 3:02e7aac23ff9 | 25 | printf("Setup successfully completed.\n"); |
tuxx0046 | 3:02e7aac23ff9 | 26 | } |
tuxx0046 | 3:02e7aac23ff9 | 27 | else |
tuxx0046 | 3:02e7aac23ff9 | 28 | { |
tuxx0046 | 10:137cf2c92871 | 29 | /// This will empty the buffer and will avoid already inputted data to be used in scanf etc. |
tuxx0046 | 10:137cf2c92871 | 30 | int c; |
tuxx0046 | 10:137cf2c92871 | 31 | do { |
tuxx0046 | 10:137cf2c92871 | 32 | c = getchar(); |
tuxx0046 | 10:137cf2c92871 | 33 | } while (c != EOF && c != '\n'); |
tuxx0046 | 10:137cf2c92871 | 34 | |
tuxx0046 | 3:02e7aac23ff9 | 35 | setup_set_room_and_building(); |
tuxx0046 | 3:02e7aac23ff9 | 36 | } |
tuxx0046 | 10:137cf2c92871 | 37 | /** |
tuxx0046 | 3:02e7aac23ff9 | 38 | printf("setup_confirm function end\n"); |
tuxx0046 | 3:02e7aac23ff9 | 39 | */ |
tuxx0046 | 3:02e7aac23ff9 | 40 | } |
tuxx0046 | 3:02e7aac23ff9 | 41 | |
tuxx0046 | 3:02e7aac23ff9 | 42 | /** |
tuxx0046 | 3:02e7aac23ff9 | 43 | Show inputted information, and call setup_confirm to ask for confirmation. |
tuxx0046 | 14:3ac7c08dbc52 | 44 | 1/13/2021 |
tuxx0046 | 3:02e7aac23ff9 | 45 | */ |
tuxx0046 | 3:02e7aac23ff9 | 46 | void setup_show_settings() |
tuxx0046 | 3:02e7aac23ff9 | 47 | { |
tuxx0046 | 3:02e7aac23ff9 | 48 | printf("Is this correct?\n"); |
tuxx0046 | 5:9a9cc43f3c2c | 49 | printf("----------------------------\n"); |
tuxx0046 | 3:02e7aac23ff9 | 50 | printf("Building: %s\n", building); |
tuxx0046 | 3:02e7aac23ff9 | 51 | printf("Room: %s\n", room); |
tuxx0046 | 3:02e7aac23ff9 | 52 | printf("----------------------------\n"); |
tuxx0046 | 3:02e7aac23ff9 | 53 | setup_confirm(); |
tuxx0046 | 3:02e7aac23ff9 | 54 | } |
tuxx0046 | 3:02e7aac23ff9 | 55 | |
tuxx0046 | 3:02e7aac23ff9 | 56 | /** |
tuxx0046 | 3:02e7aac23ff9 | 57 | Function to set building and room. Will call setup_show_settings to show what has been inputted. |
tuxx0046 | 14:3ac7c08dbc52 | 58 | 1/13/2021 |
tuxx0046 | 3:02e7aac23ff9 | 59 | */ |
tuxx0046 | 3:02e7aac23ff9 | 60 | void setup_set_room_and_building() |
tuxx0046 | 3:02e7aac23ff9 | 61 | { |
tuxx0046 | 5:9a9cc43f3c2c | 62 | char temp; |
tuxx0046 | 5:9a9cc43f3c2c | 63 | /** 1/14/2021 |
tuxx0046 | 10:137cf2c92871 | 64 | When using %s, string will be terminated when white space is found. |
tuxx0046 | 5:9a9cc43f3c2c | 65 | Therefore, set it to read white spaces with %[^\n] |
tuxx0046 | 5:9a9cc43f3c2c | 66 | Also, changed wording to reduce "please" sentences.*/ |
tuxx0046 | 5:9a9cc43f3c2c | 67 | /** |
tuxx0046 | 3:02e7aac23ff9 | 68 | printf("Please set the building (maximum 30 characters): "); |
tuxx0046 | 3:02e7aac23ff9 | 69 | scanf("%30s", building); |
tuxx0046 | 3:02e7aac23ff9 | 70 | printf("Please set the room (maximum 30 characters): "); |
tuxx0046 | 5:9a9cc43f3c2c | 71 | scanf("%30s", room); */ |
tuxx0046 | 5:9a9cc43f3c2c | 72 | printf("Enter name of building (maximum 30 characters): "); |
tuxx0046 | 5:9a9cc43f3c2c | 73 | scanf("%[^\n]", building); |
tuxx0046 | 5:9a9cc43f3c2c | 74 | printf("Enter name of room (maximum 30 characters): "); |
tuxx0046 | 5:9a9cc43f3c2c | 75 | /// temp statement to clear buffer |
tuxx0046 | 5:9a9cc43f3c2c | 76 | scanf("%c", &temp); |
tuxx0046 | 5:9a9cc43f3c2c | 77 | scanf("%[^\n]", room); |
tuxx0046 | 5:9a9cc43f3c2c | 78 | |
tuxx0046 | 3:02e7aac23ff9 | 79 | setup_show_settings(); |
tuxx0046 | 3:02e7aac23ff9 | 80 | } |
tuxx0046 | 3:02e7aac23ff9 | 81 | |
tuxx0046 | 3:02e7aac23ff9 | 82 | /** |
tuxx0046 | 3:02e7aac23ff9 | 83 | Function to run the initial setup process. |
tuxx0046 | 14:3ac7c08dbc52 | 84 | 1/13/2021 |
tuxx0046 | 3:02e7aac23ff9 | 85 | */ |
tuxx0046 | 3:02e7aac23ff9 | 86 | void setup_run_setup() |
tuxx0046 | 3:02e7aac23ff9 | 87 | { |
tuxx0046 | 3:02e7aac23ff9 | 88 | printf("\n*********************************************************\n"); |
tuxx0046 | 3:02e7aac23ff9 | 89 | printf("Welcome to the Light Control System initial setup process\n"); |
tuxx0046 | 3:02e7aac23ff9 | 90 | printf("Please set the units' location...\n\n"); |
tuxx0046 | 3:02e7aac23ff9 | 91 | setup_set_room_and_building(); |
tuxx0046 | 3:02e7aac23ff9 | 92 | } |