Esempio n. 1
0
 async def set_ibeacon_major(self,
                             crownstone_id: int,
                             major: int,
                             index: int = 0) -> MeshResult:
     """
     :param crownstone_id: int crownstoneUid, 1-255
     :param major:  int: uint16 0-65535
     :param index: for the normal uuid, index = 0, when alternating you also need to define 1 in a
                   followup command. Usually 0 has already been set by the setup procedure.
     :return:
     """
     statePacket = ControlStateSetPacket(StateType.IBEACON_MAJOR, index)
     statePacket.loadUInt16(major)
     return await self._set_state_via_mesh_acked(crownstone_id,
                                                 statePacket.getPacket())
Esempio n. 2
0
 async def set_ibeacon_uuid(self,
                            crownstone_id: int,
                            uuid: str,
                            index: int = 0) -> MeshResult:
     """
     :param crownstone_id: int crownstoneUid, 1-255
     :param uuid:  string: "d8b094e7-569c-4bc6-8637-e11ce4221c18"
     :param index: for the normal uuid, index = 0, when alternating you also need to define 1 in a
                   followup command. Usually 0 has already been set by the setup procedure.
     :return:
     """
     statePacket = ControlStateSetPacket(StateType.IBEACON_UUID, index)
     statePacket.loadByteArray(
         Conversion.ibeaconUUIDString_to_reversed_uint8_array(uuid))
     return await self._set_state_via_mesh_acked(crownstone_id,
                                                 statePacket.getPacket())
Esempio n. 3
0
 def setUartMode(self, mode):
     """
         Set UART mode.
         :param mode: : 0=none 1=RX only, 2=TX only, 3=TX and RX
         :return:
     """
     if (mode < 0) or (mode > 3):
         return
     controlPacket = ControlStateSetPacket(
         StateType.UART_ENABLED).loadUInt8(mode).getPacket()
     self._send(UartTxType.CONTROL, controlPacket)
    async def setPowerZero(self, mW: int):
        controlPacket = ControlStateSetPacket(
            StateType.POWER_ZERO).loadInt32(mW).serialize()
        uartMessage = UartMessagePacket(UartTxType.CONTROL,
                                        controlPacket).serialize()
        uartPacket = UartWrapperPacket(UartMessageType.UART_MESSAGE,
                                       uartMessage).serialize()

        resultCollector = Collector(timeout=1, topic=SystemTopics.resultPacket)
        # send the message to the Crownstone
        UartEventBus.emit(SystemTopics.uartWriteData, uartPacket)

        # wait for the collectors to fill
        commandResultData = await resultCollector.receive()

        if commandResultData is not None:
            if commandResultData.resultCode is ResultValue.BUSY:
                await asyncio.sleep(0.2)
                return await self.setPowerZero(mW)
            elif commandResultData.resultCode is not ResultValue.SUCCESS:
                raise CrownstoneException(commandResultData.resultCode,
                                          "Command has failed.")
Esempio n. 5
0
 async def _setState(self, packet: ControlStateSetPacket):
     """
     Write set state command, and check result.
     """
     await self.core.control._writeControlAndGetResult(packet.getPacket())
 async def setCurrentThresholdDimmer(self, currentAmp: float):
     packet = ControlStateSetPacket(
         StateType.CURRENT_CONSUMPTION_THRESHOLD_DIMMER)
     packet.loadUInt16(currentAmp * 1000)
     await self.core.state._setState(StateType.SWITCH_STATE, packet)
 async def set_tx_power(self, crownstone_uid_array: List[int],
                        txPower: int):
     statePacket = ControlStateSetPacket(StateType.TX_POWER)
     statePacket.loadInt8(txPower)
     return await self._command_via_mesh_broadcast_acked(
         crownstone_uid_array, statePacket.serialize())