a command line interface that can dynamically assign pins
Dependencies: TextLCD mbed PS2
Command.cpp@0:4b04cc4cccb4, 2011-10-20 (annotated)
- Committer:
- gsulc
- Date:
- Thu Oct 20 20:27:04 2011 +0000
- Revision:
- 0:4b04cc4cccb4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsulc | 0:4b04cc4cccb4 | 1 | /**************************************************************/ |
gsulc | 0:4b04cc4cccb4 | 2 | // Name: Commande.h |
gsulc | 0:4b04cc4cccb4 | 3 | // |
gsulc | 0:4b04cc4cccb4 | 4 | // Description: defines a command object for checking and |
gsulc | 0:4b04cc4cccb4 | 5 | // executing commands |
gsulc | 0:4b04cc4cccb4 | 6 | // |
gsulc | 0:4b04cc4cccb4 | 7 | /**************************************************************/ |
gsulc | 0:4b04cc4cccb4 | 8 | |
gsulc | 0:4b04cc4cccb4 | 9 | #include "Command.h" |
gsulc | 0:4b04cc4cccb4 | 10 | #include "Interface.h" |
gsulc | 0:4b04cc4cccb4 | 11 | #include "PS2Keyboard.h" |
gsulc | 0:4b04cc4cccb4 | 12 | #include <string.h> |
gsulc | 0:4b04cc4cccb4 | 13 | #include "keyname.h" |
gsulc | 0:4b04cc4cccb4 | 14 | #include "TextLCD.h" |
gsulc | 0:4b04cc4cccb4 | 15 | #include <stdlib.h> |
gsulc | 0:4b04cc4cccb4 | 16 | |
gsulc | 0:4b04cc4cccb4 | 17 | Interface interface[32]; |
gsulc | 0:4b04cc4cccb4 | 18 | |
gsulc | 0:4b04cc4cccb4 | 19 | /*Command::Command(char* cmdname){ |
gsulc | 0:4b04cc4cccb4 | 20 | strcpy(name, cmdname); |
gsulc | 0:4b04cc4cccb4 | 21 | parameter_count = 0; |
gsulc | 0:4b04cc4cccb4 | 22 | } |
gsulc | 0:4b04cc4cccb4 | 23 | |
gsulc | 0:4b04cc4cccb4 | 24 | int Command::addParameter(char* param){ |
gsulc | 0:4b04cc4cccb4 | 25 | |
gsulc | 0:4b04cc4cccb4 | 26 | return parameter_count++; |
gsulc | 0:4b04cc4cccb4 | 27 | }*/ |
gsulc | 0:4b04cc4cccb4 | 28 | |
gsulc | 0:4b04cc4cccb4 | 29 | PS2Keyboard ps2kb(p12, p11); // CLK, DAT |
gsulc | 0:4b04cc4cccb4 | 30 | //Serial pc(USBTX, USBRX); |
gsulc | 0:4b04cc4cccb4 | 31 | TextLCD pc(p15, p16, p17, p18, p19, p20); |
gsulc | 0:4b04cc4cccb4 | 32 | //char input[32]; |
gsulc | 0:4b04cc4cccb4 | 33 | |
gsulc | 0:4b04cc4cccb4 | 34 | DigitalOut testled(LED2); |
gsulc | 0:4b04cc4cccb4 | 35 | |
gsulc | 0:4b04cc4cccb4 | 36 | void execute(char* input){ |
gsulc | 0:4b04cc4cccb4 | 37 | char* cmdname = strtok(input," -"); |
gsulc | 0:4b04cc4cccb4 | 38 | char* param; |
gsulc | 0:4b04cc4cccb4 | 39 | if(strcmp(cmdname, "DIN") == 0){ |
gsulc | 0:4b04cc4cccb4 | 40 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 41 | // create operation |
gsulc | 0:4b04cc4cccb4 | 42 | if(strcmp(param, "C") == 0){ |
gsulc | 0:4b04cc4cccb4 | 43 | param = strtok (NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 44 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 45 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 46 | if(pin_num >= 5 && pin_num <= 32){ |
gsulc | 0:4b04cc4cccb4 | 47 | pc.printf("\n\nCreating D_IN..."); |
gsulc | 0:4b04cc4cccb4 | 48 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 49 | interface[pin_num-5].p_object = malloc(sizeof(DigitalIn)); |
gsulc | 0:4b04cc4cccb4 | 50 | memmove(interface[pin_num-5].p_object, &DigitalIn(getPin(pin_num)), sizeof(DigitalIn)); |
gsulc | 0:4b04cc4cccb4 | 51 | } |
gsulc | 0:4b04cc4cccb4 | 52 | } |
gsulc | 0:4b04cc4cccb4 | 53 | else { //pins not given |
gsulc | 0:4b04cc4cccb4 | 54 | } |
gsulc | 0:4b04cc4cccb4 | 55 | } |
gsulc | 0:4b04cc4cccb4 | 56 | // read operation |
gsulc | 0:4b04cc4cccb4 | 57 | else if(strcmp(param, "R") == 0){ |
gsulc | 0:4b04cc4cccb4 | 58 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 59 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 60 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 61 | if(pin_num >= 5 && pin_num <= 32){ |
gsulc | 0:4b04cc4cccb4 | 62 | pc.printf("\n\nReading..."); |
gsulc | 0:4b04cc4cccb4 | 63 | int val = ((DigitalIn)(*(DigitalIn*)interface[pin_num-5].p_object)).read(); |
gsulc | 0:4b04cc4cccb4 | 64 | pc.printf("\nI am: %d", val); |
gsulc | 0:4b04cc4cccb4 | 65 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 66 | } |
gsulc | 0:4b04cc4cccb4 | 67 | } |
gsulc | 0:4b04cc4cccb4 | 68 | } |
gsulc | 0:4b04cc4cccb4 | 69 | } |
gsulc | 0:4b04cc4cccb4 | 70 | else if((strcmp(cmdname, "DOUT")) == 0){ |
gsulc | 0:4b04cc4cccb4 | 71 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 72 | // create operation |
gsulc | 0:4b04cc4cccb4 | 73 | if(strcmp(param, "C") == 0){ |
gsulc | 0:4b04cc4cccb4 | 74 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 75 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 76 | int pin_num = str2int(param + 1); |
gsulc | 0:4b04cc4cccb4 | 77 | if(pin_num >= 5 && pin_num <= 32){ |
gsulc | 0:4b04cc4cccb4 | 78 | pc.printf("\n\nCreating D_Out.."); |
gsulc | 0:4b04cc4cccb4 | 79 | wait(1); |
gsulc | 0:4b04cc4cccb4 | 80 | //DigitalOut tmp(getPin(pin_num)); |
gsulc | 0:4b04cc4cccb4 | 81 | //interface[pin_num-5].p_object = &tmp; |
gsulc | 0:4b04cc4cccb4 | 82 | //interface[pin_num-5].dout = &DigitalOut(getPin(pin_num)); |
gsulc | 0:4b04cc4cccb4 | 83 | interface[pin_num-5].p_object = malloc(sizeof(DigitalOut)); |
gsulc | 0:4b04cc4cccb4 | 84 | //(DigitalOut)interface[pin_num-5].p_object = DigitalOut(getPin(pin_num)); |
gsulc | 0:4b04cc4cccb4 | 85 | memmove(interface[pin_num-5].p_object, &DigitalOut(getPin(pin_num)), sizeof(DigitalOut)); |
gsulc | 0:4b04cc4cccb4 | 86 | //pc.printf("\n\nwriting to %X", interface[pin_num-5].p_object); |
gsulc | 0:4b04cc4cccb4 | 87 | //wait(2); |
gsulc | 0:4b04cc4cccb4 | 88 | |
gsulc | 0:4b04cc4cccb4 | 89 | /*DigitalOut t = *((DigitalOut*)(interface[pin_num-5].p_object)); |
gsulc | 0:4b04cc4cccb4 | 90 | |
gsulc | 0:4b04cc4cccb4 | 91 | wait(4);*/ |
gsulc | 0:4b04cc4cccb4 | 92 | //interface[pin_num-5].dout = &tmp; |
gsulc | 0:4b04cc4cccb4 | 93 | |
gsulc | 0:4b04cc4cccb4 | 94 | } |
gsulc | 0:4b04cc4cccb4 | 95 | } |
gsulc | 0:4b04cc4cccb4 | 96 | else { //pins not given |
gsulc | 0:4b04cc4cccb4 | 97 | } |
gsulc | 0:4b04cc4cccb4 | 98 | } |
gsulc | 0:4b04cc4cccb4 | 99 | // write operation |
gsulc | 0:4b04cc4cccb4 | 100 | else if(strcmp(param, "W") == 0){ |
gsulc | 0:4b04cc4cccb4 | 101 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 102 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 103 | int pin_num = str2int(param + 1); |
gsulc | 0:4b04cc4cccb4 | 104 | if(pin_num >= 5 && pin_num <= 32){ |
gsulc | 0:4b04cc4cccb4 | 105 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 106 | int a = str2int(param); |
gsulc | 0:4b04cc4cccb4 | 107 | //interface[pin_num-5].dout = a; |
gsulc | 0:4b04cc4cccb4 | 108 | //(DigitalOut)(*((DigitalOut*)(interface[pin_num-5].dout))).write(a); |
gsulc | 0:4b04cc4cccb4 | 109 | //DigitalOut t = *((DigitalOut*)(interface[pin_num-5].p_object)); |
gsulc | 0:4b04cc4cccb4 | 110 | //memcpy(, sizeof(DigitalOut)); |
gsulc | 0:4b04cc4cccb4 | 111 | //pc.printf("\n\na:%X", interface[pin_num-5].p_object); |
gsulc | 0:4b04cc4cccb4 | 112 | //pc.printf("\nb:%X", &t); |
gsulc | 0:4b04cc4cccb4 | 113 | //wait(2); |
gsulc | 0:4b04cc4cccb4 | 114 | pc.printf("\n\nWriting..."); |
gsulc | 0:4b04cc4cccb4 | 115 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 116 | ((DigitalOut)(*(DigitalOut*)interface[pin_num-5].p_object)).write(a); |
gsulc | 0:4b04cc4cccb4 | 117 | //t = a; |
gsulc | 0:4b04cc4cccb4 | 118 | //(DigitalOut)(*(interface[pin_num-5].dout)).write(a); |
gsulc | 0:4b04cc4cccb4 | 119 | } |
gsulc | 0:4b04cc4cccb4 | 120 | } |
gsulc | 0:4b04cc4cccb4 | 121 | else{ //Bad pin parameter |
gsulc | 0:4b04cc4cccb4 | 122 | } |
gsulc | 0:4b04cc4cccb4 | 123 | } |
gsulc | 0:4b04cc4cccb4 | 124 | |
gsulc | 0:4b04cc4cccb4 | 125 | else if(strcmp(param, "R") == 0){ |
gsulc | 0:4b04cc4cccb4 | 126 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 127 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 128 | int pin_num = str2int(param + 1); |
gsulc | 0:4b04cc4cccb4 | 129 | if(pin_num >= 5 && pin_num <= 32){ |
gsulc | 0:4b04cc4cccb4 | 130 | pc.printf("\n\nWriting..."); |
gsulc | 0:4b04cc4cccb4 | 131 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 132 | int a = ((DigitalOut)(*(DigitalOut*)interface[pin_num-5].p_object)).read(); |
gsulc | 0:4b04cc4cccb4 | 133 | pc.printf("\n\n Value = %d", a); |
gsulc | 0:4b04cc4cccb4 | 134 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 135 | } |
gsulc | 0:4b04cc4cccb4 | 136 | } |
gsulc | 0:4b04cc4cccb4 | 137 | else{ //Bad pin parameter |
gsulc | 0:4b04cc4cccb4 | 138 | } |
gsulc | 0:4b04cc4cccb4 | 139 | } |
gsulc | 0:4b04cc4cccb4 | 140 | } |
gsulc | 0:4b04cc4cccb4 | 141 | else if(!strcmp(cmdname, "I2C")){ |
gsulc | 0:4b04cc4cccb4 | 142 | char* param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 143 | // create operation |
gsulc | 0:4b04cc4cccb4 | 144 | if(!strcmp(param, "C")){ |
gsulc | 0:4b04cc4cccb4 | 145 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 146 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 147 | pc.printf("\n\nCreating I2C..."); |
gsulc | 0:4b04cc4cccb4 | 148 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 149 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 150 | interface[pin_num-5].p_object = malloc(sizeof(I2C)); |
gsulc | 0:4b04cc4cccb4 | 151 | if(pin_num == 9 || pin_num == 10){ |
gsulc | 0:4b04cc4cccb4 | 152 | memmove(interface[pin_num-5].p_object, &I2C(p9, p10), sizeof(I2C)); |
gsulc | 0:4b04cc4cccb4 | 153 | } |
gsulc | 0:4b04cc4cccb4 | 154 | else if(pin_num == 28 || pin_num == 27){ |
gsulc | 0:4b04cc4cccb4 | 155 | memmove(interface[pin_num-5].p_object, &I2C(p28, p27), sizeof(I2C)); |
gsulc | 0:4b04cc4cccb4 | 156 | } |
gsulc | 0:4b04cc4cccb4 | 157 | } |
gsulc | 0:4b04cc4cccb4 | 158 | else { //pins not given |
gsulc | 0:4b04cc4cccb4 | 159 | } |
gsulc | 0:4b04cc4cccb4 | 160 | } |
gsulc | 0:4b04cc4cccb4 | 161 | // write operation |
gsulc | 0:4b04cc4cccb4 | 162 | else if(!strcmp(param, "W")){ |
gsulc | 0:4b04cc4cccb4 | 163 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 164 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 165 | |
gsulc | 0:4b04cc4cccb4 | 166 | pc.printf("\n\nWriting to I2C..."); |
gsulc | 0:4b04cc4cccb4 | 167 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 168 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 169 | //I2C tmp = *((I2C*)(interface[pin_num-5].p_object)); |
gsulc | 0:4b04cc4cccb4 | 170 | |
gsulc | 0:4b04cc4cccb4 | 171 | int addr, strlen; |
gsulc | 0:4b04cc4cccb4 | 172 | |
gsulc | 0:4b04cc4cccb4 | 173 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 174 | addr = hexstr2int(param); |
gsulc | 0:4b04cc4cccb4 | 175 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 176 | strlen = str2int(param); |
gsulc | 0:4b04cc4cccb4 | 177 | char cmd[strlen]; |
gsulc | 0:4b04cc4cccb4 | 178 | for(int i = 0; i < strlen; i++){ |
gsulc | 0:4b04cc4cccb4 | 179 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 180 | cmd[i] = str2int(¶m[i]); |
gsulc | 0:4b04cc4cccb4 | 181 | } |
gsulc | 0:4b04cc4cccb4 | 182 | |
gsulc | 0:4b04cc4cccb4 | 183 | |
gsulc | 0:4b04cc4cccb4 | 184 | ((I2C)(*(I2C*)interface[pin_num-5].p_object)).write(addr, cmd, strlen); |
gsulc | 0:4b04cc4cccb4 | 185 | } |
gsulc | 0:4b04cc4cccb4 | 186 | } |
gsulc | 0:4b04cc4cccb4 | 187 | //read |
gsulc | 0:4b04cc4cccb4 | 188 | else if(!strcmp(param, "R")){ |
gsulc | 0:4b04cc4cccb4 | 189 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 190 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 191 | pc.printf("\n\nReading from I2C..."); |
gsulc | 0:4b04cc4cccb4 | 192 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 193 | |
gsulc | 0:4b04cc4cccb4 | 194 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 195 | int addr, strlen; |
gsulc | 0:4b04cc4cccb4 | 196 | |
gsulc | 0:4b04cc4cccb4 | 197 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 198 | addr = str2int(param); |
gsulc | 0:4b04cc4cccb4 | 199 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 200 | strlen = str2int(param); |
gsulc | 0:4b04cc4cccb4 | 201 | char cmd[strlen]; |
gsulc | 0:4b04cc4cccb4 | 202 | |
gsulc | 0:4b04cc4cccb4 | 203 | ((I2C)(*(I2C*)interface[pin_num-5].p_object)).read(addr, cmd, strlen); |
gsulc | 0:4b04cc4cccb4 | 204 | // print the ranging data to the screen |
gsulc | 0:4b04cc4cccb4 | 205 | int e = 0; |
gsulc | 0:4b04cc4cccb4 | 206 | for(int i = 1; i < strlen; i++){ |
gsulc | 0:4b04cc4cccb4 | 207 | e = ((e << 8) + cmd[i]); |
gsulc | 0:4b04cc4cccb4 | 208 | } |
gsulc | 0:4b04cc4cccb4 | 209 | float echo = (float)e* 0.01; |
gsulc | 0:4b04cc4cccb4 | 210 | pc.printf("Value = %.4f\n", echo); |
gsulc | 0:4b04cc4cccb4 | 211 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 212 | // print the ranging data to the screen |
gsulc | 0:4b04cc4cccb4 | 213 | //float echo = 0.01 * ((cmd[0] << 8) + cmd[1]); |
gsulc | 0:4b04cc4cccb4 | 214 | //pc.printf("Range = %.2f\n", echo); |
gsulc | 0:4b04cc4cccb4 | 215 | //wait(2); |
gsulc | 0:4b04cc4cccb4 | 216 | } |
gsulc | 0:4b04cc4cccb4 | 217 | } |
gsulc | 0:4b04cc4cccb4 | 218 | } |
gsulc | 0:4b04cc4cccb4 | 219 | else if(!strcmp(cmdname, "SERIAL")){ |
gsulc | 0:4b04cc4cccb4 | 220 | //baud, putc, getc |
gsulc | 0:4b04cc4cccb4 | 221 | char* param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 222 | // create operation |
gsulc | 0:4b04cc4cccb4 | 223 | if(!strcmp(param, "C")){ |
gsulc | 0:4b04cc4cccb4 | 224 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 225 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 226 | pc.printf("\n\nCreating Serial..."); |
gsulc | 0:4b04cc4cccb4 | 227 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 228 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 229 | interface[pin_num-5].p_object = malloc(sizeof(Serial)); |
gsulc | 0:4b04cc4cccb4 | 230 | if(pin_num == 9 || pin_num == 10){ |
gsulc | 0:4b04cc4cccb4 | 231 | memmove(interface[pin_num-5].p_object, &Serial(p9, p10), sizeof(Serial)); |
gsulc | 0:4b04cc4cccb4 | 232 | } |
gsulc | 0:4b04cc4cccb4 | 233 | else if(pin_num == 13 || pin_num == 14){ |
gsulc | 0:4b04cc4cccb4 | 234 | memmove(interface[pin_num-5].p_object, &Serial(p13, p14), sizeof(Serial)); |
gsulc | 0:4b04cc4cccb4 | 235 | } |
gsulc | 0:4b04cc4cccb4 | 236 | else if(pin_num == 28 || pin_num == 27){ |
gsulc | 0:4b04cc4cccb4 | 237 | memmove(interface[pin_num-5].p_object, &Serial(p28, p27), sizeof(Serial)); |
gsulc | 0:4b04cc4cccb4 | 238 | } |
gsulc | 0:4b04cc4cccb4 | 239 | } |
gsulc | 0:4b04cc4cccb4 | 240 | else { //pins not given |
gsulc | 0:4b04cc4cccb4 | 241 | } |
gsulc | 0:4b04cc4cccb4 | 242 | } |
gsulc | 0:4b04cc4cccb4 | 243 | //putc |
gsulc | 0:4b04cc4cccb4 | 244 | else if(!strcmp(param, "P")){ |
gsulc | 0:4b04cc4cccb4 | 245 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 246 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 247 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 248 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 249 | int c = str2int(param); |
gsulc | 0:4b04cc4cccb4 | 250 | pc.printf("\n\nPutting a %d", c); |
gsulc | 0:4b04cc4cccb4 | 251 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 252 | ((Serial)(*(Serial*)interface[pin_num-5].p_object)).putc(c); |
gsulc | 0:4b04cc4cccb4 | 253 | } |
gsulc | 0:4b04cc4cccb4 | 254 | } |
gsulc | 0:4b04cc4cccb4 | 255 | //getc |
gsulc | 0:4b04cc4cccb4 | 256 | else if(!strcmp(param, "G")){ |
gsulc | 0:4b04cc4cccb4 | 257 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 258 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 259 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 260 | int val = ((Serial)(*(Serial*)interface[pin_num-5].p_object)).getc(); |
gsulc | 0:4b04cc4cccb4 | 261 | pc.printf("\nValue: %d", val); |
gsulc | 0:4b04cc4cccb4 | 262 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 263 | } |
gsulc | 0:4b04cc4cccb4 | 264 | } |
gsulc | 0:4b04cc4cccb4 | 265 | //baud |
gsulc | 0:4b04cc4cccb4 | 266 | else if(!strcmp(param, "B")){ |
gsulc | 0:4b04cc4cccb4 | 267 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 268 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 269 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 270 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 271 | int a = str2int(param); |
gsulc | 0:4b04cc4cccb4 | 272 | pc.printf("\n\nSetting baud to %d", a); |
gsulc | 0:4b04cc4cccb4 | 273 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 274 | ((Serial)(*(Serial*)interface[pin_num-5].p_object)).baud(a); |
gsulc | 0:4b04cc4cccb4 | 275 | } |
gsulc | 0:4b04cc4cccb4 | 276 | } |
gsulc | 0:4b04cc4cccb4 | 277 | } |
gsulc | 0:4b04cc4cccb4 | 278 | |
gsulc | 0:4b04cc4cccb4 | 279 | else if(!strcmp(cmdname, "PWMO")){ |
gsulc | 0:4b04cc4cccb4 | 280 | char* param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 281 | // create operation |
gsulc | 0:4b04cc4cccb4 | 282 | if(!strcmp(param, "C")){ |
gsulc | 0:4b04cc4cccb4 | 283 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 284 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 285 | int pin_num = str2int(param+1); |
gsulc | 0:4b04cc4cccb4 | 286 | if(pin_num >= 21 && pin_num <= 26){ |
gsulc | 0:4b04cc4cccb4 | 287 | pc.printf("\n\nCreating PWM..."); |
gsulc | 0:4b04cc4cccb4 | 288 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 289 | interface[pin_num-5].p_object = malloc(sizeof(PwmOut)); |
gsulc | 0:4b04cc4cccb4 | 290 | memmove(interface[pin_num-5].p_object, &PwmOut(getPin(pin_num)), sizeof(PwmOut)); |
gsulc | 0:4b04cc4cccb4 | 291 | } |
gsulc | 0:4b04cc4cccb4 | 292 | } |
gsulc | 0:4b04cc4cccb4 | 293 | else { //pins not given |
gsulc | 0:4b04cc4cccb4 | 294 | } |
gsulc | 0:4b04cc4cccb4 | 295 | } |
gsulc | 0:4b04cc4cccb4 | 296 | //write |
gsulc | 0:4b04cc4cccb4 | 297 | else if(strcmp(param, "W") == 0){ |
gsulc | 0:4b04cc4cccb4 | 298 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 299 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 300 | int pin_num = str2int(param + 1); |
gsulc | 0:4b04cc4cccb4 | 301 | if(pin_num >= 21 && pin_num <= 26){ |
gsulc | 0:4b04cc4cccb4 | 302 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 303 | //float a = str2int(param) / (sizeof(int)*8 - 1); |
gsulc | 0:4b04cc4cccb4 | 304 | float a = atof(param); |
gsulc | 0:4b04cc4cccb4 | 305 | pc.printf("\n\nWriting... a %f", a); |
gsulc | 0:4b04cc4cccb4 | 306 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 307 | ((PwmOut)(*(PwmOut*)interface[pin_num-5].p_object)).write(a); |
gsulc | 0:4b04cc4cccb4 | 308 | } |
gsulc | 0:4b04cc4cccb4 | 309 | } |
gsulc | 0:4b04cc4cccb4 | 310 | else{ //Bad pin parameter |
gsulc | 0:4b04cc4cccb4 | 311 | } |
gsulc | 0:4b04cc4cccb4 | 312 | } |
gsulc | 0:4b04cc4cccb4 | 313 | |
gsulc | 0:4b04cc4cccb4 | 314 | //read |
gsulc | 0:4b04cc4cccb4 | 315 | else if(!strcmp(param, "R")){ |
gsulc | 0:4b04cc4cccb4 | 316 | param = strtok(NULL," -"); |
gsulc | 0:4b04cc4cccb4 | 317 | if(param[0] == 'P'){ |
gsulc | 0:4b04cc4cccb4 | 318 | int pin_num = str2int(param + 1); |
gsulc | 0:4b04cc4cccb4 | 319 | if(pin_num >= 21 && pin_num <= 26){ |
gsulc | 0:4b04cc4cccb4 | 320 | float a = ((PwmOut)(*(PwmOut*)interface[pin_num-5].p_object)).read(); |
gsulc | 0:4b04cc4cccb4 | 321 | pc.printf("\n\nValue = %f", a); |
gsulc | 0:4b04cc4cccb4 | 322 | wait(2); |
gsulc | 0:4b04cc4cccb4 | 323 | } |
gsulc | 0:4b04cc4cccb4 | 324 | } |
gsulc | 0:4b04cc4cccb4 | 325 | } |
gsulc | 0:4b04cc4cccb4 | 326 | } |
gsulc | 0:4b04cc4cccb4 | 327 | } |
gsulc | 0:4b04cc4cccb4 | 328 | |
gsulc | 0:4b04cc4cccb4 | 329 | void run(){ |
gsulc | 0:4b04cc4cccb4 | 330 | /*// Read Input |
gsulc | 0:4b04cc4cccb4 | 331 | pc.printf("> "); |
gsulc | 0:4b04cc4cccb4 | 332 | pc.scanf("%s", input); |
gsulc | 0:4b04cc4cccb4 | 333 | pc.printf("\n\r"); |
gsulc | 0:4b04cc4cccb4 | 334 | pc.printf("%s\n\r", input); |
gsulc | 0:4b04cc4cccb4 | 335 | |
gsulc | 0:4b04cc4cccb4 | 336 | // Execute Instruction |
gsulc | 0:4b04cc4cccb4 | 337 | if(1) |
gsulc | 0:4b04cc4cccb4 | 338 | execute(input);*/ |
gsulc | 0:4b04cc4cccb4 | 339 | |
gsulc | 0:4b04cc4cccb4 | 340 | PS2Keyboard::keyboard_event_t evt_kb; |
gsulc | 0:4b04cc4cccb4 | 341 | char str[32]; |
gsulc | 0:4b04cc4cccb4 | 342 | for(int i = 0; i<32 ; i++) str[i] = ' '; |
gsulc | 0:4b04cc4cccb4 | 343 | int numchar = 0; |
gsulc | 0:4b04cc4cccb4 | 344 | char *p = str; |
gsulc | 0:4b04cc4cccb4 | 345 | while (1) { |
gsulc | 0:4b04cc4cccb4 | 346 | if (ps2kb.processing(&evt_kb)) { |
gsulc | 0:4b04cc4cccb4 | 347 | for (int i = 0; i < evt_kb.length; i++) { |
gsulc | 0:4b04cc4cccb4 | 348 | if(evt_kb.scancode[i] == 0xf0){ |
gsulc | 0:4b04cc4cccb4 | 349 | i++; |
gsulc | 0:4b04cc4cccb4 | 350 | char c = evt_kb.scancode[i]; |
gsulc | 0:4b04cc4cccb4 | 351 | if(c == 0x5A){ |
gsulc | 0:4b04cc4cccb4 | 352 | // Gordon can call a function here to use str to do whatever |
gsulc | 0:4b04cc4cccb4 | 353 | execute(p); |
gsulc | 0:4b04cc4cccb4 | 354 | |
gsulc | 0:4b04cc4cccb4 | 355 | for(int i = 0; i<32 ; i++) |
gsulc | 0:4b04cc4cccb4 | 356 | p[i] = ' '; |
gsulc | 0:4b04cc4cccb4 | 357 | numchar = 0; |
gsulc | 0:4b04cc4cccb4 | 358 | } |
gsulc | 0:4b04cc4cccb4 | 359 | else numchar = curstr(p,numchar,c); |
gsulc | 0:4b04cc4cccb4 | 360 | } |
gsulc | 0:4b04cc4cccb4 | 361 | } |
gsulc | 0:4b04cc4cccb4 | 362 | for(int i = 0; i<32 ; i++) |
gsulc | 0:4b04cc4cccb4 | 363 | pc.printf("%c", str[i]); |
gsulc | 0:4b04cc4cccb4 | 364 | pc.printf("\n\n"); |
gsulc | 0:4b04cc4cccb4 | 365 | } |
gsulc | 0:4b04cc4cccb4 | 366 | |
gsulc | 0:4b04cc4cccb4 | 367 | } |
gsulc | 0:4b04cc4cccb4 | 368 | } |
gsulc | 0:4b04cc4cccb4 | 369 | |
gsulc | 0:4b04cc4cccb4 | 370 | int str2int(char* str) { |
gsulc | 0:4b04cc4cccb4 | 371 | int num = 0, i = 0; |
gsulc | 0:4b04cc4cccb4 | 372 | while(str[i] != NULL){ |
gsulc | 0:4b04cc4cccb4 | 373 | num = num * 10 + str[i] - '0'; |
gsulc | 0:4b04cc4cccb4 | 374 | i++; |
gsulc | 0:4b04cc4cccb4 | 375 | } |
gsulc | 0:4b04cc4cccb4 | 376 | return num; |
gsulc | 0:4b04cc4cccb4 | 377 | } |
gsulc | 0:4b04cc4cccb4 | 378 | |
gsulc | 0:4b04cc4cccb4 | 379 | int hexstr2int(char* str) { |
gsulc | 0:4b04cc4cccb4 | 380 | int num = 0, i = 0; |
gsulc | 0:4b04cc4cccb4 | 381 | while(str[i] != NULL){ |
gsulc | 0:4b04cc4cccb4 | 382 | num = num * 16 + str[i] - '0'; |
gsulc | 0:4b04cc4cccb4 | 383 | i++; |
gsulc | 0:4b04cc4cccb4 | 384 | } |
gsulc | 0:4b04cc4cccb4 | 385 | return num; |
gsulc | 0:4b04cc4cccb4 | 386 | } |