:)
Dependencies: MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2
Revision 15:236d90e38951, committed 2014-12-09
- Comitter:
- ddrew73
- Date:
- Tue Dec 09 18:21:26 2014 +0000
- Parent:
- 14:2d47b97c2028
- Child:
- 16:028a8548ab22
- Commit message:
- UI + scan working, wifi down;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 08 19:52:15 2014 +0000
+++ b/main.cpp Tue Dec 09 18:21:26 2014 +0000
@@ -66,7 +66,7 @@
lcd.locate(0,1);
lcd.printf("Vdd: %1.1f V",vddval);
lcd.locate(0,0);
- lcd.printf("Row %d: %1.1f V",selected+1,rowval);
+ lcd.printf("Row %d: %1.1f V",selected,rowval);
}
@@ -83,10 +83,13 @@
// - SPI CLK => (pin D13)
// plus wifi network SSID, password, security level and smart-configuration flag.
+/*
+
mbed_cc3000::cc3000 wifi(D8, D9, D10, SPI(D11, D12, D13),
"SSID", "PASSWORD", WPA2, false);
Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
+
void add_to_json(const std::string& s, std::back_insert_iterator<std::string> oi) {
// this chunk of code lifted from the MbedJSONValue
char buf[7];
@@ -131,6 +134,7 @@
add_to_json("]}",json_str);
return s;
}
+*/
bool voltages_equal(float voltage1,float voltage2) {
return (voltage1 > voltage2-0.01) && (voltage1 < voltage2+0.01);
@@ -138,38 +142,40 @@
void read_voltages(float voltages[48]) {
int sn = 0;
- for (int x=0;x<2;x++) { // iterate over two columns of breadboard
- for (int y=0;y<24;y++) { // iterate over 24 rows of each column
- sn = (x*24)+y+1; // maybe?????
- A_in = (sn-1)%2;
- B_in = ((sn-1)/2)%2;
- C_in = ((sn-1)/4)%2;
- D_in = ((sn-1)/8)%2;
- E_in = ((sn-1)/16)%2;
- F_in = ((sn-1)/32)%2;
+ for (int i=0;i<48;i++) { // iterate over two columns of breadboard
+ // iterate over 24 rows of each column
+ sn = i; // maybe?????
+ D_in = (sn)%2;
+ E_in = ((sn)/2)%2;
+ F_in = ((sn)/4)%2;
+ A_in = ((sn)/8)%2;
+ B_in = ((sn)/16)%2;
+ C_in = ((sn)/32)%2;
- voltages[sn-1] = adc.read();
- }
+ voltages[sn] = adc.read();
+
}
}
void compare_voltages(float voltages[48], float clientdata[48], int colselect, int rowselect, float vddval) {
// get selected row voltage
- float rowval = voltages[(colselect*24)+rowselect];
+ float rowval = voltages[(colselect*24)+ rowselect];
for (int i=0;i<48;i++) {
int client_index = (colselect*24)+rowselect;
- int sn = i+1;//(colselect+1)*(rowselect+1);
- A_in = (sn-1)%2;
- B_in = ((sn-1)/2)%2;
- C_in = ((sn-1)/4)%2;
- D_in = ((sn-1)/8)%2;
- E_in = ((sn-1)/16)%2;
- F_in = ((sn-1)/32)%2;
+ int sn = i;//(colselect+1)*(rowselect+1);
+ D_in = (sn)%2;
+ E_in = ((sn)/2)%2;
+ F_in = ((sn)/4)%2;
+ A_in = ((sn)/8)%2;
+ B_in = ((sn)/16)%2;
+ C_in = ((sn)/32)%2;
float in_val = adc.read();
+
+
if (!voltages_equal(voltages[i],in_val)) {
// this row is floating
- set_led(i,LED_RED);
+ set_led(i,LED_OFF);
clientdata[client_index] = 100.0;
} else if (voltages_equal(voltages[i],vddval)) {
// this row matches vdd
@@ -184,6 +190,7 @@
set_led(i,LED_GREEN);
clientdata[client_index] = rowval;
} else {
+ set_led(i,LED_OFF);
clientdata[client_index] = voltages[i];
}
}
@@ -195,11 +202,13 @@
//Scan init
float originalvoltages[48] = {};
+ float newvoltages[48] = {};
float clientdata[48] = {};
float vddval = 0.0;
+ float rowval = 0.0;
//LED init
- int rowselect = 0, moved = 1, colselect = 0, selected = 0;
+ int rowselect = 0, moved = 1, colselect = 0, selected = 0, oldselected = 49;
ledbar_left.begin(0x70);
ledbar_left.clear();
ledbar_left.writeDisplay();
@@ -212,7 +221,7 @@
lcd.cls();
int written = 0;
- wifi.init();
+ //wifi.init();
//Osci
int loopcount = 0, pressed = 0;
@@ -220,6 +229,7 @@
while(1) {
+ /*
if (wifi.is_connected() == false) {
pc.printf("trying to connect to wifi\r\n");
if (wifi.connect() == -1) {
@@ -232,6 +242,9 @@
ws.connect();
}
+ */
+
+
//Display
if (moved ==1) {
ledbar_left.clear();
@@ -245,14 +258,14 @@
rowselect = rowselect-1;
moved = 1;
written = 0;
- wait(0.75);
+ wait(0.3);
}
if (downbutton.read() == 0) {
rowselect = rowselect+1;
moved = 1;
written = 0;
- wait(0.75);
+ wait(0.3);
}
if (leftbutton.read() == 0) {
@@ -260,7 +273,7 @@
ledbar_right.clear();
moved =1;
written = 0;
- wait(0.75);
+ wait(0.3);
}
if (rightbutton.read() == 0) {
@@ -268,7 +281,7 @@
ledbar_left.clear();
moved =1;
written = 0;
- wait(0.75);
+ wait(0.3);
}
//Boundary checking
@@ -279,15 +292,17 @@
rowselect = 0;
}
+ selected = (colselect * 24) + (rowselect+1);
+
//Implementing scanning
if (scanbutton.read() == 0) {
- A_in = 1;
+ A_in = 0;
B_in = 1;
C_in = 1;
D_in = 1;
- E_in = 1;
- F_in = 1;
+ E_in = 0;
+ F_in = 0;
vddval = adc.read();
@@ -296,38 +311,41 @@
// first set of voltages read into old_volt_mat
read_voltages(originalvoltages);
+ wait(0.2);
+ read_voltages(newvoltages);
// second set for comparison, read into clientdata
+ wait(0.2);
compare_voltages(originalvoltages,clientdata,colselect,rowselect,vddval);
- selected = rowselect;
- if (colselect == 1) {
- selected = selected+24;
- }
+ selected = (colselect * 24) + (rowselect+1);
+ rowval = newvoltages[selected-1];
written = 0;
moved = 0;
//DEBUGGING TOOLS //////////////
- pc.printf("\r\n%1.3f %1.3f \r\n", vddval, clientdata[selected]);
+ pc.printf("\r\n%1.3f %1.3f \r\n", vddval, rowval);
for (int i = 0; i<48; i++) {
pc.printf(" %1.3f ", clientdata[i]);
}
pc.printf(" \r\n \r\n ");
for (int x = 0; x < 48; x++) {
- pc.printf("%1.3f \r\n", originalvoltages[x]);
+ pc.printf("%1.3f %1.3f \r\n", originalvoltages[x], newvoltages[x]);
}
////////////////////////
- wait(1); //THIS NEEDS TO GO AWAY!
+ wait(0.3); //THIS NEEDS TO GO AWAY!
} // END OF SCANBUTTON IF STATEMENT
if (moved==0 && written == 0) {
ledbar_left.writeDisplay();
ledbar_right.writeDisplay();
- lcd_write_voltage_info(vddval,selected+1,clientdata[selected]);
+ lcd_write_voltage_info(vddval*3.3,selected,rowval*3.3);
+
+ /*
// send data to websocket
if (wifi.is_connected()) {
std::string json = build_json(vddval,selected,clientdata);
@@ -338,11 +356,14 @@
delete[] writable;
delete[] &json;
}
+ */
+
written = 1;
- } else if (written == 0) {
+ } else if (oldselected != selected) {
lcd_write_selected_info(selected);
- written = 1;
+
}
+ oldselected = selected;
@@ -365,24 +386,6 @@
/*
- FLOAT NODE CHECKER
- add another "for" around the two for the 48 row checker:
-
- if (u == 0){
- old_volt_mat[x,y] = in_val
- }
- else{
- volt_mat[x,y] = in_val
- if (old_volt_mat[x,y] != volt_mat[x,y] ) {
- volt_mat[x,y] = 100;
- }
-
- PUT ALL ROW LIGHTING (CON_MAT) STUFF HERE
- }
-
- */
-
- /*
OSCILLISCOPE