def doPreview(self): dbg("doPreview") self.state = PREVIEW self.__cancelLater() self.callLater = reactor.callLater(20, self.transport.loseConnection) #self.callLater.addErrback(log.err) self.__doCommand(2)
def registerListener(klass, address, listener): if not address in klass.listeners: klass.listeners[address] = list() if listener not in klass.listeners[address]: dbg("adding listener") klass.listeners[address].append(listener)
def set(self, option, value): dbg("set %s->%s" % (option, value) ) if option=="size": self.doSetSize(value) from airi.api import UpdateManager UpdateManager.propagate(self.address, {"size": value}) else: dbg("ignored")
def doSCO(self, enable): if not getattr(bluetooth, "SCOReader", None): dbg("sco not supported in this platform") return if enable: return self.enableSCO() else: return self.disableSCO()
def welcomeCheck(): while len(self.buffer) > 0 and self.buffer.find('\n') > -1: welcome, self.buffer = self.buffer.split('\n', 1) dbg("welcome", welcome) welcome = welcome.strip().lower().strip('\x00') for k, v in WELCOME.iteritems(): if welcome.find(v) > -1: return k
def internalDoCommand(self): if len(self.pending) == 0: return command, value, timeout = self.pending.pop(0) if callable(value): value = value() dbg("doCommand $%s%s" % (command, value)) self.transport.write("$%s%s\n\r" % (command, value)) self.callLater = reactor.callLater(timeout, self.internalDoCommand)
def set(self, option, value): dbg("set %s-> %s" % (option, value)) if option == "size": self.doCommand(option, SIZES[value]) elif option == "flash": self.doCommand(option, "0" if not value else "1") elif option == "pan" or option == "exposure": self.doCommand(option, value.upper()) else: dbg("ignored")
def doSetSize(self, size=None): self.state = ECHO self.__cancelLater() if not size: camera=settings.getCamera(self.address) size = "QVGA" #default if camera: size = camera.get("size", size) dbg("doSetSize(%s)", size) self.__doCommand(SIZES[size]) self.callLater = reactor.callLater(2, self.doPreview)
def set(self, option, value): dbg("set %s-> %s" % (option, value)) if option == "size": self.doCommand(option, SIZES[value]) elif option == "flash" or option == "stream": self.doCommand(option, "0" if not value else "1") elif option == "pan" or option == "exposure": self.doCommand(option, value.upper()) elif option == "voice": self.doSCO(value) else: dbg("ignored")
def doSetup(self): dbg("doSetup") nsets = settings.getCamera(self.address) sets = self.defaults size = self.size if nsets: sets.update(nsets) dbg(sets) self.callLater = reactor.callLater(4, self.internalDoCommand) self.doCommand("date", lambda: datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")) self.doCommand("size", SIZES[sets["size"]]) self.doCommand("flash", "0" if not sets["flash"] else "1") self.doCommand("pan", sets["pan"].upper()[0])
def doSetup(self): dbg("doSetup") nsets = settings.getCamera(self.address) sets = self.defaults size = self.size if nsets: sets.update(nsets) dbg(sets) self.callLater = reactor.callLater(1, self.internalDoCommand) self.doCommand("date", lambda: datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")) self.doCommand("size", SIZES[sets["size"]]) self.doCommand("stream", "1" if sets["stream"] else "0") self.doCommand("flash", "0" if not sets["flash"] else "1") self.doCommand("pan", sets["pan"].upper()[0])
def doINIT(self): def welcomeCheck(): while len(self.buffer) > 0 and self.buffer.find('\n') > -1: welcome, self.buffer = self.buffer.split('\n', 1) dbg("welcome", welcome) welcome = welcome.strip().lower().strip('\x00') for k, v in WELCOME.iteritems(): if welcome.find(v) > -1: return k dbg("doINIT", self.buffer) if self.buffer.find("\n") == -1: dbg("Welcome not received") if not self.callLater: self.callLater = reactor.callLater(3, self.invalidCamera) self.callLater.reset(2) return kind = welcomeCheck() if not kind: if not self.callLater: self.callLater = reactor.callLater(3, self.invalidCamera) self.callLater.reset(2) return self.kind = kind log.msg("Connected to a %s camera" % self.kind) dbg("still in buffer", len(self.buffer)) self.state = IDLE settings.setCameraSetting(self.address, "address", self.address) settings.setCameraSetting(self.address, "type", self.kind) settings.setCameraSetting(self.address, "name", "NN") settings.setCameraSetting(self.address, "last", strftime("%m/%d/%Y %H:%M:%S", localtime())) settings.save() self.client = TYPES[self.kind]["class"](self) if self.callLater: self.callLater.cancel() self.callLater = None
def __init__(self, address): dbg("new camera instance for (%s)", address) setattr(self, "client", None) setattr(self, "buffer", "") self.address = address
def doCommandMode(self): dbg("doCommandMode") self.state = COMMAND_MODE self.__doCommand(1) self.__cancelLater() self.callLater = reactor.callLater(1, self.doSetSize)
def disconnect(self): dbg("AIRi.disconnect")
def disconnect(self): dbg("AIRi.disconnect") self.disableSCO()
def disconnect(self): dbg("OptiEyes.disconnect") self.__doCommand(1)