def activate(self):
     iface_called_plugin.activate(self)
     log_info("Starting the HTTP Server on Port %d"%self.options["http_port"])
     self.s_thread = http_server_thread(self.options["http_port"],self.options["html_dir"])
     self.s_thread.start()
     if not os.path.exists(self.options["html_dir"]+"/index.html"):
         self.write_info_html()
Exemplo n.º 2
0
 def activate(self):
     from panic_button.panic_button_listener import panic_button_listener
     iface_general_plugin.activate(self)
     log_info("Starting panic button listener")
     self.panic_thread = panic_button_listener(
         int(self.options["idVendor"], 0),
         int(self.options["idProduct"], 0), self.options["panic_msg"])
     self.panic_thread.start()
Exemplo n.º 3
0
 def activate(self):        
     from panic_button.panic_button_listener import panic_button_listener
     iface_general_plugin.activate(self)
     log_info("Starting panic button listener")
     self.panic_thread = panic_button_listener(int(self.options["idVendor"], 0),
                                               int(self.options["idProduct"], 0),
                                               self.options["panic_msg"])
     self.panic_thread.start()
Exemplo n.º 4
0
class panic_button_listener(Thread):
    idVendor = None
    idProduct = None
    running = True
    msg = "lunch panic"

    def __init__(self, idV, idP, msg):
        super(panic_button_listener, self).__init__()
        self.idVendor = idV
        self.idProduct = idP
        self.msg = msg

    def findButton(self):
        for bus in usb.busses():
            for dev in bus.devices:
                if dev.idVendor == self.idVendor and dev.idProduct == self.idProduct:
                    return dev
        return None

    def run(self):
        dev = self.findButton()
        if dev == None:
            log_error("Cannot find panic button device")
            return
        handle = dev.open()
        interface = dev.configurations[0].interfaces[0][0]
        endpoint = interface.endpoints[0]

        try:
            handle.detachKernelDriver(interface)
        except Exception, _:
            # It may already be unloaded.
            pass

        handle.claimInterface(interface)

        unbuffer = False
        while self.running:
            # USB setup packet. I think it's a USB HID SET_REPORT.
            result = handle.controlMsg(
                requestType=0x21,  # OUT | CLASS | INTERFACE
                request=0x09,  # SET_REPORT
                value=0x0200,  # report type: OUTPUT
                buffer="\x00\x00\x00\x00\x00\x00\x00\x02")

            try:
                result = handle.interruptRead(endpoint.address,
                                              endpoint.maxPacketSize)
                if 22 == result[0]:
                    if not unbuffer:
                        log_info("pressed the Panic Button")
                        get_server().call_all_members(self.msg)
                    unbuffer = True
                else:
                    unbuffer = False
                #print [hex(x) for x in result]
            except Exception, _:
                # Sometimes this fails. Unsure why.
                pass

            time.sleep(endpoint.interval / float(1000))
Exemplo n.º 5
0
 def deactivate(self):
     log_info("Stopping panic button listener")
     if self.panic_thread != None:
         self.panic_thread.stop_daemon()
         #TODO: self.panic_thread.join()
     iface_general_plugin.deactivate(self)
 def deactivate(self):
     log_info("Stopping HTTP Server")
     if self.s_thread:
         self.s_thread.stop_server()
         self.s_thread.join()
     iface_called_plugin.deactivate(self)
Exemplo n.º 7
0
 def deactivate(self):
     log_info("Stopping panic button listener")
     if self.panic_thread != None:
         self.panic_thread.stop_daemon()
         #TODO: self.panic_thread.join()
     iface_general_plugin.deactivate(self)