コード例 #1
0
ファイル: PiPhi.py プロジェクト: tnewman/Python-WiFi-Radio
            # If 'QuickMix' found, always put at head of list
            if name == 'QuickMix':
                ids.insert(0, id)
                names.insert(0, name)
            else:
                ids.append(id)
                names.append(name)
    return names, ids


# --------------------------------------------------------------------------
# Initialization

atexit.register(clean_exit)

lcd = Adafruit_CharLCDPlate()
lcd.home()
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.create_char(i, bitmap)

# Create up/down icon (char 6)
lcd.create_char(
    6,
    [0b00100, 0b01110, 0b11111, 0b00000, 0b00000, 0b11111, 0b01110, 0b00100])
コード例 #2
0
from Adafruit_CharLCD import Adafruit_CharLCDPlate

display = Adafruit_CharLCDPlate()

display.set_backlight(1)
display.message("DLNA Control\nInitilising")

import SOAPpy
import xml.etree.ElementTree
import time
import sys

server = SOAPpy.SOAPProxy(
    sys.argv[1] + "/upnp/control/rendertransport1",
    namespace="urn:schemas-upnp-org:service:AVTransport:1")

while True:
    Position = server._sa(
        "urn:schemas-upnp-org:service:AVTransport:1#GetPositionInfo"
    ).GetPositionInfo(InstanceID=0)
    #Track = server._sa("urn:schemas-upnp-org:service:AVTransport:1#GetPositionInfo").GetPositionInfo(InstanceID = 0)

    #print Position.RelTime
    #print Position.TrackDuration
    #print Position.TrackMetaData

    namespaces = {"dc": "http://purl.org/dc/elements/1.1/"}

    try:
        trackData = xml.etree.ElementTree.fromstring(Position.TrackMetaData)
        trackName = trackData[0].find('dc:title', namespaces).text
コード例 #3
0
DEBUG = 1
DISPLAY_ROWS = 2
DISPLAY_COLS = 16

# Char LCD plate button names.
SELECT = 0
RIGHT = 1
DOWN = 2
UP = 3
LEFT = 4

# set to 0 if you want the LCD to stay on, 1 to turn off and on auto
AUTO_OFF_LCD = 0

# set busnum param to the correct value for your pi
lcd = Adafruit_CharLCDPlate(busnum=1)

# in case you add custom logic to lcd to check if it is connected (useful)
# if lcd.connected == 0:
#    quit()

# lcd.begin(DISPLAY_COLS, DISPLAY_ROWS)
# #lcd.backlight(lcd.OFF)


# commands
def UpdateSongs():
    tree = etree.parse(configfile)
    root = tree.getroot()
    # This breaks if i move the sogs folder in XML doc
    songs = root[2][1]
コード例 #4
0
from Adafruit_CharLCD import Adafruit_CharLCDPlate as Display

display = Display()

display.clear()

コード例 #5
0
ファイル: __init__.py プロジェクト: mcfitz2/raspwii-scale
	def __init__(self):
		Adafruit_CharLCDPlate.__init__(self)
		self._gpio.setup(5, GPIO.OUT)
コード例 #6
0
class ChirimbolitoDisplay(object):

    lcd = Adafruit_CharLCDPlate()
    info = None
    mode = 0
    offset = 0
    maxOffset = 0
    screen = []

    def __init__(self, configuration):
        self.configuration = configuration
        self.lcd.clear()

        # start with the LCD backlight: blue
        self.lcd.set_color(0.0, 0.0, 1.0)

    #Show initial info (call after network connected)
    def initInfo(self):
        self.info = ChirimbolitoInfo(self.configuration)

    #Send text to display
    def dispScreen(self, newScreen):
        self.screen = newScreen
        self.offset = 0
        try:
            self.maxOffset = max((len(self.screen[0]) - 16),
                                 (len(self.screen[1]) - 16))
            self.lcd.clear()
            s = self.screen[0] + '\n' + self.screen[1]
            self.lcd.message(s)

            # scroll left if the screen is longer than the display
            while self.maxOffset > self.offset:
                time.sleep(1)
                self.scrollLeft()
        except TypeError:
            self.lcd.clear()

    #Offset text to the right
    def scrollLeft(self):
        if self.offset >= self.maxOffset: return
        self.lcd.move_left()
        self.offset += 1

    #Offset text to the left
    def scrollRight(self):
        if self.offset <= 0: return
        self.lcd.scrollDisplayRight()
        self.offset -= 1

    #Display next info screen
    def modeUp(self):
        self.mode += 1
        if self.mode >= len(self.info.screen): self.mode = 0
        self.update()

    #Display previous info screen
    def modeDown(self):
        self.mode -= 1
        if self.mode < 0: self.mode = len(self.info.screen)
        self.update()

    def update(self):
        # refresh screens and data
        self.info.refresh()

        # set backlight color
        if self.info.priceLast >= self.info.priceYesterday:
            # green
            self.lcd.set_color(0.0, 1.0, 0.0)
        else:
            # red
            self.lcd.set_color(1.0, 0.0, 0.0)

        # display screen
        self.dispScreen(self.info.screen[self.mode])
コード例 #7
0
DEBUG = 1
DISPLAY_ROWS = 2
DISPLAY_COLS = 16

# Char LCD plate button names.
SELECT = 0
RIGHT = 1
DOWN = 2
UP = 3
LEFT = 4

# set to 0 if you want the LCD to stay on, 1 to turn off and on auto
AUTO_OFF_LCD = 0

# set busnum param to the correct value for your pi
lcd = Adafruit_CharLCDPlate(busnum=1)

# in case you add custom logic to lcd to check if it is connected (useful)
# if lcd.connected == 0:
#    quit()

# lcd.begin(DISPLAY_COLS, DISPLAY_ROWS)
# #lcd.backlight(lcd.OFF)


class Music_player():
    def __init__(self):
        self.playing = False
        self.song = ''
        self.song_str = ''
コード例 #8
0
class PiMinerDisplay:

    col = []
    prevCol = 0
    lcd = Adafruit_CharLCDPlate()
    info = None
    mode = 1
    offset = 0
    maxOffset = 0
    screen = []

    def __init__(self):
        self.lcd.clear()
        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):
        self.info = PiMinerInfo()
        self.dispLocalInfo()

    #Display Local Info - Accepted, Rejected, HW Errors \n Average Hashrate
    def dispLocalInfo(self):
        self.dispScreen(self.info.screen1)

    #Display Pool Name \n Remote hashrate
    def dispPoolInfo(self):
        self.dispScreen(self.info.screen2)

    #Display Rewards (confirmed + unconfirmed) \n Current Hash
    def dispRewardsInfo(self):
        self.dispScreen(self.info.screen3)

    #Display Error rate & Uptime
    def dispUptimeInfo(self):
        self.dispScreen(self.info.screen4)

#Display rewards & price

    def dispValueInfo(self):
        self.dispScreen(self.info.screen5)

    #Send text to display
    def dispScreen(self, newScreen):
        self.screen = newScreen
        try:
            self.maxOffset = max((len(self.screen[0]) - 16),
                                 (len(self.screen[1]) - 16))
            self.lcd.clear()
            s = self.screen[0] + '\n' + self.screen[1]
            self.lcd.message(s)
        except TypeError:
            self.lcd.clear()
            self.lcd.message('connecting\nto cgminer ...')

    #Cycle Backlight Color / On/Off
    def backlightStep(self):
        if self.prevCol is (len(self.col) - 1): self.prevCol = -1
        newCol = self.prevCol + 1
        self.lcd.set_color(self.col[newCol][0], self.col[newCol][1],
                           self.col[newCol][2])
        self.prevCol = newCol

    #Offset text to the right
    def scrollLeft(self):
        if self.offset >= self.maxOffset: return
        self.lcd.scrollDisplayLeft()
        self.offset += 1

    #Offset text to the left
    def scrollRight(self):
        if self.offset <= 0: return
        self.lcd.scrollDisplayRight()
        self.offset -= 1

    #Display next info screen
    def modeUp(self):
        self.mode += 1
        if self.mode > 4: self.mode = 0
        self.update()

    #Display previous info screen
    def modeDown(self):
        self.mode -= 1
        if self.mode < 0: self.mode = 4
        self.update()

    #Update display
    def update(self):
        self.info.refresh()
        if self.mode == 0: self.dispPoolInfo()
        elif self.mode == 1: self.dispLocalInfo()
        elif self.mode == 2: self.dispRewardsInfo()
        elif self.mode == 3: self.dispUptimeInfo()
        elif self.mode == 4: self.dispValueInfo()
コード例 #9
0
def logic_loop():
    global TIMER_BUTTON_PRESSED
    global NAME_BUTTON_PRESSED

    light_sensors = setup()

    lcd = Adafruit_CharLCDPlate()

    program_state = ProgramState.IDLE
    next_state = ProgramState.IDLE
    previous_state = None

    runner_name = ''
    start_time = None

    raw_duration = 0
    duration = 0

    penalties = 0
    laser_times = [0 for _ in range(len(light_sensors))]

    while True:
        if program_state != previous_state:
            print("{0}->{1}".format(previous_state, program_state))
        if program_state == ProgramState.IDLE:
            if previous_state != ProgramState.IDLE:
                lcd.set_color(*WHITE)
                lcd.set_cursor(*START_TOP_ROW)
                lcd.message("READY FOR")
                lcd.set_cursor(*START_BOTTOM_ROW)
                lcd.message("FIRST RUNNER!")

            if NAME_BUTTON_PRESSED:
                next_state = ProgramState.NAME_ENTRY

        elif program_state == ProgramState.NAME_ENTRY:
            runner_name = name_entry(lcd)
            next_state = ProgramState.READY_TO_GO

        elif program_state == ProgramState.READY_TO_GO:
            if previous_state != ProgramState.READY_TO_GO:
                record = get_best_record()
                new_record = False
                set_name_and_time(lcd, YELLOW, runner_name, 0)

            # start executing lasers early, so there's not a big time penalty at the beginning
            beams_broken, penalties, laser_times = laser_beam_penalties(
                laser_times, light_sensors, penalties, time.time())
            # This is important to make sure the LDRs don't get messed up
            time.sleep(LDR_QUERY_DELAY)
            if TIMER_BUTTON_PRESSED:
                next_state = ProgramState.TIMING

        elif program_state == ProgramState.TIMING:
            if previous_state != ProgramState.TIMING:
                lcd.set_color(*GREEN)
                start_time = time.time()
                laser_times = [
                    start_time - 2 * LASER_BREAK_BOUNCE_TIME
                    for _ in range(len(light_sensors))
                ]
                penalties = 0

            current_time = time.time()
            beams_broken, penalties, laser_times = laser_beam_penalties(
                laser_times, light_sensors, penalties, time.time())

            if any(beams_broken) and (current_time -
                                      start_time) >= STARTUP_DELAY:
                lcd.set_color(*RED)
                GPIO.output(BUZZER_PIN, True)
            else:
                lcd.set_color(*GREEN)
                GPIO.output(BUZZER_PIN, False)

            raw_duration = current_time - start_time
            duration = raw_duration + (penalties * TRIP_TIME_PENALTY)

            lcd.set_cursor(*START_TOP_ROW)
            lcd.message(format_time(duration))

            if TIMER_BUTTON_PRESSED:
                next_state = ProgramState.JUST_FINISHED
            else:
                time.sleep(LDR_QUERY_DELAY)

        elif program_state == ProgramState.JUST_FINISHED:
            if previous_state != ProgramState.JUST_FINISHED:
                set_name_and_time(lcd, WHITE, runner_name, duration)
                write_attempt_to_file(runner_name, duration, raw_duration,
                                      penalties, TRIP_TIME_PENALTY)

                if record is None or (duration < record):
                    new_record = True
                    color_index = 0
                    record_color_time_swap = time.time()

            if new_record and (record_color_time_swap < time.time()):
                lcd.set_color(*RECORD_COLORS[color_index])
                record_color_time_swap = time.time() + RECORD_TIME_COLOR_DWELL
                color_index = (color_index + 1) % len(RECORD_COLORS)

            if NAME_BUTTON_PRESSED:
                next_state = ProgramState.NAME_ENTRY

        previous_state = program_state
        program_state = next_state

        TIMER_BUTTON_PRESSED = False
        NAME_BUTTON_PRESSED = False
コード例 #10
0
 def __init__(self, timeout=5):
     # customize constructor, use superclass init
     Adafruit_CharLCDPlate.__init__(self)
     SonosUtils.__init__(self)
     self.timeout = timeout  # default backlight timeout
     self.display_start_time = time.time()