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