Source

wd_pys60 / fdbfischerpys60.py

# -*- coding: utf-8 -*-

import time
from wd_Edisplay import E
import sys
from fdbfischer import *

import appuifw
from graphics import *
import e32
import lightblue

	
class BlueSerial:
	def __init__(self,targetMac='00:11:03:07:05:92',targetPort=1):
		self.blue=lightblue.socket()
		self.blue.connect((targetMac,targetPort))
	def write(self,data):
		self.blue.send(data)
	def read(self,args):
		return self.blue.recv(args)
	def close(self):
		self.blue.close()
class fdbpys60(fdb):
	keyDic={
	49 : (4,1,"n"),
	50 : (4,1,"s"),
	52 : (4,2,"n"),
	53 : (4,2,"s"),
	55 : (4,3,"n"),
	56 : (4,3,"s"),
	42 : (4,4,"n"),
	48 : (4,4,"s"),
	}
	def dash_board_init(self):
		self.center=(160,120)
		self.Es=[]
		for i in range(1,9):
			self.Es.append(E(Enum=i))
		self._s=file("dummySerial","w+")
		self._s=BlueSerial()
		appuifw.app.screen='full'
		self.img=None
		self.myfont=u'Sans MT 936_S60'
		self.running=1
		self.canvas=appuifw.Canvas(
		event_callback=self._handle_event,
		redraw_callback=self._handle_redraw)
		appuifw.app.body=self.canvas
		self.img=Image.new(self.canvas.size)
		pass
	def _handle_redraw(self,rect):
		if self.img:
			self.img.clear(0)
			self.img.text((0,24),unicode(repr(self.board_controll_char)),0x008000,self.myfont)
			self.img.text((0,60),unicode(repr(self.input_char)),0x008000,self.myfont)
			for _E in self.Es:
				_E.state=int(self.get_input_char()[0][self.Es.index(_E)])
				self.img.point(_E.pos(),_E.color(),width=15)
				self.img.text(_E.text_pos(),unicode(str(_E.state)),_E.text_color())
			self.canvas.blit(self.img)
		pass
	def _handle_event(self,event):
		#print event
		self.img.clear(0)
		self._handle_redraw(())
		if event['type'] == appuifw.EEventKey:
			if event['keycode']==57:
				self.quit()
				return
			self.output(*self.keyDic[event['keycode']])
		elif event['type'] == appuifw.EEventKeyUp:
			self.all_stop()
		pass
	def quit(self):
		self._s.close()
		self.running=0


	def run(self,cycleTime=1):
		while self.running:
			#self.send(0x00)
			#self.recv=ord(self.blue.recv(1))
		   
			#self.canvas.text((0,24),unicode(hex(self.recv)),0x008000,self.myfont)
			#self._handle_redraw(())
			#time.sleep(cycleTime)
			#e32.ao_sleep(cycleTime)
			self.OPT()
			self._handle_redraw(())
			e32.ao_sleep(0.05)
			e32.ao_yield()
MAC=['00:11:03:07:05:92','00:11:04:29:02:65']
choices = [u"wd", u"yyb"]
index = appuifw.popup_menu(choices, u"Select:") 
s=fdbpys60(4)
#s=BlueFischer(targetMac='00:11:03:07:05:92',targetPort=1)
#s=BlueFischer(targetMac='00:11:04:29:02:65',targetPort=1)
s.run()