float cPosLat = 0,cPosLon = 0,cSOG=0, cCOG=0, cDepth=0,cWindDir=0,cHeading=0,c680T,c680L; float c680TB[] = new float[32]; int c680TBn = 0; int date[] = new int[4];; int timezone = -11; int leap = 0; int dpy = 365+leap; boolean mapMode = true; boolean mp = false; float PIOVER180 = PI / 180; BFont fontA; BImage map; float mapWESN[] = new float[4]; void setup() { size(640,480); //status("Uwungulema Dredge Monitor 0.5 - "+julianday()+":"+hour()+":"+minute()+":"+second()+"\n"); fontA = loadFont("Meta-Bold.vlw.gz"); textFont(fontA,24); loadMap(); framerate(1); } void mousePressed() { mp = true; } float mapLon(float lon) { if(mapWESN[0] < lon && lon < mapWESN[1]) { return (lon-mapWESN[0]) / (mapWESN[1]-mapWESN[0]); } else if(mapWESN[0] < lon+360 && lon+360 < mapWESN[1]) { return (lon+360-mapWESN[0]) / (mapWESN[1]-mapWESN[0]); } //status("Here (LON"+lon+") be dragons, as far as I can tell"); return 0; } float mapLat(float lat) { if(mapWESN[2] < lat && lat < mapWESN[3]) { return (lat-mapWESN[2]) / (mapWESN[3] - mapWESN[2]); } //status("Here (LAT"+lat+") be dragons"); return 0; } void drawMap() { if(map==null) { //status("No map."); return; } float mapX = mapLon(cPosLon); float mapY = mapLat(cPosLat); stroke(0); fill(0,0,0,0); rect(width/2-5,height/2-5,10,10); stroke(100); rect(width/2-7,height/2-7,14,14); push(); translate(width/2,height/2); translate(-mapX*map.width,-(1-mapY)*map.height); image(map,0,0); pop(); } void loadMap() { status("Loading images... This may take a while (512K)"); map=loadImage("map.jpg"); String data[] = loadStrings("map.txt"); mapWESN = splitFloats(data[0]); status("Load Map: ["+mapWESN[0]+","+mapWESN[1]+","+mapWESN[2]+","+mapWESN[3]+"]"); status(""); } void uiColor() { fill(100,100,100,200); stroke(200); } void drawCompass() { uiColor(); push(); translate(10,10); ellipse(0,0,100,100); for(float deg = 0 ; deg < 360 ; deg += 15) { float tdeg = (deg-89.999)*PI/180; if(deg == 0) { stroke(255,100,100); line(cos(tdeg)*50+50,sin(tdeg)*50+50,cos(tdeg)*35+50,sin(tdeg)*35+50); } else if(deg % 90 == 0) { stroke(255); line(cos(tdeg)*50+50,sin(tdeg)*50+50,cos(tdeg)*40+50,sin(tdeg)*40+50); } else if(deg % 45 == 0) { stroke(200); line(cos(tdeg)*50+50,sin(tdeg)*50+50,cos(tdeg)*43+50,sin(tdeg)*43+50); } else { stroke(180); line(cos(tdeg)*50+50,sin(tdeg)*50+50,cos(tdeg)*45+50,sin(tdeg)*45+50); } } if(cWindDir != 0) { float wa = (cWindDir - 90) * PI / 180; stroke(240,100,100); fill(200,100,100); triangle(cos(wa)*52+50,sin(wa)*52+50, cos(wa+0.1)*58+50,sin(wa+0.1)*58+50, cos(wa-0.1)*58+50,sin(wa-0.1)*58+50); } if(cHeading != 0) { stroke(100,240,100); fill(100,200,100); float h = (cHeading-89.9999)*PI/180; line(cos(h)*-35+50,sin(h)*-35+50,cos(h)*35+50,sin(h)*35+50); triangle(cos(h)*35+50,sin(h)*35+50, cos(h-0.1)*30+50,sin(h-0.1)*30+50, cos(h+0.1)*30+50,sin(h+0.1)*30+50); } textMode(ALIGN_CENTER); fill(255); textFont(fontA,16); text(cSOG+" kts",50,65); pop(); } void drawButtons() { uiColor(); if(mp) { if(mouseX > 10 && mouseX < 120+10 && (mouseY) > 120 && (mouseY) < 120+20) { mapMode = !mapMode; } } rect(10,120,100,20); fill(255); if(mapMode) { textFont(fontA,16); text("Map Mode",35,135); } else { textFont(fontA,16); text("Dredge Mode",26,135); } } void drawDredge() { fill(100,100,255); stroke(100,100,255); rect(0,50,width,height-50); fill(150); stroke(200); rect(width-200,50,75,-25); } String mmode(float deg) { float abdeg = abs(deg); int sign = (int)(deg/abdeg); int degint = (int)floor(abdeg); float rem = abdeg - (float)degint; return degint*sign + "* " + nf(rem*60.0,2,3) + "'"; } void drawConsole() { uiColor(); push(); translate(120,10); rect(0,0,260,65); fill(255); textFont(fontA,16); textMode(ALIGN_LEFT); String la,lo; if(cPosLat < 0) { la = "S"; } else { la = "N"; } if(cPosLon < 0) { lo = "W"; } else { lo = "S"; } text("Latitude: " + mmode(abs(cPosLat)) + la,6,18*1); text("Longitude: " + mmode(abs(cPosLon)) + lo,6,18*2); text("GMT Time: " + date[0]+" "+nf(date[1],2)+":"+nf(date[2],2)+":"+nf(date[3],2),6,18*3); line(145,0,145,65); text("Depth: " + nf(cDepth,4,1) +" m",156,18*1); text("Wind Dir: " + nf(cWindDir,3,1),156,18*2); text("Heading: " + nf(cHeading,3,1),156,18*3); pop(); } void drawTension() { uiColor(); push(); translate(10,120); rect(0,0,100,100); line(0,64,100,64); fill(255); text("Wire: " + nf(c680L,0,0) + " m",6,64+15*1); text("Tens: " + nf(c680T,0,0) + " lbs",6,64+15*2); stroke(255,100,100); beginShape(LINE_STRIP); for(int i = 0 ; i < 32 ; i++) { vertex((float)i*(100/32),64 - (float)c680TB[(i+c680TBn)%32] * (64.0 / 12000.0)); } endShape(); pop(); } void loop() { background(35); getData(); if(mapMode) { drawMap(); } else { drawDredge(); }; drawCompass(); //drawTime(); drawConsole(); //drawButtons(); if(c680T > 50) { drawTension(); } mp = false; } /* * DATA ROUTINES FOR SHIPBOARD DATA * */ int julianday() { int d=day(); int m=month(); if(m>1){d+=31;} if(m>2){d+=28+leap;} if(m>3){d+=31;} if(m>4){d+=30;} if(m>5){d+=31;} if(m>6){d+=30;} if(m>7){d+=31;} if(m>8){d+=31;} if(m>9){d+=30;} if(m>10){d+=31;} if(m>11){d+=30;} return d; } int lastUpdate; void getData() { if(lastUpdate == second()) { return; } lastUpdate = second(); String posnfo[] = loadStrings("http://earthref.org/cruisewatch/data/datasourceER.php?inid="+second()); //String posnfo[] = loadStrings("http://192.168.2.52/cruisewatch/data/datasourceLive.php?inid="+second()); if(posnfo == null ) { status("Could not connect to data source"); return; } // // println("Str: " + posnfo[posnfo.length-1]); float data[] = splitFloats(posnfo[0]); /*println("Num: " + data.length); for(int i = 0 ; i < data.length ; i++) { println(i + ": " + data[i]); }*/ if(data[0] == 0) { status("Data unavailable"); return; } date[0] = (int)data[0]; date[1]=(int)data[1]; date[2]=(int)data[2]; date[3]=(int)data[3]; //1,2,8,4,11,28 cPosLat = data[4]; cPosLon = data[5]; cHeading = data[6]; cSOG = data[7]; cDepth = data[8]; cWindDir = data[9]; if(data.length > 9) { c680L = data[10]; c680T = data[11]; c680TB[++c680TBn % 32] = c680T; } }