def imd_playback (): global mode mode = "play" song = menu.imd_db.record(cursong) oled.clear() oled.flush() n = isnum bc = border_color y = offset for i in range(0, 12): oled.fill(0, y + i, 129, y + i+1, [bc.r - (n(bc.r) * i), bc.g - (n(bc.g) * i), bc.b - (n(bc.b) * i)]) oled.flush() oled.textbox(x = 65, y = 4, text = "Now Playing", color = black, align = 2) oled.flush() tcolor = blue oled.textbox(x = 65, y = 35, text = song.title, color = tcolor, mode = 1, align = 2) oled.flush() oled.textbox(x = 65, y = 50, text = song.artist, color = tcolor, mode = 1, align = 2) oled.flush() oled.textbox(x = 65, y = 65, text = song.album, color = tcolor, mode = 1, align = 2) oled.flush() oled.redraw() oled.flush() timer().start() return song
def calibrate (): i = 1 while i > -1: oled.clear() oled.flush() oled.textbox(x = 65, y = 50, text = "Calibrating in %s" % i, align = 2) oled.flush() oled.redraw() oled.flush() sleep(1) i -= 1 tty.write("c") sleep(.4)
def menu_load (data, index = 0, cursor = menu_start, top = 0): # Until this is better coded, if you specify an index, you MUST specify a cursor position, AND a top curmenu.name = data[0] curmenu.items = data[1] curmenu.len = len(curmenu.items) curmenu.index = index curmenu.cursor = cursor curmenu.top = top if curmenu.len < menu_rows: # If the menu isn't big enough to fill the screen, # find out where it ends on screen (y position) curmenu.end = curmenu.len * row_height + menu_start else: curmenu.end = menu_end menu_draw() oled.redraw() oled.flush()
def menu_draw (): # Clear the frame buffer first oled.clear() oled.flush() # Draw blue bars at top and bottom of screen n = isnum bc = border_color y = offset for i in range(0, 12): oled.fill(0, y + i, 129, y + i+1, [bc.r - (n(bc.r) * i), bc.g - (n(bc.g) * i), bc.b - (n(bc.b) * i)]) oled.flush() y = 116 + offset for i in range(0, 12): oled.fill(0, y + i, 129, y + i+1, [bc.r - (n(bc.r) * i), bc.g - (n(bc.g) * i), bc.b - (n(bc.b) * i)]) oled.flush() # Show title of menu on the top blue bar that was just drawn oled.textbox(x=65, y=4, text=curmenu.name, color=[0, 0, 0], align=2) oled.flush() # Show current item index and total on bottom blue bar oled.textbox(x=65, y=119, text="%s/%s" % (curmenu.index + 1, curmenu.len), color=[0, 0, 0], align=2) oled.flush() # Redraw the counter (bottom blue bar) oled.redraw(116 + offset) for y in range(menu_start, curmenu.end, row_height): if y == curmenu.cursor: # Fill the row of the center menu item because for the selection cursor, iPod-ish style :) h = highlight_color for i in range(0, 6): oled.fill(0, y + i, 129, y + i+1, [h.r - (n(h.r) * i), h.g - (n(h.g) * i), h.b - (n(h.b) * i)]) oled.flush() i2 = 0 for i in range(6, 11): oled.fill(0, y + i, 129, y + i+1, [h.r - (10 * n(h.r)) + i2, h.g - (10 * n(h.r)) + i2, h.b - (10 * n(h.r)) + i2]) oled.flush() i2 += 1 # Also invert selected item's text color oled.textbox (x = 1, y = y + 2, text = curmenu.items[curmenu.top + ((y - menu_start) / row_height)][0], color=texth_color, mode=2) else: # Plain menu items (but they might get selected later!) oled.textbox (x = 1, y = y + 2, text = curmenu.items[curmenu.top + ((y - menu_start) / row_height)][0], color=text_color, mode=2) oled.flush()
def run (self): sleep(.5) while 1: if mode == "play": times = audeng.getpos() #print times sleep(.8) if times: percent_elapsed = times[0] * 1.0 / times[1] oled.fill(15, 80, 114, 90, blue) oled.flush() oled.fill(16, 81, 113, 89, black) oled.flush() y = 82 h = highlight_color n = isnum #print "bar pos: %s" % (17 + int(95 * percent_elapsed)) for i in range(0, 6): oled.fill(17, y + i, 17 + int(95 * percent_elapsed), y + i+1, [h.r - (n(h.r) * i), h.g - (n(h.g) * i), h.b - (n(h.b) * i)]) oled.flush() i2 = 0 secs = (times[0] % 600) / 10 min = (times[0] - secs * 10) / 600 oled.fill(17, 93, 114, 100, black) oled.flush() oled.textbox(x=17, y=93, text="%s:%s%s" % (min, ("0", "")[secs > 9], secs), color = blue) oled.flush() time_rem = times[1] - times[0] secs_rem = (time_rem % 600) / 10 min_rem = (time_rem - secs_rem * 10) / 600 oled.textbox(x=114, y=93, text="-%s:%s%s" % (min_rem, ("0", "")[secs_rem > 9], secs_rem), color = blue, align = 1) oled.flush() oled.redraw() oled.flush() if times[0] >= times[1]: play_next() return else: return
def menu_up (): print "Menu Up" #If we're in play mode, just put volume up if mode == "play": audeng.vol_up() return # Equaly as simple as menu_down, just have to decrease the index/cursor instead # First, we simply have to check to make sure the index isn't already at 0 (anything lower is invalid) if curmenu.index > 0: curmenu.index -= 1 # Move the cursor up if possible if curmenu.cursor > menu_start: curmenu.cursor -= row_height menu_draw() oled.redraw(curmenu.cursor, curmenu.cursor + row_height * 2) else: # If the cursor can't move up, move up the menu curmenu.top -= 1 oled.copy(y = curmenu.cursor + row_height, y2 = menu_start + row_height * (menu_rows - 1) - 2, y3 = menu_start + row_height * 2) oled.flush() menu_draw() oled.redraw(menu_start, menu_start + row_height * 2) oled.flush()
def menu_down (): print "Menu Down" #If we're in play mode, just put volume down if mode == "play": audeng.vol_down() return # Very simple...just increase the menu index to go down the list... # ...as long as it isn't already at the limit if curmenu.index < curmenu.len - 1: curmenu.index += 1 # Move down the cursor if possible if curmenu.cursor < menu_end - row_height: curmenu.cursor += row_height menu_draw() oled.redraw(curmenu.cursor - row_height, curmenu.cursor + row_height) else: # Move the menu down if the cursor can't curmenu.top += 1 oled.copy(y = menu_start + row_height, y2 = menu_start + row_height * (menu_rows - 1) - 1, y3 = menu_start) oled.flush() menu_draw() oled.redraw(menu_start + (menu_rows - 2) * row_height, menu_start + menu_rows * row_height) oled.flush()
min_rem = (time_rem - secs_rem * 10) / 600 oled.textbox(x=114, y=93, text="-%s:%s%s" % (min_rem, ("0", "")[secs_rem > 9], secs_rem), color = blue, align = 1) oled.flush() oled.redraw() oled.flush() if times[0] >= times[1]: play_next() return else: return print "loading colors" load_color("highlight", green) load_color("border", pblue) text_color = blue # Highlighted text color texth_color = black #calibrate() print "starting up oled and audeng" os.system("killall oled audeng bplay") os.system("./oled < /tmp/oledmgr > /dev/null &") os.system("./audeng | bplay -s 44100 -S -b 16 &") print "loading home menu" menu_home() oled.redraw() oled.flush() print "starting threads" input().start() print "gui.py done loading"