# We add five extra spaces between each complete text scroll. if self.position > len(self.text) + 4: self.position = 0 return scrolledText def setNewText(self, newText): self.text = newText self.position = 0 # 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() lcd.begin(16, 2) lcd.clear() lcd.backlight(lcd.ON) tmr = None # Poll buttons btn = (lcd.LEFT, lcd.UP, lcd.DOWN, lcd.RIGHT, lcd.SELECT) lastArtistSong = '' scroller = TextScroller('', 16) while True: # Get current status and playtime process = subprocess.Popen('mpc', shell=True, stdout=subprocess.PIPE) status = process.communicate()[0] statusLines = status.split('\n')
# We add five extra spaces between each complete text scroll. if self.position > len(self.text) + 4 : self.position = 0 return scrolledText def setNewText(self, newText): self.text = newText self.position = 0 # 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() lcd.begin(16,2) lcd.clear() lcd.backlight(lcd.ON) tmr = None # Poll buttons btn = (lcd.LEFT, lcd.UP, lcd.DOWN, lcd.RIGHT, lcd.SELECT) lastArtistSong = '' scroller = TextScroller('', 16) while True: # Get current status and playtime process = subprocess.Popen('mpc', shell=True, stdout=subprocess.PIPE) status = process.communicate()[0] statusLines = status.split('\n')
class Device(object): def __init__(self): self.lcd = None self._color = RED self._lastbuttons = 0 self._lock = threading.Lock() def get_buttons(self): pressed = [] self._lock.acquire() try: if not self.lcd: return [] buttons = self.lcd.buttons() finally: self._lock.release() for button in BUTTONS: power = 1 << button if (buttons & power) == 0: if (self._lastbuttons & power) != 0: pressed.append(button) self._lastbuttons = buttons return pressed def color(self, color): if self.lcd: self._lock.acquire() self.lcd.backlight(color) self._lock.release() self._color = color def on(self): self._lock.acquire() self.lcd = Adafruit_CharLCDPlate() self.lcd.begin(WIDTH, 2) self.lcd.clear() self.lcd.backlight(self._color) self._lock.release() def off(self): if self.lcd: self._lock.acquire() self.lcd.clear() self.lcd.stop() self.lcd = None self._lock.release() def display(self, line1 = None, line2 = None): if not self.lcd: self.on() self._lock.acquire() if line1 is not None: line1 = str(line1).ljust(WIDTH) self.lcd.setCursor(0, 0) self.lcd.message(line1) if line2 is not None: line2 = str(line2).ljust(WIDTH) self.lcd.setCursor(0, 1) self.lcd.message(line2) self._lock.release()