Beispiel #1
0
 def get_status(self):
     self.param["org_mode"] = wiiremote.start_status()
     while wiiremote.running():
         if not self.param["org_mode"]:
             wiiremote.pause(False)  #pause release
             break
     return
Beispiel #2
0
    def init_accel(self):
        print "[--- Initalize accel ---]"
        if not self.param["acc_zero"]:  #or not param["acc_gain"]:
            acc = [[], [], []]
            self.param["acc_zero"] = [0, 0, 0]
            self.param["acc_gain"] = [0, 0, 0]
            for i in range(3):
                print "%d. Set WiiRemote %s >" % (i + 1, usage[i])
                while wiiremote.running() and not acc[i]:
                    pygame.time.wait(10)
                    if self.accel:
                        if self.param["acc_zero"] == [1, 1, 1]:
                            acc[i] = self.accel

            if not wiiremote.running():
                wiiremote.quit()
                return
            #calc
            self.param["acc_zero"][0] = (acc[0][0] + acc[1][0]) / 2
            self.param["acc_zero"][1] = (acc[0][1] + acc[2][1]) / 2
            self.param["acc_zero"][2] = (acc[1][2] + acc[2][2]) / 2
            self.param["acc_gain"][0] = acc[2][0] - self.param["acc_zero"][0]
            self.param["acc_gain"][1] = acc[1][1] - self.param["acc_zero"][1]
            self.param["acc_gain"][2] = acc[0][2] - self.param["acc_zero"][2]
            for c in range(3):
                self.conf.set("ACC_ZERO", ["x", "y", "z"][c],
                              str(self.param["acc_zero"][c]))
                self.conf.set("ACC_GAIN", ["x", "y", "z"][c],
                              str(self.param["acc_gain"][c]))

            with open(CONF_FILENAME, "wb") as fd:
                self.conf.write(fd)

        print "acc_zero =", self.param["acc_zero"]
        print "acc_gain =", self.param["acc_gain"]
        print ""
        return
Beispiel #3
0
    def main(self):
        #init
        self.load_conf()
        pygame.init()
        wiiremote.init(self)
        if not wiiremote.running(): return
        wiiremote.pause(True)  #pause to get acc and gyro data

        #visual
        visual.scene.width = self.param["width"]
        visual.scene.height = self.param["height"]
        visual.scene.title = "WiiRemote"
        visual.scene.forward = visual.vector(1, 0, 0)  # not to error ?
        visual.scene.up = visual.vector(0, 0, 1)
        visual.scene.forward = visual.vector(-1, 1, -1)
        visual.scene.autoscale = 0
        self.visual["axis"][0] = visual.arrow(color=visual.color.red,
                                              axis=(3, 0, 0),
                                              headwidth=1,
                                              shaftwidth=0.5,
                                              fixedwidth=1)
        self.visual["axis"][1] = visual.arrow(color=visual.color.green,
                                              axis=(0, 3, 0),
                                              headwidth=1,
                                              shaftwidth=0.5,
                                              fixedwidth=1)
        self.visual["axis"][2] = visual.arrow(color=visual.color.blue,
                                              axis=(0, 0, 3),
                                              headwidth=1,
                                              shaftwidth=0.5,
                                              fixedwidth=1)
        self.visual["wiiobj"] = visual.box(
            pos=(0, 0, 0),
            length=1,
            height=4,
            width=1.5,
            color=visual.color.white,
        )

        #sound
        if self.option["sound"]:
            self.init_sound()

        #status
        self.get_status()

        #accel
        self.init_accel()
        acc = [0, 0, 0]

        #pygame
        old = [self.param["height"] / 2] * 3
        view = [True, True, True]
        screen = pygame.display.set_mode(
            (self.param["width"], self.param["height"]))
        font = pygame.font.SysFont(None,
                                   int(self.param["sidebar_width"] * 1.5))
        self.param[
            "width_"] = self.param["width"] - self.param["sidebar_width"]

        print "[--- start ---]"
        if self.option["sound"]:
            print "press A to on/off saber"

        while self.param["running"]:
            #self.re.refresh()
            pygame.time.wait(100)
            pygame.display.update()

            screen.fill((0, 0, 0),
                        (self.param["width_"], 0, self.param["sidebar_width"],
                         self.param["height"]))
            screen.blit(screen, (-1, 0))

            for i in range(int(maxA * 2 + 1)):
                screen.blit(
                    font.render("%-d" % (maxA - i), True, (144, 144, 144)),
                    (self.param["width_"], float(self.param["height"]) /
                     (maxA * 2) * i - self.param["sidebar_width"] * 1.5 / 4))
                pygame.draw.line(
                    screen, (144, 144, 144),
                    (0, float(self.param["height"]) / (maxA * 2) * i),
                    (self.param["width_"], float(self.param["height"]) /
                     (maxA * 2) * i))

            #pygame
            for c in range(3):  # 3axis
                if view[c]:
                    s = int((acc[c] * self.param["height"] / maxA +
                             self.param["height"]) / 2)
                    s = max(0, min(self.param["height"] - 1, s))
                    pygame.draw.line(screen, colors[c],
                                     (self.param["width_"] - 3, old[c]),
                                     (self.param["width_"] - 2, s))
                    old[c] = s

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    wiiremote.quit()
                    sys.exit(1)
                    return
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        wiiremote.quit()
                        sys.exit(1)
                        return
                    if event.key == pygame.K_x:
                        if view[0]: view[0] = False
                        else: view[0] = True
                    elif event.key == pygame.K_y:
                        if view[1]: view[1] = False
                        else: view[1] = True
                    elif event.key == pygame.K_z:
                        if view[2]: view[2] = False
                        else: view[2] = True