# screen-brightness.conf — reTerminal DM Bridge Brightness Daemon
#
# Regulatory basis
#   IMO MSC.191(79) §8.1  : brightness adjustable, never extinguished
#   IMO MSC.302(87)       : alarms = high luminance; night mode preserves night vision
#   IHO S-52 / IEC 62288  : NIGHT / DUSK / DAY operating modes
#
# Reload without restart: systemctl reload screen-brightness
# Override from bridge console:
#   echo 3    | sudo tee /run/screen-brightness/override   # fix at level 3
#   echo auto | sudo tee /run/screen-brightness/override   # return to auto

[screen-brightness]

# ── Sysfs paths ──────────────────────────────────────────────────────────────
backlight_path = /sys/class/backlight/lcd_backlight/brightness
buzzer_path    = /sys/class/leds/usr-buzzer/brightness
lux_path       = /sys/bus/iio/devices/iio:device0/in_illuminance_input

# ── Timing ───────────────────────────────────────────────────────────────────
# How often the ambient sensor is read (seconds)
poll_interval = 2

# How often the buzzer is checked (seconds). Keep below 1 so alarms are seen quickly.
buzzer_poll = 0.5

# How long to hold maximum brightness after the buzzer stops (seconds)
# IMO MSC.302(87): alarm attention must persist long enough for crew response
buzzer_cooldown = 10

# ── Lux thresholds — IHO S-52 three-mode framework ──────────────────────────
# Adjust these to match the actual lighting environment of your bridge.
#
#  0 — lux_night_max     → NIGHT mode  (very dark, night watch)
#  lux_night_max+1 — lux_dusk_max  → DUSK  mode  (dim, dawn/dusk)
#  lux_dusk_max+1  — lux_day_dim_max → DAY-DIM
#  lux_day_dim_max+1 — lux_day_normal_max → DAY-NORMAL
#  > lux_day_normal_max  → DAY-BRIGHT (direct sunlight / tropical day)

lux_night_max      = 20
lux_dusk_max       = 200
lux_day_dim_max    = 500
lux_day_normal_max = 1000

# ── Brightness levels per mode (1 = minimum, 5 = maximum) ───────────────────
# Level 0 is NEVER used — IMO "not to extinction" principle.
# Minimum must remain legible at the navigator's position.
level_night      = 1
level_dusk       = 2
level_day_dim    = 3
level_day_normal = 4
level_day_bright = 5

# Brightness forced during ALERT (buzzer ON) and COOLDOWN states.
# IMO MSC.302(87): alarm visual indicators must be high luminous intensity.
level_alert = 5

# ── Hysteresis ───────────────────────────────────────────────────────────────
# Number of consecutive polls that must agree on a new ambient brightness
# target before the change is committed. Prevents flickering when lux hovers
# near a mode boundary (e.g. sunset making the sensor oscillate 18–22 lux).
# At poll_interval=2s and hysteresis_polls=3, a level change takes max 6s.
hysteresis_polls = 3
