School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
sc_functions.h@14:3ac7c08dbc52, 2021-01-18 (annotated)
- Committer:
- tuxx0046
- Date:
- Mon Jan 18 16:13:13 2021 +0000
- Revision:
- 14:3ac7c08dbc52
- Parent:
- 13:41debc0b9063
Documentation updated.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 10:137cf2c92871 | 1 | /** |
tuxx0046 | 10:137cf2c92871 | 2 | @file sc_functions.h |
tuxx0046 | 10:137cf2c92871 | 3 | @author Tu Tri Huynh |
tuxx0046 | 10:137cf2c92871 | 4 | @date January 15, 2021 |
tuxx0046 | 10:137cf2c92871 | 5 | @brief Functions used for Serial Communication during service. |
tuxx0046 | 10:137cf2c92871 | 6 | */ |
tuxx0046 | 10:137cf2c92871 | 7 | |
tuxx0046 | 10:137cf2c92871 | 8 | /** |
tuxx0046 | 10:137cf2c92871 | 9 | This function will prompt the user for which sensor data to fetch and print to console. |
tuxx0046 | 14:3ac7c08dbc52 | 10 | 1/15/2021 |
tuxx0046 | 10:137cf2c92871 | 11 | */ |
tuxx0046 | 10:137cf2c92871 | 12 | void sc_read_input() |
tuxx0046 | 10:137cf2c92871 | 13 | { |
tuxx0046 | 10:137cf2c92871 | 14 | char choice; |
tuxx0046 | 10:137cf2c92871 | 15 | printf("Your input: "); |
tuxx0046 | 10:137cf2c92871 | 16 | scanf("%1s", &choice); |
tuxx0046 | 10:137cf2c92871 | 17 | if (choice == '1') |
tuxx0046 | 10:137cf2c92871 | 18 | { |
tuxx0046 | 10:137cf2c92871 | 19 | printf("Current light intensity: %1.2f\n", light_sensor.read()); |
tuxx0046 | 10:137cf2c92871 | 20 | } |
tuxx0046 | 10:137cf2c92871 | 21 | else if (choice == '2') |
tuxx0046 | 10:137cf2c92871 | 22 | { |
tuxx0046 | 10:137cf2c92871 | 23 | printf("Current rotary position: %1.2f\n", rotary.read()); |
tuxx0046 | 10:137cf2c92871 | 24 | } |
tuxx0046 | 13:41debc0b9063 | 25 | else if (choice == '3') |
tuxx0046 | 13:41debc0b9063 | 26 | { |
tuxx0046 | 13:41debc0b9063 | 27 | printf("Current celsius temperature: %2.2f\n", temp.getTemperature()); |
tuxx0046 | 13:41debc0b9063 | 28 | } |
tuxx0046 | 13:41debc0b9063 | 29 | else if (choice == '4') |
tuxx0046 | 13:41debc0b9063 | 30 | { |
tuxx0046 | 13:41debc0b9063 | 31 | float fahrenheit = helper_convert_celsius_to_fahrenheit(temp.getTemperature()); |
tuxx0046 | 13:41debc0b9063 | 32 | printf("Current fahrenheit temperature: %3.2f\n", fahrenheit); |
tuxx0046 | 13:41debc0b9063 | 33 | } |
tuxx0046 | 10:137cf2c92871 | 34 | else |
tuxx0046 | 10:137cf2c92871 | 35 | { |
tuxx0046 | 10:137cf2c92871 | 36 | printf("Invalid choice.\n"); |
tuxx0046 | 10:137cf2c92871 | 37 | } |
tuxx0046 | 10:137cf2c92871 | 38 | /// This will empty the buffer and will avoid already inputted data to be used in scanf etc. |
tuxx0046 | 10:137cf2c92871 | 39 | int c; |
tuxx0046 | 10:137cf2c92871 | 40 | do |
tuxx0046 | 10:137cf2c92871 | 41 | { |
tuxx0046 | 10:137cf2c92871 | 42 | c = getchar(); |
tuxx0046 | 10:137cf2c92871 | 43 | } while (c != EOF && c != '\n'); |
tuxx0046 | 10:137cf2c92871 | 44 | } |
tuxx0046 | 10:137cf2c92871 | 45 | |
tuxx0046 | 10:137cf2c92871 | 46 | /** |
tuxx0046 | 10:137cf2c92871 | 47 | This function will show the menu for serial communication. |
tuxx0046 | 14:3ac7c08dbc52 | 48 | 1/15/2021 |
tuxx0046 | 10:137cf2c92871 | 49 | */ |
tuxx0046 | 10:137cf2c92871 | 50 | void sc_show_menu() |
tuxx0046 | 10:137cf2c92871 | 51 | { |
tuxx0046 | 10:137cf2c92871 | 52 | printf("*********************************************************************\n"); |
tuxx0046 | 10:137cf2c92871 | 53 | printf("To get data from the sensors, please enter a number and press return.\n"); |
tuxx0046 | 10:137cf2c92871 | 54 | printf("Input 1 to get current light intensity.\n"); |
tuxx0046 | 10:137cf2c92871 | 55 | printf("Input 2 to get the current position of rotary control button.\n"); |
tuxx0046 | 13:41debc0b9063 | 56 | printf("Input 3 to get the current temperature in celcius.\n"); |
tuxx0046 | 13:41debc0b9063 | 57 | printf("Input 4 to get the current temperature in fahrenheit.\n"); |
tuxx0046 | 10:137cf2c92871 | 58 | sc_read_input(); |
tuxx0046 | 10:137cf2c92871 | 59 | } |
tuxx0046 | 10:137cf2c92871 | 60 | |
tuxx0046 | 10:137cf2c92871 | 61 | |
tuxx0046 | 10:137cf2c92871 | 62 | /** |
tuxx0046 | 10:137cf2c92871 | 63 | This function will run the serial communication service. |
tuxx0046 | 14:3ac7c08dbc52 | 64 | 1/15/2021 |
tuxx0046 | 10:137cf2c92871 | 65 | */ |
tuxx0046 | 10:137cf2c92871 | 66 | void sc_run_service() |
tuxx0046 | 10:137cf2c92871 | 67 | { |
tuxx0046 | 10:137cf2c92871 | 68 | while(1) |
tuxx0046 | 10:137cf2c92871 | 69 | { |
tuxx0046 | 10:137cf2c92871 | 70 | sc_show_menu(); |
tuxx0046 | 10:137cf2c92871 | 71 | } |
tuxx0046 | 10:137cf2c92871 | 72 | } |