From ad5842419384af69858473673eb55e45884ccdc4 Mon Sep 17 00:00:00 2001 From: FrankX0 Date: Sun, 23 Jan 2022 14:33:56 +0100 Subject: [PATCH] Additional configuration for brightness sensor Possibility to configure the address of the sensor in the config file. Related to #214 . --- README.md | 7 +++---- wordclock_config/wordclock_config.reference.cfg | 3 +++ wordclock_plugins/time_default/plugin.py | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 98e19382..ed961fad 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,8 @@ * Linking the webinterface to your smartphones homescreen provides an app-like usage of the interface * Hardware buttons are not mandatory anymore. * Integration to your instance of [home-assistant](https://www.home-assistant.io/) using [this repository](https://github.com/bk1285/rpi_wordclock_for_homeassistant/) + * Support for a brightness sensor (TSL2561) -### ⏳ In progress - * Integration of a brightness sensor - ### :books: Further reading * Exemplary builds are available at [pinterest](https://www.pinterest.de/berndkrolla/wordclock-gallery/) * [Roadmap](https://github.com/bk1285/rpi_wordclock/projects) @@ -77,11 +75,12 @@ Install adafruit-circuitpython-tsl2561 lib sudo pip3 install adafruit-circuitpython-tsl2561 ``` -Set use_brightness_sensor config value to true +Set use_brightness_sensor config value to true and its address ``` # Set the brightness of the display (between 1 and 255) brightness = 200 use_brightness_sensor = True +sensor_address = 0x39 ``` #### Cronjob diff --git a/wordclock_config/wordclock_config.reference.cfg b/wordclock_config/wordclock_config.reference.cfg index 6a8914d2..4dc7a9a4 100755 --- a/wordclock_config/wordclock_config.reference.cfg +++ b/wordclock_config/wordclock_config.reference.cfg @@ -34,7 +34,10 @@ default_font = wcfont # Set the brightness of the display (between 1 and 255) brightness = 255 +# Supported sensor: TSL2561 use_brightness_sensor = False +# Sensor I2C address in decimal: 41 (0x29), 57 (0x39), 73 (0x49) +sensor_address = 57 [wordclock_interface] # Defines type of interface (gpio_low: pin is set to low on event, gpio_high: pin is set to high on event, no_gpio: no pins are read at all (= disabled hardware buttons)) diff --git a/wordclock_plugins/time_default/plugin.py b/wordclock_plugins/time_default/plugin.py index 01260902..6ccb0d9c 100644 --- a/wordclock_plugins/time_default/plugin.py +++ b/wordclock_plugins/time_default/plugin.py @@ -119,6 +119,7 @@ def __init__(self, config): self.brightness_change = 8 self.use_brightness_sensor = config.getboolean('wordclock_display', 'use_brightness_sensor') + self.brightness_sensor_address = config.getint('wordclock_display', 'sensor_address') print(('Using brigtness sensor : ' + str(self.use_brightness_sensor))) if self.use_brightness_sensor: @@ -127,7 +128,7 @@ def __init__(self, config): import busio import adafruit_tsl2561 i2c = busio.I2C(board.SCL, board.SDA) - self.sensor = adafruit_tsl2561.TSL2561(i2c) + self.sensor = adafruit_tsl2561.TSL2561(i2c,self.brightness_sensor_address) # save current brightness for switching back from sleep mode self.wake_brightness = self.brightness_mode_pos