Created
August 3, 2014 22:16
-
-
Save jwatte/2e412dac849a3404186d to your computer and use it in GitHub Desktop.
voltservice.py file using dbus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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