Ejemplo n.º 1
0
    def main(f):
        phrases = [
            "It is certain.", "It is decidedly so.", "Without a doubt.",
            "Yes - definitely.", "You may rely on it.", "As I see it, yes.",
            "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.",
            "Reply hazy, try again", "Ask again later.",
            "Better not tell you now.", "Cannot predict now.",
            "Concentrate and ask again.", "Don't count on it.",
            "My reply is no.", "My sources say no.", "Outlook not so good.",
            "Very doubtful."
        ]
        i2c = machine.I2C(scl=Pin(22), sda=Pin(21))
        epd.init()
        epd.set_rotate(gxgde0213b1.ROTATE_270)
        epd.clear_frame(fb)
        epd.display_frame(fb)
        prev_orientation = None

        keep_on = [True]

        def exit_loop():
            keep_on[0] = False

        exit_button = TouchButton(Pin(32), exit_loop)

        while keep_on[0]:
            exit_button.read()
            orientation = MagicBall.get_orientation(i2c)

            if orientation and orientation != prev_orientation:
                if orientation == 'upright':
                    MagicBall.show_message(urandom.choice(phrases))
                elif orientation == 'prone':
                    MagicBall.clear_screen()
            prev_orientation = orientation
Ejemplo n.º 2
0
    def main(f):
        i2c = machine.I2C(scl=Pin(22), sda=Pin(21))
        epd.init()
        epd.set_rotate(gxgde0213b1.ROTATE_270)
        epd.clear_frame(fb)
        epd.display_frame(fb)
        keep_on = [True]

        def exit_loop():
            keep_on[0] = False

        exit_button = TouchButton(Pin(32), exit_loop)

        while keep_on[0]:
            exit_button.read()
            orientation = Accelerometer.get_orientation(i2c)
            x = "x={0}".format(orientation[0])
            y = "y={0}".format(orientation[1])
            z = "z={0}".format(orientation[2])
            print(x, y, z)
            epd.clear_frame(fb)
            epd.set_rotate(gxgde0213b1.ROTATE_270)
            epd.display_string_at(fb, 10, 0, x, font16, gxgde0213b1.COLORED)
            epd.display_string_at(fb, 10, 24, y, font16, gxgde0213b1.COLORED)
            epd.display_string_at(fb, 10, 48, z, font16, gxgde0213b1.COLORED)
            epd.display_frame(fb)
            time.sleep(1)
Ejemplo n.º 3
0
    def drawMenu(self):
        epd.clear_frame(fb)
        ypos = 20
        xpos = 15
        ydelta = 12
        xdelta = 125
        epd.display_string_at(fb, 0, 0, self.menutitle, font16,
                              gxgde0213b1.COLORED)

        for i in self.menuitems:
            epd.display_string_at(fb, xpos, ypos, i['text'], font12,
                                  gxgde0213b1.COLORED)
            if i == self.cur_opt:
                epd.display_string_at(fb, xpos - 14, ypos, "->", font12,
                                      gxgde0213b1.COLORED)

            ypos += ydelta
            if ypos > (9 * 12):
                ypos = 20
                xpos += xdelta
        epd.display_frame(fb)
Ejemplo n.º 4
0
    def menuloop(self, up, down, left, right, run, exit):
        m = self
        epd.clear_frame(fb)
        epd.display_frame(fb)
        epd.initPart()

        m.drawMenu()
        touchdelay = 0.01
        touchthres = 800
        while True:
            if up.read() < touchthres:
                m.handleKey("up")
                while up.read() < touchthres:
                    time.sleep(touchdelay)
                m.drawMenu()
            if down.read() < touchthres:
                m.handleKey("down")
                while down.read() < touchthres:
                    time.sleep(touchdelay)
                m.drawMenu()
            if left.read() < touchthres:
                m.handleKey("left")
                while left.read() < touchthres:
                    time.sleep(touchdelay)
                m.drawMenu()
            if right.read() < touchthres:
                m.handleKey("right")
                while right.read() < touchthres:
                    time.sleep(touchdelay)
                m.drawMenu()
            if run.read() < touchthres:
                m.handleKey("launch")
                while run.read() < touchthres:
                    time.sleep(touchdelay)
                m.drawMenu()
            if exit.read() < touchthres:
                m.handleKey("right")
                while exit.read() < touchthres:
                    time.sleep(touchdelay)
                return
Ejemplo n.º 5
0
    def handleKey(self, key):
        f = self.cur_opt['function']
        if key == "up":
            self.move(-1)
        elif key == "down":
            self.move(1)
        elif key == "right":
            self.move(8)
        elif key == "left":
            self.move(-8)
        elif key == "launch":
            if f != None:
                print("Launching %s" % f)
                epd.init()
                epd.clear_frame(fb)
                epd.display_string_at(fb, 0, 0, "Launching", font16,
                                      gxgde0213b1.COLORED)
                epd.display_string_at(fb, 0, 16, self.cur_opt['text'] + " ..",
                                      font16, gxgde0213b1.COLORED)
                epd.display_frame(fb)
                time.sleep(1)
                f(self.cur_opt['text'])
                epd.clear_frame(fb)
                epd.display_string_at(fb, 0, 0, "App Finished!", font16,
                                      gxgde0213b1.COLORED)
                epd.display_string_at(fb, 0, 16, self.cur_opt['text'] + " ..",
                                      font16, gxgde0213b1.COLORED)
                epd.display_frame(fb)
                time.sleep(1)
                epd.clear_frame(fb)
                epd.display_frame(fb)
                epd.initPart()

            else:
                print("Could not launch '%s' no function attatched!" %
                      self.cur_opt['text'])
Ejemplo n.º 6
0
 def show_message(message):
     epd.init()
     epd.clear_frame(fb)
     epd.display_string_at(fb, 0, 52, message, font16, gxgde0213b1.COLORED)
     epd.display_frame(fb)
Ejemplo n.º 7
0
 def clear_screen():
     epd.initPart()
     epd.clear_frame(fb)
     epd.display_frame(fb)
Ejemplo n.º 8
0
import font16
import gxgde0213b1
import machine
import struct
from ohsbadge import epd
from ohsbadge import fb

i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
i2c.writeto_mem(30, 0x18, b'\x80')
ACCX = struct.unpack("h", i2c.readfrom_mem(30, 0x6, 2))
ACCY = struct.unpack("h", i2c.readfrom_mem(30, 0x8, 2))
ACCZ = struct.unpack("h", i2c.readfrom_mem(30, 0x10, 2))
print("accelerometer: x={0} y={1} z={2}".format(ACCX[0], ACCY[0], ACCZ[0]))

epd.clear_frame(fb)
epd.display_string_at(fb, 0, 0, "accelerometer:", font16, gxgde0213b1.COLORED)
epd.display_string_at(fb, 0, 24,
                      "x={0} y={1} z={2}".format(ACCX[0], ACCY[0], ACCZ[0]),
                      font16, gxgde0213b1.COLORED)
epd.display_frame(fb)

time.sleep(2)