| 24 | } |
| 25 | |
| 26 | void attachDevices() { |
| 27 | LOGGER.info("Adding devices"); |
| 28 | |
| 29 | auto lock = getSyncLock()->asScopedLock(); |
| 30 | lock.lock(); |
| 31 | |
| 32 | // Start displays (their related touch devices start automatically within) |
| 33 | |
| 34 | LOGGER.info("Start displays"); |
| 35 | auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display); |
| 36 | for (const auto& display: displays) { |
| 37 | if (display->supportsLvgl()) { |
| 38 | if (display->startLvgl()) { |
| 39 | LOGGER.info("Started {}", display->getName()); |
| 40 | auto lvgl_display = display->getLvglDisplay(); |
| 41 | assert(lvgl_display != nullptr); |
| 42 | auto settings = settings::display::loadOrGetDefault(); |
| 43 | lv_display_rotation_t rotation = settings::display::toLvglDisplayRotation(settings.orientation); |
| 44 | if (rotation != lv_display_get_rotation(lvgl_display)) { |
| 45 | lv_display_set_rotation(lvgl_display, rotation); |
| 46 | } |
| 47 | } else { |
| 48 | LOGGER.error("Start failed for {}", display->getName()); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Start touch |
| 54 | |
| 55 | // TODO: Consider implementing support for multiple displays |
| 56 | auto primary_display = !displays.empty() ? displays[0] : nullptr; |
| 57 | |
| 58 | // Start display-related peripherals |
| 59 | if (primary_display != nullptr) { |
| 60 | LOGGER.info("Start touch devices"); |
| 61 | auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch); |
| 62 | for (const auto& touch_device: touch_devices) { |
| 63 | // Start any touch devices that haven't been started yet |
| 64 | if (touch_device->supportsLvgl() && touch_device->getLvglIndev() == nullptr) { |
| 65 | if (touch_device->startLvgl(primary_display->getLvglDisplay())) { |
| 66 | LOGGER.info("Started {}", touch_device->getName()); |
| 67 | } else { |
| 68 | LOGGER.error("Start failed for {}", touch_device->getName()); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Start keyboards |
| 74 | LOGGER.info("Start keyboards"); |
| 75 | auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard); |
| 76 | for (const auto& keyboard: keyboards) { |
| 77 | if (keyboard->isAttached()) { |
| 78 | if (keyboard->startLvgl(primary_display->getLvglDisplay())) { |
| 79 | lv_indev_t* keyboard_indev = keyboard->getLvglIndev(); |
| 80 | hardware_keyboard_set_indev(keyboard_indev); |
| 81 | LOGGER.info("Started {}", keyboard->getName()); |
| 82 | } else { |
| 83 | LOGGER.error("Start failed for {}", keyboard->getName()); |
nothing calls this directly
no test coverage detected