示例#1
0
    def data_received(self, data):
        message = from_binary(data)
        if isinstance(message, SetPin):  #compare classes
            pin = message.pin
            state = message.state
            time.sleep(5)
            if pin in pins_to_control:
                GPIO.output(pin, GPIO.HIGH) if state else GPIO.output(
                    pin, GPIO.LOW)
                response = Response(pin, state, True)
            else:
                response = Response(pin, state, False)

        if isinstance(message, CheckPins):
            response_list = []
            for i in range(1, 41):
                if i in pins_to_control:
                    response_list.append(GPIO.input(i))
                else:
                    response_list.append(0)
            response = CheckPinsResponse(response_list)

        print('Send to client: {}'.format(response))
        self.transport.write(response.get_binary())
        self.transport.close()
示例#2
0
 def parse_response(self, data):
     response = from_binary(data)
     print("Received: {}".format(response))
     if isinstance(response, Response):
         if response.success:
             self.statuses[response.pin - 1] = response.state
             self.bulbs[response.pin -
                        1].setPixmap(self.bulb_image_on if response.
                                     state else self.bulb_image_off)
             self.toggle_buttons[response.pin - 1].setEnabled(True)
     if isinstance(response, CheckPinsResponse):
         for pin, bulb in zip(response.statuses, self.bulbs):
             bulb.setPixmap(self.bulb_image_on) if pin else bulb.setPixmap(
                 self.bulb_image_off)
         self.statuses = response.statuses
         for button in self.toggle_buttons.values():
             button.setEnabled(True)
示例#3
0
 def data_received(self, data):
     response = from_binary(data)
     if isinstance(response, Response):
         print("Command: Set Pin command")
         print("Pin: {}".format(response.pin))
         print("Success: {}".format(response.state))
示例#4
0
 def parse_response(self, data):
     response = from_binary(data)
     print('Received: {}'.format(response))