From 4a891ac073e0a96c8855fe6977214108afab5be5 Mon Sep 17 00:00:00 2001 From: grog Date: Wed, 15 Nov 2023 17:28:33 -0800 Subject: [PATCH] updates --- .../java/org/myrobotlab/service/InMoov2.java | 106 +++++------------- .../java/org/myrobotlab/service/NeoPixel.java | 12 +- .../service/config/InMoov2Config.java | 2 +- .../service/config/NeoPixelConfig.java | 36 ++++++ .../service/data/LedDisplayData.java | 8 +- 5 files changed, 80 insertions(+), 84 deletions(-) diff --git a/src/main/java/org/myrobotlab/service/InMoov2.java b/src/main/java/org/myrobotlab/service/InMoov2.java index 59ad222ab1..2e328bdf87 100644 --- a/src/main/java/org/myrobotlab/service/InMoov2.java +++ b/src/main/java/org/myrobotlab/service/InMoov2.java @@ -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; @@ -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; @@ -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 configList; @@ -159,8 +157,6 @@ public static boolean loadFile(String file) { protected Long lastPirActivityTime; - protected Map ledDisplayMap = new TreeMap<>(); - /** * supported locales */ @@ -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")); @@ -511,14 +499,6 @@ 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 @@ -526,18 +506,12 @@ public void flash(String name) { * @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() { @@ -1074,6 +1048,7 @@ public PredicateEvent onChangePredicate(PredicateEvent event) { public void onConfigFinished(String configName) { log.info("onConfigFinished"); + configStarted = false; invoke("publishBoot"); } @@ -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"); } } @@ -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"); @@ -1531,19 +1493,24 @@ public List 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; } /** @@ -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 @@ -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 diff --git a/src/main/java/org/myrobotlab/service/NeoPixel.java b/src/main/java/org/myrobotlab/service/NeoPixel.java index 8e7b84eafa..780d0a15b4 100644 --- a/src/main/java/org/myrobotlab/service/NeoPixel.java +++ b/src/main/java/org/myrobotlab/service/NeoPixel.java @@ -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) { diff --git a/src/main/java/org/myrobotlab/service/config/InMoov2Config.java b/src/main/java/org/myrobotlab/service/config/InMoov2Config.java index c4c69f3cb9..227d20e5d3 100644 --- a/src/main/java/org/myrobotlab/service/config/InMoov2Config.java +++ b/src/main/java/org/myrobotlab/service/config/InMoov2Config.java @@ -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"))); diff --git a/src/main/java/org/myrobotlab/service/config/NeoPixelConfig.java b/src/main/java/org/myrobotlab/service/config/NeoPixelConfig.java index e7fbb17cbe..7f012d7e38 100644 --- a/src/main/java/org/myrobotlab/service/config/NeoPixelConfig.java +++ b/src/main/java/org/myrobotlab/service/config/NeoPixelConfig.java @@ -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; @@ -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 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; + } + } + diff --git a/src/main/java/org/myrobotlab/service/data/LedDisplayData.java b/src/main/java/org/myrobotlab/service/data/LedDisplayData.java index 3658782913..b46ab5e862 100644 --- a/src/main/java/org/myrobotlab/service/data/LedDisplayData.java +++ b/src/main/java/org/myrobotlab/service/data/LedDisplayData.java @@ -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?;