display backlight and bluetooth reference counting (#639)

This commit is contained in:
Ken Van Hoeylandt
2026-08-29 23:37:31 +02:00
committed by GitHub
parent 19b11eb9a8
commit 64fb1a9f52
16 changed files with 80 additions and 33 deletions
+1
View File
@@ -99,6 +99,7 @@ void setupDisplay() {
} else {
LOG_E(TAG, "Failed to set brightness of %s", backlight->name);
}
device_put(backlight);
} else {
LOG_I(TAG, "No backlight for %s", display->name);
}
+3
View File
@@ -74,6 +74,7 @@ void onBacklightSliderEvent(lv_event_t* event) {
ctx->displaySettings.backlightDuty = static_cast<uint8_t>(slider_value);
ctx->displaySettingsUpdated = true;
backlight_set_brightness(backlight, ctx->displaySettings.backlightDuty);
device_put(backlight);
}
void onOrientationSet(lv_event_t* event) {
@@ -184,6 +185,8 @@ void createWidgets(lv_obj_t* parent, void* userData) {
lv_slider_set_value(brightness_slider, ctx->displaySettings.backlightDuty, LV_ANIM_OFF);
}
// Only compared against nullptr below, never dereferenced again, so releasing it here is safe.
device_put(backlight);
}
// Orientation
+14 -7
View File
@@ -138,20 +138,23 @@ static void bt_event_bridge(BtEvent event) {
}
} else if (has_hid_device_auto) {
LOG_I(TAG, "HID device auto-start (bonded peer found)");
if (Device* dev = bluetooth_hid_device_get_device()) {
if (Device* dev = bluetooth_hid_device_get()) {
bluetooth_hid_device_start(dev, BT_HID_DEVICE_MODE_KEYBOARD);
device_put(dev);
}
} else {
if (settings::shouldSppAutoStart()) {
LOG_I(TAG, "Auto-starting SPP server");
if (Device* dev = bluetooth_serial_get_device()) {
if (Device* dev = bluetooth_serial_get()) {
bluetooth_serial_start(dev);
device_put(dev);
}
}
if (settings::shouldMidiAutoStart()) {
LOG_I(TAG, "Auto-starting MIDI server");
if (Device* dev = bluetooth_midi_get_device()) {
if (Device* dev = bluetooth_midi_get()) {
bluetooth_midi_start(dev);
device_put(dev);
}
}
}
@@ -476,18 +479,21 @@ void connect(const std::array<uint8_t, 6>& addr, int profileId) {
if (profileId == BT_PROFILE_HID_HOST) {
hidHostConnect(addr);
} else if (profileId == BT_PROFILE_HID_DEVICE) {
if (Device* dev = bluetooth_hid_device_get_device()) {
if (Device* dev = bluetooth_hid_device_get()) {
bluetooth_hid_device_start(dev, BT_HID_DEVICE_MODE_KEYBOARD);
device_put(dev);
}
} else if (profileId == BT_PROFILE_SPP) {
if (Device* dev = bluetooth_serial_get_device()) {
if (Device* dev = bluetooth_serial_get()) {
bluetooth_serial_start(dev);
settings::setSppAutoStart(true);
device_put(dev);
}
} else if (profileId == BT_PROFILE_MIDI) {
if (Device* dev = bluetooth_midi_get_device()) {
if (Device* dev = bluetooth_midi_get()) {
bluetooth_midi_start(dev);
settings::setMidiAutoStart(true);
device_put(dev);
}
}
}
@@ -497,8 +503,9 @@ void disconnect(const std::array<uint8_t, 6>& addr, int profileId) {
if (profileId == BT_PROFILE_HID_HOST) {
hidHostDisconnect();
} else if (profileId == BT_PROFILE_HID_DEVICE) {
if (Device* dev = bluetooth_hid_device_get_device()) {
if (Device* dev = bluetooth_hid_device_get()) {
bluetooth_hid_device_stop(dev);
device_put(dev);
}
} else {
Device* dev;
@@ -38,7 +38,6 @@ static void setBacklightBrightness(uint8_t brightness) {
if (device_get_first_active_by_type(&DISPLAY_TYPE, &display) == ERROR_NONE) {
::Device* backlight;
if (display_get_backlight(display, &backlight) == ERROR_NONE) {
device_get(backlight);
backlight_set_brightness(backlight, brightness);
device_put(backlight);
}
@@ -53,6 +52,7 @@ static bool hasDisplayWithBacklight() {
::Device* backlight;
if (display_get_backlight(display, &backlight) == ERROR_NONE) {
result = true;
device_put(backlight);
}
device_put(display);
}
@@ -178,10 +178,16 @@ class StatusbarService final : public Service {
}
}
Device* serial_dev = bluetooth_serial_get_device();
Device* midi_dev = bluetooth_midi_get_device();
Device* serial_dev = bluetooth_serial_get();
Device* midi_dev = bluetooth_midi_get();
bool connected = (serial_dev && bluetooth_serial_is_connected(serial_dev)) ||
(midi_dev && bluetooth_midi_is_connected(midi_dev));
if (serial_dev) {
device_put(serial_dev);
}
if (midi_dev) {
device_put(midi_dev);
}
const char* desired_icon = getBluetoothStatusIcon(radio_state, scanning, connected);
if (bt_last_icon != desired_icon) {
if (desired_icon != nullptr) {