![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
Interpreter.cpp@24:bf62c46acb3e, 2018-04-25 (annotated)
- Committer:
- KlaasGovaerts
- Date:
- Wed Apr 25 13:25:13 2018 +0000
- Revision:
- 24:bf62c46acb3e
- Parent:
- 20:fe6a58e84929
- Child:
- 30:915f6cb7ffa5
Verzenden via queues
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KlaasGovaerts | 18:5ee34e60a31d | 1 | #include "Interpreter.h" |
KlaasGovaerts | 18:5ee34e60a31d | 2 | |
KlaasGovaerts | 24:bf62c46acb3e | 3 | |
KlaasGovaerts | 24:bf62c46acb3e | 4 | |
KlaasGovaerts | 24:bf62c46acb3e | 5 | Interpreter::Interpreter(Queue<int,8> *queue){ |
KlaasGovaerts | 24:bf62c46acb3e | 6 | Interpreter::queue=queue; |
KlaasGovaerts | 18:5ee34e60a31d | 7 | } |
KlaasGovaerts | 18:5ee34e60a31d | 8 | |
KlaasGovaerts | 18:5ee34e60a31d | 9 | void Interpreter::executeCommand(char* command){ |
KlaasGovaerts | 24:bf62c46acb3e | 10 | for(int i=0;i<8;i++){ |
KlaasGovaerts | 24:bf62c46acb3e | 11 | LED[i]=-1; |
KlaasGovaerts | 24:bf62c46acb3e | 12 | } //Set all default on 0 |
KlaasGovaerts | 24:bf62c46acb3e | 13 | |
KlaasGovaerts | 20:fe6a58e84929 | 14 | char *ID=strtok(command,"-"); |
KlaasGovaerts | 18:5ee34e60a31d | 15 | char *direction=strtok(NULL," "); |
KlaasGovaerts | 18:5ee34e60a31d | 16 | while((ID!=NULL)&&(direction!=NULL)){ |
KlaasGovaerts | 18:5ee34e60a31d | 17 | int IDNumber=atoi(ID); |
KlaasGovaerts | 18:5ee34e60a31d | 18 | int directionNumber=directionToNumber(direction); |
KlaasGovaerts | 18:5ee34e60a31d | 19 | if((IDNumber>=0)&&(IDNumber<=11)&&(directionNumber>=-1)&&(directionNumber<=3)){ |
KlaasGovaerts | 18:5ee34e60a31d | 20 | //lock->lock(); |
KlaasGovaerts | 18:5ee34e60a31d | 21 | LED[IDNumber]=directionNumber; |
KlaasGovaerts | 18:5ee34e60a31d | 22 | //lock->unlock(); |
KlaasGovaerts | 18:5ee34e60a31d | 23 | } |
KlaasGovaerts | 20:fe6a58e84929 | 24 | ID=strtok(NULL,"-"); |
KlaasGovaerts | 18:5ee34e60a31d | 25 | direction=strtok(NULL," "); |
KlaasGovaerts | 18:5ee34e60a31d | 26 | } |
KlaasGovaerts | 24:bf62c46acb3e | 27 | |
KlaasGovaerts | 24:bf62c46acb3e | 28 | for(int i=0;i<8;i++){ |
KlaasGovaerts | 24:bf62c46acb3e | 29 | queue->put(&LED[i]); |
KlaasGovaerts | 24:bf62c46acb3e | 30 | } |
KlaasGovaerts | 24:bf62c46acb3e | 31 | |
KlaasGovaerts | 24:bf62c46acb3e | 32 | for(int i=0;i<8;i++){ |
KlaasGovaerts | 24:bf62c46acb3e | 33 | printf("LED %i, richting: %i\r\n",i,LED[i]); |
KlaasGovaerts | 24:bf62c46acb3e | 34 | } |
KlaasGovaerts | 18:5ee34e60a31d | 35 | } |
KlaasGovaerts | 18:5ee34e60a31d | 36 | |
KlaasGovaerts | 18:5ee34e60a31d | 37 | int Interpreter::directionToNumber(char* direction){ |
KlaasGovaerts | 20:fe6a58e84929 | 38 | if(strcmp(direction,"left")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 39 | return 0; |
KlaasGovaerts | 20:fe6a58e84929 | 40 | else if(strcmp(direction,"right")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 41 | return 1; |
KlaasGovaerts | 20:fe6a58e84929 | 42 | else if(strcmp(direction,"up")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 43 | return 2; |
KlaasGovaerts | 20:fe6a58e84929 | 44 | else if(strcmp(direction,"down")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 45 | return 3; |
KlaasGovaerts | 18:5ee34e60a31d | 46 | else |
KlaasGovaerts | 18:5ee34e60a31d | 47 | return -1; |
KlaasGovaerts | 18:5ee34e60a31d | 48 | } |