Exemplo n.º 1
0
def factoryReset() -> bool:
    logging.log(logging.INFO, "Factory reset")
    try:
        controlPacket = ControlPacketsGenerator.getCommandFactoryResetPacket()
        uartMessage = UartMessagePacket(UartTxType.CONTROL,
                                        controlPacket).getPacket()
        uartPacket = UartWrapperPacket(UartMessageType.UART_MESSAGE,
                                       uartMessage).getPacket()
        result = UartWriter(uartPacket).write_with_result_sync(
            [ResultValue.SUCCESS, ResultValue.WAIT_FOR_SUCCESS])
        if result.resultCode is ResultValue.SUCCESS:
            # This always returns SUCCESS, while we should actually wait.
            time.sleep(10.0)
            return True
        if result.resultCode is ResultValue.WAIT_FOR_SUCCESS:
            # Actually we should wait for the next result code..
            time.sleep(10.0)
            return True
        logging.log(logging.WARN, f"Factory reset failed, result={result}")
        return False

    except CrownstoneException as e:
        logging.log(logging.WARN, f"Failed to factory reset: {e}")
        return False
Exemplo n.º 2
0
 async def commandFactoryReset(self):
     """
       If you have the keys, you can use this to put the crownstone back into factory default mode
     """
     await self._writeControlPacket(
         ControlPacketsGenerator.getCommandFactoryResetPacket())