| 51 | } |
| 52 | |
| 53 | void ButtonControl::readCallback(lv_indev_t* indev, lv_indev_data_t* data) { |
| 54 | // Defaults |
| 55 | data->enc_diff = 0; |
| 56 | data->state = LV_INDEV_STATE_RELEASED; |
| 57 | |
| 58 | auto* self = static_cast<ButtonControl*>(lv_indev_get_driver_data(indev)); |
| 59 | |
| 60 | if (self->mutex.lock(100)) { |
| 61 | |
| 62 | for (int i = 0; i < self->pinConfigurations.size(); i++) { |
| 63 | const auto& config = self->pinConfigurations[i]; |
| 64 | std::vector<PinState>::reference state = self->pinStates[i]; |
| 65 | const bool trigger = (config.event == Event::ShortPress && state.triggerShortPress) || |
| 66 | (config.event == Event::LongPress && state.triggerLongPress); |
| 67 | state.triggerShortPress = false; |
| 68 | state.triggerLongPress = false; |
| 69 | if (trigger) { |
| 70 | switch (config.action) { |
| 71 | case Action::UiSelectNext: |
| 72 | data->enc_diff = 1; |
| 73 | break; |
| 74 | case Action::UiSelectPrevious: |
| 75 | data->enc_diff = -1; |
| 76 | break; |
| 77 | case Action::UiPressSelected: |
| 78 | data->state = LV_INDEV_STATE_PRESSED; |
| 79 | break; |
| 80 | case Action::AppClose: |
| 81 | tt::app::stop(); |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | self->mutex.unlock(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void ButtonControl::updatePin(std::vector<PinConfiguration>::const_reference configuration, std::vector<PinState>::reference state, bool pressed) { |
| 91 | auto now = tt::kernel::getMillis(); |