So this is my last resort, all my IT graduate friends are busy and cannot help me right now.
First of all, i dont really have much knowledge about coding specially java. this project is my thesis for school. (im taking computer engineering right now)
We (thesis group) paid someone to do our thesis prototype including the database that shows all the data our wireless blood pressure have recorded. But then our panel didnt approved it firsthand and wanted a few more upgrades.
THIS IS HOW MY PROFESSOR WANT THE UI TO BE:
BTW. I USE XAMPP FOR DATABASE. BUT HAVE TO ACTIVATE APACHE FIRST FOR THE DATA TO BE SHOWN
THIS IS THE CODE:
import processing.serial.*;
import controlP5.*;
PrintWriter saveData;
ControlP5 cp5;
String text;
import de.bezier.data.sql.*;
MySQL SQLCon;
String host = "localhost";
String user = "root";
String pass = "";
String database = "wirelessbp";
boolean DBConnected = false;
String[] dDate;
String[] dBP;
String[] dTemp;
Serial myPort;
String inString;
int lf = 10;
String patientname;
int systolic = 0;
int diastolic = 0;
int heartrate = 0;
int bodyTemp = 0;
void setup() {
fullScreen();
cp5 = new ControlP5(this);
cp5.addTextfield("").setPosition(1600,200).setSize(200,25).setAutoClear(false);
cp5.addButton("SUBMIT").setPosition(1660,240).setSize(80,25);
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[2], 9600);
myPort.bufferUntil(lf);
SQLCon = new MySQL( this, host, database, user, pass );
DBConnected = SQLCon.connect();
//insertData(SQLCon, DBConnected, "tblreadings", 90, 80, 65, 29);
//println(countRows(SQLCon, DBConnected, "tblreadings"));
getData(SQLCon, DBConnected, "tblreadings");
}
void draw() {
background(0);
if (inString != null){
try{
decodeSerialData(inString);
inString = "";
}catch (Exception e){}
}
stroke(255);
strokeWeight(1);
noFill();
// Hearth Rate Data
//line(width * 0.80, height * 0.10, width * 0.98, height * 0.10);
//line(width * 0.98, height * 0.10, width, height * 0.12);
// Blood Pressure Data
line(width * 0.80, height * 0.30, width * 0.98, height * 0.30);
line(width * 0.98, height * 0.30, width, height * 0.32);
// Body Temperature Data
line(width * 0.80, height * 0.70, width * 0.98, height * 0.70);
line(width * 0.98, height * 0.70, width, height * 0.72);
//textAlign(CENTER);
//fill(0, 255, 0);
//textSize(65);
//text(heartrate, width * 0.89, height * 0.22);
//textSize(20);
//text("bpm", width * 0.89, height * 0.27);
//textAlign(LEFT);
//textSize(14);
//text("Heart Rate", width * 0.80, height * 0.12);
textAlign(CENTER);
fill(0, 255, 255);
textSize(70);
text(systolic + "/" + diastolic, width * 0.89, height * 0.46);
textSize(20);
text("mmHg", width * 0.89, height * 0.52);
textAlign(LEFT);
textSize(14);
text("Blood Pressure", width * 0.80, height * 0.32);
textAlign(CENTER);
fill(255, 255, 0);
textSize(70);
text(bodyTemp, width * 0.89, height * 0.84);
textSize(20);
text("deg.C", width * 0.89, height * 0.89);
textAlign(LEFT);
textSize(14);
text("Body Temperature", width * 0.80, height * 0.72);
textAlign(CENTER);
fill(0, 255, 255);
textSize(20);
text("Patient Name:", width * 0.89, height * 0.17);
textSize(30);
textAlign(LEFT);
fill(255);
text("Blood Pressure Monitor Prototype", width * 0.01, height * 0.05);
getData(SQLCon, DBConnected, "tblreadings");
//refreshData();
}
void serialEvent(Serial p) {
inString = p.readString();
}
void refreshData(){
noFill();
rect(width * 0.01, height * 0.10, width * 0.75, height * 0.85);
textSize(16);
float dtLeft = width * 0.02;
// text("DateTime", dtLeft, height * 0.14);
float bpLeft = width * 0.32;
// text("Blood Pressure", bpLeft, height * 0.14);
float tmpLeft = width * 0.62;
// text("Body Temperature", tmpLeft, height * 0.14);
//float top = height * 0.18;
//String[] logData = loadStrings("log.txt");
//for (int i = 0; i < logData.length; i++){
// String[] decode = split(logData[i], ",");
// if (decode.length == 5){
// String dDt = decode[0];
// String dSys = decode[1];
// String dDia = decode[2];
// String dHr = decode[3];
// String dTmp = decode[4];
// text(dDt, dtLeft, top);
// text(dSys + "/" + dDia, bpLeft, top);
// text(dTmp, tmpLeft, top);
// top += height * 0.04;
// }
//}
float top = height * 0.14;
//String[] logData = loadStrings("log.txt");
for (int i = 0; i < dDate.length; i++){
//String[] decode = split(logData[i], ",");
//if (decode.length == 5){
// String dDt = decode[0];
// String dSys = decode[1];
// String dDia = decode[2];
// String dHr = decode[3];
// String dTmp = decode[4];
text(dDate[i], dtLeft, top);
text(dBP[i], bpLeft, top);
text(dTemp[i], tmpLeft, top);
top += height * 0.04;
//}
}
//println(logData.length);
}
//void decodeSerialData(String sData){
// String tempData;
// String[] d = split(sData, ',');
// if (d.length == 3){
// //printArray(d);
// text("received: " + inString, width * 0.01, height * 0.98);
// // Systolic
// tempData = trim(d[0]);
// systolic = int(tempData);
// //println(d[0], systolic, tempData.length());
// // Diastolic
// tempData = trim(d[1]);
// diastolic = int(tempData);
// //println(d[1], diastolic, tempData.length());
// // Heart Rate
// tempData = trim(d[2]);
// heartrate = int(tempData);
// //println(d[2], heartrate, tempData.length());
// }
//}
void decodeSerialData(String sData){
String tempData;
String strData = "";
String[] d = split(sData, ',');
if (d.length == 4){
//printArray(d);
text("received: " + inString, width * 0.01, height * 0.98);
// Systolic
tempData = trim(d[0]);
systolic = int(tempData);
//println(d[0], systolic, tempData.length());
// Diastolic
tempData = trim(d[1]);
diastolic = int(tempData);
//println(d[1], diastolic, tempData.length());
// Heart Rate
tempData = trim(d[2]);
heartrate = int(tempData);
//println(d[2], heartrate, tempData.length());
// Heart Rate
tempData = trim(d[3]);
bodyTemp = int(tempData);
//println(d[3], bodyTemp, tempData.length());
//writeToFile(sData);
insertData(SQLCon, DBConnected, "tblreadings", systolic, diastolic, heartrate, bodyTemp, patientname);
}
}
void writeToFile(String data){
String[] oldData = loadStrings("log.txt");
saveData = createWriter("log.txt");
for(int i = 0; i < oldData.length; i++){
saveData.println(oldData[i]);
}
saveData.print(data);
saveData.flush();
saveData.close();
}
int countRows(MySQL SQLConnection, boolean conStat, String tblName ){
int rCount = -1;
if ( conStat ){
SQLConnection.query( "SELECT COUNT(*) as count FROM %s", tblName );
SQLConnection.next();
rCount = SQLConnection.getInt("count");
}
return rCount;
}
void insertData(MySQL SQLConnection, boolean conStat, String tblName, int sys, int dia, int hr, int temp, String patient){
if ( conStat ){
SQLConnection.query( "INSERT INTO %s SET dDate = Now(), dSystolic = '%s', dDiastolic = '%s', dHeartRate = '%s', dTemp='%s', Patient='%s'", tblName, "" + sys, "" + dia, "" + hr, "" + temp, "" + patient );
//SQLConnection.next();
}
}
void getData(MySQL SQLConnection, boolean conStat, String tblName){
if ( conStat ){
noFill();
rect(width * 0.01, height * 0.10, width * 0.75, height * 0.85);
textSize(16);
float dtLeft = width * 0.02;
text("DateTime", dtLeft, height * 0.14);
float pleft = width * 0.25;
text("Patient", pleft, height * 0.14);
float bpLeft = width * 0.42;
//text("Patient", dtLeft, height * 0.14);
text("Blood Pressure", bpLeft, height * 0.14);
float tmpLeft = width * 0.62;
text("Body Temperature", tmpLeft, height * 0.14);
float top = height * 0.18;
//for (int i = 0; i < dDate.length; i++){
// text(dDate[i], dtLeft, top);
// text(dBP[i], bpLeft, top);
// text(dTemp[i], tmpLeft, top);
// top += height * 0.04;
//}
SQLConnection.query("SELECT * FROM %s ORDER BY id DESC LIMIT 20", tblName);
println(SQLConnection);
while (SQLConnection.next())
{
String t = SQLConnection.getString("dDate");
int s = int(SQLConnection.getString("dSystolic"));
int d = int(SQLConnection.getString("dDiastolic"));
String f = SQLConnection.getString("dTemp");
String p = SQLConnection.getString("Patient");
//println(t, s, d, f);
//dDate = append(dDate, t);
//dBP = append(dBP, s + "/" + d);
//dTemp = append(dTemp, f);
text(t, dtLeft, top);
text(s + "/" + d, bpLeft, top);
text(f, tmpLeft, top);
if (p != null) {
text(p, pleft, top);
} else {
text("N/A", pleft, top);
}
top += height * 0.04;
}
}
}
public void SUBMIT(){
patientname=cp5.get(Textfield.class,"").getText();
}