School project.

Dependencies:   Timezone NTPClient BSP_DISCO_F746NG Grove_temperature

Committer:
tuxx0046
Date:
Thu Jan 14 08:16:03 2021 +0000
Revision:
5:9a9cc43f3c2c
Parent:
3:02e7aac23ff9
Child:
9:fd1f07a4a0ff
Changed code to allow for white spaces in building and room name during setup process.; Minor changes in wording.

Who changed what in which revision?

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