Finalny program mbed2
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
main.cpp@0:33ff53112cc9, 2020-06-09 (annotated)
- Committer:
- azmuth_sd
- Date:
- Tue Jun 09 08:24:40 2020 +0000
- Revision:
- 0:33ff53112cc9
Ostatni program drugiej czesci mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
azmuth_sd | 0:33ff53112cc9 | 1 | #include "mbed.h" |
azmuth_sd | 0:33ff53112cc9 | 2 | #include <string.h> |
azmuth_sd | 0:33ff53112cc9 | 3 | #include "servo.h" |
azmuth_sd | 0:33ff53112cc9 | 4 | #include "command_decoder.h" |
azmuth_sd | 0:33ff53112cc9 | 5 | |
azmuth_sd | 0:33ff53112cc9 | 6 | DigitalOut led_green(LED1); |
azmuth_sd | 0:33ff53112cc9 | 7 | DigitalOut led_red(LED2); |
azmuth_sd | 0:33ff53112cc9 | 8 | |
azmuth_sd | 0:33ff53112cc9 | 9 | Serial uart(USBTX, USBRX); |
azmuth_sd | 0:33ff53112cc9 | 10 | |
azmuth_sd | 0:33ff53112cc9 | 11 | Servo myServo; |
azmuth_sd | 0:33ff53112cc9 | 12 | Ticker myTimer; |
azmuth_sd | 0:33ff53112cc9 | 13 | Token myToken; |
azmuth_sd | 0:33ff53112cc9 | 14 | |
azmuth_sd | 0:33ff53112cc9 | 15 | unsigned char UART_puts(char * pcString, unsigned char ucSize) |
azmuth_sd | 0:33ff53112cc9 | 16 | { |
azmuth_sd | 0:33ff53112cc9 | 17 | unsigned char ucLoopCounter; |
azmuth_sd | 0:33ff53112cc9 | 18 | if( *(pcString + ucSize - 1) != NULL ) return 1; |
azmuth_sd | 0:33ff53112cc9 | 19 | for(ucLoopCounter = 0; ucLoopCounter < (ucSize-1); ucLoopCounter++) { |
azmuth_sd | 0:33ff53112cc9 | 20 | uart.putc(pcString[ucLoopCounter]); |
azmuth_sd | 0:33ff53112cc9 | 21 | } |
azmuth_sd | 0:33ff53112cc9 | 22 | uart.putc('\r'); |
azmuth_sd | 0:33ff53112cc9 | 23 | return 0; |
azmuth_sd | 0:33ff53112cc9 | 24 | } |
azmuth_sd | 0:33ff53112cc9 | 25 | |
azmuth_sd | 0:33ff53112cc9 | 26 | unsigned char UART_gets(char *pcDestString, unsigned char ucSize) |
azmuth_sd | 0:33ff53112cc9 | 27 | { |
azmuth_sd | 0:33ff53112cc9 | 28 | unsigned char ucLoopCounter; |
azmuth_sd | 0:33ff53112cc9 | 29 | for(ucLoopCounter = 0; ucLoopCounter < (ucSize-1); ucLoopCounter++) { |
azmuth_sd | 0:33ff53112cc9 | 30 | pcDestString[ucLoopCounter] = uart.getc(); |
azmuth_sd | 0:33ff53112cc9 | 31 | if(pcDestString[ucLoopCounter] == '\r') { |
azmuth_sd | 0:33ff53112cc9 | 32 | pcDestString[ucLoopCounter] = NULL; |
azmuth_sd | 0:33ff53112cc9 | 33 | return 0; |
azmuth_sd | 0:33ff53112cc9 | 34 | } |
azmuth_sd | 0:33ff53112cc9 | 35 | } |
azmuth_sd | 0:33ff53112cc9 | 36 | return 1; |
azmuth_sd | 0:33ff53112cc9 | 37 | } |
azmuth_sd | 0:33ff53112cc9 | 38 | |
azmuth_sd | 0:33ff53112cc9 | 39 | void ServoUpdate (void){ |
azmuth_sd | 0:33ff53112cc9 | 40 | myServo.Automat(); |
azmuth_sd | 0:33ff53112cc9 | 41 | } |
azmuth_sd | 0:33ff53112cc9 | 42 | |
azmuth_sd | 0:33ff53112cc9 | 43 | int main() |
azmuth_sd | 0:33ff53112cc9 | 44 | { |
azmuth_sd | 0:33ff53112cc9 | 45 | uart.baud(9600); |
azmuth_sd | 0:33ff53112cc9 | 46 | char acUartBuffor[15]; |
azmuth_sd | 0:33ff53112cc9 | 47 | |
azmuth_sd | 0:33ff53112cc9 | 48 | myTimer.attach(&ServoUpdate, 0.2); |
azmuth_sd | 0:33ff53112cc9 | 49 | |
azmuth_sd | 0:33ff53112cc9 | 50 | myServo.Callib(); |
azmuth_sd | 0:33ff53112cc9 | 51 | |
azmuth_sd | 0:33ff53112cc9 | 52 | while(1) { |
azmuth_sd | 0:33ff53112cc9 | 53 | |
azmuth_sd | 0:33ff53112cc9 | 54 | if (uart.readable()){ |
azmuth_sd | 0:33ff53112cc9 | 55 | UART_gets(acUartBuffor,15); |
azmuth_sd | 0:33ff53112cc9 | 56 | myToken.DecodeMsg(acUartBuffor); |
azmuth_sd | 0:33ff53112cc9 | 57 | |
azmuth_sd | 0:33ff53112cc9 | 58 | if( (myToken.ucTokenNr != 0) && (KEYWORD == myToken.asToken[0].eType) ) |
azmuth_sd | 0:33ff53112cc9 | 59 | { |
azmuth_sd | 0:33ff53112cc9 | 60 | switch(myToken.asToken[0].uValue.eKeyword) |
azmuth_sd | 0:33ff53112cc9 | 61 | { |
azmuth_sd | 0:33ff53112cc9 | 62 | case ID: |
azmuth_sd | 0:33ff53112cc9 | 63 | UART_puts("ID 1234\n", 9); |
azmuth_sd | 0:33ff53112cc9 | 64 | break; |
azmuth_sd | 0:33ff53112cc9 | 65 | |
azmuth_sd | 0:33ff53112cc9 | 66 | case CALIB: |
azmuth_sd | 0:33ff53112cc9 | 67 | myServo.Callib(); |
azmuth_sd | 0:33ff53112cc9 | 68 | UART_puts("ok\n", 4); |
azmuth_sd | 0:33ff53112cc9 | 69 | break; |
azmuth_sd | 0:33ff53112cc9 | 70 | |
azmuth_sd | 0:33ff53112cc9 | 71 | case GOTO: |
azmuth_sd | 0:33ff53112cc9 | 72 | UART_puts("ok\n", 4); |
azmuth_sd | 0:33ff53112cc9 | 73 | myServo.GoTo(myToken.asToken[1].uValue.uiNumber); |
azmuth_sd | 0:33ff53112cc9 | 74 | break; |
azmuth_sd | 0:33ff53112cc9 | 75 | |
azmuth_sd | 0:33ff53112cc9 | 76 | case STEP: |
azmuth_sd | 0:33ff53112cc9 | 77 | UART_puts("ok\n", 4); |
azmuth_sd | 0:33ff53112cc9 | 78 | myServo.StepRight(myToken.asToken[1].uValue.uiNumber); |
azmuth_sd | 0:33ff53112cc9 | 79 | break; |
azmuth_sd | 0:33ff53112cc9 | 80 | } |
azmuth_sd | 0:33ff53112cc9 | 81 | } |
azmuth_sd | 0:33ff53112cc9 | 82 | else if((myToken.ucTokenNr != 0)){ |
azmuth_sd | 0:33ff53112cc9 | 83 | UART_puts("unknowncommand\n", 16); |
azmuth_sd | 0:33ff53112cc9 | 84 | } |
azmuth_sd | 0:33ff53112cc9 | 85 | |
azmuth_sd | 0:33ff53112cc9 | 86 | } |
azmuth_sd | 0:33ff53112cc9 | 87 | |
azmuth_sd | 0:33ff53112cc9 | 88 | } |
azmuth_sd | 0:33ff53112cc9 | 89 | } |