mbed2 zad 5b
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
main.cpp@5:cafab5a4d1c9, 2020-06-09 (annotated)
- Committer:
- krzysiek99
- Date:
- Tue Jun 09 12:30:01 2020 +0000
- Revision:
- 5:cafab5a4d1c9
- Parent:
- 4:7855d3ab4c15
mbed2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
krzysiek99 | 4:7855d3ab4c15 | 1 | #include "Servo.h" |
krzysiek99 | 4:7855d3ab4c15 | 2 | #include "FunkcjeUART.h" |
krzysiek99 | 4:7855d3ab4c15 | 3 | #include "Tokeny.h" |
krzysiek99 | 4:7855d3ab4c15 | 4 | |
krzysiek99 | 4:7855d3ab4c15 | 5 | DigitalIn DetectorSignal(USER_BUTTON); |
krzysiek99 | 4:7855d3ab4c15 | 6 | Serial pc(USBTX, USBRX); |
bcostm | 0:d4dacd8a359b | 7 | |
krzysiek99 | 4:7855d3ab4c15 | 8 | unsigned char ucTokenNr; |
krzysiek99 | 4:7855d3ab4c15 | 9 | struct Token asToken[MAX_TOKEN_NR]; |
krzysiek99 | 4:7855d3ab4c15 | 10 | struct Keyword asKeywordList[MAX_KEYWORD_NR] = |
krzysiek99 | 4:7855d3ab4c15 | 11 | { |
krzysiek99 | 4:7855d3ab4c15 | 12 | {ID, "id"}, |
krzysiek99 | 4:7855d3ab4c15 | 13 | {CAL, "callib"}, |
krzysiek99 | 4:7855d3ab4c15 | 14 | {GT, "goto"}, |
krzysiek99 | 4:7855d3ab4c15 | 15 | {ST, "step"} |
krzysiek99 | 4:7855d3ab4c15 | 16 | }; |
bcostm | 0:d4dacd8a359b | 17 | |
krzysiek99 | 4:7855d3ab4c15 | 18 | Servo MyServo; |
bcostm | 0:d4dacd8a359b | 19 | |
bcostm | 0:d4dacd8a359b | 20 | int main() |
krzysiek99 | 4:7855d3ab4c15 | 21 | { |
krzysiek99 | 4:7855d3ab4c15 | 22 | char cString[MAX_KEYWORD_STRING_LTH]; |
krzysiek99 | 4:7855d3ab4c15 | 23 | while (true) |
krzysiek99 | 4:7855d3ab4c15 | 24 | { |
krzysiek99 | 4:7855d3ab4c15 | 25 | gets(cString, MAX_KEYWORD_STRING_LTH); |
krzysiek99 | 4:7855d3ab4c15 | 26 | DecodeMsg(cString); |
krzysiek99 | 4:7855d3ab4c15 | 27 | if((asToken[0].eType == KEYWORD) && (ucTokenNr > 0)) |
krzysiek99 | 4:7855d3ab4c15 | 28 | { |
krzysiek99 | 4:7855d3ab4c15 | 29 | if((asToken[0].uValue.eKeyword == ID) && (ucTokenNr == 1)) |
krzysiek99 | 4:7855d3ab4c15 | 30 | { |
krzysiek99 | 4:7855d3ab4c15 | 31 | puts("id anyidentifier", 16); |
krzysiek99 | 4:7855d3ab4c15 | 32 | } |
krzysiek99 | 4:7855d3ab4c15 | 33 | else if((asToken[0].uValue.eKeyword == CAL) && (ucTokenNr == 1)) |
krzysiek99 | 4:7855d3ab4c15 | 34 | { |
krzysiek99 | 4:7855d3ab4c15 | 35 | puts("ok", 2); |
krzysiek99 | 4:7855d3ab4c15 | 36 | MyServo.Callib(); |
krzysiek99 | 4:7855d3ab4c15 | 37 | } |
krzysiek99 | 4:7855d3ab4c15 | 38 | else if((asToken[0].uValue.eKeyword == GT) && (asToken[1].eType == NUMBER)) |
krzysiek99 | 4:7855d3ab4c15 | 39 | { |
krzysiek99 | 4:7855d3ab4c15 | 40 | puts("ok", 2); |
krzysiek99 | 4:7855d3ab4c15 | 41 | MyServo.GoTo(asToken[1].uValue.uiNumber); |
krzysiek99 | 4:7855d3ab4c15 | 42 | } |
krzysiek99 | 4:7855d3ab4c15 | 43 | else if((asToken[0].uValue.eKeyword == ST) && (asToken[1].eType == NUMBER)) |
krzysiek99 | 4:7855d3ab4c15 | 44 | { |
krzysiek99 | 4:7855d3ab4c15 | 45 | puts("ok", 2); |
krzysiek99 | 4:7855d3ab4c15 | 46 | MyServo.GoTo(MyServo.uiCurrentPosition+asToken[1].uValue.uiNumber); |
krzysiek99 | 4:7855d3ab4c15 | 47 | } |
krzysiek99 | 4:7855d3ab4c15 | 48 | else |
krzysiek99 | 4:7855d3ab4c15 | 49 | puts("unknowncommand", 14); |
krzysiek99 | 4:7855d3ab4c15 | 50 | } |
krzysiek99 | 4:7855d3ab4c15 | 51 | else |
krzysiek99 | 4:7855d3ab4c15 | 52 | puts("unknowncommand", 14); |
bcostm | 0:d4dacd8a359b | 53 | } |
krzysiek99 | 4:7855d3ab4c15 | 54 | } |