Skip to content

Commit

Permalink
inmoov2 pre heart (#1419)
Browse files Browse the repository at this point in the history
* inmoov2 pre heart

* trying a resource fix
  • Loading branch information
supertick authored Apr 24, 2024
1 parent fbc7dd7 commit e617d81
Show file tree
Hide file tree
Showing 29 changed files with 551 additions and 558 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,8 @@
<!-- do not upgrade this version jacoco will break -->
<version>3.2.2</version>
<configuration>
<forkCount>1</forkCount> <!-- Use one JVM -->
<reuseForks>true</reuseForks> <!-- Reuse this JVM for all tests -->
<!-- critical for jacoco to have original argLine prefixed here-->
<argLine>${argLine} -Djava.library.path=libraries/native
-Djna.library.path=libraries/native</argLine>
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/myrobotlab/programab/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

Expand Down Expand Up @@ -93,7 +95,7 @@ private synchronized Chat getChat() {
return chat;
}

public void savePredicates() {
synchronized public void savePredicates() {
StringBuilder sb = new StringBuilder();
TreeSet<String> sort = new TreeSet<>();
sort.addAll(getChat().predicates.keySet());
Expand All @@ -120,9 +122,14 @@ public void savePredicates() {
* Get all current predicate names and values
* @return
*/
public Map<String, String> getPredicates() {
synchronized public Map<String, String> getPredicates() {
TreeMap<String, String> sort = new TreeMap<>();
sort.putAll(getChat().predicates);
// copy keys, making this sort thread safe
Set<String> keys = new HashSet(getChat().predicates.keySet());
for (String key: keys) {
String value = getChat().predicates.get(key);
sort.put(key, value);
}
return sort;
}

Expand Down
90 changes: 28 additions & 62 deletions src/main/java/org/myrobotlab/service/AudioFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,13 @@ public class AudioFile extends Service<AudioFileConfig> implements AudioPublishe
// https://stackoverflow.com/questions/25798200/java-record-mic-to-byte-array-and-play-sound
//

String currentTrack = DEFAULT_TRACK;
/**
* status field, the current track being played
*/
protected String currentTrack = DEFAULT_TRACK;

transient Map<String, AudioProcessor> processors = new HashMap<String, AudioProcessor>();

double volume = 1.0f;
// if set to true, playback will become a no-op
private boolean mute = false;

protected String currentPlaylist = "default";

protected Map<String, List<String>> playlists = new HashMap<>();

final private transient PlaylistPlayer playlistPlayer = new PlaylistPlayer(this);

public void attach(Attachable attachable) {
Expand Down Expand Up @@ -185,7 +180,7 @@ public AudioData play(String filename, boolean blocking) {

public AudioData play(String filename, boolean blocking, Integer repeat, String track) {

log.info("Play called for Filename {}", filename);
log.info("Play called for Filename {}", filename);
if (track == null || track.isEmpty()) {
track = currentTrack;
}
Expand Down Expand Up @@ -254,7 +249,7 @@ public AudioData playAudioData(AudioData data) {
data.track = currentTrack;
}
setTrack(data.track);
processors.get(data.track).setVolume(volume);
processors.get(data.track).setVolume(config.volume);
if (AudioData.MODE_QUEUED.equals(data.mode)) {
// stick it on top of queue and let our default player play it
return processors.get(data.track).add(data);
Expand Down Expand Up @@ -329,15 +324,15 @@ public void silence() {
*
*/
public void setVolume(float volume) {
this.volume = volume;
config.volume = volume;
}

public void setVolume(double volume) {
setVolume((float) volume);
}

public double getVolume() {
return this.volume;
return config.volume;
}

public String getTrack() {
Expand Down Expand Up @@ -384,6 +379,14 @@ public List<File> getFiles(String subDir, boolean recurse) {
return new ArrayList<File>();
}

@Override
public void releaseService() {
super.releaseService();
for (AudioProcessor processor: processors.values()) {
processor.stopPlaying();
}
}

public AudioData repeat(String filename) {
return repeat(filename, -1);
}
Expand Down Expand Up @@ -433,28 +436,28 @@ public void deleteFile(String filename) {
}

public boolean isMute() {
return mute;
return config.mute;
}

public void setMute(boolean mute) {
this.mute = mute;
config.mute = mute;
}

public void setPlaylist(String name) {
currentPlaylist = name;
config.currentPlaylist = name;
}

public void addPlaylist(String folderPath) {
addPlaylist(currentPlaylist, folderPath);
addPlaylist(config.currentPlaylist, folderPath);
}

public void addPlaylist(String name, String path) {

List<String> list = null;
if (!playlists.containsKey(name)) {
if (!config.playlists.containsKey(name)) {
list = new ArrayList<String>();
} else {
list = playlists.get(name);
list = config.playlists.get(name);
}
File check = new File(path);
if (!check.exists()) {
Expand All @@ -465,7 +468,7 @@ public void addPlaylist(String name, String path) {
list.addAll(scanForMusicFiles(path));
}
int filecount = list.size();
playlists.put(name, list);
config.playlists.put(name, list);
log.info("{} playlist added {} files", name, filecount);
}

Expand Down Expand Up @@ -497,15 +500,15 @@ private List<String> scanForMusicFiles(String path) {
}

public List<String> getPlaylist(String name) {
return playlists.get(name);
return config.playlists.get(name);
}

public Map<String, List<String>> getPlaylists() {
return playlists;
return config.playlists;
}

public void startPlaylist() {
startPlaylist(currentPlaylist, false, false, currentPlaylist);
startPlaylist(config.currentPlaylist, false, false, DEFAULT_TRACK);
}

public void startPlaylist(String playlist) {
Expand All @@ -517,54 +520,17 @@ public void startPlaylist(String playlist, boolean shuffle, boolean repeat) {
}

public void startPlaylist(String playlist, boolean shuffle, boolean repeat, String track) {
if (!playlists.containsKey(playlist)) {
if (!config.playlists.containsKey(playlist)) {
error("cannot play playlist %s does not exists", playlist);
return;
}
playlistPlayer.start(playlists.get(playlist), shuffle, repeat, track);
playlistPlayer.start(config.playlists.get(playlist), shuffle, repeat, track);
}

public void stopPlaylist() {
playlistPlayer.stop();
}

@Override
public AudioFileConfig getConfig() {

AudioFileConfig c = (AudioFileConfig) super.getConfig();
// FIXME - remove members keep data in config !
// FIXME - the following is not needed nor desired
// useless self assignment
c.mute = mute;
c.currentTrack = currentTrack;
c.currentPlaylist = currentPlaylist;
// c.peakMultiplier = peakMultiplier;
c.volume = volume;
c.playlists = playlists;
// config.peakSampleInterval <- this one is done correctly no maintenance
c.audioListeners = getAttached("publishAudio").toArray(new String[0]);

return config;
}

public AudioFileConfig apply(AudioFileConfig config) {
super.apply(config);
setMute(config.mute);
setTrack(config.currentTrack);
setVolume(config.volume);
setPlaylist(config.currentPlaylist);
if (config.playlists != null) {
playlists = config.playlists;
}

if (config.audioListeners != null) {
for (String listener : config.audioListeners) {
attachAudioListener(listener);
}
}

return config;
}

public double publishPeak(double peak) {
log.debug("publishPeak {}", peak);
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/myrobotlab/service/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static class LogEntry {
public String threadName;
public String className;
public String body;
public String src;

public LogEntry(ILoggingEvent event) {
ts = event.getTimeStamp();
Expand All @@ -63,6 +64,11 @@ public LogEntry(ILoggingEvent event) {
body = event.getFormattedMessage();
}

public LogEntry() {
ts = System.currentTimeMillis();
threadName = Thread.currentThread().getName();
}

@Override
public String toString() {
return String.format("%d %s %s %s %s", ts, level, threadName, className, body);
Expand Down Expand Up @@ -132,6 +138,7 @@ public void addError(String msg) {

@Override
public void addError(String arg0, Throwable arg1) {
System.out.println("addError");
}

@Override
Expand Down Expand Up @@ -202,6 +209,18 @@ synchronized public void flush() {
if (buffer.size() > 0) {
// bucket add to sliding window
logs.addAll(buffer);

List<LogEntry> errors = new ArrayList<>();
for(int i = 0; i < buffer.size(); ++i) {
LogEntry entry = buffer.get(i);
if ("ERROR".equals(entry.level)) {
errors.add(entry);
}
}
if (errors.size() > 0) {
invoke("publishErrors", errors);
}

invoke("publishLogEvents", buffer);
buffer = new ArrayList<>(maxSize);
lastPublishLogTimeTs = System.currentTimeMillis();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/myrobotlab/service/NeoPixel.java
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ public void playIronman() {
public void releaseService() {
super.releaseService();
clear();
worker.stop();
}

@Override
Expand Down Expand Up @@ -936,7 +937,7 @@ public void setPixel(String matrixName, Integer pixelSetIndex, int address, int
// Runtime.getService(controller);
ServiceInterface sc = Runtime.getService(controller);
if (sc == null) {
error("controler %s not valid", controller);
error("controller %s not valid", controller);
return;
}

Expand Down Expand Up @@ -1050,4 +1051,4 @@ public void setPixel(int address, String color) {
}
setPixel(address, rgb[0], rgb[1], rgb[2]);
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/myrobotlab/service/OakD.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

/**
*
* https://github.com/luxonis/depthai
* python3 depthai_demo.py -cb callbacks.py
*
*
* https://github.com/luxonis/depthai-experiments/tree/master/gen2-face-recognition
*
* @author GroG
*
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/org/myrobotlab/service/ProgramAB.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,15 @@ public Response getResponse(String userName, String botName, String text, boolea
// update the current session if we want to change which bot is at
// attention.
if (updateCurrentSession) {

boolean sessionChanged = (!userName.equals(config.currentUserName) || !botName.equals(config.currentBotName));

setCurrentUserName(userName);
setCurrentBotName(botName);

if (sessionChanged) {
invoke("publishSession", getSessionKey(userName, botName));
}
}

// Get the actual bots aiml based response for this session
Expand Down Expand Up @@ -711,12 +718,25 @@ public Session startSession(String path, String userName, String botName, java.u
}

session = new Session(this, userName, botInfo);
sessions.put(getSessionKey(userName, botName), session);
String sessionKey = getSessionKey(userName, botName);
sessions.put(sessionKey, session);

log.info("Started session for bot botName:{} , userName:{}", botName, userName);
setCurrentSession(userName, botName);

invoke("publishSession", sessionKey);

return session;
}

/**
* When a new session is started this event is published with the session's key
* @param sessionKey of new Session
* @return sessionKey
*/
public String publishSession(String sessionKey) {
return sessionKey;
}

/**
* setting the current session is equivalent to setting current user name and
Expand Down
Loading

0 comments on commit e617d81

Please sign in to comment.