示例#1
0
# --------------------------------------------------------------------------
# Initialization

atexit.register(cleanExit)

lcd = Adafruit_CharLCDPlate()
lcd.begin(16, 2)
lcd.clear()

# Create volume bargraph custom characters (chars 0-5):
for i in range(6):
    bitmap = []
    bits = (255 << (5 - i)) & 0x1f
    for j in range(8):
        bitmap.append(bits)
    lcd.createChar(i, bitmap)

# Create up/down icon (char 6)
lcd.createChar(
    6,
    [0b00100, 0b01110, 0b11111, 0b00000, 0b00000, 0b11111, 0b01110, 0b00100])

# By default, char 7 is loaded in 'pause' state
lcd.createChar(7, charSevenBitmaps[1])

# Get last-used volume and station name from pickle file
try:
    f = open(PICKLEFILE, 'rb')
    v = pickle.load(f)
    f.close()
    volNew = v[0]
示例#2
0
class Display():

	CHAR_SET ={'default':
			   [
				[0b00000, # 0 <-
				 0b00010,
				 0b00110,
				 0b01110,
				 0b00110,
				 0b00010,
				 0b00000,
				 0b00000],
				[0b00000, # 1 ->
				 0b01000,
				 0b01100,
				 0b01110,
				 0b01100,
				 0b01000,
				 0b00000,
				 0b00000],
				[0b00000, # 2 ^
				 0b00000,
				 0b00100,
				 0b01110,
				 0b11111,
				 0b00000,
				 0b00000,
				 0b00000],
				[0b00000, # 3 v
				 0b00000,
				 0b11111,
				 0b01110,
				 0b00100,
				 0b00000,
				 0b00000,
				 0b00000],
				[0b00110, # 4 Degree
				 0b01001,
				 0b01001,
				 0b00110,
				 0b00000,
				 0b00000,
				 0b00000,
				 0b00000],
				[0b11111, # 5 Black Block
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111],
				[0b10101, # 6 Gray Block
				 0b01010,
				 0b10101,
				 0b01010,
				 0b10101,
				 0b01010,
				 0b10101,
				 0b01010],
				[0b10010, # 7 Light Gray Block
				 0b01001,
				 0b00100,
				 0b10010,
				 0b01001,
				 0b00100,
				 0b10010,
				 0b01001]
			   ],
			   'TemperatureExtend':
			   [
				[0b11111, # 0 Black Block
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111],
				[0b11111, # 1 Dark Gray Block
				 0b01101,
				 0b10110,
				 0b11011,
				 0b01101,
				 0b10110,
				 0b11011,
				 0b11111],
				[0b11111, # 2 Gray Block
				 0b01010,
				 0b10101,
				 0b01010,
				 0b10101,
				 0b01010,
				 0b10101,
				 0b11111],
				[0b11111, # 3 Light Gray Block
				 0b01001,
				 0b00100,
				 0b10010,
				 0b01001,
				 0b00100,
				 0b10010,
				 0b11111],
				[0b00111, # 4 Left
				 0b01000,
				 0b10000,
				 0b10000,
				 0b10000,
				 0b10000,
				 0b01000,
				 0b00111],
				[0b11100, # 5 Right
				 0b11110,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11111,
				 0b11110,
				 0b11100],
				[0b00110, # 6 Degree
				 0b01001,
				 0b01001,
				 0b00110,
				 0b00000,
				 0b00000,
				 0b00000,
				 0b00000]
			    ]}

	OPSET = (Adafruit_CharLCDPlate.LEFT,
			 Adafruit_CharLCDPlate.RIGHT,
			 Adafruit_CharLCDPlate.UP,
			 Adafruit_CharLCDPlate.DOWN,
			 Adafruit_CharLCDPlate.SELECT)

	OPLANG = {Adafruit_CharLCDPlate.LEFT:'LEFT',
			  Adafruit_CharLCDPlate.RIGHT:'RIGHT',
			  Adafruit_CharLCDPlate.UP:'UP',
			  Adafruit_CharLCDPlate.DOWN:'DOWN',
			  Adafruit_CharLCDPlate.SELECT:'SELECT'}

	MENU = {0:'     SELECT ' + chr(1) + '   \nSystem Info',
			1:'   ' + chr(0) + ' SELECT ' + chr(1) + '   \nNetwork Info',
			2:'   ' + chr(0) + ' SELECT ' + chr(1) + '   \nTemperature',
			3:'   ' + chr(0) + ' SELECT ' + chr(1) + '   \nDisk Info',
			4:'   ' + chr(0) + ' SELECT ' + chr(1) + '   \nSystem Tools',
			5:'   ' + chr(0) + ' SELECT ' + chr(1) + '   \nWeather',
			98:'   ' + chr(0) + ' SELECT ' + chr(1) + '   \nSetting',
			99:'   ' + chr(0) + ' SELECT     \nExit'}

	# State transition table
	STT = {
		# MENU_0 SYSTEM INFO
		0:{
			0:{
				Adafruit_CharLCDPlate.RIGHT : (1, 0),
				Adafruit_CharLCDPlate.SELECT: (0, 1)
			},
			# DEFAULT
			1:{
				Adafruit_CharLCDPlate.LEFT: (0, 0)
			}
		},
		# MENU_1 NETWORK INFO
		1:{
			0:{
				Adafruit_CharLCDPlate.LEFT  : (0, 0),
				Adafruit_CharLCDPlate.RIGHT : (2, 0),
				Adafruit_CharLCDPlate.SELECT: (1, 1)
			},
			# DEFAULT
			1:{
				Adafruit_CharLCDPlate.LEFT  : (1, 0),
				Adafruit_CharLCDPlate.UP    : (1, 2),
				Adafruit_CharLCDPlate.DOWN  : (1, 3)
			},
			# PAGE UP
			2:{
				Adafruit_CharLCDPlate.LEFT  : (1, 0),
				Adafruit_CharLCDPlate.UP    : (1, 2),
				Adafruit_CharLCDPlate.DOWN  : (1, 3)
			},
			# PAGE DOWN
			3:{
				Adafruit_CharLCDPlate.LEFT  : (1, 0),
				Adafruit_CharLCDPlate.UP    : (1, 2),
				Adafruit_CharLCDPlate.DOWN  : (1, 3)
			}
		},
		# MENU_2 TEMPERATURE
		2:{
			0:{
				Adafruit_CharLCDPlate.LEFT  : (1, 0),
				Adafruit_CharLCDPlate.RIGHT : (3, 0),
				Adafruit_CharLCDPlate.SELECT: (2, 1)
			},
			# DEFAULT
			1:{
				Adafruit_CharLCDPlate.LEFT: (2, 0)
			}
		},
		# MENU_3 DISK INFO
		3:{
			0:{
				Adafruit_CharLCDPlate.LEFT  : (2, 0),
				Adafruit_CharLCDPlate.RIGHT : (4, 0),
				Adafruit_CharLCDPlate.SELECT: (3, 1)
			},
			# DEFAULT
			1:{
				Adafruit_CharLCDPlate.LEFT: (3, 0)
			}
		},
		# MENU_4 SYSTEM TOOLS
		4:{
			0:{
				Adafruit_CharLCDPlate.LEFT  : (3, 0),
				Adafruit_CharLCDPlate.RIGHT : (5, 0),
				Adafruit_CharLCDPlate.SELECT: (4, 1)
			},
			# TOOL LIST
			1:{
				Adafruit_CharLCDPlate.LEFT  : (4, 0),
				Adafruit_CharLCDPlate.UP    : (4, 2),
				Adafruit_CharLCDPlate.DOWN  : (4, 3),
				Adafruit_CharLCDPlate.SELECT: (4, 4)
			},
			# TOOL LIST UP
			2:{
				Adafruit_CharLCDPlate.LEFT  : (4, 0),
				Adafruit_CharLCDPlate.UP    : (4, 2),
				Adafruit_CharLCDPlate.DOWN  : (4, 3),
				Adafruit_CharLCDPlate.SELECT: (4, 4)
			},
			# TOOL LIST DOWN
			3:{
				Adafruit_CharLCDPlate.LEFT  : (4, 0),
				Adafruit_CharLCDPlate.UP    : (4, 2),
				Adafruit_CharLCDPlate.DOWN  : (4, 3),
				Adafruit_CharLCDPlate.SELECT: (4, 4)
			},
			# TOOL DIALOG SELECT ONE
			4:{
				Adafruit_CharLCDPlate.SELECT: (4, 6),
				Adafruit_CharLCDPlate.RIGHT : (4, 5)
			},
			# TOOL DIALOG SELECT TWO
			5:{
				Adafruit_CharLCDPlate.SELECT: (4, 7),
				Adafruit_CharLCDPlate.LEFT  : (4, 4)
			},
			# TOOL DIALOG SELECT EXCUTE ONE
			6:{
				Adafruit_CharLCDPlate.SELECT: (4, 1)
			},
			# TOOL DIALOG SELECT EXCUTE TWO
			7:{
				Adafruit_CharLCDPlate.SELECT: (4, 1)
			}
		},
		# MENU_5 WEATHER
		5:{
			0:{
				Adafruit_CharLCDPlate.LEFT  : (4, 0),
				Adafruit_CharLCDPlate.RIGHT : (98, 0),
				Adafruit_CharLCDPlate.SELECT: (5, 1)
			},
			# DEFAULT
			1:{
				Adafruit_CharLCDPlate.LEFT: (5, 0)
			}
		},
		# MENU_98 SETTING
		98:{
			0:{
				Adafruit_CharLCDPlate.LEFT  : (4, 0),
				Adafruit_CharLCDPlate.RIGHT : (99, 0),
				Adafruit_CharLCDPlate.SELECT: (98, 1)
			},
			# SETTING LIST
			1:{
				Adafruit_CharLCDPlate.LEFT  : (98, 0),
				Adafruit_CharLCDPlate.UP    : (98, 2),
				Adafruit_CharLCDPlate.DOWN  : (98, 3),
				Adafruit_CharLCDPlate.SELECT: (98, 4)
			},
			# SETTING LIST UP
			2:{
				Adafruit_CharLCDPlate.LEFT  : (98, 0),
				Adafruit_CharLCDPlate.UP    : (98, 2),
				Adafruit_CharLCDPlate.DOWN  : (98, 3),
				Adafruit_CharLCDPlate.SELECT: (98, 4)
			},
			# SETTING LIST DOWN
			3:{
				Adafruit_CharLCDPlate.LEFT  : (98, 0),
				Adafruit_CharLCDPlate.UP    : (98, 2),
				Adafruit_CharLCDPlate.DOWN  : (98, 3),
				Adafruit_CharLCDPlate.SELECT: (98, 4)
			},
			# SETTING DIALOG SELECT ONE
			4:{
				Adafruit_CharLCDPlate.SELECT: (98, 6),
				Adafruit_CharLCDPlate.RIGHT : (98, 5)
			},
			# SETTING DIALOG SELECT TWO
			5:{
				Adafruit_CharLCDPlate.SELECT: (98, 7),
				Adafruit_CharLCDPlate.LEFT  : (98, 4)
			},
			# SETTING DIALOG SELECT EXCUTE ONE
			6:{
				Adafruit_CharLCDPlate.SELECT: (98, 1)
			},
			# SETTING DIALOG SELECT EXCUTE TWO
			7:{
				Adafruit_CharLCDPlate.SELECT: (98, 1)
			}
		},
		# MENU_99 EXIT
		99:{
			0:{
				Adafruit_CharLCDPlate.LEFT  : (98, 0),
				Adafruit_CharLCDPlate.SELECT: (99, 1)
			},
			# NO
			1:{
				Adafruit_CharLCDPlate.SELECT: (99, 0),
				Adafruit_CharLCDPlate.RIGHT : (99, 2)
			},
			# YES
			2:{
				Adafruit_CharLCDPlate.SELECT: (99, 3),
				Adafruit_CharLCDPlate.LEFT  : (99, 1)
			},
			# EXIT
			3:{
			}
		}
	}
	
	def __init__(self, curMenu = 0, debug = False):
		# Init EventMethods
		self.AUTO_REFRESH_PERIOD = 5
		self.EventMethods = {
			'EventMethods_0_1': self.EventMethods_SystemInfo,

			'EventMethods_1_1': self.EventMethods_NetworkInfo,
			'EventMethods_1_2': self.EventMethods_NetworkInfo_Up,
			'EventMethods_1_3': self.EventMethods_NetworkInfo_Down,

			'EventMethods_2_1': self.EventMethods_Temperature,

			'EventMethods_3_1': self.EventMethods_DiskInfo,

			'EventMethods_4_1': self.EventMethods_Tools,
			'EventMethods_4_2': self.EventMethods_Tools_Up,
			'EventMethods_4_3': self.EventMethods_Tools_Down,
			'EventMethods_4_4': self.EventMethods_Tools_One,
			'EventMethods_4_5': self.EventMethods_Tools_Two,
			'EventMethods_4_6': self.EventMethods_Tools_Excute_One,
			'EventMethods_4_7': self.EventMethods_Tools_Excute_Two,

			'EventMethods_5_1': self.EventMethods_Weather,

			'EventMethods_98_1': self.EventMethods_Setting,
			'EventMethods_98_2': self.EventMethods_Setting_Up,
			'EventMethods_98_3': self.EventMethods_Setting_Down,
			'EventMethods_98_4': self.EventMethods_Setting_One,
			'EventMethods_98_5': self.EventMethods_Setting_Two,
			'EventMethods_98_6': self.EventMethods_Setting_Excute_One,
			'EventMethods_98_7': self.EventMethods_Setting_Excute_Two,

			'EventMethods_99_1': self.EventMethods_Exit_No,
			'EventMethods_99_2': self.EventMethods_Exit_Yes,
			'EventMethods_99_3': self.EventMethods_Exit
		}
		self.TOOLS_NUM  = 2
		self.TOOLS_LIST = (
			{'name':'Reboot', 'handle':self.EventMethods_Reboot },
			{'name':'Power Off', 'handle':self.EventMethods_PowerOff }
		)
		self.SETTING_NUM  = 3
		self.SETTING_LIST = (
			{'name':'Backlight', 'handle':self.EventMethods_Backlight },
			{'name':'Auto Refresh', 'handle':self.EventMethods_AutoRefresh },
			{'name':'Weather Report', 'handle':self.EventMethods_Backlight }
		)
		# Init LCD
		self.lcd = Adafruit_CharLCDPlate()
		self.lcd.begin(16, 2)
		self.lcd.backlight(Adafruit_CharLCDPlate.RED)
		sleep(1)
		self.lcd.backlight(Adafruit_CharLCDPlate.GREEN)
		sleep(1)
		self.lcd.backlight(Adafruit_CharLCDPlate.BLUE)
		sleep(1)
		self.lcd.backlight(Adafruit_CharLCDPlate.ON)
		# Init Char Set
		self.loadCharset()
		# Set default screen
		self.curMenu = curMenu
		self.curPage = 0
		self.debug = debug
		# Init AutoRefeashMethods
		self.AutoRefreshMethod = None
		thread.start_new_thread(self.autoRefresh, ())

	def loadCharset(self, charset = 'default'):
		for i, item in enumerate(self.CHAR_SET[charset]):
			self.lcd.createChar(i, item)

	def autoRefresh(self):
		if(self.debug):
			print 'Auto refresh thread started!'
		while True:
			if self.AutoRefreshMethod != None:
				try:
					self.EventMethods[self.AutoRefreshMethod]()
				except Exception, e:
					if(self.debug):
						print str(e)
				if(self.debug):
					print self.AutoRefreshMethod, ' fired!'
			sleep(self.AUTO_REFRESH_PERIOD)
示例#3
0
文件: fogonmain.py 项目: fogpi/FogPi
rainsensor = rainsense.rainsense(
    12, 1, 15
)  # rainsensor, 1st # is seconds per polling period, 2nd # is number of ticks to signify rain, 3rd # is GPIO channel(board)
# Make the LCD messaging queue
lcd_queue = Queue()

# Buttons for the LCD
NONE = 0x00
LEFT = 0x10
UP = 0x08
DOWN = 0x04
RIGHT = 0x02
SELECT = 0x01

# up/down custom character
lcd.createChar(0, [0b00100, 0b01110, 0b11111, 0b00000, 0b00000, 0b11111, 0b01110, 0b00100])

# Custom characters for the LCD
# This will generate the FogPi logo
lcd.createChar(1, [0b11100, 0b10000, 0b11100, 0b10000, 0b10111, 0b10101, 0b00111, 0b00000])

lcd.createChar(2, [0b11100, 0b10100, 0b11100, 0b00111, 0b00101, 0b11111, 0b00100, 0b00100])

lcd.createChar(3, [0b00000, 0b00000, 0b00000, 0b10000, 0b00000, 0b10000, 0b10000, 0b10000])

lcd.createChar(4, [0b10100, 0b10100, 0b10100, 0b11100, 0b00011, 0b00100, 0b00100, 0b00011])

lcd.createChar(5, [0b01100, 0b10000, 0b01000, 0b00100, 0b11011, 0b00100, 0b00100, 0b00011])

GPIO.setwarnings(False)  # shuts up GPIO warnings
GPIO.setmode(GPIO.BOARD)  # sets gpio to board mode
示例#4
0
left = 16

FNULL = open(os.devnull, 'w')

lcd = Adafruit_CharLCDPlate()

play_char = [0b10000, 0b11000, 0b11100, 0b11000, 0b10000, 0b0, 0b0, 0b0]
rand_char = [0b0, 0b0, 0b0, 0b0, 0b111, 0b101, 0b110, 0b101]
pr_char = []
arrow = [0b100, 0b1110, 0b11111, 0b0, 0b0, 0b11111, 0b1110, 0b100]
sun = [0b1001, 0b10010, 0b11000, 0b11011, 0b11000, 0b10010, 0b1001, 0b1000]
moon = [0b0, 0b1110, 0b111, 0b11, 0b111, 0b1110, 0b0, 0b0]
for i in range(8):
    pr_char.append(play_char[i] | rand_char[i])

lcd.createChar(0, play_char)
lcd.createChar(1, rand_char)
lcd.createChar(2, pr_char)
lcd.createChar(3, arrow)
lcd.createChar(4, sun)
lcd.createChar(5, moon)

lcd_string_prev = ''
wait_time = 1
alph = list(string.ascii_uppercase)
alph.append("Other")
type_choice = ["Artist", "Playlist"]
ip_settings = ["Wifi", "Ethernet"]
settings = ["Set hour:", "Set minute:"]
mpc_settings = ["Play", "Pause", "Stop", "Next", "Prev", "Random", "Sleep", "Cancel Sleep", "Load"]
menus = ["Set Alarm", "Set Backlight", "Power Management", "IP Addresses"]
示例#5
0
class Display():

	BARRIER = [
			  [[0b00000, # Frame 0
			    0b00000,
			    0b00000,
			    0b00100,
			    0b01110,
			    0b01110,
			    0b11111,
			    0b11111],
			   [0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]],
			  [[0b00000, # Frame 1 in
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000],
			   [0b00000,
			    0b00000,
			    0b00000,
			    0b01000,
			    0b11100,
			    0b11100,
			    0b11110,
			    0b11110]],
			  [[0b00000, # Frame 1
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00001,
			    0b00001],
			   [0b00000,
			    0b00000,
			    0b00000,
			    0b10000,
			    0b11000,
			    0b11000,
			    0b11100,
			    0b11100]],
			  [[0b00000, # Frame 2 in
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00001,
			    0b00001,
			    0b00011,
			    0b00011],
			   [0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b10000,
			    0b10000,
			    0b11000,
			    0b11000]],
			  [[0b00000, # Frame 2
			    0b00000,
			    0b00000,
			    0b00001,
			    0b00011,
			    0b00011,
			    0b00111,
			    0b00111],
			   [0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b10000,
			    0b10000]],
			  [[0b00000, # Frame 3
			    0b00000,
			    0b00000,
			    0b00010,
			    0b00111,
			    0b00111,
			    0b01111,
			    0b01111],
			   [0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]]]

	RUNNER = [
			  [[0b00000, # Frame 0
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000],
			   [0b00000, 
			    0b00000,
			    0b00000,
			    0b01110,
			    0b11111,
			    0b10101,
			    0b11111,
			    0b01110]],
			  [[0b00000, # Frame 1
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000],
			   [0b00000, 
			    0b00000,
			    0b00000,
			    0b01110,
			    0b11111,
			    0b10101,
			    0b11111,
			    0b01110]],
			  [[0b00000, # Frame 2
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000],
			   [0b00100, 
			    0b01110,
			    0b11111,
			    0b10101,
			    0b11111,
			    0b01110,
			    0b01110,
			    0b00000]],
			  [[0b00000, # Frame 3
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b01110],
			   [0b11111, 
			    0b10101,
			    0b11111,
			    0b01110,
			    0b00100,
			    0b00000,
			    0b00000,
			    0b00000]],
			  [[0b00000, # Frame 4
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b01110,
			    0b01110,
			    0b10101],
			   [0b11111, 
			    0b01110,
			    0b00100,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]],
			  [[0b00000, # Frame 5
			    0b00000,
			    0b00000,
			    0b00000,
			    0b01110,
			    0b11111,
			    0b10101,
			    0b11111],
			   [0b01110, 
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]],
			  [[0b00000, # Frame 6
			    0b00000,
			    0b01110,
			    0b11111,
			    0b10101,
			    0b11111,
			    0b01110,
			    0b01110],
			   [0b00000, 
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]],
			  [[0b00000, # Frame 7
			    0b01110,
			    0b10101,
			    0b11111,
			    0b01110,
			    0b00000,
			    0b00000,
			    0b00000],
			   [0b00000, 
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]],
			  [[0b01110, # Frame 8
			    0b10101,
			    0b11111,
			    0b01110,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000],
			   [0b00000, 
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]],
			  [[0b11111, # Frame 9
			    0b10101,
			    0b01110,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000],
			   [0b00000, 
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]]]

	def __init__(self):
		# Init LCD 
		self.lcdString = [[' ' for col in range(Layer.WIDTH)] for row in range(Layer.HEIGHT)]
		# Init layer
		self.canvas  = Layer()
		self.runner  = Layer()
		self.barrier = Layer()
		# Init pixelSet
		self.pixelSet = [list(Layer.EMPTY) for i in range(8)]
		# Init LCD
		self.lcd = Adafruit_CharLCDPlate()
		self.lcd.begin(16, 2)
		self.lcd.backlight(Adafruit_CharLCDPlate.ON)
		# Init Game
		self.game = Game(self.lcd)

	def mergeLayers(self):
		# Merge layer to canvas
		#self.canvas.mergeLayer(self.runner).mergeLayer(self.barrier)
		self.canvas.mergeLayer(self.barrier)
		self.canvas.mergeLayer(self.runner)


	def updateLcdString(self):
		# Update game screen
		count = 0
		for row in range(Layer.HEIGHT):
			for col in range(Layer.WIDTH):
				if self.canvas.bitmap[row][col] == Layer.EMPTY:
					self.lcdString[row][col] = ' '
				else:
					index = self.findInPixelSet(self.canvas.bitmap[row][col], count)
					#print '[', str(row), '][', str(col), ']: ' + str(index)
					#print self.canvas.bitmap[row][col]
					if index == -1:
						self.pixelSet[count] = list(self.canvas.bitmap[row][col])
						self.lcdString[row][col] = chr(count)
						count += 1
					else:
						self.lcdString[row][col] = chr(index)

		# Update score board
		score = str(self.game.score)
		index = 0
		for i in range(Layer.WIDTH - len(score), Layer.WIDTH):
			self.lcdString[0][i] = score[index]
			index += 1
		

	def loadCharset(self):
		for i, item in enumerate(self.pixelSet):
			self.lcd.createChar(i, item)

	def findInPixelSet(self, pixel, count):
		for i in range(count):
			if self.pixelSet[i] == pixel:
				return i
		return -1

	def draw(self):
		if self.game.state == Game.STATE_START:
			self.lcd.message('Press SELECT to\n  START GAME    ')
		elif self.game.state == Game.STATE_END:
			self.lcd.message('  SCORE ' + str(self.game.score) + '\n   GAME  OVER   ')
		else:
			line_1 = ''.join(self.lcdString[0])
			line_2 = ''.join(self.lcdString[1])
			
			self.lcd.message(line_1 + '\n' + line_2)
			self.loadCharset()

	def drawBarriers(self):
		for barrier in self.game.barriers:
			self.barrier.drawPointX(barrier[1], barrier[0], self.game.frame, self.BARRIER[self.game.frame])

	def drawRunner(self):
		self.runner.drawPointY(1, 0, self.RUNNER[self.game.runner])

	def run(self):
		while True:
			self.game.tick()
			if self.game.state == Game.STATE_RUNNING:
				self.drawBarriers()
				self.drawRunner()
				self.mergeLayers()
				self.updateLcdString()

			self.game.gameOver(self.barrier.bitmap[1][1], self.runner.bitmap[1][1])
			self.draw()
			
			self.canvas  = Layer()
			self.runner  = Layer()
			self.barrier = Layer()
			sleep(.03)
if len(sys.argv) >= 2:
    sock_path = sys.argv[1]
else:
    sock_path = "/run/lcd/socket"

print('Use socket : ' + sock_path)

# Initialize the LCD plate.  Should auto-detect correct I2C bus.  If not,
# pass '0' for early 256 MB Model B boards or '1' for all later versions
lcd = Adafruit_CharLCDPlate()
atexit.register(lcd.stop)
lcd.backlight(True)


lcd.createChar(0, Sprites.horizontalLines)

# Clear display and show greeting, pause 1 sec
lcd.clear()
lcd.message("Adafruit RGB LCD\nPlate w/Keypad!\x00")
sleep(1)

# Cycle through backlight colors
col = (lcd.RED , lcd.YELLOW, lcd.GREEN, lcd.TEAL,
       lcd.BLUE, lcd.VIOLET, lcd.WHITE, lcd.OFF)
for c in col:
    lcd.ledRGB(c)
    sleep(.5)

# Poll buttons, display message & set backlight accordingly
buttonState = 0
示例#7
0
# --------------------------------------------------------------------------
# Initialization

atexit.register(cleanExit)

lcd = Adafruit_CharLCDPlate()
lcd.begin(16, 2)
lcd.clear()

# Create volume bargraph custom characters (chars 0-5):
for i in range(6):
    bitmap = []
    bits   = (255 << (5 - i)) & 0x1f
    for j in range(8): bitmap.append(bits)
    lcd.createChar(i, bitmap)

# Create up/down icon (char 6)
lcd.createChar(6,
  [0b00100,
   0b01110,
   0b11111,
   0b00000,
   0b00000,
   0b11111,
   0b01110,
   0b00100])

# By default, char 7 is loaded in 'pause' state
lcd.createChar(7, charSevenBitmaps[1])
示例#8
0
文件: fippi.py 项目: fsargent/Fippi
        time.sleep(30)
        exit(0)
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8', 0))
        lcd.backlight(lcd.GREEN)
        lcd.backlight(lcd.ON)
        lcd.message('My IP address is\n' + s.getsockname()[0])
        time.sleep(5)
        break         # Success -- let's hear some music!
    except:
        time.sleep(1)  # Pause a moment, keep trying


# create some custom characters
lcd.createChar(1, [2, 3, 2, 2, 14, 30, 12, 0])
lcd.createChar(2, [0, 1, 3, 22, 28, 8, 0, 0])
lcd.createChar(3, [0, 14, 21, 23, 17, 14, 0, 0])
lcd.createChar(4, [31, 17, 10, 4, 10, 17, 31, 0])
lcd.createChar(5, [8, 12, 10, 9, 10, 12, 8, 0])
lcd.createChar(6, [2, 6, 10, 18, 10, 6, 2, 0])
lcd.createChar(7, [31, 17, 21, 21, 21, 21, 17, 31])
lcd.createChar(8, [0, 0, 10, 21, 17, 10, 4, 0])  # Heart
lcd.createChar(9, [2, 3, 2, 2, 14, 30, 12, 0])  # Musical note


# Show button state.
lcd.clear()
lcd.backlight(lcd.VIOLET)
lcd.message('I \x08 you Jenni!\nPress a button!')
示例#9
0
# -*- coding: utf-8 -*-

from time import sleep
import copy
import atexit
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
import convertAccentCharutf8
from GlyphSprites import Sprites

# Initialize the LCD plate.  Should auto-detect correct I2C bus.  If not,
# pass '0' for early 256 MB Model B boards or '1' for all later versions
lcd = Adafruit_CharLCDPlate()
atexit.register(lcd.stop)
lcd.backlight(True)

lcd.createChar(0, Sprites.horizontalLines)

# Clear display and show greeting, pause 1 sec
lcd.clear()
lcd.message("Adafruit RGB LCD\nPlate w/Keypad!\x00")
sleep(1)

# Cycle through backlight colors
col = (lcd.RED, lcd.YELLOW, lcd.GREEN, lcd.TEAL, lcd.BLUE, lcd.VIOLET,
       lcd.WHITE, lcd.OFF)
for c in col:
    lcd.ledRGB(c)
    sleep(.5)

# Poll buttons, display message & set backlight accordingly
btn = ((lcd.LEFT, u'\x00Vin très rouge à boire dans le vignoble du chateau',
示例#10
0
class Display():

    CHAR_SET = {
        'default': [
            [
                0b00000,  # 0 <-
                0b00010,
                0b00110,
                0b01110,
                0b00110,
                0b00010,
                0b00000,
                0b00000
            ],
            [
                0b00000,  # 1 ->
                0b01000,
                0b01100,
                0b01110,
                0b01100,
                0b01000,
                0b00000,
                0b00000
            ],
            [
                0b00000,  # 2 ^
                0b00000,
                0b00100,
                0b01110,
                0b11111,
                0b00000,
                0b00000,
                0b00000
            ],
            [
                0b00000,  # 3 v
                0b00000,
                0b11111,
                0b01110,
                0b00100,
                0b00000,
                0b00000,
                0b00000
            ],
            [
                0b00110,  # 4 Degree
                0b01001,
                0b01001,
                0b00110,
                0b00000,
                0b00000,
                0b00000,
                0b00000
            ],
            [
                0b11111,  # 5 Black Block
                0b11111,
                0b11111,
                0b11111,
                0b11111,
                0b11111,
                0b11111,
                0b11111
            ],
            [
                0b10101,  # 6 Gray Block
                0b01010,
                0b10101,
                0b01010,
                0b10101,
                0b01010,
                0b10101,
                0b01010
            ],
            [
                0b10010,  # 7 Light Gray Block
                0b01001,
                0b00100,
                0b10010,
                0b01001,
                0b00100,
                0b10010,
                0b01001
            ]
        ],
        'TemperatureExtend': [
            [
                0b11111,  # 0 Black Block
                0b11111,
                0b11111,
                0b11111,
                0b11111,
                0b11111,
                0b11111,
                0b11111
            ],
            [
                0b11111,  # 1 Dark Gray Block
                0b01101,
                0b10110,
                0b11011,
                0b01101,
                0b10110,
                0b11011,
                0b11111
            ],
            [
                0b11111,  # 2 Gray Block
                0b01010,
                0b10101,
                0b01010,
                0b10101,
                0b01010,
                0b10101,
                0b11111
            ],
            [
                0b11111,  # 3 Light Gray Block
                0b01001,
                0b00100,
                0b10010,
                0b01001,
                0b00100,
                0b10010,
                0b11111
            ],
            [
                0b00111,  # 4 Left
                0b01000,
                0b10000,
                0b10000,
                0b10000,
                0b10000,
                0b01000,
                0b00111
            ],
            [
                0b11100,  # 5 Right
                0b11110,
                0b11111,
                0b11111,
                0b11111,
                0b11111,
                0b11110,
                0b11100
            ],
            [
                0b00110,  # 6 Degree
                0b01001,
                0b01001,
                0b00110,
                0b00000,
                0b00000,
                0b00000,
                0b00000
            ]
        ]
    }

    OPSET = (Adafruit_CharLCDPlate.LEFT, Adafruit_CharLCDPlate.RIGHT,
             Adafruit_CharLCDPlate.UP, Adafruit_CharLCDPlate.DOWN,
             Adafruit_CharLCDPlate.SELECT)

    OPLANG = {
        Adafruit_CharLCDPlate.LEFT: 'LEFT',
        Adafruit_CharLCDPlate.RIGHT: 'RIGHT',
        Adafruit_CharLCDPlate.UP: 'UP',
        Adafruit_CharLCDPlate.DOWN: 'DOWN',
        Adafruit_CharLCDPlate.SELECT: 'SELECT'
    }

    MENU = {
        0: '     SELECT ' + chr(1) + '   \nSystem Info',
        1: '   ' + chr(0) + ' SELECT ' + chr(1) + '   \nNetwork Info',
        2: '   ' + chr(0) + ' SELECT ' + chr(1) + '   \nTemperature',
        3: '   ' + chr(0) + ' SELECT ' + chr(1) + '   \nDisk Info',
        4: '   ' + chr(0) + ' SELECT ' + chr(1) + '   \nSystem Tools',
        5: '   ' + chr(0) + ' SELECT ' + chr(1) + '   \nWeather',
        98: '   ' + chr(0) + ' SELECT ' + chr(1) + '   \nSetting',
        99: '   ' + chr(0) + ' SELECT     \nExit'
    }

    # State transition table
    STT = {
        # MENU_0 SYSTEM INFO
        0: {
            0: {
                Adafruit_CharLCDPlate.RIGHT: (1, 0),
                Adafruit_CharLCDPlate.SELECT: (0, 1)
            },
            # DEFAULT
            1: {
                Adafruit_CharLCDPlate.LEFT: (0, 0)
            }
        },
        # MENU_1 NETWORK INFO
        1: {
            0: {
                Adafruit_CharLCDPlate.LEFT: (0, 0),
                Adafruit_CharLCDPlate.RIGHT: (2, 0),
                Adafruit_CharLCDPlate.SELECT: (1, 1)
            },
            # DEFAULT
            1: {
                Adafruit_CharLCDPlate.LEFT: (1, 0),
                Adafruit_CharLCDPlate.UP: (1, 2),
                Adafruit_CharLCDPlate.DOWN: (1, 3)
            },
            # PAGE UP
            2: {
                Adafruit_CharLCDPlate.LEFT: (1, 0),
                Adafruit_CharLCDPlate.UP: (1, 2),
                Adafruit_CharLCDPlate.DOWN: (1, 3)
            },
            # PAGE DOWN
            3: {
                Adafruit_CharLCDPlate.LEFT: (1, 0),
                Adafruit_CharLCDPlate.UP: (1, 2),
                Adafruit_CharLCDPlate.DOWN: (1, 3)
            }
        },
        # MENU_2 TEMPERATURE
        2: {
            0: {
                Adafruit_CharLCDPlate.LEFT: (1, 0),
                Adafruit_CharLCDPlate.RIGHT: (3, 0),
                Adafruit_CharLCDPlate.SELECT: (2, 1)
            },
            # DEFAULT
            1: {
                Adafruit_CharLCDPlate.LEFT: (2, 0)
            }
        },
        # MENU_3 DISK INFO
        3: {
            0: {
                Adafruit_CharLCDPlate.LEFT: (2, 0),
                Adafruit_CharLCDPlate.RIGHT: (4, 0),
                Adafruit_CharLCDPlate.SELECT: (3, 1)
            },
            # DEFAULT
            1: {
                Adafruit_CharLCDPlate.LEFT: (3, 0)
            }
        },
        # MENU_4 SYSTEM TOOLS
        4: {
            0: {
                Adafruit_CharLCDPlate.LEFT: (3, 0),
                Adafruit_CharLCDPlate.RIGHT: (5, 0),
                Adafruit_CharLCDPlate.SELECT: (4, 1)
            },
            # TOOL LIST
            1: {
                Adafruit_CharLCDPlate.LEFT: (4, 0),
                Adafruit_CharLCDPlate.UP: (4, 2),
                Adafruit_CharLCDPlate.DOWN: (4, 3),
                Adafruit_CharLCDPlate.SELECT: (4, 4)
            },
            # TOOL LIST UP
            2: {
                Adafruit_CharLCDPlate.LEFT: (4, 0),
                Adafruit_CharLCDPlate.UP: (4, 2),
                Adafruit_CharLCDPlate.DOWN: (4, 3),
                Adafruit_CharLCDPlate.SELECT: (4, 4)
            },
            # TOOL LIST DOWN
            3: {
                Adafruit_CharLCDPlate.LEFT: (4, 0),
                Adafruit_CharLCDPlate.UP: (4, 2),
                Adafruit_CharLCDPlate.DOWN: (4, 3),
                Adafruit_CharLCDPlate.SELECT: (4, 4)
            },
            # TOOL DIALOG SELECT ONE
            4: {
                Adafruit_CharLCDPlate.SELECT: (4, 6),
                Adafruit_CharLCDPlate.RIGHT: (4, 5)
            },
            # TOOL DIALOG SELECT TWO
            5: {
                Adafruit_CharLCDPlate.SELECT: (4, 7),
                Adafruit_CharLCDPlate.LEFT: (4, 4)
            },
            # TOOL DIALOG SELECT EXCUTE ONE
            6: {
                Adafruit_CharLCDPlate.SELECT: (4, 1)
            },
            # TOOL DIALOG SELECT EXCUTE TWO
            7: {
                Adafruit_CharLCDPlate.SELECT: (4, 1)
            }
        },
        # MENU_5 WEATHER
        5: {
            0: {
                Adafruit_CharLCDPlate.LEFT: (4, 0),
                Adafruit_CharLCDPlate.RIGHT: (98, 0),
                Adafruit_CharLCDPlate.SELECT: (5, 1)
            },
            # DEFAULT
            1: {
                Adafruit_CharLCDPlate.LEFT: (5, 0)
            }
        },
        # MENU_98 SETTING
        98: {
            0: {
                Adafruit_CharLCDPlate.LEFT: (4, 0),
                Adafruit_CharLCDPlate.RIGHT: (99, 0),
                Adafruit_CharLCDPlate.SELECT: (98, 1)
            },
            # SETTING LIST
            1: {
                Adafruit_CharLCDPlate.LEFT: (98, 0),
                Adafruit_CharLCDPlate.UP: (98, 2),
                Adafruit_CharLCDPlate.DOWN: (98, 3),
                Adafruit_CharLCDPlate.SELECT: (98, 4)
            },
            # SETTING LIST UP
            2: {
                Adafruit_CharLCDPlate.LEFT: (98, 0),
                Adafruit_CharLCDPlate.UP: (98, 2),
                Adafruit_CharLCDPlate.DOWN: (98, 3),
                Adafruit_CharLCDPlate.SELECT: (98, 4)
            },
            # SETTING LIST DOWN
            3: {
                Adafruit_CharLCDPlate.LEFT: (98, 0),
                Adafruit_CharLCDPlate.UP: (98, 2),
                Adafruit_CharLCDPlate.DOWN: (98, 3),
                Adafruit_CharLCDPlate.SELECT: (98, 4)
            },
            # SETTING DIALOG SELECT ONE
            4: {
                Adafruit_CharLCDPlate.SELECT: (98, 6),
                Adafruit_CharLCDPlate.RIGHT: (98, 5)
            },
            # SETTING DIALOG SELECT TWO
            5: {
                Adafruit_CharLCDPlate.SELECT: (98, 7),
                Adafruit_CharLCDPlate.LEFT: (98, 4)
            },
            # SETTING DIALOG SELECT EXCUTE ONE
            6: {
                Adafruit_CharLCDPlate.SELECT: (98, 1)
            },
            # SETTING DIALOG SELECT EXCUTE TWO
            7: {
                Adafruit_CharLCDPlate.SELECT: (98, 1)
            }
        },
        # MENU_99 EXIT
        99: {
            0: {
                Adafruit_CharLCDPlate.LEFT: (98, 0),
                Adafruit_CharLCDPlate.SELECT: (99, 1)
            },
            # NO
            1: {
                Adafruit_CharLCDPlate.SELECT: (99, 0),
                Adafruit_CharLCDPlate.RIGHT: (99, 2)
            },
            # YES
            2: {
                Adafruit_CharLCDPlate.SELECT: (99, 3),
                Adafruit_CharLCDPlate.LEFT: (99, 1)
            },
            # EXIT
            3: {}
        }
    }

    def __init__(self, curMenu=0, debug=False):
        # Init EventMethods
        self.AUTO_REFRESH_PERIOD = 5
        self.EventMethods = {
            'EventMethods_0_1': self.EventMethods_SystemInfo,
            'EventMethods_1_1': self.EventMethods_NetworkInfo,
            'EventMethods_1_2': self.EventMethods_NetworkInfo_Up,
            'EventMethods_1_3': self.EventMethods_NetworkInfo_Down,
            'EventMethods_2_1': self.EventMethods_Temperature,
            'EventMethods_3_1': self.EventMethods_DiskInfo,
            'EventMethods_4_1': self.EventMethods_Tools,
            'EventMethods_4_2': self.EventMethods_Tools_Up,
            'EventMethods_4_3': self.EventMethods_Tools_Down,
            'EventMethods_4_4': self.EventMethods_Tools_One,
            'EventMethods_4_5': self.EventMethods_Tools_Two,
            'EventMethods_4_6': self.EventMethods_Tools_Excute_One,
            'EventMethods_4_7': self.EventMethods_Tools_Excute_Two,
            'EventMethods_5_1': self.EventMethods_Weather,
            'EventMethods_98_1': self.EventMethods_Setting,
            'EventMethods_98_2': self.EventMethods_Setting_Up,
            'EventMethods_98_3': self.EventMethods_Setting_Down,
            'EventMethods_98_4': self.EventMethods_Setting_One,
            'EventMethods_98_5': self.EventMethods_Setting_Two,
            'EventMethods_98_6': self.EventMethods_Setting_Excute_One,
            'EventMethods_98_7': self.EventMethods_Setting_Excute_Two,
            'EventMethods_99_1': self.EventMethods_Exit_No,
            'EventMethods_99_2': self.EventMethods_Exit_Yes,
            'EventMethods_99_3': self.EventMethods_Exit
        }
        self.TOOLS_NUM = 2
        self.TOOLS_LIST = ({
            'name': 'Reboot',
            'handle': self.EventMethods_Reboot
        }, {
            'name': 'Power Off',
            'handle': self.EventMethods_PowerOff
        })
        self.SETTING_NUM = 3
        self.SETTING_LIST = ({
            'name': 'Backlight',
            'handle': self.EventMethods_Backlight
        }, {
            'name': 'Auto Refresh',
            'handle': self.EventMethods_AutoRefresh
        }, {
            'name': 'Weather Report',
            'handle': self.EventMethods_Backlight
        })
        # Init LCD
        self.lcd = Adafruit_CharLCDPlate()
        self.lcd.begin(16, 2)
        self.lcd.backlight(Adafruit_CharLCDPlate.RED)
        sleep(1)
        self.lcd.backlight(Adafruit_CharLCDPlate.GREEN)
        sleep(1)
        self.lcd.backlight(Adafruit_CharLCDPlate.BLUE)
        sleep(1)
        self.lcd.backlight(Adafruit_CharLCDPlate.ON)
        # Init Char Set
        self.loadCharset()
        # Set default screen
        self.curMenu = curMenu
        self.curPage = 0
        self.debug = debug
        # Init AutoRefeashMethods
        self.AutoRefreshMethod = None
        thread.start_new_thread(self.autoRefresh, ())

    def loadCharset(self, charset='default'):
        for i, item in enumerate(self.CHAR_SET[charset]):
            self.lcd.createChar(i, item)

    def autoRefresh(self):
        if (self.debug):
            print 'Auto refresh thread started!'
        while True:
            if self.AutoRefreshMethod != None:
                try:
                    self.EventMethods[self.AutoRefreshMethod]()
                except Exception, e:
                    if (self.debug):
                        print str(e)
                if (self.debug):
                    print self.AutoRefreshMethod, ' fired!'
            sleep(self.AUTO_REFRESH_PERIOD)
示例#11
0
TimeChar =   [0b00000,0b01110,0b10101,0b10111,0b10001,0b01110,0b00000]
IdleChar =   [0b00000,0b11011,0b01110,0b00100,0b01110,0b11011,0b00000]
FailedChar = [0b00000,0b01110,0b10001,0b11011,0b10101,0b01010,0b01110]
JobChar =    [0b00000,0b00001,0b00011,0b10110,0b11100,0b01000,0b00000]
ExtrChar =   [0b11111,0b01110,0b01110,0b01110,0b01110,0b01110,0b00100]
BedChar =    [0b00000,0b11111,0b10001,0b10001,0b10001,0b11111,0b00000]
RunningChar =	[[0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000],
		[0b11111,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000],
		[0b11111,0b11111,0b00000,0b00000,0b00000,0b00000,0b00000],
		[0b11111,0b11111,0b11111,0b00000,0b00000,0b00000,0b00000],
		[0b11111,0b11111,0b11111,0b11111,0b00000,0b00000,0b00000],
		[0b11111,0b11111,0b11111,0b11111,0b11111,0b00000,0b00000],
		[0b11111,0b11111,0b11111,0b11111,0b11111,0b11111,0b00000],
		[0b11111,0b11111,0b11111,0b11111,0b11111,0b11111,0b11111]]

lcd.createChar(0, ArrowChar)
lcd.createChar(1, DegreeChar)
lcd.createChar(2, TimeChar)
lcd.createChar(3, IdleChar)
lcd.createChar(4, JobChar)
lcd.createChar(5, ExtrChar)
lcd.createChar(6, BedChar)

# Turn off Backlight after 120 sec
def LCDBckLightOff():
	if DEBUG:
		print "LCD backlight off"
	lcd.backlight(lcd.OFF)

t = Timer(LCDOFF, LCDBckLightOff)
t.start()
示例#12
0
class lcdScreen(object):
  """Class for handling the Adafruit LCDPlate display"""
  def __init__(self, bgColor, txt):
    self.bgColor = bgColor
    self.lcd = Adafruit_CharLCDPlate()
    self.lcd.clear()
    self.lcd.backlight(bgColor)
    self.lcd.message(txt)

    # Create custom characters for LCD for big clock display
    
    # Create some custom characters
    self.lcd.createChar(0, [0, 0, 0, 0, 0, 0, 0, 0])
    self.lcd.createChar(1, [16, 24, 24, 24, 24, 24, 24, 16])
    self.lcd.createChar(2, [1, 3, 3, 3, 3, 3, 3, 1])
    self.lcd.createChar(3, [17, 27, 27, 27, 27, 27, 27, 17])
    self.lcd.createChar(4, [31, 31, 0, 0, 0, 0, 0, 0])
    self.lcd.createChar(5, [0, 0, 0, 0, 0, 0, 31, 31])
    self.lcd.createChar(6, [31, 31, 0, 0, 0, 0, 0, 31])
    self.lcd.createChar(7, [31, 0, 0, 0, 0, 0, 31, 31])
     


    self.timeSinceAction = 0  # The time since the last keypress. Use timeout to start switching screens
#    self.switchScreenTime = 8 #Number of seconds between switching screens
    self.lastScreenTime = time.time()    # time since last screen switch
    self.prevStr = ""
    self.screens = ((self.bigTimeView,6),          # Rotating list of views on LCD with how many seconds to display each display. Round robin style.
                    (self.connectedUserView,4),
                    (self.bigTimeView,6),
                    (self.precisionView,4),
                    (self.bigTimeView,6),
                    (self.ntptimeInfo,5),
                    (self.bigTimeView,6),
                    (self.clockperfView,5),
                    ) # list of all views for rotation
                    
    self.nrofscreens = len(self.screens)
    self.currentScreen = 0

  def writeLCD(self, s):
    """Checks the string, if different than last call, update screen."""
    if self.prevStr.decode("ISO-8859-1") != s.decode("ISO-8859-1"):  # Oh what a shitty way around actually learning the ins and outs of encoding chars...
      # Display string has changed, update LCD
      self.lcd.clear()
      self.lcd.message(s)
      self.prevStr = s  # Save so we can test if screen changed between calls, don't update if not needed to reduce LCD flicker

  def bigTimeView(self):
    """Shows custom large local time on LCD"""

    now=time.localtime()
    hrs=int(time.strftime("%H"))
    minutes=int(time.strftime("%M"))
    sec=int(time.strftime("%S"))
    
    # Build string representing top and bottom rows
    L1="0"+str(digits[hrs][0]).zfill(5)+str(digits[minutes][0]).zfill(5)+str(digits[sec][0]).zfill(5)
    L2="0"+str(digits[hrs][1]).zfill(5)+str(digits[minutes][1]).zfill(5)+str(digits[sec][1]).zfill(5)
    
    # Convert strings from digits into pointers to custom character
    i=0
    XL1=""
    XL2=""
    while i < len(L1):
        XL1=XL1+chr(int(L1[i]))
        XL2=XL2+chr(int(L2[i]))
        i += 1
    
    self.writeLCD(XL1+"\n" +XL2)


  def precisionView(self):
    """Calculate and display the NTPD accuracy"""
    try:
      output = subprocess.check_output("ntpq -c rv", shell=True)
      returncode = 0
    except subprocess.CalledProcessError as e:
        output = e.output
        returncode = e.returncode
        print returncode
        exit(1)
        
    precision = ""
    clkjitter = ""
    clkwander = ""
    theStr = ""
    searchResult = re.search( r'precision=(.*?),', output, re.S)
    precision = searchResult.group(1)
    searchResult = re.search( r'.*clk_jitter=(.*?),', output, re.S)
    clk_jitter = searchResult.group(1)
    if precision and clk_jitter:
      precision = (1/2.0**abs(float(precision)))*1000000.0
      theStr = "Prec: {:.5f} {}s\n".format(precision,chr(0xE4))
      theStr += "ClkJit: {:>4} ms".format(clk_jitter)
    else:
      theStr = "Error: No\nPrecision data"
    self.writeLCD(theStr)

  def ntptimeInfo(self):
    """Statistics from ntptime command"""
    try:
      output = subprocess.check_output("ntptime", shell=True)
    except subprocess.CalledProcessError as e:
        output = e.output
        returncode = e.returncode
        print returncode
    precision = re.search( r'precision (.* us).*stability (.* ppm)', output, re.M|re.S)
    if precision:
      theStr = "Precis: {:>8}\n".format(precision.group(1))
      theStr += "Stabi: {:>9}".format(precision.group(2))
    else:
      theStr = "No info\nError"
    self.writeLCD(theStr)

  def clockperfView(self):
    """Shows jitter etc"""
    output = subprocess.check_output("ntptime", shell=True)
    search = re.search( r'TAI offset.*offset (.*? us).*jitter (.* us)', output, re.M|re.S)
    if search:
      theStr = "Offset: {:>8}\n".format(search.group(1))
      theStr += "OSjitt: {:>8}".format(search.group(2))
    else:
      theStr = "No offset\ninfo error"
    self.writeLCD(theStr)
    
  def updateLCD(self):
    """Called from main loop to update GPS info on LCD screen"""
    # Check status of GPS unit if it has a lock, otherwise change color of background on LCD to red.
    if time.time() - self.lastScreenTime > self.screens[self.currentScreen][1]: # Time to switch display
      self.currentScreen = self.currentScreen +1
      self.lastScreenTime = time.time()   # reset screen timer
      if self.currentScreen > self.nrofscreens - 1:
        self.currentScreen = 0
    self.screens[self.currentScreen][0]()
      
  def connectedUserView(self):
    """Shows connected clients to ntpd"""
    highestCount = "NaN"
    try:
      output = subprocess.check_output("ntpdc -n -c monlist | awk '{if(NR>2)print $1}' | uniq | wc -l", shell=True)  # Gets all the connected clients from ntp
    except subprocess.CalledProcessError as e:
        output = e.output
        returncode = e.returncode
        print returncode
    
    try:
      highestCount = subprocess.check_output("ntpdc -n -c monlist | awk '{if(NR>2)print $4}' | sort -nrk1,1 | line", shell=True)  # Gets the highest connections from connected clients
    except subprocess.CalledProcessError as e:
        output = e.output
        returncode = e.returncode
        print returncode
    theStr = "Con users: {:>6}".format(output)
    theStr += "Hi cons: {:>8}".format(highestCount)
    self.writeLCD(theStr)
示例#13
0
#!/usr/bin/python2
# -*- coding: utf-8 -*-


from time import sleep
import copy
import atexit
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from GlyphSprites import Sprites
import requests
import dateutil.parser

lcd = Adafruit_CharLCDPlate()
atexit.register(lcd.stop)
lcd.backlight(True)
lcd.createChar(0, Sprites.bar0)
lcd.createChar(1, Sprites.bar1)
lcd.createChar(2, Sprites.bar2)
lcd.createChar(3, Sprites.bar3)
lcd.createChar(4, Sprites.bar4)

while (True):
  r = requests.get('http://192.168.1.101:25555/api/ets2/telemetry').json();

  truck = r['truck']
  navigation = r['navigation']
  game = r['game']

  speed = int(truck['speed'])
  speed_str = str(speed).rjust(3)