Exemple #1
0
    def start(self, address):
        print "Wii-Controller starting"

        global sleep

        board = None

        ready = False
        sleep = True
        connected = False

        if self.board1_addr is None:
            self.board1_addr = address
            print "Board1 Address Done"
        elif self.board2_addr is None:
            self.board2_addr = address
            print "Board2 Address Done"
        elif self.board3_addr is None:
            self.board3_addr = address
            print "Board3 Address Done"
        elif self.board4_addr is None:
            self.board4_addr = address
            print "Board4 Address Done"
        else:
            print "Serious Error"

        board = wiiboard.Wiiboard()

        while True:
            if connected is not board.isConnected():
                connected = board.isConnected()

            if not connected:
                #Turn off lights
                time.sleep(0.1)  # This is needed for wiiboard.py
                board.setLight(False)

            if not board.isConnected():
                # Re initialize each run due to bug in wiiboard
                # Note: Seems to be working though :/
                board = wiiboard.Wiiboard()
                print "Connecting to " + address
                board.connect(address)
                print "Connecting to ", address
            if board.isConnected():
                connected = True

                if self.board4_addr is not None:
                    self.board4 = board
                elif self.board3_addr is not None:
                    self.board3 = board
                elif self.board2_addr is not None:
                    self.board2 = board
                elif self.board1_addr is not None:
                    self.board1 = board
                else:
                    print "Error all boards connected"
                break
Exemple #2
0
def main():
    board = wiiboard.Wiiboard()

    pygame.init()

    address = board.discover()
    board.connect(address)  #The wii board must be in sync mode at this time

    time.sleep(0.1)
    board.setLight(True)
    done = False

    while (not done):
        time.sleep(0.05)
        for event in pygame.event.get():
            if event.type == wiiboard.WIIBOARD_MASS:
                if (
                        event.mass.totalWeight > 10
                ):  #10KG. otherwise you would get alot of useless small events!
                    print "--Mass event--   Total weight: " + ` event.mass.totalWeight ` + ". Top left: " + ` event.mass.topLeft `
                #etc for topRight, bottomRight, bottomLeft. buttonPressed and buttonReleased also available but easier to use in seperate event

            elif event.type == wiiboard.WIIBOARD_BUTTON_PRESS:
                print "Button pressed!"

            elif event.type == wiiboard.WIIBOARD_BUTTON_RELEASE:
                print "Button released"
                done = True

            #Other event types:
            #wiiboard.WIIBOARD_CONNECTED
            #wiiboard.WIIBOARD_DISCONNECTED

    board.disconnect()
    pygame.quit()
Exemple #3
0
def main():
    board = wiiboard.Wiiboard()

    pygame.init()

    address = board.discover()
    board.connect(address)  #The wii board must be in sync mode at this time

    time.sleep(0.1)
    board.setLight(True)
    done = False

    leanThreadhold = 20
    bottomLeadThreshhold = 50
    attackNumber = 80

    while (not done):
        time.sleep(0.05)
        for event in pygame.event.get():
            if event.type == wiiboard.WIIBOARD_MASS:
                if (
                        event.mass.totalWeight > 10
                ):  #10KG. otherwise you would get alot of useless small events!
                    print "--Mass event--   Total weight: " + ` event.mass.totalWeight ` + ". Top left: " + ` event.mass.topLeft `
                    leanThreadhold = event.mass.totalWeight / 3.5
                    bottomLeadThreshhold = event.mass.totalWeight / 1.5
                    leftMass = event.mass.topLeft + event.mass.bottomLeft
                    rightMass = event.mass.topRight + event.mass.bottomRight
                    topMass = event.mass.topLeft + event.mass.topRight
                    bottomMass = event.mass.bottomLeft + event.mass.bottomRight
                    if leftMass > rightMass + leanThreadhold:
                        print "LEANING LEFT"
                    elif rightMass > leftMass + leanThreadhold:
                        print "LEANING RIGHT"
                    if topMass > bottomMass + leanThreadhold:
                        print "LEANING UP"
                    elif bottomMass > topMass + bottomLeadThreshhold:
                        print "LEANING DOWN"

                    if (event.mass.totalWeight > attackNumber):
                        print "ATTACK"
                else:
                    print "JUMPING"

                #etc for topRight, bottomRight, bottomLeft. buttonPressed and buttonReleased also available but easier to use in seperate event

            elif event.type == wiiboard.WIIBOARD_BUTTON_PRESS:
                print "Button pressed!"

            elif event.type == wiiboard.WIIBOARD_BUTTON_RELEASE:
                print "Button released"
                done = True

            #Other event types:
            #wiiboard.WIIBOARD_CONNECTED
            #wiiboard.WIIBOARD_DISCONNECTED

    board.disconnect()
    pygame.quit()
Exemple #4
0
 def initData(self):
     self.wii_board = wiiboard.Wiiboard()
     self.reference_mass = 0
     self.mass_timer = QtCore.QBasicTimer()
     self.display_timer = QtCore.QBasicTimer()
     self.time_out = 100
     self.ts_x = TimeSeries(50, 200)
     self.ts_y = TimeSeries(50, 200)
     self.acquisition_mode = False
     self.acquisition_start = None
     self.acquisition_data = []
Exemple #5
0
    def initData(self):
        self.wii_board = wiiboard.Wiiboard()

        self.calibration_mass = 80

        self.timer = QtCore.QBasicTimer()
        interval = 200
        bin_count = 50
        self.ts_mass = TimeSeries(interval, bin_count)
        self.ts_tl = TimeSeries(interval, bin_count)
        self.ts_tr = TimeSeries(interval, bin_count)
        self.ts_bl = TimeSeries(interval, bin_count)
        self.ts_br = TimeSeries(interval, bin_count)

        self.ts_x = TimeSeries(interval, bin_count)
        self.ts_y = TimeSeries(interval, bin_count)
        self.ts_x1 = TimeSeries(50, 200)
        self.ts_y1 = TimeSeries(50, 200)
Exemple #6
0
def main():
    address = None
    board = wiiboard.Wiiboard()

    print "Press the red sync button under the battery hatch"

    while (address is None):
        print "Searching for Wii Balance Board..."
        address = board.discover()

    cmd_wiibind = "../scripts/xwiibind.sh " + address
    cmd_npm = "npm config set wii-scale:address " + address

    subprocess.call(cmd_wiibind, shell=True)

    print "Finishing up.."

    subprocess.check_call(cmd_npm, shell=True)

    print "All done!"
Exemple #7
0
def main():
    try:
        lastWeights = []

        balance = Balance()
        board = wiiboard.Wiiboard()

        pygame.init()

        #address = board.discover()
        address = "78:A2:A0:22:28:E8"

        disconnect_devices()

        log("Connecting to wiiboard address {}".format(address))
        board.connect(address) #The wii board must be in sync mode at this time
        log("Board connected")

        time.sleep(0.1)
        board.setLight(True)


        while True:

            if int(time.time() % 60) == 0:
                blink(board, times=1)
                time.sleep(1)

            time.sleep(0.05)
            events = pygame.event.get()
            #if len(events) > 10:
            #    print("Too many elements on queue {}".format(len(events)))

            for event in events:
                if event.type == wiiboard.WIIBOARD_MASS:
                    weight = event.mass.totalWeight
                    if (weight > 40):
                        #print "Total weight: {}. Top left: {} ".format(weight, event.mass.topLeft)


                        weight = round2(weight) # Weight becomes a string
                        lastWeights = add_list(lastWeights,weight)

                        if len(lastWeights) == MAX_STABLE_WEIGHTS and all_same(lastWeights):

                            if weight > 60:
                                user = "******"
                            else:
                                user = "******"

                            log("Saving weight {weight} for user {user}".format(**locals()))
                            balance.save(weight, user)

                            lastWeights = []

                            blink(board)
                            board.setLight(False)

                            for x in range(0,25): # Sleeps for 2.5 seconds while emptying queue
                                pygame.event.clear()
                                time.sleep(0.1)

                            board.setLight(True)
                    elif lastWeights:
                        log("Removing cached weights {}".format(lastWeights))
                        lastWeights = []

                #else:
                #    print ("Got different event type {}".format(event.type))
    except KeyboardInterrupt as e:
        log("Interrupt, exiting...")

        if board:
            log("Disconnecting board")
            board.disconnect()

    except BluetoothError as e:
        log("Got bluetooth error {}".format(e), level = "ERROR")

        if board:
            log("Disconnecting board")
            board.disconnect()
            main() #Retrying
    except Exception as e:
        log("Got unexpected error {}".format(e), level = "ERROR")
        if board:
            log("Disconnecting board")
            board.disconnect()
            main() #Retrying
def main():

    connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        connexion.connect((host, port))
    except socket.error:
        print "La connexion a echoue."
        sys.exit()
    print "Connexion etablie avec le serveur."
    #  if(raw_input == "exit"):
    #        connexion.close()
    #    th_E = ThreadEmission(connexion)
    #    th_E.start()

    #
    # initialization wiifit
    board = wiiboard.Wiiboard()
    pygame.init()
    address = board.discover()
    board.connect(address)  # The wii board must be in sync mode at this time#
    # initializations
    time.sleep(0.1)
    board.setLight(True)
    done = False
    time_limit = 60
    weight_threshold = 4
    recording = False
    # MAIN LOOP
    while (not done):
        time.sleep(0.05)
        for event in pygame.event.get():
            str(pygame.event.get())
            if event.type == wiiboard.WIIBOARD_MASS:
                if (event.mass.totalWeight > weight_threshold):
                    # time.sleep(0.05)
                    if recording:
                        total = event.mass.totalWeight
                        x = ((event.mass.topRight + event.mass.bottomRight) -
                             (event.mass.topLeft +
                              event.mass.bottomLeft)) / total
                        y = (
                            (event.mass.bottomRight + event.mass.bottomLeft) -
                            (event.mass.topRight + event.mass.topLeft)) / total
                        time.sleep(0.001)
                        pos = ( ` x ` + ',' + ` y ` + '|')
                        print pos
                        if x is not None and x is not '':
                            if y is not None and y is not '':
                                connexion.send(pos)
                                t = time.time() - init_time
                                save_name = "test.csv"
                                save = open(save_name, "a")
                                save.write( ` t ` + ',' + ` x ` + ',' + ` y ` +
                                            '\n')
                        time.sleep(0.001)

                        # End of recording ?
                        if ((time.time() - init_time) > time_limit):
                            recording = False
                            print "End of recording"
            # The BUTTON event activates recording
            elif event.type == wiiboard.WIIBOARD_BUTTON_PRESS:
                print "Bouton devant"
                print "Button pressed!"
            elif event.type == wiiboard.WIIBOARD_BUTTON_RELEASE:
                if not recording:
                    print "Bouton inconnu"
                    print "Button released -> recording...."
                    init_time = time.time()
                    recording = True
                elif recording:
                    recording = False
                    init_time = time.time()
                    recording = True
            # Press any key on the computer keyboard to quit
            elif event.type == QUIT:
                print "Quit !"
                # output_file.close()
                done = True
                pygame.display.update()
            # Other event types:
            # wiiboard.WIIBOARD_CONNECTED
            # wiiboard.WIIBOARD_DISCONNECTED
    pygame.quit()
    board.disconnect()
    sys.exit()
Exemple #9
0
    def update(self):
        global screen_res, sys_font_weight_fgcolour, sys_font_weight, screen_res

        if True:
            self.text = "%.2f" % self.weight
            self.image = sys_font_weight.render(self.text, True,
                                                sys_font_weight_fgcolour)

            self.rect = self.image.get_rect()
            self.rect.bottomright = screen_res


if True:

    board = wiiboard.Wiiboard()

    system_file = "system.ini"
    sconf = ConfigParser()
    sconf.read(system_file)

    xdisplay = sconf.get("display", "xdisplay")

    pygame.init()
    sys_font_weight = pygame.font.SysFont(
        sconf.get("font_weight", "face"), int(sconf.get("font_weight",
                                                        "size")))

    sys_font_weight.set_italic(False)
    sys_font_weight.set_underline(False)
Exemple #10
0
def main(argv):
	options(argv)
	print "Wii-Scale started"

	global sleep
	global port
	global config_address
	global calibrate
	global board

	ready = False
	sleep = True
	connected = False
	calculate = CalculateWeight()
	socket = WebSocketIO()
	board = wiiboard.Wiiboard()

	# Scale	
	while(True):

		# Check if connection status changed
		if connected is not board.isConnected():
			connected = board.isConnected()
			if connected:
				socket.send_status("CONNECTED")
			else:				
				socket.send_status("DISCONNECTED")
				#Turn off lights
				time.sleep(0.1) # This is needed for wiiboard.py
				board.setLight(False)

		# Waiting for disconnect/sleep command
		socket.wait()
		if sleep:
			continue


		# Reset
		done = False
		total = []
		firstStep = True
		skipReadings = 5


		# Connect to balance board
		if not board.isConnected():
			# Re initialize each run due to bug in wiiboard
			# Note: Seems to be working though :/
			board = wiiboard.Wiiboard()
			socket.send_status("SYNC")

			if not config_address:
				address = board.discover()
			else:
				address = config_address

			if not address:
				sleep = True
				socket.send_status("NO DEVICE FOUND")
				continue

			socket.send_status("CONNECTING")
			board.connect(address)

			if board.isConnected():
				connected = True
				socket.send_status("CONNECTED")


		#Board is connected and ready
		if board.isConnected():

			# Post ready status once
			if not ready:
				ready = True
				time.sleep(0.1) # This is needed for wiiboard.py
				board.setLight(True)
				socket.send_status("READY")

			#Measure weight
			if board.mass.totalWeight > sensitivity:
				while(not done):
					time.sleep(0.1)

					if firstStep:
						firstStep = False
						socket.send_status("MEASURING")

					# Skips the first readings when the user steps on the balance board
					skipReadings -= 1
					if(skipReadings < 0):
						total.append(board.mass.totalWeight)
						socket.send_weight(calculate.weight(total))

					if board.mass.totalWeight <= sensitivity and not firstStep:
						done = True
						socket.send_status("DONE")
				ready = False
Exemple #11
0
def main():
    board = wiiboard.Wiiboard()
    pygame.init()
    address = board.discover()
    board.connect(address)  #The wii board must be in sync mode at this time
    time.sleep(0.5)
    board.setLight(True)
    done = False
    mediante = []
    risultato = list()
    while (not done):
        for event in pygame.event.get():
            if event.type == wiiboard.WIIBOARD_MASS:
                preso = True
                l = list()
                l.append( ` event.mass.topRight `)
                l.append( ` event.mass.bottomRight `)
                l.append( ` event.mass.topLeft `)
                l.append( ` event.mass.bottomLeft `)
                print(l)
                mediante.append(l)
                #etc for topRight, bottomRight, bottomLeft. buttonPressed and buttonReleased also available but easier to use in seperate event

            elif event.type == wiiboard.WIIBOARD_BUTTON_PRESS:
                print "Button pressed!"

            elif event.type == wiiboard.WIIBOARD_BUTTON_RELEASE:
                print "Button released"
                done = True

            #Other event types:
            #wiiboard.WIIBOARD_CONNECTED
            #wiiboard.WIIBOARD_DISCONNECTED
        risultato = media(mediante)  # [14.000000,24.000000,30.00000,0]
        mediante = list()
        tot = 0
        max1 = 0
        max2 = 0
        grejo = risultato[:]

        for i in risultato:
            tot = tot + i
        if tot > 20:
            grejo.sort()
            max1 = grejo[3]

            max2 = grejo[2]

            max1t = False
            max2t = False
            print(max1)
            print(max2)
            for i in range(0, 4):
                if risultato[i] == max1 and not max1t:
                    max1 = i
                    max1t = True
                elif risultato[i] == max2 and not max2t:
                    max2 = i
                    max2t = True
            #[mtl,mtr,mbr,mbl]
            print(max1, max2)
            m = 0
            for i in risultato:
                m = m + i
            m = m / 4
            print m

            s = ""

            if (risultato[0] - m < 5) and (risultato[1] - m < 5) and (
                    risultato[2] - m < 5) and (risultato[3] - m < 5):
                stop()
            else:
                if (max1 == 0 and max2 == 2) or (max1 == 2 and max2 == 0):
                    avanti()
                elif (max1 == 0 and max2 == 3) or (max1 == 3 and max2 == 0):
                    tuttodestra()
                elif (max1 == 1 and max2 == 3) or (max1 == 3 and max2 == 1):
                    indietro()
                elif (max1 == 1 and max2 == 2) or (max1 == 2 and max2 == 1):
                    tuttosinistra()
                elif (max1 == 2 and max2 == 3) or (max1 == 3 and max2 == 2):
                    destra()
                elif (max1 == 1 and max2 == 0) or (max1 == 0 and max2 == 1):
                    sinistra()
            preso = False
        elif preso:
            stop()

    board.disconnect()
    pygame.quit()