:)
Dependencies: MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2
Revision 19:fea62e9c1ac4, committed 2014-12-10
- Comitter:
- jn80842
- Date:
- Wed Dec 10 06:47:50 2014 +0000
- Parent:
- 18:f7a00c31ff58
- Child:
- 20:b30b958dbd86
- Commit message:
- more fixes
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Dec 10 01:25:43 2014 +0000
+++ b/main.cpp Wed Dec 10 06:47:50 2014 +0000
@@ -111,7 +111,7 @@
char row[1] = ""; // holder for row tokens
char rowvoltage[4] = ""; // holder for voltage values
add_to_json("{\"vddval\":",json_str);
- sprintf(rowvoltage,"%.1f",vddval);
+ sprintf(rowvoltage,"%.1f",vddval*3.3);
add_to_json(rowvoltage,json_str);
add_to_json(", \"selected\":",json_str);
sprintf(row,"%d",selected);
@@ -129,7 +129,7 @@
sprintf(row, "%d", i);
add_to_json(row,json_str);
add_to_json("\":",json_str);
- sprintf(rowvoltage,"%.1f",clientdata[i]);
+ sprintf(rowvoltage,"%.1f",clientdata[i]*3.3);
add_to_json(rowvoltage,json_str);
add_to_json("}",json_str);
}
@@ -146,8 +146,7 @@
void read_voltages(float voltages[48]) {
scan_select = 0;
int sn = 0;
- for (int i=0;i<48;i++) { // iterate over two columns of breadboard
- // iterate over 24 rows of each column
+ for (int i=0;i<48;i++) {
sn = i;
D_in = (sn)%2;
E_in = ((sn)/2)%2;
@@ -188,7 +187,7 @@
if ((in_val < voltages[sn]-0.006) || (in_val > voltages[sn]+0.006)){
- voltages[sn] = 100;
+ voltages[sn] = 100.0;
}
@@ -203,7 +202,6 @@
scan_select = 0;
float rowval = voltages[(colselect*24)+ rowselect];
for (int i=0;i<48;i++) {
- int client_index = (colselect*24)+rowselect;
int sn = i;//(colselect+1)*(rowselect+1);
D_in = (sn)%2;
E_in = ((sn)/2)%2;
@@ -216,29 +214,29 @@
if (floatchecked[sn] == 100){
set_led(i,LED_OFF);
- clientdata[client_index] = 100.0;
+ clientdata[i] = 100.0;
}
else {
if (!voltages_equal(voltages[i],in_val)) {
// this row is floating
set_led(i,LED_OFF);
- clientdata[client_index] = 100.0;
+ clientdata[i] = 100.0;
} else if (voltages_equal(voltages[i],vddval)) {
// this row matches vdd
set_led(i,LED_RED);
- clientdata[client_index] = vddval;
+ clientdata[i] = vddval;
} else if (voltages_equal(voltages[i],0.0)) {
// this row matches ground
set_led(i,LED_YELLOW);
- clientdata[client_index] = 0.0;
+ clientdata[i] = 0.0;
} else if (voltages_equal(voltages[i],rowval)) {
// this row matches selected row
set_led(i,LED_GREEN);
- clientdata[client_index] = rowval;
+ clientdata[i] = rowval;
} else {
set_led(i,LED_OFF);
- clientdata[client_index] = voltages[i];
+ clientdata[i] = voltages[i];
}
} // else if closing
} //for loop closing
@@ -272,6 +270,7 @@
int written = 0;
wifi.init();
+ Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
//Osci
int loopcount = 0, pressed = 0;
@@ -287,13 +286,11 @@
} else {
pc.printf("IP address: %s \r\n", wifi.getIPAddress());
}
- }
- /*
- else {
- Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
+ } else if (ws.is_connected() == false) {
+ pc.printf("connecting to ws\r\n");
ws.connect();
}
- */
+
pc.printf("Okay took care of wifi stuff\r\n");
@@ -410,21 +407,13 @@
// send data to websocket
if (wifi.is_connected()) {
- Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
- ws.connect();
- pc.printf("create json string with vdd %.1f, selected %d\r\n",vddval,selected);
std::string json = build_json(vddval,selected,clientdata);
- pc.printf("declare writable\r\n");
char * writable = new char[json.size() + 1];
- pc.printf("copy json string into writable\r\n");
std::copy(json.begin(), json.end(), writable);
- pc.printf("add string delimiter to writable\r\n");
writable[json.size()] = '\0';
- pc.printf("send writable to ws\r\n");
pc.printf(writable);
pc.printf("\r\n");
- ws.send(writable);
- pc.printf("deallocate writable\r\n");
+ pc.printf("ws is connected ? %d\r\n", ws.is_connected()); ws.send(writable);
delete[] writable;
}