Пример #1
0
def do_iterate_light():
    global _state

    if not _state.apds.color_data_ready:
        return

    # get the data and print the different channels
    currLux = _state.currLux
    r, g, b, _c = _state.apds.color_data
    newLux = colorutility.calculate_lux(r, g, b)

    _state.currLux = max(0, int(newLux))
    now = datetime.now()
    tdelta = now - _state.luxLastPeriodicReport

    # Reasons why lux should be reported:
    # 1) explicitly asked to do so
    # 2) predetermined report interval
    # 3) high/low watermark reached
    # 4) big delta
    sendLuxEvent = False
    if _state.forceNextLuxEvent:
        _state.forceNextLuxEvent = False
        sendLuxEvent = True
    elif int(tdelta.total_seconds()) > const.motion_luxReportPeriodInSeconds:
        sendLuxEvent = True
    elif _state.currLux >= const.motion_luxHighWatermark and not _state.luxAboveWatermark:
        _state.luxAboveWatermark = True
        sendLuxEvent = True
    elif _state.currLux <= const.motion_luxLowWatermark and _state.luxAboveWatermark:
        _state.luxAboveWatermark = False
        sendLuxEvent = True
    elif abs(_state.lastLuxReported -
             _state.currLux) >= const.motion_luxDeltaThreshold:
        sendLuxEvent = True

    if not sendLuxEvent:
        return

    logger.debug("lux update from {} to {}".format(currLux, _state.currLux))

    # create lux event and send it to main
    _state.luxLastPeriodicReport = now
    _state.lastLuxReported = _state.currLux
    if _state.luxNotifyEnabled:
        event = events.MotionLux(_state.currLux)
        _notifyEvent(event)
Пример #2
0
# SPDX-License-Identifier: MIT

import time
import board
import busio
from adafruit_apds9960.apds9960 import APDS9960
from adafruit_apds9960 import colorutility

i2c = busio.I2C(board.SCL, board.SDA)
apds = APDS9960(i2c)
apds.enable_color = True

while True:
    # create some variables to store the color data in

    # wait for color data to be ready
    while not apds.color_data_ready:
        time.sleep(0.005)

    # get the data and print the different channels
    r, g, b, c = apds.color_data
    print("red: ", r)
    print("green: ", g)
    print("blue: ", b)
    print("clear: ", c)

    print("color temp {}".format(
        colorutility.calculate_color_temperature(r, g, b)))
    print("light lux {}".format(colorutility.calculate_lux(r, g, b)))
    time.sleep(0.5)
Пример #3
0
i2c = busio.I2C(board.SCL, board.SDA)
apds = APDS9960(i2c)
apds.enable_color = True

while True:
    #create some variables to store the color data in

    #wait for color data to be ready
    while not apds.color_data_ready:
        time.sleep(0.005)

    #get the data and print the different channels
    r, g, b, c = apds.color_data

    temp = colorutility.calculate_color_temperature(r, g, b)
    lux = colorutility.calculate_lux(r, g, b)

    # print("red: ", r)
    # print("green: ", g)
    # print("blue: ", b)
    # print("clear: ", c)
    # print("color temp {0:0.2f}".format(temp))
    # print("light lux {0:0.2f}".format(lux))

    client.publish('psz/apds9960/red', r)
    client.publish('psz/apds9960/green', g)
    client.publish('psz/apds9960/blue', b)
    client.publish('psz/apds9960/clear', c)
    client.publish('psz/apds9960/color_temp', '{0:0.2f}'.format(temp))
    client.publish('psz/apds9960/lux', '{0:0.2f}'.format(lux))
Пример #4
0
import board
import busio
import digitalio
from adafruit_apds9960.apds9960 import APDS9960
from adafruit_apds9960 import colorutility

i2c = busio.I2C(board.SCL, board.SDA)
int_pin = digitalio.DigitalInOut(board.D5)
apds = APDS9960(i2c)
apds.enable_color = True


while True:
    #create some variables to store the color data in

    #wait for color data to be ready
    while not apds.color_data_ready:
        time.sleep(0.005)


    #get the data and print the different channels
    r, g, b, c = apds.color_data
    print("red: ", r)
    print("green: ", g)
    print("blue: ", b)
    print("clear: ", c)

    print("color temp {}".format(colorutility.calculate_color_temperature(r, g, b)))
    print("light lux {}".format(colorutility.calculate_lux(r, g, b)))
    time.sleep(0.5)