def __init__(self):
        self.thread = None

        options = load_options()

        if options.hidraw:
            raise ValueError("HID mode not supported")
            backend = HidrawBackend(Daemon.logger)
        else:
            subprocess.run(["hciconfig", "hciX", "up"])
            backend = BluetoothBackend(Daemon.logger)

        backend.setup()

        self.thread = create_controller_thread(1, options.controllers[0])

        self.thread.controller.setup_device(next(backend.devices))

        self.shim = ActionShim(self.thread.controller)
        self.thread.controller.actions.append(self.shim)
        self.shim.enable()

        self._color = (None, None, None)
        self._rumble = (None, None)
        self._flash = (None, None)

        # ensure we get a value before returning
        while self.shim.values is None:
            pass
class ds4_driver_BLE(ControllerRos):
    def __init__(self, ros2_node):
        super(ds4_driver_BLE, self).__init__(ros2_node)
        self.ros2_node = ros2_node
        # Publish Connect Status
        self.DS4_Connect_Status = self.ros2_node.create_publisher(
            Int32, "ds4_connect_status")
        #
        # self.device_addr = rospy.get_param('~device_addr', None)
        self.device_addr = None
        backend_type = 'bluetooth'
        #backend_type = rospy.get_param('~backend', 'hidraw')
        # Connect Status
        self.Status = Int32()
        self.Status.data = 0
        # backend_type
        if backend_type == 'bluetooth':
            self.backend = BluetoothBackend(Logger('backend'))
        else:
            self.backend = HidrawBackend(Logger('backend'))
        self.ds4_connect()

    def ds4_connect(self):
        try:
            self.backend.setup()
        except BackendError as err:
            #rospy.logerr(err)
            ros2_node.get_logger().info('Error')
            sys.exit(1)
        #
        print('Wait....')
        for device in self.backend.devices:
            self.ros2_node.get_logger().info('I heard: "%s"' %
                                             format(device.name))
            #rospy.loginfo('Connected to {0}'.format(device.name))
            if self.device_addr in (None, '', device.device_addr):
                self.setup_device(device)
                break
            #rospy.loginfo('Waiting for specified controller')
            self.ros2_node.get_logger().info(
                'Waiting for specified controller')
        # DS4 Connect Status
        # Status = Int32()
        self.Status.data = 1
        self.DS4_Connect_Status.publish(self.Status)
        # Status
        # self.DS4_Connect_Status.publish(Status)

    def ds4_Not_connect(self):
        # DS4 Connect Status
        # Status = Int32()
        self.Status.data = 0
        self.DS4_Connect_Status.publish(self.Status)
        # Status
        # self.DS4_Connect_Status.publish(Status)
        #
        self.ros2_node.get_logger().info('Disconnected...')
        # self.exit()
        self.loop.stop()
        self.ds4_connect()
        # Run
        self.loop.register_event('device-report', self.cb_report)
        self.loop.register_event('device-cleanup', self.ds4_Not_connect)
        self.run()
        '''
        if self.is_alive():
            self.join()
        '''

    def ds4_Start(self):
        if not self.is_alive():
            self.start()
            self.loop.register_event('device-report', self.cb_report)
            self.loop.register_event('device-cleanup', self.ds4_Not_connect)

    def Send_Connect_Status(self):
        self.DS4_Connect_Status.publish(self.Status)