Luca Jel
/
mbed5a_testy
sdsd
Fork of mbed5a_testy by
main.cpp@0:e69a0b7f4b41, 2017-05-05 (annotated)
- Committer:
- Robsonik16
- Date:
- Fri May 05 19:54:49 2017 +0000
- Revision:
- 0:e69a0b7f4b41
- Child:
- 2:0fcc9b85c8f6
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Robsonik16 | 0:e69a0b7f4b41 | 1 | #include "mbed.h" |
Robsonik16 | 0:e69a0b7f4b41 | 2 | //#include "servo.h" |
Robsonik16 | 0:e69a0b7f4b41 | 3 | //#include "command_decoder.h" |
Robsonik16 | 0:e69a0b7f4b41 | 4 | #include "led.h" |
Robsonik16 | 0:e69a0b7f4b41 | 5 | #include "serwo.h" |
Robsonik16 | 0:e69a0b7f4b41 | 6 | #include "command_decoder.h" |
Robsonik16 | 0:e69a0b7f4b41 | 7 | |
Robsonik16 | 0:e69a0b7f4b41 | 8 | |
Robsonik16 | 0:e69a0b7f4b41 | 9 | |
Robsonik16 | 0:e69a0b7f4b41 | 10 | //#define DETECTOR_bm (PA4) |
Robsonik16 | 0:e69a0b7f4b41 | 11 | |
Robsonik16 | 0:e69a0b7f4b41 | 12 | |
Robsonik16 | 0:e69a0b7f4b41 | 13 | //DigitalIn det(PA_5); |
Robsonik16 | 0:e69a0b7f4b41 | 14 | //Ticker serwoTim; |
Robsonik16 | 0:e69a0b7f4b41 | 15 | |
Robsonik16 | 0:e69a0b7f4b41 | 16 | |
Robsonik16 | 0:e69a0b7f4b41 | 17 | |
Robsonik16 | 0:e69a0b7f4b41 | 18 | |
Robsonik16 | 0:e69a0b7f4b41 | 19 | //************************************************************************/ |
Robsonik16 | 0:e69a0b7f4b41 | 20 | |
Robsonik16 | 0:e69a0b7f4b41 | 21 | /******************************************************************/ |
Robsonik16 | 0:e69a0b7f4b41 | 22 | //------------------------------------ |
Robsonik16 | 0:e69a0b7f4b41 | 23 | // Hyperterminal configuration |
Robsonik16 | 0:e69a0b7f4b41 | 24 | // 9600 bauds, 8-bit data, no parity |
Robsonik16 | 0:e69a0b7f4b41 | 25 | //------------------------------------ |
Robsonik16 | 0:e69a0b7f4b41 | 26 | |
Robsonik16 | 0:e69a0b7f4b41 | 27 | RawSerial pc(USBTX,USBRX,9600); |
Robsonik16 | 0:e69a0b7f4b41 | 28 | |
Robsonik16 | 0:e69a0b7f4b41 | 29 | DigitalOut led_green(LED1); |
Robsonik16 | 0:e69a0b7f4b41 | 30 | DigitalOut led_red(LED2); |
Robsonik16 | 0:e69a0b7f4b41 | 31 | |
Robsonik16 | 0:e69a0b7f4b41 | 32 | |
Robsonik16 | 0:e69a0b7f4b41 | 33 | |
Robsonik16 | 0:e69a0b7f4b41 | 34 | Timeout LedTimeout; |
Robsonik16 | 0:e69a0b7f4b41 | 35 | Ticker Sender; |
Robsonik16 | 0:e69a0b7f4b41 | 36 | |
Robsonik16 | 0:e69a0b7f4b41 | 37 | void LedOff() |
Robsonik16 | 0:e69a0b7f4b41 | 38 | { |
Robsonik16 | 0:e69a0b7f4b41 | 39 | led_red=0; |
Robsonik16 | 0:e69a0b7f4b41 | 40 | } |
Robsonik16 | 0:e69a0b7f4b41 | 41 | |
Robsonik16 | 0:e69a0b7f4b41 | 42 | int my_puts(char tab[],int size) |
Robsonik16 | 0:e69a0b7f4b41 | 43 | { |
Robsonik16 | 0:e69a0b7f4b41 | 44 | //retutn 0 if string is valid |
Robsonik16 | 0:e69a0b7f4b41 | 45 | bool StringIsValid=false; |
Robsonik16 | 0:e69a0b7f4b41 | 46 | for( int index=0; index<size; index++) { |
Robsonik16 | 0:e69a0b7f4b41 | 47 | if (tab[index]==NULL) { |
Robsonik16 | 0:e69a0b7f4b41 | 48 | StringIsValid = true; |
Robsonik16 | 0:e69a0b7f4b41 | 49 | break; |
Robsonik16 | 0:e69a0b7f4b41 | 50 | } |
Robsonik16 | 0:e69a0b7f4b41 | 51 | } |
Robsonik16 | 0:e69a0b7f4b41 | 52 | if(StringIsValid == false) { |
Robsonik16 | 0:e69a0b7f4b41 | 53 | LedTimeout.attach(&LedOff, 0.5); |
Robsonik16 | 0:e69a0b7f4b41 | 54 | led_red=1; |
Robsonik16 | 0:e69a0b7f4b41 | 55 | return(1); |
Robsonik16 | 0:e69a0b7f4b41 | 56 | } |
Robsonik16 | 0:e69a0b7f4b41 | 57 | |
Robsonik16 | 0:e69a0b7f4b41 | 58 | for( int index=0; index<size; index++) { |
Robsonik16 | 0:e69a0b7f4b41 | 59 | if (tab[index]==NULL) { |
Robsonik16 | 0:e69a0b7f4b41 | 60 | pc.putc('\r'); |
Robsonik16 | 0:e69a0b7f4b41 | 61 | while(!pc.writeable()); |
Robsonik16 | 0:e69a0b7f4b41 | 62 | pc.putc('\n'); |
Robsonik16 | 0:e69a0b7f4b41 | 63 | return(0); |
Robsonik16 | 0:e69a0b7f4b41 | 64 | } |
Robsonik16 | 0:e69a0b7f4b41 | 65 | while(!pc.writeable()); |
Robsonik16 | 0:e69a0b7f4b41 | 66 | pc.putc(tab[index]); |
Robsonik16 | 0:e69a0b7f4b41 | 67 | } |
Robsonik16 | 0:e69a0b7f4b41 | 68 | return(0); |
Robsonik16 | 0:e69a0b7f4b41 | 69 | } |
Robsonik16 | 0:e69a0b7f4b41 | 70 | |
Robsonik16 | 0:e69a0b7f4b41 | 71 | void hardbeatSend() |
Robsonik16 | 0:e69a0b7f4b41 | 72 | { |
Robsonik16 | 0:e69a0b7f4b41 | 73 | static int count=0; |
Robsonik16 | 0:e69a0b7f4b41 | 74 | char tekst[25]; |
Robsonik16 | 0:e69a0b7f4b41 | 75 | sprintf(tekst,"hardbeat number: %d \r\n", count ); |
Robsonik16 | 0:e69a0b7f4b41 | 76 | //pc.printf("This program runs since %d seconds.\r\n", i); |
Robsonik16 | 0:e69a0b7f4b41 | 77 | my_puts(tekst,22); |
Robsonik16 | 0:e69a0b7f4b41 | 78 | count++; |
Robsonik16 | 0:e69a0b7f4b41 | 79 | } |
Robsonik16 | 0:e69a0b7f4b41 | 80 | |
Robsonik16 | 0:e69a0b7f4b41 | 81 | char my_gets(char str[],int size) |
Robsonik16 | 0:e69a0b7f4b41 | 82 | { |
Robsonik16 | 0:e69a0b7f4b41 | 83 | if (!pc.readable())return (NULL); |
Robsonik16 | 0:e69a0b7f4b41 | 84 | char c; |
Robsonik16 | 0:e69a0b7f4b41 | 85 | for(int index=0; index <size; index++) { |
Robsonik16 | 0:e69a0b7f4b41 | 86 | c=pc.getc(); |
Robsonik16 | 0:e69a0b7f4b41 | 87 | pc.putc(c); |
Robsonik16 | 0:e69a0b7f4b41 | 88 | if ((c=='\r')||(c=='\n')) { |
Robsonik16 | 0:e69a0b7f4b41 | 89 | pc.putc('\r'); |
Robsonik16 | 0:e69a0b7f4b41 | 90 | pc.putc('\n'); |
Robsonik16 | 0:e69a0b7f4b41 | 91 | str[index]=NULL; |
Robsonik16 | 0:e69a0b7f4b41 | 92 | return (1); |
Robsonik16 | 0:e69a0b7f4b41 | 93 | } |
Robsonik16 | 0:e69a0b7f4b41 | 94 | str[index]=c; |
Robsonik16 | 0:e69a0b7f4b41 | 95 | } |
Robsonik16 | 0:e69a0b7f4b41 | 96 | LedTimeout.attach(&LedOff, 5); |
Robsonik16 | 0:e69a0b7f4b41 | 97 | led_red=1; |
Robsonik16 | 0:e69a0b7f4b41 | 98 | return (1); |
Robsonik16 | 0:e69a0b7f4b41 | 99 | } |
Robsonik16 | 0:e69a0b7f4b41 | 100 | |
Robsonik16 | 0:e69a0b7f4b41 | 101 | |
Robsonik16 | 0:e69a0b7f4b41 | 102 | |
Robsonik16 | 0:e69a0b7f4b41 | 103 | |
Robsonik16 | 0:e69a0b7f4b41 | 104 | |
Robsonik16 | 0:e69a0b7f4b41 | 105 | |
Robsonik16 | 0:e69a0b7f4b41 | 106 | int main (){ |
Robsonik16 | 0:e69a0b7f4b41 | 107 | |
Robsonik16 | 0:e69a0b7f4b41 | 108 | |
Robsonik16 | 0:e69a0b7f4b41 | 109 | unsigned int uiPreviusPos; |
Robsonik16 | 0:e69a0b7f4b41 | 110 | //ButtonInit(); |
Robsonik16 | 0:e69a0b7f4b41 | 111 | //Servo_Init(500); |
Robsonik16 | 0:e69a0b7f4b41 | 112 | char cOdebranyString[20]; |
Robsonik16 | 0:e69a0b7f4b41 | 113 | char init[] = "system start\r\n"; |
Robsonik16 | 0:e69a0b7f4b41 | 114 | const char tekstSize = 20; |
Robsonik16 | 0:e69a0b7f4b41 | 115 | my_puts(init,tekstSize); |
Robsonik16 | 0:e69a0b7f4b41 | 116 | |
Robsonik16 | 0:e69a0b7f4b41 | 117 | Servo_Init(100); |
Robsonik16 | 0:e69a0b7f4b41 | 118 | //Servo_Callib(); |
Robsonik16 | 0:e69a0b7f4b41 | 119 | |
Robsonik16 | 0:e69a0b7f4b41 | 120 | while(1){ |
Robsonik16 | 0:e69a0b7f4b41 | 121 | |
Robsonik16 | 0:e69a0b7f4b41 | 122 | |
Robsonik16 | 0:e69a0b7f4b41 | 123 | |
Robsonik16 | 0:e69a0b7f4b41 | 124 | |
Robsonik16 | 0:e69a0b7f4b41 | 125 | |
Robsonik16 | 0:e69a0b7f4b41 | 126 | |
Robsonik16 | 0:e69a0b7f4b41 | 127 | |
Robsonik16 | 0:e69a0b7f4b41 | 128 | if (my_gets(cOdebranyString,tekstSize)!=NULL) { |
Robsonik16 | 0:e69a0b7f4b41 | 129 | //if(eReciever_GetStatus() == READY){ |
Robsonik16 | 0:e69a0b7f4b41 | 130 | |
Robsonik16 | 0:e69a0b7f4b41 | 131 | //Reciever_GetStringCopy( cOdebranyString ); |
Robsonik16 | 0:e69a0b7f4b41 | 132 | DecodeMsg( cOdebranyString ); |
Robsonik16 | 0:e69a0b7f4b41 | 133 | if ((ucTokenNr > 0) && (asToken[0].eType == KEYWORD)){ |
Robsonik16 | 0:e69a0b7f4b41 | 134 | switch (asToken[0].uValue.eKeyword){ |
Robsonik16 | 0:e69a0b7f4b41 | 135 | case CALLIB: |
Robsonik16 | 0:e69a0b7f4b41 | 136 | Servo_Callib(); |
Robsonik16 | 0:e69a0b7f4b41 | 137 | break; |
Robsonik16 | 0:e69a0b7f4b41 | 138 | case GOTO: |
Robsonik16 | 0:e69a0b7f4b41 | 139 | if (asToken[1].eType == NUMBER){ |
Robsonik16 | 0:e69a0b7f4b41 | 140 | Servo_GoTo(asToken[1].uValue.uiNumber); |
Robsonik16 | 0:e69a0b7f4b41 | 141 | uiPreviusPos = asToken[1].uValue.uiNumber; |
Robsonik16 | 0:e69a0b7f4b41 | 142 | } |
Robsonik16 | 0:e69a0b7f4b41 | 143 | break; |
Robsonik16 | 0:e69a0b7f4b41 | 144 | case STEP: |
Robsonik16 | 0:e69a0b7f4b41 | 145 | if (asToken[1].eType == NUMBER){ |
Robsonik16 | 0:e69a0b7f4b41 | 146 | Servo_GoTo(uiPreviusPos + asToken[1].uValue.uiNumber); |
Robsonik16 | 0:e69a0b7f4b41 | 147 | uiPreviusPos = uiPreviusPos + asToken[1].uValue.uiNumber; |
Robsonik16 | 0:e69a0b7f4b41 | 148 | } |
Robsonik16 | 0:e69a0b7f4b41 | 149 | break; |
Robsonik16 | 0:e69a0b7f4b41 | 150 | case ID: |
Robsonik16 | 0:e69a0b7f4b41 | 151 | my_puts("ID:0x1234",15); |
Robsonik16 | 0:e69a0b7f4b41 | 152 | break; |
Robsonik16 | 0:e69a0b7f4b41 | 153 | default: |
Robsonik16 | 0:e69a0b7f4b41 | 154 | break; |
Robsonik16 | 0:e69a0b7f4b41 | 155 | } |
Robsonik16 | 0:e69a0b7f4b41 | 156 | } |
Robsonik16 | 0:e69a0b7f4b41 | 157 | } |
Robsonik16 | 0:e69a0b7f4b41 | 158 | |
Robsonik16 | 0:e69a0b7f4b41 | 159 | } |
Robsonik16 | 0:e69a0b7f4b41 | 160 | } |
Robsonik16 | 0:e69a0b7f4b41 | 161 | |
Robsonik16 | 0:e69a0b7f4b41 | 162 | |
Robsonik16 | 0:e69a0b7f4b41 | 163 | |
Robsonik16 | 0:e69a0b7f4b41 | 164 | |
Robsonik16 | 0:e69a0b7f4b41 | 165 | |
Robsonik16 | 0:e69a0b7f4b41 | 166 | |
Robsonik16 | 0:e69a0b7f4b41 | 167 | |
Robsonik16 | 0:e69a0b7f4b41 | 168 | |
Robsonik16 | 0:e69a0b7f4b41 | 169 | /* |
Robsonik16 | 0:e69a0b7f4b41 | 170 | int main() |
Robsonik16 | 0:e69a0b7f4b41 | 171 | { |
Robsonik16 | 0:e69a0b7f4b41 | 172 | |
Robsonik16 | 0:e69a0b7f4b41 | 173 | |
Robsonik16 | 0:e69a0b7f4b41 | 174 | bool flag=false; |
Robsonik16 | 0:e69a0b7f4b41 | 175 | |
Robsonik16 | 0:e69a0b7f4b41 | 176 | const char tekstSize = 7; |
Robsonik16 | 0:e69a0b7f4b41 | 177 | char tekst[tekstSize]; |
Robsonik16 | 0:e69a0b7f4b41 | 178 | //my_puts("[2J",5);//clear console |
Robsonik16 | 0:e69a0b7f4b41 | 179 | //pc.putc('[2J'); |
Robsonik16 | 0:e69a0b7f4b41 | 180 | pc.putc(27); |
Robsonik16 | 0:e69a0b7f4b41 | 181 | char init[] = "system start\r\n"; |
Robsonik16 | 0:e69a0b7f4b41 | 182 | my_puts(init,tekstSize); |
Robsonik16 | 0:e69a0b7f4b41 | 183 | Sender.attach(&hardbeatSend,1); |
Robsonik16 | 0:e69a0b7f4b41 | 184 | |
Robsonik16 | 0:e69a0b7f4b41 | 185 | |
Robsonik16 | 0:e69a0b7f4b41 | 186 | |
Robsonik16 | 0:e69a0b7f4b41 | 187 | while(1) { |
Robsonik16 | 0:e69a0b7f4b41 | 188 | |
Robsonik16 | 0:e69a0b7f4b41 | 189 | |
Robsonik16 | 0:e69a0b7f4b41 | 190 | |
Robsonik16 | 0:e69a0b7f4b41 | 191 | if (my_gets(tekst,tekstSize)!=NULL) { |
Robsonik16 | 0:e69a0b7f4b41 | 192 | |
Robsonik16 | 0:e69a0b7f4b41 | 193 | my_puts(tekst,tekstSize); |
Robsonik16 | 0:e69a0b7f4b41 | 194 | if(strcmp(tekst,"on"))flag = true; |
Robsonik16 | 0:e69a0b7f4b41 | 195 | if(strcmp(tekst,"off"))flag = false; |
Robsonik16 | 0:e69a0b7f4b41 | 196 | if(strcmp(tekst,"toggle"))flag = !flag; |
Robsonik16 | 0:e69a0b7f4b41 | 197 | led_green =flag; |
Robsonik16 | 0:e69a0b7f4b41 | 198 | } |
Robsonik16 | 0:e69a0b7f4b41 | 199 | |
Robsonik16 | 0:e69a0b7f4b41 | 200 | } |
Robsonik16 | 0:e69a0b7f4b41 | 201 | } |
Robsonik16 | 0:e69a0b7f4b41 | 202 | */ |
Robsonik16 | 0:e69a0b7f4b41 | 203 |