def __init__(self, menu_layout, debug=0, mirror_mode=0, rotate=0, spi_display=0): debug_argument = debug self.offset = 0 #carryover self.post_offset = 0 #carryover self.menu_layout = menu_layout self.exitvar = 0 # Create Display Object # Maybe instead of create? get passed display object from hueberry? would make this less independent though... and confusing... if (mirror_mode == 1): self.hb_display = hb_display.display(console=1, mirror=mirror_mode) else: self.hb_display = hb_display.display(console=debug_argument, mirror=mirror_mode, rotation=rotate, spi_display=spi_display) # Create Encoder Object if (debug_argument == 0): self.encoder = hb_encoder.RotaryClass() elif (debug_argument == 1): self.encoder = hb_encoder.RotaryClass(debug=1)
def display_textbrowser(self, text, centered=0): try: hb_encoder.__name__ except: try: import hb_encoder except ImportError: print("This function requires the hb_encoder module") encoder = hb_encoder.RotaryClass() encoder.pos = 0 pos, pushed = encoder.get_state() #text = 'One very extremely long string that cannot possibly fit \ #into a small number of pixels of horizontal width, and the idea \ #is to break this text up into multiple lines that can be placed like \ #a paragraph into our image' lines, tmp, h, total_h = self.IntelliDraw(self.draw, text, self.font, self.width) j = 0 encoder.wait_for_button_release() while True: self.draw.rectangle((0, 0, self.width, self.height), outline=0, fill=0) offset = ((h / 2) * -1) * pos j = 0 for i in lines: if (centered == 1): x_pos = (self.width / 2) - (self.string_width(self.font, i) / 2) else: x_pos = 0 self.draw.text((x_pos, offset + (j * h)), i, font=self.font, fill=255) j = j + 1 self.disp.image(self.image) self.disp.display() pos, pushed = encoder.get_state() if pushed == 1: break time.sleep(0.01) encoder.wait_for_button_release() return
def __init__(self,debug = 0, mirror_mode = 0, rotate = 0): self.debug_argument = debug self.hb_display = hb_display.display(console = self.debug_argument,mirror = mirror_mode, rotation = rotate) self.encoder = hb_encoder.RotaryClass(debug = self.debug_argument)
#screen.addstr(0, 0, 'right') return "right" elif char == curses.KEY_LEFT: #screen.addstr(0, 0, 'left ') return "left" elif char == curses.KEY_UP: #screen.addstr(0, 0, 'up ') return "up" elif char == curses.KEY_DOWN: #screen.addstr(0, 0, 'down ') return "down" elif char == curses.KEY_ENTER: #screen.addstr(0, 0, 'enter ') return "enter" if __name__ == "__main__": import time import hb_encoder test = hb_encoder.RotaryClass(debug=1) test.callback(1) time.sleep(.5) test.callback(1) time.sleep(.5) test.callback(1) time.sleep(.5) test.callback(-1) print "testing button... please push the encoder or enter" pos, pushed = test.get_state() print "pos: " + str(pos) + " pushed: " + str(pushed)
def get_start_pos(): #do something and math to get start position start_pos = rev_bri_calc(0) return int(start_pos) def bri_calc(encoder_pos): brightness = encoder_pos * 10.16 return int(brightness) def rev_bri_calc(brightness): encoder_pos = brightness / 10.16 return int(encoder_pos) def hue_lights(bri): print("in hue lights: something hue lights: " + str(bri)) return def timedout(encoder_pos): print("in timed out: timed out on " + str(encoder_pos)) return if __name__ == '__main__': encoder = hb_encoder.RotaryClass(debug=debug_argument) l_control_newtype(1) print("lol finished")