Skip to content

Instantly share code, notes, and snippets.

@pklaus
Created March 4, 2010 17:24
Show Gist options
  • Save pklaus/321922 to your computer and use it in GitHub Desktop.
Save pklaus/321922 to your computer and use it in GitHub Desktop.
PyS60 Accelerometer for 3rd edition (FP1 and FP2+)
obexftp.exe -b 00:1d:5d:5b:53:fc -B 11 --chdir /E:/Python/ --put ./PyS60_3rdFP1_accelerometer.py
obexftp.exe -b 00:1d:5d:5b:53:fc -B 11 --chdir /E:/Python/ --put ./PyS60_3rdFP2+_accelerometer.py
!/bin/sh
obexftp -b 00:1d:5d:5b:53:fc -B 11 --chdir /E:/Python/ --put ./PyS60_3rdFP1_accelerometer.py
obexftp -b 00:1d:5d:5b:53:fc -B 11 --chdir /E:/Python/ --put ./PyS60_3rdFP2+_accelerometer.py
#!/usr/bin/env python
# -*- encoding: UTF8 -*-
# originally from Andreas Jakl, 2009 on <http://www.symbianresources.com/tutorials/general/python/Python.pdf>
# modified 2010 by Philipp Klaus <philipp.l.klaus AT web-dot-de>
import appuifw,e32,sensor
def get_sensor_data(status):
"Callback function for regular accelerometer status"
print "x: %d, y: %d, z: %d" % (status['data_1'], status['data_2'], status['data_3'])
def exit_key_handler():
# Disconnect from the sensor and exit
acc_sensor.disconnect()
app_lock.signal()
appuifw.app.exit_key_handler = exit_key_handler
# Retrieve the acceleration sensor
sensor_type = sensor.sensors()['AccSensor']
# Create an acceleration sensor object
acc_sensor = sensor.Sensor(sensor_type['id'],sensor_type['category'])
# Connect to the sensor
acc_sensor.connect(get_sensor_data)
# Wait for sensor data and the exit event
app_lock = e32.Ao_lock()
app_lock.wait()
#!/usr/bin/env python
# -*- encoding: UTF8 -*-
# originally from Andreas Jakl, 2009 on <http://www.symbianresources.com/tutorials/general/python/Python.pdf>
# modified 2010 by Philipp Klaus <philipp.l.klaus AT web-dot-de>
from sensor import *
import e32, time, appuifw
class DemoApp():
def __init__(self):
self.accelerometer = AccelerometerXYZAxisData(data_filter=LowPassFilter())
self.accelerometer.set_callback(data_callback=self.my_callback)
self.counter = 0
def my_callback(self):
# For stream sensor data the callback is hit 35 times per sec (On 5800).
# The device cannot handle resource hungry operations like print in the callback function
# for such high frequencies. A workaround is to sample the data as demonstrated below.
if self.counter % 5 == 0:
print "X:%s, Y:%s, Z:%s" % (self.accelerometer.x,
self.accelerometer.y, self.accelerometer.z)
self.counter = self.counter + 1
def run(self):
self.accelerometer.start_listening()
def exit_key_handler():
# Disconnect from the sensor and exit
global d
d.accelerometer.stop_listening()
print "Exiting Accelorometer"
app_lock.signal()
if __name__ == '__main__':
appuifw.app.exit_key_handler = exit_key_handler
d = DemoApp()
d.run()
app_lock = e32.Ao_lock()
app_lock.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment