Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
sensors working, output printed to screen on demand
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Nussbaumer <st9fan@gmail.com>
  • Loading branch information
nuss committed Jan 11, 2017
1 parent dd732fc commit 7eb9002
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 45 deletions.
19 changes: 6 additions & 13 deletions app/src/main/java/net/videosc/VideOSC.java
Expand Up @@ -84,10 +84,6 @@ public class VideOSC extends PApplet {
static boolean printFramerate = true;
static boolean displayFramerate = false;

static int uiXright;
static int uiYtop;
static int uiYbottom;

static int backKeyState;
static ArrayList<String> optionsList = new ArrayList<String>();
static boolean preferencesListInvisible;
Expand Down Expand Up @@ -249,9 +245,9 @@ public void setup() {

VideOSCUI.loadUIImages(this);

uiYtop = 80;
uiXright = width - 130;
uiYbottom = height - 90;
VideOSCUI.uiYtop = 80;
VideOSCUI.uiXright = width - 130;
VideOSCUI.uiYbottom = height - 90;

backKeyState = 0;

Expand Down Expand Up @@ -438,12 +434,9 @@ public void draw() {
if (displayFramerate)
VideOSCUI.printFramerate(this, printFramerate);
VideOSCPreferences.darkenBackground(this);
// Log.d(TAG, "sensors in use: " + VideOSCDB.listSensorsInUse(db).size());
// for (String key : VideOSCSensors.sensorsInUse.keySet()) {
// Log.d(TAG, VideOSCSensors.sensorsInUse.get(key));
// }
if (!sensorsPrinting && printSensors)
VideOSCSensors.printSensors(this, db);
if (sensorsPrinting) {
VideOSCSensors.updatePrintedSensors();
}
} else {
if (play && lastInputList.size() >= dimensions) {
int index = frameCount % calcsPerPeriod;
Expand Down
35 changes: 23 additions & 12 deletions app/src/main/java/net/videosc/VideOSCPreferences.java
Expand Up @@ -318,8 +318,9 @@ public void onClickWidget(APWidget apWidget) {
int nextYPos = 50;
final APCheckBox useOri, useAcc, useLinAcc, useMag, useGrav, useProx, useLight, usePress, useTemp, useHum, useLoc;

useOri = new APCheckBox(50, nextYPos, "use orientation sensor (rotation in degrees - '/" + VideOSC.rootCmd + "/ori', x, y, z, timestamp, accuracy)");
useOri = new APCheckBox(50, nextYPos, "orientation sensor: rotation in degrees - '/" + VideOSC.rootCmd + "/ori', x, y, z, timestamp, accuracy");
useOri.setTextSize(16);
useOri.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isOrientationAvailable())
useOri.setText(useOri.getText() + " (not available)");
useOri.setChecked(VideOSCSensors.useOri);
Expand All @@ -333,8 +334,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useOri);
nextYPos += 50 * density;

useAcc = new APCheckBox(50, nextYPos, "use accelerometer (force in m/s^2 - '/" + VideOSC.rootCmd + "/acc', x, y, z, timestamp, accuracy)");
useAcc = new APCheckBox(50, nextYPos, "accelerometer: force in m/s^2 - '/" + VideOSC.rootCmd + "/acc', x, y, z, timestamp, accuracy");
useAcc.setTextSize(16);
useAcc.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isAccelerometerAvailable())
useAcc.setText(useAcc.getText() + " (not available)");
useAcc.setChecked(VideOSCSensors.useAcc);
Expand All @@ -348,8 +350,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useAcc);
nextYPos += 50 * density;

useLinAcc = new APCheckBox(50, nextYPos, "use linear acceleration sensor (m/s^2 minus gravity - '/" + VideOSC.rootCmd + "/lin_acc', x, y, z, timestamp, accuracy)");
useLinAcc = new APCheckBox(50, nextYPos, "linear acceleration sensor: m/s^2 minus gravity - '/" + VideOSC.rootCmd + "/lin_acc', x, y, z, timestamp, accuracy");
useLinAcc.setTextSize(16);
useLinAcc.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isLinearAccelerationAvailable())
useLinAcc.setText(useLinAcc.getText() + " (not available)");
useLinAcc.setChecked(VideOSCSensors.useLinAcc);
Expand All @@ -363,8 +366,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useLinAcc);
nextYPos += 50 * density;

useMag = new APCheckBox(50, nextYPos, "use magnetic field sensor (geomagnetic field in uT - '/" + VideOSC.rootCmd + "/mag', x, y, z, timestamp, accuracy)");
useMag = new APCheckBox(50, nextYPos, "magnetic field sensor: geomagnetic field in uT - '/" + VideOSC.rootCmd + "/mag', x, y, z, timestamp, accuracy");
useMag.setTextSize(16);
useMag.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isMagenticFieldAvailable())
useMag.setText(useMag.getText() + " (not available)");
useMag.setChecked(VideOSCSensors.useMag);
Expand All @@ -378,8 +382,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useMag);
nextYPos += 50 * density;

useGrav = new APCheckBox(50, nextYPos, "use gravity sensor (force of gravity in m/s^2 - '/" + VideOSC.rootCmd + "/grav', x, y, z, timestamp, accuracy)");
useGrav = new APCheckBox(50, nextYPos, "gravity sensor: force of gravity in m/s^2 - '/" + VideOSC.rootCmd + "/grav', x, y, z, timestamp, accuracy");
useGrav.setTextSize(16);
useGrav.setSize(applet.width - 220, (int) (45 * density));
if ((!sensors.isGyroscopeAvailable() && !sensors.isAccelerometerAvailable() && !sensors.isMagenticFieldAvailable()) ||
(sensors.isGyroscopeAvailable() && !sensors.isAccelerometerAvailable()))
useGrav.setText(useGrav.getText() + " (not available)");
Expand All @@ -395,8 +400,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useGrav);
nextYPos += 50 * density;

useProx = new APCheckBox(50, nextYPos, "use proximity sensor (distance from sensor, typically 0, 1 - '/" + VideOSC.rootCmd + "/prox', distance, timestamp, accuracy)");
useProx = new APCheckBox(50, nextYPos, "proximity sensor: distance from sensor, typically 0, 1 - '/" + VideOSC.rootCmd + "/prox', distance, timestamp, accuracy");
useProx.setTextSize(16);
useProx.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isProximityAvailable())
useProx.setText(useProx.getText() + " (not available)");
useProx.setChecked(VideOSCSensors.useProx);
Expand All @@ -410,8 +416,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useProx);
nextYPos += 50 * density;

useLight = new APCheckBox(50, nextYPos, "use light sensor (illumination from sensor in lx - '/" + VideOSC.rootCmd + "/light', illumination, timestamp, accuracy)");
useLight = new APCheckBox(50, nextYPos, "light sensor: illumination from sensor in lx - '/" + VideOSC.rootCmd + "/light', illumination, timestamp, accuracy");
useLight.setTextSize(16);
useLight.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isLightAvailable())
useLight.setText(useLight.getText() + " (not available)");
useLight.setChecked(VideOSCSensors.useLight);
Expand All @@ -425,8 +432,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useLight);
nextYPos += 50 * density;

usePress = new APCheckBox(50, nextYPos, "use air pressure sensor (ambient pressure in hPa or mbar - '/" + VideOSC.rootCmd + "/press', pressure, timestamp, accuracy)");
usePress = new APCheckBox(50, nextYPos, "air pressure sensor: ambient pressure in hPa or mbar - '/" + VideOSC.rootCmd + "/press', pressure, timestamp, accuracy");
usePress.setTextSize(16);
usePress.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isPressureAvailable())
usePress.setText(usePress.getText() + " (not available)");
usePress.setChecked(VideOSCSensors.usePress);
Expand All @@ -440,8 +448,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(usePress);
nextYPos += 50 * density;

useTemp = new APCheckBox(50, nextYPos, "use temperature sensor (temperature in degrees in °C - '/" + VideOSC.rootCmd + "/temp', temperature)");
useTemp = new APCheckBox(50, nextYPos, "temperature sensor: temperature in degrees in °C - '/" + VideOSC.rootCmd + "/temp', temperature");
useTemp.setTextSize(16);
useTemp.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isAmbientTemperatureAvailable())
useTemp.setText(useTemp.getText() + " (not available)");
useTemp.setChecked(VideOSCSensors.useTemp);
Expand All @@ -455,8 +464,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useTemp);
nextYPos += 50 * density;

useHum = new APCheckBox(50, nextYPos, "use humidity sensor (ambient humidity in % - '/" + VideOSC.rootCmd + "/hum', humidity)");
useHum = new APCheckBox(50, nextYPos, "humidity sensor: ambient humidity in % - '/" + VideOSC.rootCmd + "/hum', humidity");
useHum.setTextSize(16);
useHum.setSize(applet.width - 220, (int) (45 * density));
if (!sensors.isRelativeHumidityAvailable())
useHum.setText(useHum.getText() + " (not available)");
useHum.setChecked(VideOSCSensors.useHum);
Expand All @@ -470,8 +480,9 @@ public void onClickWidget(APWidget apWidget) {
apContainer.addWidget(useHum);
nextYPos += 50 * density;

useLoc = new APCheckBox(50, nextYPos, "use geo location ('/" + VideOSC.rootCmd +"/loc', latitude, longitude, altitude)");
useLoc = new APCheckBox(50, nextYPos, "geo location: '/" + VideOSC.rootCmd +"/loc', latitude, longitude, altitude");
useLoc.setTextSize(16);
useLoc.setSize(applet.width - 220, (int) (45 * density));
useLoc.setChecked(VideOSCSensors.useLoc);

apContainer.addWidget(useLoc);
Expand Down Expand Up @@ -630,7 +641,7 @@ public void onClickWidget(APWidget apWidget) {
}

static void darkenBackground(PApplet applet) {
if (curOptions.length() > 0) {
if (curOptions.length() > 0 || sensorsPrinting) {
applet.fill(0, 153);
applet.rect(0, 0, applet.width, applet.height);
}
Expand Down
32 changes: 18 additions & 14 deletions app/src/main/java/net/videosc/VideOSCSensors.java
Expand Up @@ -108,7 +108,7 @@ public class VideOSCSensors extends VideOSC {

// strings to be printed to screen
public volatile static Map<String, String> sensorsInUse = new HashMap<String, String>();
static ArrayList<APText> texts = new ArrayList<APText>();
static HashMap<String, APText> texts = new HashMap<String, APText>();

static void availableSensors() {
Log.d(TAG, "is orientation available: " + sensors.isOrientationAvailable());
Expand Down Expand Up @@ -291,41 +291,45 @@ static boolean printSensors(final PApplet applet, KetaiSQLite db) {
int nextYPos = 50;

completeSensorsInUse(db);

applet.fill(0, 153);
applet.rect(0, 0, applet.width, applet.height);

for (APText t : texts) {
container.removeWidget(t);

for (String key : texts.keySet()) {
container.removeWidget(texts.get(key));
}
texts.clear();

for (String key : VideOSCSensors.sensorsInUse.keySet()) {
Log.d(TAG, VideOSCSensors.sensorsInUse.get(key));

text = new APText(50, nextYPos, applet.width - 230, 100);
text = new APText(50, nextYPos, applet.width - 230, 120);
text.setText(VideOSCSensors.sensorsInUse.get(key));
texts.add(text);
text.setTextSize(16);
texts.put(key, text);
nextYPos = text.getY() + text.getHeight() + 10;
}
close.setPosition(50, nextYPos);
close.setPosition((applet.width - 220) / 4 + 50, nextYPos);
close.addOnClickWidgetListener(new OnClickWidgetListener() {
@Override
public void onClickWidget(APWidget apWidget) {
for (APText t : texts) {
container.removeWidget(t);
for (String key : texts.keySet()) {
container.removeWidget(texts.get(key));
}
container.removeWidget(close);
VideOSC.sensorsPrinting = false;
VideOSC.printSensors = false;
}
});

for (APText t : texts) {
container.addWidget(t);
for (String key : texts.keySet()) {
container.addWidget(texts.get(key));
}
container.addWidget(close);

return true;
}

static void updatePrintedSensors() {
for (String key : VideOSCSensors.sensorsInUse.keySet()) {
texts.get(key).setText(VideOSCSensors.sensorsInUse.get(key));
}
}
}
16 changes: 13 additions & 3 deletions app/src/main/java/net/videosc/VideOSCUI.java
Expand Up @@ -63,6 +63,10 @@ public class VideOSCUI extends VideOSC {
// snapshots, etc.)
static boolean selectionListActive = false;

static int uiXright;
static int uiYtop;
static int uiYbottom;

static void loadUIImages(PApplet applet) {
startBut = applet.loadImage("start.png");
stopBut = applet.loadImage("stop.png");
Expand Down Expand Up @@ -156,7 +160,7 @@ static void processUIClicks(PApplet applet, int x, int y, KetaiSQLite db) {
KetaiList snapshotsSelect;
KetaiList preferencesList;

if (!selectionListActive) {
if (!selectionListActive && !sensorsPrinting) {
// only allow interaction if screen is not overlayed by some selection list
if (x > 100 && y > 100 && x < applet.width - 130 && !displayRGBselector && curOptions.equals
("")) {
Expand Down Expand Up @@ -217,6 +221,12 @@ static void processUIClicks(PApplet applet, int x, int y, KetaiSQLite db) {
}
} else if (x <= 100 && y <= 100 && curOptions.equals("")) {
showHide = true;
} else if (x > 100 && x <= 350 && y <= 100 && curOptions.equals("")) {
// Log.d(TAG, "clicked: sensors printed? " + sensorsPrinting + printSensors);
printSensors = true;
if (!sensorsPrinting && printSensors) {
sensorsPrinting = VideOSCSensors.printSensors(applet, db);
}
}

if (mode.equals(InteractionModes.SINGLE_PIXEL)) {
Expand Down Expand Up @@ -283,9 +293,9 @@ static void drawTools(PApplet applet, KetaiSQLite db) {
else
applet.image(hideMenu, 70, 70, 62, 62);

Log.d(TAG, "number of active sensors: " + VideOSCDB.listSensorsInUse(db).size());
// Log.d(TAG, "number of active sensors: " + VideOSCDB.listSensorsInUse(db).size());
if (VideOSCDB.listSensorsInUse(db).size() > 0)
applet.image(sensors, 250, 70, 229, 62);
applet.image(sensors, 250, uiYtop - 10, 229, 62);

if (!rgbMode.equals(RGBModes.RGB)) {
if (showFB)
Expand Down
Expand Up @@ -28,7 +28,7 @@ public void run() {
String light = "intensity: " + VideOSCSensors.lightIntensity;
String time = ", timestamp: " + VideOSCSensors.lightTime;
String accuracy = ", accuracy: " + VideOSCSensors.lightAcc;
VideOSCSensors.sensorsInUse.put("light", "light sensor - " + light + time + accuracy +"lx");
VideOSCSensors.sensorsInUse.put("light", "light sensor - " + light + time + accuracy);
}
oscLight = VideOSCOscHandling.makeMessage(oscLight, "/" + VideOSC.rootCmd + "/light");
oscLight.add(VideOSCSensors.lightIntensity).add(VideOSCSensors.lightTime).add(VideOSCSensors.lightAcc);
Expand Down
Expand Up @@ -28,7 +28,7 @@ public void run() {
String pressure = "pressure: " + VideOSCSensors.pressIntensity;
String time = ", timestamp: " + VideOSCSensors.pressTime;
String accuracy = ", accuracy: " + VideOSCSensors.pressAcc;
VideOSCSensors.sensorsInUse.put("press", "air pressure sensor - " + pressure + time + accuracy + "hPa/mBar");
VideOSCSensors.sensorsInUse.put("press", "air pressure sensor - " + pressure + time + accuracy);
}
oscPress = VideOSCOscHandling.makeMessage(oscPress, "/" + VideOSC.rootCmd + "/press");
oscPress.add(VideOSCSensors.pressIntensity).add(VideOSCSensors.pressTime).add(VideOSCSensors.pressAcc);
Expand Down
Expand Up @@ -26,7 +26,7 @@ public void run() {
try {
if (VideOSC.printSensors) {
String temperature = "temperature: " + VideOSCSensors.tempCels;
VideOSCSensors.sensorsInUse.put("temp", "temperature sensor - " + temperature + "°C");
VideOSCSensors.sensorsInUse.put("temp", "temperature sensor - " + temperature);
}
oscTemp = VideOSCOscHandling.makeMessage(oscTemp, "/" + VideOSC.rootCmd + "/temp");
oscTemp.add(VideOSCSensors.tempCels);
Expand Down

0 comments on commit 7eb9002

Please sign in to comment.