Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pysamples
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-10-28 11:27:23 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-10-28 11:27:23 (GMT)
commitd1aa47ebca8e0eb40d7ee22fea609dfa507b6f70 (patch)
tree217d9315dd57272e47c3c0ce327325b49786ad15 /pysamples
parentc6e80efd903a1635625a8001e1a5f7e970051ddb (diff)
sensors example revisted
Diffstat (limited to 'pysamples')
-rw-r--r--pysamples/sensors.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/pysamples/sensors.py b/pysamples/sensors.py
new file mode 100644
index 0000000..b05b6c7
--- /dev/null
+++ b/pysamples/sensors.py
@@ -0,0 +1,33 @@
+#Copyright (c) 2010-11, Walter Bender, Tony Forster
+#
+# This Python block returns with the brightness sensor value in the heap
+# a range of parameters can be measured, for example, substitute any of
+# these strings for the string in the program below.
+#
+# /sys/devices/platform/olpc-battery.0/power_supply/olpc-battery/current_now
+# /sys/devices/platform/olpc-battery.0/power_supply/olpc-battery/voltage_now
+# /sys/devices/platform/dcon/backlight/dcon-bl/actual_brightness
+
+
+def myblock(tw, x): # ignores second argument
+ import os
+
+ # The light sensor is only available on the XO 1.75
+ device = '/sys/devices/platform/olpc-ols.0/power_state'
+
+ if os.path.exists(device):
+ fh = open(device)
+ string = fh.read()
+ fh.close()
+ tw.lc.heap.append(float(string)) # append as a float value to the heap
+ else:
+ tw.lc.heap.append(-1)
+
+# If you can work out how to use them...
+# accelerometer: /dev/input/event0 ???
+# power button: /dev/input/event1
+# lid switch: /dev/input/event2
+# ebook: /dev/input/event3
+# headphone jack: /dev/input/event7
+# microphone jack: /dev/input/event8
+# rotate, cursor, and game pad keys: /dev/input/event10