Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bounce.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-10-02 19:53:15 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-10-02 19:53:15 (GMT)
commitedf6dc746af7d59a72722aa8e8311eb8e632f30c (patch)
tree21a83a7b69897d8758ecb373368956c205f4a03e /bounce.py
parent172de6f1253ad04f91f8a62e0f26828bdf4ccadb (diff)
add accelerometer support
Diffstat (limited to 'bounce.py')
-rw-r--r--bounce.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/bounce.py b/bounce.py
index c289e15..dfe2ccd 100644
--- a/bounce.py
+++ b/bounce.py
@@ -17,7 +17,9 @@ FRACTIONS = [('1/2', 0.5, 12), ('2/8', 0.25, 12), ('1/3', 1 / 3., 12),
('4/6', 2 / 3., 12), ('2/6', 1 / 3., 12), ('5/6', 5 / 6., 12),
('1/6', 1 / 6., 12), ('1/5', 0.2, 10)]
BAR_HEIGHT = 20
-STEPS = 100.
+STEPS = 100. # number of time steps per bounce rise and fall
+
+ACCELEROMETER_DEVICE = '/sys/devices/platform/lis3lv02d/position'
import gtk
from random import uniform
@@ -103,6 +105,11 @@ class Bounce():
self.canvas = canvas
parent.show_all()
+ if os.path.exists(ACCELEROMETER_DEVICE):
+ self.accererometer = True
+ else:
+ self.accererometer = False
+
self.canvas.set_flags(gtk.CAN_FOCUS)
self.canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self.canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
@@ -218,6 +225,13 @@ class Bounce():
self.new_bounce = False
self.dy = self.ddy * (1 - STEPS) / 2 # initial step size
+ if self.accererometer:
+ fh = open(ACCELEROMETER_DEVICE)
+ string = fh.read()
+ xyz = string[1:-2].split(',')
+ self.dx = int(float(xyz[0]) / 18.)
+ fh.close()
+
if self.ball.get_xy()[0] + self.dx > 0 and \
self.ball.get_xy()[0] + self.dx < self.width - self.ball.rect[2]:
self.ball.move_relative((self.dx, self.dy))
@@ -271,7 +285,7 @@ class Bounce():
self.dx = -5
elif k in ['l', 'Right', 'KP_Right']:
self.dx = 5
- elif k in ['KP_Page_Up']:
+ elif k in ['KP_Page_Up', 'Return']:
self._choose_a_fraction()
self._move_ball()
else: