/*
============================================
* https://forum.processing.org/one/topic/video-library-not-found-in-eclipse-using-proclipsing.html
*
*/
package kucky;
import java.io.File;
import java.util.*;
import jssc.SerialPortList; /// 2.8.0
import jssc.SerialPort;
import processing.video.*; /// 1.0.2
import processing.core.*; /// 3.2.4 64bit
import processing.event.MouseEvent;
import processing.opengl.PJOGL;
import controlP5.*; /// 2.2.6
import controlP5.Controller;
public class Main_CockPit extends PApplet{
//Standard classes
Capture cam;
ControlP5 cp5;
Canvas optcanvas;
MyControlListener myListener;
//Owen classes
Horizon horizon;
Flyer flyer;
Compass compass;
Altimeter altimeter;
RollLevel rollLevel;
PitchLevel pitchLevel;
SpeedControl speedControl;
SerialConnect serialConnect;
LogFile logfile;
Battery battery;
final static String TITLE = "Cockpit for Kuckycopter";
static private final int BARHEIGHT = 22;
static private final float THROTTLE_SIZE = 1.0f;
static private final float ROLL_SIZE = 1.0f;
static private final float HOR_SIZE = 1.0f;
static private final float PITCH_SIZE = 1.0f;
static private final float ALTI_SIZE = 1.0f;
static private final float FLYER_SIZE = 0.8f;
static private final float COMP_SIZE = 1.0f;
static private final float BATTERY_SIZE = 1.0f;
static private final int CAMERA_WIDTH = 320;
static private final int CAMERA_HEIGTH = 240;
float xPos1, xPos2, xPos3, xPos4; /// Device positions
float yPos1, yPos2, yPos3;
float consoleXpos, consoleYpos; ///
private final int DEVICEFRAMECOLOR = color(190);
int backGroundColor = color(30);
public int s1 = 30;
int deviceColor = (100);
public int s2 = 100;
long btBlinkTime = 0;
String[] logfileArray = new String[3];
// String logfileTxt;
String system1, system2, system3, system4, system5;
/// Serial Part
int current_BaudRate = 115200; ///< Default.
float[] receivedData = new float[15];
SerialPort usbPort;
/// Controller
ScrollableList sbFile, sbBaute, sbCOM, sbCamera, sbOptions;
Textarea sysOutput, logOutput;
Accordion accordion;
Group group1;
Println sysConsole;
PFont cFont, /// controller
scaleFont,
menuBarFont, /// Menubar
accordionFont,
connectFont,
batteryFont;
PImage btConnect, btDisconnect;
Boolean isConnect = false;
Boolean isCOMport = false;
Boolean runCamera = false;
Boolean isBtBlinkOn = true;
Boolean isOverCompass = false;
Boolean isAMD64 = true;
//--------------------------- end of dimensions and initializations -------------------------------
/**
* @param passedArgs the command line arguments
*/
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] {Main_CockPit.class.getName()};
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}//---------------------------- end of main ---------------------------------------------------
@Override
public void settings(){
fullScreen(P3D);
// size(1300, 700, P3D);
system1 = javaVersionName;
system2 = System.getProperty("os.arch");
system3 = System.getProperty("os.name");
system4 = System.getProperty("os.version");
system5 = System.getProperty("user.dir");
if(isAMD64)
PJOGL.setIcon("D:\\Benutzer\\Willi\\MyProjects\\KuckyCopter\\Eclipse\\CockPit4\\src\\data\\X-Wing.png");
else
PJOGL.setIcon("D:\\Users\\Kucky\\MyProjects\\KuckyCopter\\Eclipse_Java\\CockPit4\\src\\data\\X-Wing.png");
}//--------------------------- end of settings() ----------------------------------------------
@Override
public void setup(){
xPos1 = width*15.4f/100; /// Device positions
xPos2 = width*35.6f/100;
xPos3 = width*60.0f/100;
xPos4 = width*84.4f/100;
yPos1 = height*25.0f/100;
yPos2 = height*65.1f/100;
yPos3 = height*89.8f/100;
consoleXpos = width*7.6f/100;
consoleYpos = height*54.3f/100;
if(isAMD64){
cFont = loadFont("D:\\Benutzer\\Willi\\MyProjects\\KuckyCopter\\Eclipse\\CockPit4\\src\\data\\ArialMT-12.vlw");
scaleFont = loadFont("D:\\Benutzer\\Willi\\MyProjects\\KuckyCopter\\Eclipse\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-14.vlw");
menuBarFont = loadFont("D:\\Benutzer\\Willi\\MyProjects\\KuckyCopter\\Eclipse\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-16.vlw");
connectFont = loadFont("D:\\Benutzer\\Willi\\MyProjects\\KuckyCopter\\Eclipse\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-24.vlw");
batteryFont = loadFont("D:\\Benutzer\\Willi\\MyProjects\\KuckyCopter\\Eclipse\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-24.vlw");
}
else
{
cFont = loadFont("D:\\Users\\Kucky\\MyProjects\\KuckyCopter\\Eclipse_Java\\CockPit4\\src\\data\\ArialMT-12.vlw");
scaleFont = loadFont("D:\\Users\\Kucky\\MyProjects\\KuckyCopter\\Eclipse_Java\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-14.vlw");
connectFont = loadFont("D:\\Users\\Kucky\\MyProjects\\KuckyCopter\\Eclipse_Java\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-24.vlw");
menuBarFont = loadFont("D:\\Users\\Kucky\\MyProjects\\KuckyCopter\\Eclipse_Java\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-16.vlw");
batteryFont = loadFont("D:\\Users\\kucky\\MyProjects\\KuckyCopter\\Eclipse_Java\\CockPit4\\src\\data\\TimesNewRomanPS-BoldMT-24.vlw");
}
btConnect = loadImage("BT.png");
btDisconnect = loadImage("BT1_disconnect2.png");
surface.setTitle(TITLE);
cp5 = new ControlP5(this);
optcanvas = new OptCanvas();
textAlign(CENTER);
speedControl = new SpeedControl(this, xPos1, yPos1+40, THROTTLE_SIZE, deviceColor,DEVICEFRAMECOLOR, scaleFont);
pitchLevel = new PitchLevel(this, xPos2, yPos1, PITCH_SIZE, deviceColor, DEVICEFRAMECOLOR, menuBarFont);
horizon = new Horizon(this, xPos3, yPos1, HOR_SIZE, deviceColor, DEVICEFRAMECOLOR, scaleFont, menuBarFont);
rollLevel = new RollLevel(this, xPos4, yPos1, ROLL_SIZE, deviceColor, DEVICEFRAMECOLOR, menuBarFont);
altimeter = new Altimeter(this, xPos2, yPos2, ALTI_SIZE, deviceColor, DEVICEFRAMECOLOR, menuBarFont);
flyer = new Flyer(this, xPos3-20, yPos2-20, FLYER_SIZE, menuBarFont);
compass = new Compass(this, xPos4, yPos2, COMP_SIZE, deviceColor, DEVICEFRAMECOLOR, scaleFont);
battery = new Battery(this, xPos1, yPos3, BATTERY_SIZE, deviceColor, batteryFont);
serialConnect = new SerialConnect();
logfile = new LogFile(this, cFont, menuBarFont, scaleFont);
myListener = new MyControlListener();
sysOutput = cp5.addTextarea("txt1")
.setPosition(consoleXpos, consoleYpos)
.setSize(215, 215)
.setFont(cFont)
.setColor(color(200))
.setCaptionLabel("Options")
.setColorBackground(color(50))
.setColorForeground(color(255, 100));
sysConsole = cp5.addConsole(sysOutput);
println ("Java Version "+system1);
println ("os.arch: "+system2);
println ("os.name: "+system3);
println ("os.versio: "+system4);
println ("User path: "+system5);
List<String> Dateil = Arrays.asList("Neu","Öffnen","Schließen","Speichern","Beenden");
sbFile = cp5.addScrollableList("DateiList");
sbFile.setCaptionLabel("Datei").setPosition(0, 0).setSize(90, 140)
.setBarHeight(BARHEIGHT).setItemHeight(20).setFont(menuBarFont);
sbFile.getCaptionLabel().getStyle().marginTop = 4;
sbFile.getCaptionLabel().toUpperCase(false);
sbFile.getValueLabel().getStyle().marginTop = 4;
sbFile.getValueLabel().toUpperCase(false);
sbFile.addItems(Dateil);
sbFile.close();
///-------- COM Port Listbox
sbCOM = cp5.addScrollableList("ComList");
sbCOM.setCaptionLabel("COM Ports").setPosition(90, 0).setSize(100, 120)
.setBarHeight(BARHEIGHT).setItemHeight(20).setFont(menuBarFont);
sbCOM.getCaptionLabel().getStyle().marginTop = 4;
sbCOM.getCaptionLabel().toUpperCase(false);
sbCOM.getValueLabel().getStyle().marginTop = 4;
sbCOM.getValueLabel().toUpperCase(false);
RefreshCOMport();
///-------- Baude List
List<String> Baute = Arrays.asList("9600","57600","115200");
sbBaute = cp5.addScrollableList("BauteList");
sbBaute.setCaptionLabel("Baute List").setPosition(190, 0).setSize(90, 120)
.setBarHeight(BARHEIGHT).setItemHeight(20).setFont(menuBarFont);
sbBaute.getCaptionLabel().getStyle().marginTop = 4;
sbBaute.getCaptionLabel().toUpperCase(false);
sbBaute.getValueLabel().getStyle().marginTop = 4;
sbBaute.getValueLabel().toUpperCase(false);
sbBaute.addItems(Baute);
sbBaute.close();
///-------- Camera part
String[] cameras = Capture.list();
if (cameras == null) {
println("Failed to retrieve the list of available cameras, will try the default...");
}
String[] listItem = new String[cameras.length + 1];
for(int i = 0; i < cameras.length; i++) {
listItem[i] = cameras[i];
}
listItem[cameras.length] = "Stop camera";
List<String> cameraList = Arrays.asList(listItem);
sbCamera = cp5.addScrollableList("CameraList");
sbCamera.setCaptionLabel("List of cameras").setPosition(610, 0).setSize(350, 270)
.setBarHeight(BARHEIGHT).setItemHeight(20).setFont(menuBarFont);
sbCamera.getCaptionLabel().getStyle().marginTop = 4;
sbCamera.getCaptionLabel().toUpperCase(false);
sbCamera.getValueLabel().getStyle().marginTop = 4;
sbCamera.getValueLabel().toUpperCase(false);
sbCamera.addItems(cameraList);
sbCamera.close();
///-------- Logfile part
group1 = cp5.addGroup("Options")
.setFont(menuBarFont)
.setBackgroundColor(128)
.setBackgroundHeight(135)
.addListener(myListener)
.setBarHeight(BARHEIGHT);
group1.getCaptionLabel().toUpperCase(false);
group1.getCaptionLabel().getStyle().marginTop = 3;
group1.addCanvas(new OptCanvas());
cp5.begin(100,100); /// cp5.begin(100, 100); in example
cp5.addSlider("s1").setPosition(10, 20).moveTo(group1).setRange(0, 70).setValue(30)
.setSize(80, 15).linebreak();
cp5.addSlider("s2").setPosition(10, 50).moveTo(group1).setRange(80, 120).setValue(100)
.setSize(80, 15).linebreak();
cp5.addSlider("s3").setPosition(10, 80).moveTo(group1).setRange(50, 100).setValue(75)
.setSize(80, 15);
cp5.end();
cp5.getController("s1").setCaptionLabel("Backgound");
cp5.getController("s1").getCaptionLabel().getStyle().marginLeft = -104;
cp5.getController("s1").getCaptionLabel().getStyle().marginTop = -12;
Style("s1");
cp5.getController("s2").setCaptionLabel("Devices");
cp5.getController("s2").getCaptionLabel().getStyle().marginLeft = -104;
cp5.getController("s2").getCaptionLabel().getStyle().marginTop = -12;
Style("s2");
cp5.getController("s3").setCaptionLabel("Others");
cp5.getController("s3").getCaptionLabel().getStyle().marginLeft = -104;
cp5.getController("s3").getCaptionLabel().getStyle().marginTop = -12;
Style("s3");
accordion = cp5.addAccordion("accordion").setPosition(370, 0).setWidth(120)
.addItem(group1)
.addListener(myListener);
accordion.close(0);
accordion.setCollapseMode(Accordion.MULTI);
logOutput = cp5.addTextarea("txt2")
.setPosition(200, 100)
.setSize(400, 300)
.setFont(scaleFont)
.setVisible(false)
.setColor(color(200))
// .setCaptionLabel("Options")
.setColorBackground(color(50))
.setColorForeground(color(255, 100));
btBlinkTime = millis();
println("Height "+height+" Width "+width); /// For debug
}//--------------------------- end of setup() -------------------------------------------------
public void Style(String theControllerName){
Controller c =cp5.getController(theControllerName);
c.getCaptionLabel().align(LEFT, CENTER);
c.setWidth(100);
c.setHeight(15);
c.setFont(cFont);
c.addListener(myListener);
c.getCaptionLabel().toUpperCase(false);
}//--------------------- End of Style() ----------------------------------------------------
@Override
public void draw(){
hint(ENABLE_DEPTH_TEST);
background(backGroundColor);
pushMatrix();
/*-- Testarea --*/ strokeWeight(0.5f); /// Only for creating
stroke(255, 0, 0);
line(10, height/2, width-10, height/2);
line(width/2, 10, width/2, height-10);
fill(255);
textFont(cFont);
float mouseXPos = (int)map(mouseX, 0, width, -width/2, width/2);
text("Mouse X : "+mouseXPos+" / "+mouseX, width-200, height-80);
float mouseYPos = (int)map(mouseY, 0, height, height/2, -height/2);
text("Mouse Y : "+mouseYPos+" / "+mouseY, width-200, height-65);
receivedData[4] = (int)map(mouseX, 0, height, 0, 300); /// AltitudeCM
receivedData[0] = (int)map(mouseX, 0, width, -90, 90); /// X
text("Roll: "+(int)receivedData[0], width-200, height-50);
receivedData[1] = (int)map(mouseY, 0, height, -90, 90); /// Y
text("Pitch: "+(int)receivedData[1], width-200, height-35);
receivedData[3] = (int)map(mouseY, 0, height, 1000, 0); /// Throttle
receivedData[9] = (int)receivedData[3]; /// Power 0-3
receivedData[10] = (int)receivedData[3];
receivedData[11] = (int)receivedData[3];
receivedData[12] = (int)receivedData[3];
receivedData[8] = (int)map(mouseY, 0, height, 800, 990); /// BatteryLevel
receivedData[2] = (int)receivedData[1]; /// Y = X for debug
/*-- End of testarea --*/
//-------------------------------------------------draw video part
pushMatrix();
translate(xPos3, yPos2);
rectMode(CENTER);
stroke(255);
rect(0, 0, 330, 250, 5);
fill(127, 127, 127);
if(runCamera){
if (cam.available() == true) {
cam.read();
}
image(cam, 160-(CAMERA_WIDTH/2) , 120-(CAMERA_HEIGTH/2));
}
popMatrix();
//-------------------------------------------------end of video part
rectMode(CORNER);
strokeWeight(5);
stroke(DEVICEFRAMECOLOR);
rect(consoleXpos-3, consoleYpos-3, 220, 220, 6, 6, 6, 6);
//-------------------------------------------------end of console part
popMatrix();
imageMode(CENTER);
if(isConnect)
image(btConnect, width*97/100, height*13/100, 50, 60);
else
{
if(millis() - btBlinkTime >= 500){
isBtBlinkOn = !isBtBlinkOn;
btBlinkTime = millis();
}
if(isBtBlinkOn)
image(btDisconnect, width*97/100, height*13/100, 50, 60);
}
//-------------------------------------------------end of BT part
MouseInFied();
horizon.drawHorizon((int)receivedData[0], (int)receivedData[1], (int)receivedData[2]); /// X Y Z
compass.drawCompass((int)receivedData[2]); /// Z
altimeter.drawAltimeter((int)receivedData[4]); /// altiudeCM
rollLevel.DrawRollLevel((int)receivedData[0]); /// X
pitchLevel.DrawPitchLevel((int)receivedData[1]); /// Y /// Y
flyer.drawFlyer((int)receivedData[0], (int)receivedData[1], (int)receivedData[2]); /// X Y Z
speedControl.drawSpeedControl((int)receivedData[3], (int)receivedData[9],
(int)receivedData[10], (int)receivedData[11], (int)receivedData[12]); /// Thr, and Power 0-3
battery.drawBattery((int)receivedData[8]);
logfile.PrintLogFile(receivedData);
receivedData = serialConnect.getReceivedValues();
hint(DISABLE_DEPTH_TEST);
}//--------------------------- end of draw() ---------------------------------------------------
public void DateiList(int value) {
switch(value) {
case 0:
println("NEU");
break;
case 1:
openData();
break;
case 2:
logOutput.setVisible(false);
break;
case 3:
println("Speichern");
break;
case 4:
if(isCOMport && isConnect ){
if(serialConnect.ClosePort());{
try{
Thread.sleep(1000);
}
catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
logfile.CloseLogfile();
exit();
}
}
else{
logfile.CloseLogfile();
exit();
}
} /// end of switch
}//--------------------------- end of DateiList() -----------------------------------------
public void openData() {
println("open data...");
noLoop(); /// stop the draw() function
selectInput("Select a file...", "myFile");
println("...function end.");
}//--------------------------- end of openData() ----------------------------------------------
public void myFile(File selection) {
// io=1;
if (selection == null) {
println("No file selected.");
} else {
println("File selected: " + selection.getAbsolutePath());
// counter=0;
logOutput.setVisible(true);
logfileArray = (loadStrings(selection.getAbsolutePath())); /// My modifying.
String joinedLogFile = join(logfileArray, "\n");
logOutput.setText(joinedLogFile);
}
loop(); /// restart the draw() function
// io=0;
}//--------------------------- end of myFile() ----------------------------------------------
public void BauteList(int value){
String select = cp5.get(ScrollableList.class, "BauteList").getItem(value).get("name").toString();
current_BaudRate = Integer.parseInt(select);
println("Bautrate is :"+ current_BaudRate);
}//--------------------------- End of BauteList() -----------------------------------------
public void ComList(int value){
String select = cp5.get(ScrollableList.class, "ComList").getItem(value).get("name").toString();
println("Selectet is :"+ select);
if(select != "Close Port")
isConnect = serialConnect.initSerial(select, current_BaudRate);
else {
serialConnect.ClosePort();
isConnect = false;
}
}//--------------------------- End of ComList() -------------------------------------------
public void CameraList(int value){
String select = cp5.get(ScrollableList.class, "CameraList").getItem(value).get("name").toString();
println("Selectet is :"+ select);
if(select !="Stop camera"){
cam = new Capture(this, 320, 240, select);
cam.start();
runCamera = true;
}
else {
if(runCamera){
// cam.dispose();
cam.stop();
runCamera = false;
}
}
}//--------------------------- End of CameraList() ----------------------------------------
public void RefreshCOMport() {
String[] portNames = SerialPortList.getPortNames();
String[] listIteme = new String[portNames.length+1];
if(portNames.length > 0)
isCOMport = true;
for (int i = 0; i < portNames.length; i++){
listIteme[i] = portNames[i];
}
listIteme[portNames.length] = "Close Port";
List<String> Ports = Arrays.asList(listIteme);
sbCOM.addItems(Ports);
sbCOM.close();
}//--------------------------- End of ConnectBoc() ----------------------------------------
public void MouseInFied(){
if(mouseX > xPos4-100 && mouseX < xPos4+100 && mouseY > yPos2-100 && mouseY < yPos2+100) {
isOverCompass = true;
}
else {
isOverCompass = false;
}
// println("Compass "+isOverCompass); /// for debug
}//--------------------------- end of MouseInFied() -------------------------------------------
@Override
public void mouseWheel(MouseEvent event) {
float e = event.getCount();
if(isOverCompass) {
compass.CorrectionArrow(e);
}
// println(e); /// for debug
}//--------------------------- end of mouseWheel() ---------------------------------------------
class MyControlListener implements ControlListener {
public void controlEvent(ControlEvent theEvent) {
if (theEvent.isController()){
PApplet.println("got something from a controller " /// for debug
+theEvent.getController().getName());
if(theEvent.getController().getName().equals("s1")){
// PApplet.println("Backgroundcolor is select "); /// for debug
backGroundColor = (int)theEvent.getController().getValue();
}
else if(theEvent.getController().getName().equals("s2")){
// PApplet.println("Devicegroundcolor is select "); /// for debug
altimeter.deviceColor = (int)theEvent.getController().getValue();
compass.deviceColor = (int)theEvent.getController().getValue();
horizon.deviceColor = (int)theEvent.getController().getValue();
pitchLevel.deviceColor = (int)theEvent.getController().getValue();
rollLevel.deviceColor = (int)theEvent.getController().getValue();
speedControl.deviceColor = (int)theEvent.getController().getValue();
}
/* else if(theEvent.getController().getName().equals("s3")){
PApplet.println("Others are select ");
}
if(theEvent.getController().getName().equalsIgnoreCase("CameraList")) {
println(theEvent.getController().getName());
runCamera = true;
}
*/
}
}//--------------------------- End of controlEvent ----------------------------------------
}//--------------------------- End of MyControlListener Class ---------------------------------
class OptCanvas extends Canvas {
float n, a;
public OptCanvas(){
n = 1;
// PApplet.println("starting a opt canvas.");
}
public void draw(PGraphics pg) {
n += 0.01;
pg.fill(lerpColor(color(0,100,200),color(0,200,100),PApplet.map(PApplet.sin(n),-1,1,0,1)));
pg.rect(0,0,120,135);
pg.fill(255,150);
a+=0.01;
// pg.ellipse(105,cursorPosA,10,10);
}
}//------------------------- End of LogCanvas Class -------------------------------------------
}//----------------------------- End of Main_CockPit ----------------------------------------------