Hi Gadgetoid,
I have received my little pHats and I’m starting to code to let them serve my purposes.
The idea is to use the Touch pHat to navigate to a menu and choose some apps, run them and show the results on the Scroll pHat HD.
I’m a beginner coder with Python and till now I have developed a script to handle the buttons and move through the menu and choose the apps (using a couple of global variables to check if you’re in an app or still in the main menu).
The code is the following one:
#!/usr/bin/python
# This Python file uses the following encoding: utf-8
import signal
import time
import touchphat as tp
import scrollphathd as sphd
def clear_sphd():
sphd.clear()
sphd.show()
def write_sphd(text):
clear_sphd()
sphd.set_brightness(0.4)
sphd.write_string(text + " ", x=17, y=0)
sphd.show()
def main_menu():
@tp.on_release('Back')
def handle_touch(event):
global main
global app
if app == 1:
print “You’re inside an app, to exit press B”
else:
#write_sphd(main)
main -= 1
print main
@tp.on_release('Enter')
def handle_touch():
global main
global app
if app == 1:
print "You’re inside an app, to exit press B"
else:
#write_sphd(main)
main += 1
print main
@tp.on_release('A')
def handle_touch(event):
global main
global app
if app == 0:
#write_sphd(main)
app = 1
print “You’re entering an app”
print “The application number is ” , main
else:
print “You’re already in the app number“, main
print “If you want to exit press B“
@tp.on_release('B')
def handle_touch(event):
global main
global app
if app == 1:
#write_sphd(main)
print “You’re exiting the app”
print “and going back to the main menu, where you left: ”, main
app = 0
else:
print “This is not allowed in the main menu”
print “Enter an app pressing the A button”
signal.pause()
main = 0
app = 0
main_menu()
Once inside an app, I’d like to run a function to display the app name on the scroll pHat (write_sphd(main) commented out now) and subsequently call another function to run the real app. But I’m facing an error (see below) and I can’t understand why.
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 231, in run
if self.todo() == False:
File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 457, in _poll
self._handle_alert()
File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 450, in _handle_alert
self._trigger_handler(x, inputs[x])
File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 466, in _trigger_handler
self.handlers[event][channel](channel, event)
TypeError: _handle_release() takes exactly 1 argument (2 given)
Please, could you help me to understand what I’m doing wrong?
Thanks in advance.
Kyashan