a
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
main.cpp@3:6fc7976cc5bf, 2020-05-20 (annotated)
- Committer:
- matis755
- Date:
- Wed May 20 16:37:25 2020 +0000
- Revision:
- 3:6fc7976cc5bf
- Parent:
- 2:8788d711db7e
- Child:
- 4:e48aee3e8d09
Create class for decoding strings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matis755 | 0:e65dff476cf0 | 1 | #include "mbed.h" |
matis755 | 2:8788d711db7e | 2 | #include "string.h" |
matis755 | 0:e65dff476cf0 | 3 | |
matis755 | 2:8788d711db7e | 4 | #define BUFFER_SIZE 100 |
matis755 | 2:8788d711db7e | 5 | |
matis755 | 2:8788d711db7e | 6 | Serial MySerial(USBTX, USBRX); |
matis755 | 0:e65dff476cf0 | 7 | DigitalOut led_green(LED1); |
matis755 | 0:e65dff476cf0 | 8 | DigitalOut led_red(LED2); |
matis755 | 0:e65dff476cf0 | 9 | |
matis755 | 2:8788d711db7e | 10 | char gets(char *pStr, unsigned char ucSize){ |
matis755 | 2:8788d711db7e | 11 | unsigned char ucStrPtr = 0; |
matis755 | 2:8788d711db7e | 12 | while(ucStrPtr < ucSize) { |
matis755 | 2:8788d711db7e | 13 | pStr[ucStrPtr] = MySerial.getc(); |
matis755 | 2:8788d711db7e | 14 | if(pStr[ucStrPtr] == '\r') { |
matis755 | 2:8788d711db7e | 15 | pStr[ucStrPtr] = NULL; |
matis755 | 2:8788d711db7e | 16 | return 0; |
matis755 | 2:8788d711db7e | 17 | } |
matis755 | 2:8788d711db7e | 18 | ucStrPtr ++; |
matis755 | 2:8788d711db7e | 19 | } |
matis755 | 2:8788d711db7e | 20 | return 1; |
matis755 | 2:8788d711db7e | 21 | } |
matis755 | 1:42a82d41947f | 22 | |
matis755 | 2:8788d711db7e | 23 | char puts(char *pStr, unsigned char ucSize){ |
matis755 | 2:8788d711db7e | 24 | unsigned char ucNullPtr; |
matis755 | 2:8788d711db7e | 25 | for(ucNullPtr = 0; ucNullPtr <= ucSize; ucNullPtr++){ |
matis755 | 2:8788d711db7e | 26 | if(pStr[ucNullPtr] == NULL) { |
matis755 | 2:8788d711db7e | 27 | break; |
matis755 | 2:8788d711db7e | 28 | } |
matis755 | 2:8788d711db7e | 29 | else {} |
matis755 | 2:8788d711db7e | 30 | } |
matis755 | 2:8788d711db7e | 31 | if (ucNullPtr == ucSize) { |
matis755 | 2:8788d711db7e | 32 | return 1; |
matis755 | 2:8788d711db7e | 33 | } |
matis755 | 0:e65dff476cf0 | 34 | |
matis755 | 2:8788d711db7e | 35 | for(unsigned char ucIdx = 0; ucIdx < ucNullPtr; ucIdx ++) { |
matis755 | 2:8788d711db7e | 36 | MySerial.putc(pStr[ucIdx]); |
matis755 | 2:8788d711db7e | 37 | } |
matis755 | 2:8788d711db7e | 38 | MySerial.putc('\r'); |
matis755 | 2:8788d711db7e | 39 | return 0; |
matis755 | 2:8788d711db7e | 40 | } |
matis755 | 2:8788d711db7e | 41 | |
matis755 | 2:8788d711db7e | 42 | |
matis755 | 2:8788d711db7e | 43 | int main() { |
matis755 | 3:6fc7976cc5bf | 44 | Tokenizer MyTokenizer; |
matis755 | 2:8788d711db7e | 45 | char cTablica[BUFFER_SIZE]; |
matis755 | 3:6fc7976cc5bf | 46 | |
matis755 | 2:8788d711db7e | 47 | |
matis755 | 2:8788d711db7e | 48 | while(1){ |
matis755 | 2:8788d711db7e | 49 | if(!gets(cTablica, BUFFER_SIZE)){ |
matis755 | 3:6fc7976cc5bf | 50 | MyTokenizer.DecodeMsg(cTablica); |
matis755 | 3:6fc7976cc5bf | 51 | if ((MyTokenizer.eGetTokenType(0) == KEYWORD) & (MyTokenizer.GetTokenCnt() != 0)){ |
matis755 | 3:6fc7976cc5bf | 52 | switch (MyTokenizer.eGetKeyword(0)){ |
matis755 | 3:6fc7976cc5bf | 53 | case (CLB): |
matis755 | 3:6fc7976cc5bf | 54 | led_green = !led_green; |
matis755 | 3:6fc7976cc5bf | 55 | break; |
matis755 | 3:6fc7976cc5bf | 56 | case (GT): |
matis755 | 3:6fc7976cc5bf | 57 | led_red = !led_red; |
matis755 | 3:6fc7976cc5bf | 58 | break; |
matis755 | 3:6fc7976cc5bf | 59 | default: |
matis755 | 3:6fc7976cc5bf | 60 | break; |
matis755 | 3:6fc7976cc5bf | 61 | } |
matis755 | 2:8788d711db7e | 62 | } |
matis755 | 0:e65dff476cf0 | 63 | } |
matis755 | 0:e65dff476cf0 | 64 | } |
matis755 | 0:e65dff476cf0 | 65 | } |