mirror of
https://github.com/OMGeeky/homecontrol.esp-sensors.git
synced 2026-02-23 15:49:52 +01:00
add configuration system for ESP Sensors project
This commit is contained in:
@@ -16,6 +16,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')
|
||||
|
||||
from src.esp_sensors.oled_display import OLEDDisplay
|
||||
from src.esp_sensors.dht22 import DHT22Sensor
|
||||
from src.esp_sensors.config import load_config, get_sensor_config, get_display_config, get_button_config
|
||||
|
||||
# Import hardware-specific modules if available (for ESP32/ESP8266)
|
||||
try:
|
||||
@@ -44,28 +45,29 @@ def main():
|
||||
"""
|
||||
Main function to demonstrate button-triggered sensor display.
|
||||
"""
|
||||
# Initialize a DHT22 sensor
|
||||
# Load configuration
|
||||
config = load_config()
|
||||
|
||||
# Initialize a DHT22 sensor using configuration
|
||||
dht_sensor = DHT22Sensor(
|
||||
name="Living Room",
|
||||
pin=4, # GPIO pin for DHT22 data
|
||||
interval=5, # Read every 5 seconds
|
||||
unit="C" # Celsius
|
||||
config=config # Pass the loaded config
|
||||
)
|
||||
print(f"Initialized DHT22 sensor: {dht_sensor.name}, pin: {dht_sensor.pin}")
|
||||
|
||||
# Initialize an OLED display
|
||||
# Initialize an OLED display using configuration
|
||||
display = OLEDDisplay(
|
||||
name="Status Display",
|
||||
scl_pin=22, # GPIO pin for I2C clock
|
||||
sda_pin=21, # GPIO pin for I2C data
|
||||
width=128, # Display width in pixels
|
||||
height=64, # Display height in pixels
|
||||
interval=1 # Update every second
|
||||
config=config # Pass the loaded config
|
||||
)
|
||||
print(f"Initialized OLED display: {display.name}, size: {display.width}x{display.height}")
|
||||
|
||||
# Set up button using configuration
|
||||
button_config = get_button_config("main_button", config)
|
||||
button_pin = button_config.get("pin", 0)
|
||||
print(f"Using button on pin: {button_pin}")
|
||||
|
||||
# Set up button on GPIO pin 0 (common button pin on many ESP boards)
|
||||
button_pin = 0
|
||||
if not SIMULATION:
|
||||
button = Pin(button_pin, Pin.IN, Pin.PULL_UP)
|
||||
pull_up = button_config.get("pull_up", True)
|
||||
button = Pin(button_pin, Pin.IN, Pin.PULL_UP if pull_up else None)
|
||||
|
||||
# Display initialization message
|
||||
display.clear()
|
||||
|
||||
Reference in New Issue
Block a user