Use STM32 platform, install FreeRTOS, implement UART CLI for next functionality: - light on LED for specified period in seconds, other commands are available while LED is ON. When after specified period led is off - notify user with text message on same console - set/get brightness for LED - return state of user button - enable/disable button monitoring, asynchronously monitor state of button and if it's state changed(pressed/unpressed) notify user with text message on same console - help CLI must be user friendly as much as possible. Result: you can connect device to PC and work with CLI
main.cpp@3:dd96529b7ae9, 2017-12-09 (annotated)
- Committer:
- gjgsd
- Date:
- Sat Dec 09 16:18:22 2017 +0000
- Revision:
- 3:dd96529b7ae9
- Parent:
- 2:35f13b7f3659
- Child:
- 4:d4aeacb47955
first draft
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:5701b41769fd | 1 | #include "mbed.h" |
bcostm | 0:5701b41769fd | 2 | |
bcostm | 0:5701b41769fd | 3 | void print_char(char c = '*') |
bcostm | 0:5701b41769fd | 4 | { |
bcostm | 0:5701b41769fd | 5 | printf("%c", c); |
bcostm | 0:5701b41769fd | 6 | fflush(stdout); |
bcostm | 0:5701b41769fd | 7 | } |
bcostm | 0:5701b41769fd | 8 | |
bcostm | 2:35f13b7f3659 | 9 | Thread thread; |
gjgsd | 3:dd96529b7ae9 | 10 | Thread thread1; |
gjgsd | 3:dd96529b7ae9 | 11 | int print = 1; |
gjgsd | 3:dd96529b7ae9 | 12 | char input [64]; |
gjgsd | 3:dd96529b7ae9 | 13 | int lamp = 50; |
bcostm | 2:35f13b7f3659 | 14 | |
gjgsd | 3:dd96529b7ae9 | 15 | //DigitalOut led1(LED1); |
gjgsd | 3:dd96529b7ae9 | 16 | PwmOut led1(D11); |
gjgsd | 3:dd96529b7ae9 | 17 | //PwmOut led2(D13); |
bcostm | 0:5701b41769fd | 18 | |
bcostm | 2:35f13b7f3659 | 19 | void print_thread() |
bcostm | 0:5701b41769fd | 20 | { |
bcostm | 0:5701b41769fd | 21 | while (true) { |
gjgsd | 3:dd96529b7ae9 | 22 | |
gjgsd | 3:dd96529b7ae9 | 23 | if (print == 1) { |
gjgsd | 3:dd96529b7ae9 | 24 | // printf("\r\n*** Do you love me too? ***\r\n"); |
gjgsd | 3:dd96529b7ae9 | 25 | printf("\r\nLamp is ON\r\n"); |
gjgsd | 3:dd96529b7ae9 | 26 | printf("\r\nPlese type + or - to change brightness\r\n"); |
gjgsd | 3:dd96529b7ae9 | 27 | print = 0; |
gjgsd | 3:dd96529b7ae9 | 28 | } |
gjgsd | 3:dd96529b7ae9 | 29 | scanf("%s",input); |
gjgsd | 3:dd96529b7ae9 | 30 | printf("\r\n* %s *\r\n",input); |
gjgsd | 3:dd96529b7ae9 | 31 | if (!strcmp(input,"-")){ |
gjgsd | 3:dd96529b7ae9 | 32 | if (lamp < 90) lamp = lamp + 10; |
gjgsd | 3:dd96529b7ae9 | 33 | else if (lamp < 100) lamp = lamp + 1; |
gjgsd | 3:dd96529b7ae9 | 34 | printf("\r\n*** Lamp brightness is %d ***\r\n", lamp); |
gjgsd | 3:dd96529b7ae9 | 35 | } |
gjgsd | 3:dd96529b7ae9 | 36 | else if (!strcmp(input,"+")){ |
gjgsd | 3:dd96529b7ae9 | 37 | printf("\r\n*** %d ***\r\n", lamp); |
gjgsd | 3:dd96529b7ae9 | 38 | if (lamp > 10) lamp = lamp - 10; |
gjgsd | 3:dd96529b7ae9 | 39 | else if (lamp > 0) lamp = lamp - 1; |
gjgsd | 3:dd96529b7ae9 | 40 | printf("\r\n*** Lamp brightness is %d ***\r\n", lamp); |
gjgsd | 3:dd96529b7ae9 | 41 | } |
gjgsd | 3:dd96529b7ae9 | 42 | else { |
gjgsd | 3:dd96529b7ae9 | 43 | printf("\r\n(plese type + or -)\r\n"); |
gjgsd | 3:dd96529b7ae9 | 44 | } |
bcostm | 0:5701b41769fd | 45 | } |
bcostm | 0:5701b41769fd | 46 | } |
bcostm | 0:5701b41769fd | 47 | |
bcostm | 0:5701b41769fd | 48 | int main() |
bcostm | 0:5701b41769fd | 49 | { |
gjgsd | 3:dd96529b7ae9 | 50 | printf("\r\n*** Welcome ***\n\r"); |
bcostm | 2:35f13b7f3659 | 51 | |
bcostm | 2:35f13b7f3659 | 52 | thread.start(print_thread); |
gjgsd | 3:dd96529b7ae9 | 53 | |
bcostm | 2:35f13b7f3659 | 54 | |
bcostm | 0:5701b41769fd | 55 | while (true) { |
gjgsd | 3:dd96529b7ae9 | 56 | led1 = (0.01 * lamp); |
gjgsd | 3:dd96529b7ae9 | 57 | // led2 = !led2; |
gjgsd | 3:dd96529b7ae9 | 58 | wait(0.2); |
gjgsd | 3:dd96529b7ae9 | 59 | // led1 = led1 + 0.01; |
gjgsd | 3:dd96529b7ae9 | 60 | // wait(0.2); |
gjgsd | 3:dd96529b7ae9 | 61 | // if(led1 == 1.0) { |
gjgsd | 3:dd96529b7ae9 | 62 | // led1 = 0; |
gjgsd | 3:dd96529b7ae9 | 63 | // } |
gjgsd | 3:dd96529b7ae9 | 64 | |
gjgsd | 3:dd96529b7ae9 | 65 | } |
gjgsd | 3:dd96529b7ae9 | 66 | |
bcostm | 0:5701b41769fd | 67 | } |