Skip to content

Instantly share code, notes, and snippets.

@jwatte
Created August 3, 2014 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwatte/2e412dac849a3404186d to your computer and use it in GitHub Desktop.
Save jwatte/2e412dac849a3404186d to your computer and use it in GitHub Desktop.
voltservice.py file using dbus
#!/usr/bin/python2
import gtk
import dbus
import dbus.service
import dbus.mainloop
import dbus.mainloop.glib
import spivolt
from dbus.mainloop.glib import DBusGMainLoop
class SpiVoltService(dbus.service.Object):
def __init__(self):
self.dev = spivolt.SpiVolt()
bus_name = dbus.service.BusName('net.watte.robots.voltmon', bus = dbus.SystemBus())
dbus.service.Object.__init__(self, object_path='/net/watte/robots/voltmon', bus_name=bus_name);
@dbus.service.method('net.watte.robots.voltmon')
def read(self):
ret = self.dev.read()
if not ret:
return 0.0
return ret
@dbus.service.method('net.watte.robots.voltmon')
def off(self):
self.dev.off()
if __name__ == "__main__":
theLoop = DBusGMainLoop(set_as_default=True)
theSvc = SpiVoltService()
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment