Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Nov 16, 2023
1 parent 9431841 commit 4a891ac
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 84 deletions.
106 changes: 29 additions & 77 deletions src/main/java/org/myrobotlab/service/InMoov2.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.apache.commons.io.FilenameUtils;
import org.myrobotlab.framework.Message;
import org.myrobotlab.framework.Plan;
import org.myrobotlab.framework.Platform;
import org.myrobotlab.framework.Registration;
import org.myrobotlab.framework.Service;
Expand All @@ -35,7 +36,6 @@
import org.myrobotlab.service.config.OpenCVConfig;
import org.myrobotlab.service.config.SpeechSynthesisConfig;
import org.myrobotlab.service.data.JoystickData;
import org.myrobotlab.service.data.LedDisplayData;
import org.myrobotlab.service.data.Locale;
import org.myrobotlab.service.interfaces.IKJointAngleListener;
import org.myrobotlab.service.interfaces.JoystickListener;
Expand Down Expand Up @@ -106,8 +106,6 @@ public static boolean loadFile(String file) {
*/
protected String bootedConfig = null;

protected LedDisplayData led = new LedDisplayData();

protected transient ProgramAB chatBot;

protected List<String> configList;
Expand Down Expand Up @@ -159,8 +157,6 @@ public static boolean loadFile(String file) {

protected Long lastPirActivityTime;

protected Map<String, LedDisplayData> ledDisplayMap = new TreeMap<>();

/**
* supported locales
*/
Expand Down Expand Up @@ -200,14 +196,6 @@ public InMoov2(String n, String id) {
stateDefaults.add("powerDown"); // stops heartbeat, listening ?
stateDefaults.add("shutdown");// ends mrl

ledDisplayMap.put("error", new LedDisplayData(120, 0, 0, 3, 30, 30));
ledDisplayMap.put("info", new LedDisplayData(0, 0, 120, 1, 30, 30));
ledDisplayMap.put("success", new LedDisplayData(0, 0, 120, 2, 30, 30));
ledDisplayMap.put("warn", new LedDisplayData(100, 100, 0, 3, 30, 30));
ledDisplayMap.put("heartbeat", new LedDisplayData(210, 110, 0, 2, 100, 30));
ledDisplayMap.put("pirOn", new LedDisplayData(60, 200, 90, 3, 100, 30));
ledDisplayMap.put("onPeakColor", new LedDisplayData(180, 53, 21, 3, 60, 30));

customSoundMap.put("boot", FileIO.gluePaths(getResourceDir(), "system/sounds/Notifications/confirmation.wav"));
customSoundMap.put("wake", FileIO.gluePaths(getResourceDir(), "system/sounds/Notifications/ting.wav"));
customSoundMap.put("firstInit", FileIO.gluePaths(getResourceDir(), "system/sounds/Notifications/select.wav"));
Expand Down Expand Up @@ -511,33 +499,19 @@ public void firstInit() {
}
}

public void flash(String name) {
LedDisplayData led = ledDisplayMap.get(name);
if (led == null) {
led = ledDisplayMap.get("default");
}
invoke("publishFlash", led.red, led.green, led.blue, led.count, led.timeOn, led.timeOff);
}

/**
* used to configure a flashing event - could use configuration to signal
* different colors and states
*
* @return
*/
public void flash() {
if (ledDisplayMap.get("default") != null) {
LedDisplayData led = ledDisplayMap.get("default");
invoke("publishFlash", led.red, led.green, led.blue, led.count, led.timeOn, led.timeOff);
}
invoke("publishFlash", "default");
}

public void flash(int r, int g, int b, int count) {
// FIXME - this should be checking a protected "state"
if (ledDisplayMap.get("default") != null) {
LedDisplayData led = ledDisplayMap.get("default");
invoke("publishFlash", r, g, b, count, led.timeOn, led.timeOff);
}
public String flash(String name) {
invoke("publishFlash", name);
return name;
}

public void fullSpeed() {
Expand Down Expand Up @@ -1074,6 +1048,7 @@ public PredicateEvent onChangePredicate(PredicateEvent event) {

public void onConfigFinished(String configName) {
log.info("onConfigFinished");
configStarted = false;
invoke("publishBoot");
}

Expand Down Expand Up @@ -1161,11 +1136,10 @@ public void onHeartbeat() {

// flash error until errors are cleared
if (config.healthCheckFlash) {
if (errors.size() > 0 && ledDisplayMap.containsKey("error")) {
invoke("publishFlash", ledDisplayMap.get("error"));
} else if (ledDisplayMap.containsKey("heartbeat")) {
LedDisplayData heartbeat = ledDisplayMap.get("heartbeat");
invoke("publishFlash", heartbeat);
if (errors.size() > 0) {
invoke("publishFlash", "error");
} else {
invoke("publishFlash", "heartbeat");
}
}

Expand Down Expand Up @@ -1289,21 +1263,9 @@ public void onPeak(double volume) {
}
}

/**
* onPeak volume callback TODO - maybe make it variable with volume ?
*
* @param volume
*/
public void onPirOn() {
led.action = "flash";
led.red = 50;
led.green = 100;
led.blue = 150;
led.count = 5;
led.timeOn = 500;
led.timeOff = 10;
// FIXME flash on config.flashOnBoot
invoke("publishFlash");

invoke("publishFlash", "pirOn");
ProgramAB chatBot = (ProgramAB)getPeer("chatBot");
if (chatBot != null) {
String botState = chatBot.getPredicate("botState");
Expand Down Expand Up @@ -1531,19 +1493,24 @@ public List<String> publishConfigList() {
return configList;
}

public LedDisplayData publishFlash(int r, int g, int b, int count, long timeOn, long timeOff) {
LedDisplayData data = new LedDisplayData();
data.red = r;
data.green = g;
data.blue = b;
data.count = count;
data.timeOn = timeOn;
data.timeOff = timeOff;
return data;
/**
* publishes a name for NeoPixel.onFlash to consume
* @param name
* @return
*/
public String publishFlash(String name) {
return name;
}

public LedDisplayData publishFlash(LedDisplayData data) {
return data;

/**
* publishes a name for NeoPixel.onFlash to consume,
* in a seperate channel to potentially be used by
* "speaking only" leds
* @param name
* @return
*/
public String publishSpeakingFlash(String name) {
return name;
}

/**
Expand All @@ -1555,16 +1522,6 @@ public void publishInactivity() {
fsm.fire("inactvity");
}

/**
* used to configure a flashing event - could use configuration to signal
* different colors and states
*
* @return
*/
public LedDisplayData publishFlash() {
return led;
}

/**
* A more extensible interface point than publishEvent FIXME - create
* interface for this
Expand Down Expand Up @@ -2345,12 +2302,7 @@ public void closeHands() {
closeLeftHand();
closeRightHand();
}

public Event onEvent(Event event) {

return event;
}

public void wake() {
log.info("wake");
// do waking things - based on config
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/myrobotlab/service/NeoPixel.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,15 @@ public void flash(int r, int g, int b, int count, long timeOn, long timeOff) {
data.timeOff = timeOff;
displayQueue.add(data);
}

public void onFlash(LedDisplayData data) {
displayQueue.add(data);

/**
* Publishes a flash based on a predefined name
* @param name
*/
public void onFlash(String name) {
if (config.flashMap != null && config.flashMap.containsKey(name)) {
displayQueue.add(config.flashMap.get(name));
}
}

public void flashBrightness(double brightNess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public Plan getDefault(Plan plan, String name) {
// mouth_audioFile.listeners.add(new Listener("publishAudioStart", name));

// InMoov2 --to--> service
listeners.add(new Listener("publishFlash", getPeerName("neoPixel"), "onLedDisplay"));
listeners.add(new Listener("publishFlash", getPeerName("neoPixel")));
listeners.add(new Listener("publishEvent", getPeerName("chatBot"), "getResponse"));
listeners.add(new Listener("publishPlayAudioFile", getPeerName("audioPlayer")));

Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/myrobotlab/service/config/NeoPixelConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.myrobotlab.service.config;

import java.util.HashMap;
import java.util.Map;

import org.myrobotlab.framework.Plan;
import org.myrobotlab.service.data.LedDisplayData;

public class NeoPixelConfig extends ServiceConfig {

public Integer pin = null;
Expand All @@ -16,5 +22,35 @@ public class NeoPixelConfig extends ServiceConfig {
// auto clears flashes
public boolean autoClear = false;
public int idleTimeout = 1000;

/**
* Map of predefined led flashes, defined here in configuration.
* Another service simply needs to publishFlash(name) and the
* neopixel will get the defined flash data if defined and process
* it.
*/
public Map<String, LedDisplayData> flashMap = new HashMap<>();


/**
* reason why we initialize default for flashMap here, is so
* we don't need to do a data copy over to a service's member variable
*/
public Plan getDefault(Plan plan, String name) {
super.getDefault(plan, name);

flashMap.put("error", new LedDisplayData(120, 0, 0, 3, 30, 30));
flashMap.put("info", new LedDisplayData(0, 0, 120, 1, 30, 30));
flashMap.put("success", new LedDisplayData(0, 0, 120, 2, 30, 30));
flashMap.put("warn", new LedDisplayData(100, 100, 0, 3, 30, 30));
flashMap.put("heartbeat", new LedDisplayData(210, 110, 0, 2, 100, 30));
flashMap.put("pirOn", new LedDisplayData(60, 200, 90, 3, 100, 30));
flashMap.put("onPeakColor", new LedDisplayData(180, 53, 21, 3, 60, 30));
flashMap.put("speaking", new LedDisplayData(0, 183, 90, 2, 60, 30));

return plan;
}


}

8 changes: 5 additions & 3 deletions src/main/java/org/myrobotlab/service/data/LedDisplayData.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public class LedDisplayData {

public String action; // fill | flash | play animation | stop | clear

public int red;
public int red = 0;

public int green;
public int green = 0;

public int blue;
public int blue = 0;

// public int brightness = 255;

// public int white?;

Expand Down

0 comments on commit 4a891ac

Please sign in to comment.