示例#1
0
def action_set_all(on=True, interval=0.15, maxIntensity=100):
    print('action: set all to ' + ("on" if on else "off"))
    dimming.rotating = False
    intensity = maxIntensity if on else 0
    for device in dimming.deviceList:
        # put light to maximum brightness
        intensity = maxIntensity if on else 0
        values = {
            "light_level": intensity,
            "fade_time": dimming.fade_time,
            "response_time": 0,
            "override_time": 0,
            "lock_light_control": False
        }
        ble_xim.advLightControl(device, values)
        time.sleep(interval)
示例#2
0
def action_set_intensity_for(device_id=-1, intensity=0):
    print('action: set_intensity_for: device_id: ' + str(device_id) +
          " with intensity: " + str(intensity))
    # dimming.updateDeviceList()

    for device in dimming.deviceList:
        if device.deviceId[0] == device_id:
            values = {
                "light_level": intensity,
                "fade_time": 0,
                "response_time": 0,
                "override_time": 0,
                "lock_light_control": False
            }
            # finally, actually issue the advertising command
            ble_xim.advLightControl(device, values)
            return
    print "Error: could not locate device with ID {}".format(device_id)
示例#3
0
def action_set_group(on=True,
                     interval=0.15,
                     maxIntensity=100,
                     group=DEFAULT_GROUP):
    """
    Set a group of LEDs on, off or to a specific intensity.
    Note that the group numbers in the range 0 - 16535, but when advertising
    to a group, the address is 0xC000 (49152) plus the group number.
    """
    print('action: set group ' + str(group) + ' to ' + ("on" if on else "off"))
    dimming.rotating = False
    device_group = ble_device.NetDeviceId([0, 0, 0, 0], [49152 + group])
    intensity = maxIntensity if on else 0
    values = {
        "light_level": intensity,
        "fade_time": dimming.fade_time,
        "response_time": 0,
        "override_time": 0,
        "lock_light_control": False
    }
    ble_xim.advLightControl(device_group, values)
示例#4
0
def action_set_intensity_for(device_id=-1, intensity=0):
    print('action: set_intensity_for: device_id: ' + str(device_id) +
          " with intensity: " + str(intensity))
    # dimming.updateDeviceList()
    devices = dimming.orderedDeviceList.items()
    if len(devices) >= device_id:
        device = dimming.orderedDeviceList.items()[
            device_id -
            1]  # orderedList is 0 based index, the LED ID is one based index.
        # we only want to deal with one device so if our filtered list has more than one member we don't proceed
        # now we create the values dictionary.
        # the names and acceptable values of each parameter can be found in the API documentation for each call
        values = {
            "light_level": intensity,
            "fade_time": 0,
            "response_time": 0,
            "override_time": 0,
            "lock_light_control": False
        }
        # finally, actually issue the advertising command
        ble_xim.advLightControl(device[0], values)
        # time.sleep(0.15)
    else:
        print "Error: could not locate device with ID {}".format(device_id)
示例#5
0
 def run(self):
     if True:
         self.updateDeviceList()
         # print(d)
         while self._keep_alive:
             with self.lock:
                 ### State - Breathing: It should breath: 0 - 100 - 0 sequence for arbitary duration
                 if self.breathing:
                     action_set_group(True,
                                      self.fade_time,
                                      group=self.group)
                     time.sleep(self.fade_time / 1000.0)
                     action_set_group(False,
                                      self.fade_time,
                                      group=self.group)
                     time.sleep(self.fade_time / 1000.0)
                 ### State - Breath Fading: It should dim the max intensity to zero
                 ### i.e: 0 - 100 - 0 - 90 - 0 - 80 - 0 - 70 - 0 - ....
                 elif self.breathFading:
                     fading_values = [100, 90, 60, 30, 15, 10, 5, 2, 1, 0]
                     for v in fading_values:
                         action_set_group(True,
                                          self.fade_time,
                                          maxIntensity=v,
                                          group=self.group)
                         time.sleep(self.fade_time / 1000.0)
                         if v != 0:
                             action_set_group(False,
                                              self.fade_time,
                                              group=self.group)
                             time.sleep(self.fade_time / 1000.0)
                     self.breathFading = False  # This sequence should be terminated after completion
                 else:
                     ### State - Rotating: it should be paired in dimming: LED 1/5 LED 2/6 LED 3/7 LED 4/8
                     for group in self.groupedDeviceList:
                         if self.rotating:
                             # print("XIM: " + str(ximID))
                             # put light to maximum brightness
                             # devices = filter(lambda ndi: ndi.deviceId == [ximID], self.deviceList)
                             # print(devices)
                             print('dim on')
                             for device in group:
                                 intensity = 10
                                 values = {
                                     "light_level": intensity,
                                     "fade_time": self.fade_time,
                                     "response_time": 0,
                                     "override_time": 0,
                                     "lock_light_control": False
                                 }
                                 ble_xim.advLightControl(device, values)
                                 time.sleep(0.15)
                             time.sleep(self.fade_time / 1000 + 0.1)
                             # put light to minimum brightness
                             print('dim off')
                             for device in group:
                                 intensity = 0
                                 values = {
                                     "light_level": intensity,
                                     "fade_time": self.fade_time,
                                     "response_time": 0,
                                     "override_time": 0,
                                     "lock_light_control": False
                                 }
                                 ble_xim.advLightControl(device, values)
                                 time.sleep(0.15)
                             time.sleep(self.fade_time / 1000 + 0.1)
                     # sleep until next loop is due
                     if self.rotating:
                         self.rotating = False  # This sequence should be terminated after the completion
                         print('Rotation Sequence ended')
                         action_set_group(
                             False
                         )  # Need to force turn off all since it sometimes stuck turned on.
                 time.sleep(self._interval)