Skip to content
This repository was archived by the owner on Feb 14, 2018. It is now read-only.

Update uses of LCD library #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions PiMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import sys, subprocess, time, urllib2, socket
sys.path.append("/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_CharLCDPlate")
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from Adafruit_CharLCD import Adafruit_CharLCDPlate
import Adafruit_CharLCD as LCD
from PiMinerDisplay import PiMinerDisplay

HOLD_TIME = 3.0 #Time (seconds) to hold select button for shut down
Expand All @@ -11,7 +12,7 @@
display = PiMinerDisplay()
lcd = display.lcd
prevCol = -1
prev = -1
prev = ""
lastTime = time.time()

def shutdown():
Expand All @@ -38,17 +39,11 @@ def internetOn():
t = time.time()
while True:
lcd.clear()
lcd.message('checking network\nconnection ...')
if (time.time() - t) > 120:
# No connection reached after 2 minutes
lcd.clear()
lcd.message('network is\nunavailable')
time.sleep(30)
exit(0)
lcd.message('checking network\nconnection (' + str(int(time.time() - t)) + 's)...')
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 0))
lcd.backlight(lcd.ON)
lcd.set_color(1.0, 1.0, 1.0)
lcd.clear()
lcd.message('IP address:\n' + s.getsockname()[0])
time.sleep(5)
Expand All @@ -64,23 +59,32 @@ def internetOn():
time.sleep(1) # Pause a moment, keep trying
'''

buttons = ( (LCD.SELECT, 'Select', (1,1,1)),
(LCD.LEFT, 'Left' , (1,0,0)),
(LCD.UP, 'Up' , (0,0,1)),
(LCD.DOWN, 'Down' , (0,1,0)),
(LCD.RIGHT, 'Right' , (1,0,1)) )

# Listen for button presses
while True:
b = lcd.buttons()
if b is not prev:
if lcd.buttonPressed(lcd.SELECT):
b = ""
for button in buttons:
if lcd.is_pressed(button[0]):
b += button[1]
if b != prev:
if lcd.is_pressed(LCD.SELECT):
tt = time.time() # Start time of button press
while lcd.buttonPressed(lcd.SELECT): # Wait for button release
while lcd.is_pressed(LCD.SELECT): # Wait for button release
if (time.time() - tt) >= HOLD_TIME: # Extended hold?
shutdown() # We're outta here
display.backlightStep()
elif lcd.buttonPressed(lcd.LEFT):
elif lcd.is_pressed(LCD.LEFT):
display.scrollRight()
elif lcd.buttonPressed(lcd.RIGHT):
elif lcd.is_pressed(LCD.RIGHT):
display.scrollLeft()
elif lcd.buttonPressed(lcd.UP):
elif lcd.is_pressed(LCD.UP):
display.modeUp()
elif lcd.buttonPressed(lcd.DOWN):
elif lcd.is_pressed(LCD.DOWN):
display.modeDown()
prev = b
lastTime = time.time()
Expand Down
14 changes: 7 additions & 7 deletions PiMinerDisplay.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python

from PiMinerInfo import PiMinerInfo
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from Adafruit_CharLCD import Adafruit_CharLCDPlate

class PiMinerDisplay:

Expand All @@ -16,11 +16,11 @@ class PiMinerDisplay:

def __init__(self):
self.lcd.clear()
self.col = (self.lcd.ON, self.lcd.OFF, self.lcd.YELLOW, self.lcd.OFF,
self.lcd.GREEN, self.lcd.OFF, self.lcd.TEAL, self.lcd.OFF,
self.lcd.BLUE, self.lcd.OFF, self.lcd.VIOLET, self.lcd.OFF,
self.lcd.RED, self.lcd.OFF)
self.lcd.backlight(self.col[self.prevCol])
self.col = ((1.0, 1.0, 0.0),
(0.0, 1.0, 0.0), (0.0, 1.0, 1.0),
(0.0, 0.0, 1.0), (1.0, 0.0, 1.0),
(1.0, 0.0, 0.0))
self.lcd.set_color(self.col[self.prevCol][0], self.col[self.prevCol][1], self.col[self.prevCol][2])

#Show initial info (call after network connected)
def initInfo(self):
Expand Down Expand Up @@ -64,7 +64,7 @@ def dispScreen(self, newScreen):
def backlightStep(self):
if self.prevCol is (len(self.col) -1): self.prevCol = -1
newCol = self.prevCol + 1
self.lcd.backlight(self.col[newCol])
self.lcd.set_color(self.col[newCol][0], self.col[newCol][1], self.col[newCol][2])
self.prevCol = newCol

#Offset text to the right
Expand Down