Skip to content

Commit

Permalink
Filter local monitor signals at Python backend instead of js; use cus…
Browse files Browse the repository at this point in the history
…tom 'display' property instead of device name to indicate whether signals should be forwarded to front end.
  • Loading branch information
malloch committed Dec 5, 2023
1 parent a88e265 commit 95c4dbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 0 additions & 4 deletions js/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ function Graph() {
let hidden = this.devices.some(d => d.hidden == true);
let last = devs.length - 1;
for (var i in devs) {
// Skip if webmapper device
if (devs[i].name.includes('webmapper')) continue;
let dev = this.devices.add(devs[i], i == last);
if (hidden)
dev.hidden = true;
Expand Down Expand Up @@ -386,8 +384,6 @@ function Graph() {
this.add_signals = function(cmd, sigs) {
let last = sigs.length - 1;
for (var i in sigs) {
// Skip if from webmapper device
if (sigs[i].device.includes('webmapper')) continue;
let dev = this.devices.find(sigs[i].device);
if (!dev) {
console.log("error adding signal: couldn't find device", sigs[i].device);
Expand Down
21 changes: 14 additions & 7 deletions webmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ def launch():
launcher.start()

graph = mpr.Graph()
webmapper_dev = mpr.Device("webmapper")
webmapper_dev = mpr.Device("webmapper", graph)
webmapper_dev['display'] = False

def monitor_handler(sig, event, id, val, timetag):
server.send_command("update_sig_monitor", val)

monitor_sig = webmapper_dev.add_signal(mpr.Direction.INCOMING, "monitor", 1,
mpr.Type.FLOAT, None, -100000, 100000, None, monitor_handler)
monitor_sig = webmapper_dev.add_signal(mpr.Direction.INCOMING, "monitor", 1, mpr.Type.FLOAT,
None, -100000, 100000, None, monitor_handler)
monitor_sig['display'] = False

if '--iface' in sys.argv:
iface = sys.argv[sys.argv.index('--iface')+1]
graph.set_interface(iface)
Expand Down Expand Up @@ -168,7 +171,7 @@ def map_props(map):
return props

def on_device(type, dev, event):
# print('ON_DEVICE')
# print('ON_DEVICE:', event, dev)
dev = dev_props(dev)
if event == mpr.Graph.Event.NEW or event == mpr.Graph.Event.MODIFIED:
new_devs[dev['key']] = dev
Expand All @@ -177,15 +180,15 @@ def on_device(type, dev, event):
del_devs[dev['key']] = dev

def on_signal(type, sig, event):
# print('ON_SIGNAL')
# print('ON_SIGNAL:', event)
sig = sig_props(sig)
if event == mpr.Graph.Event.NEW or event == mpr.Graph.Event.MODIFIED:
new_sigs[sig['key']] = sig
elif event == mpr.Graph.Event.REMOVED:
del_sigs[sig['key']] = sig

def on_map(type, map, event):
# print('ON_MAP')
# print('ON_MAP:', event)
map = map_props(map)
if event == mpr.Graph.Event.NEW or event == mpr.Graph.Event.MODIFIED:
new_maps[map['key']] = map
Expand Down Expand Up @@ -399,8 +402,12 @@ def init_graph(arg):
graph.subscribe(None, mpr.Type.OBJECT, -1)

for d in graph.devices():
if 'display' in d and d['display'] == False:
continue
server.send_command("add_devices", [dev_props(d)])
for s in graph.signals():
if 'display' in s and s['display'] == False:
continue
server.send_command("add_signals", [sig_props(s)])
for m in graph.maps():
server.send_command("add_maps", [map_props(m)])
Expand All @@ -409,7 +416,7 @@ def init_graph(arg):
init_graph(0)

server.add_command_handler("add_devices",
lambda x: ("add_devices", [dev_props(d) for d in graph.devices()]))
lambda x: ("add_devices", [dev_props(d) for d in graph.devices().filter('display', True, mpr.Operator.NOT_EQUAL)]))

def subscribe(device):
if device == 'all_devices':
Expand Down

0 comments on commit 95c4dbf

Please sign in to comment.