blob: ff59755691c28aad10891764a22daa75eb4ca4c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include "input/device_factory.hpp"
#include <memory>
#include "input/feedback_haptics.hpp"
#include "input/feedback_tts.hpp"
#include "input/input_device.hpp"
#include "input/input_hard_reset.hpp"
#include "input/input_nav_buttons.hpp"
#include "input/input_touch_dpad.hpp"
#include "input/input_touch_wheel.hpp"
#include "input/input_volume_buttons.hpp"
#include "input/input_media_buttons.hpp"
namespace input {
DeviceFactory::DeviceFactory(
std::shared_ptr<system_fsm::ServiceLocator> services)
: services_(services) {
if (services->touchwheel()) {
wheel_ =
std::make_shared<TouchWheel>(services->nvs(), **services->touchwheel());
}
reset_ = std::make_shared<HardReset>(services_->gpios());
}
auto DeviceFactory::createLockedInputs()
-> std::vector<std::shared_ptr<IInputDevice>> {
auto locked_mode = services_->nvs().LockedInput();
std::vector<std::shared_ptr<IInputDevice>> ret;
switch (locked_mode) {
case drivers::NvsStorage::ButtonInputModes::kDisabled:
break;
case drivers::NvsStorage::ButtonInputModes::kMediaControls:
ret.push_back(std::make_shared<MediaButtons>(services_->gpios(), services_->track_queue()));
break;
case drivers::NvsStorage::ButtonInputModes::kNavigation:
// I don't think we want navigation to work when locked?
// ret.push_back(std::make_shared<NavButtons>(services_->gpios()));
break;
case drivers::NvsStorage::ButtonInputModes::kVolumeOnly:
ret.push_back(std::make_shared<VolumeButtons>(services_->gpios()));
break;
}
ret.push_back(reset_);
return ret;
}
auto DeviceFactory::createInputs()
-> std::vector<std::shared_ptr<IInputDevice>> {
std::vector<std::shared_ptr<IInputDevice>> ret;
auto wheel_mode = services_->nvs().WheelInput();
auto buttons_mode = services_->nvs().ButtonInput();
// Make sure we always have a navigational input
if (wheel_mode == drivers::NvsStorage::WheelInputModes::kDisabled) {
if (buttons_mode != drivers::NvsStorage::ButtonInputModes::kNavigation) {
wheel_mode = drivers::NvsStorage::WheelInputModes::kRotatingWheel;
services_->nvs().WheelInput(wheel_mode);
}
}
switch (wheel_mode) {
case drivers::NvsStorage::WheelInputModes::kDisabled:
break;
case drivers::NvsStorage::WheelInputModes::kDirectionalWheel:
if (services_->touchwheel()) {
ret.push_back(std::make_shared<TouchDPad>(**services_->touchwheel()));
}
break;
case drivers::NvsStorage::WheelInputModes::kRotatingWheel:
default: // Don't break input over a bad enum value.
if (wheel_) {
ret.push_back(wheel_);
}
break;
}
switch (buttons_mode) {
case drivers::NvsStorage::ButtonInputModes::kDisabled:
break;
case drivers::NvsStorage::ButtonInputModes::kMediaControls:
ret.push_back(std::make_shared<MediaButtons>(services_->gpios(), services_->track_queue()));
break;
case drivers::NvsStorage::ButtonInputModes::kNavigation:
ret.push_back(std::make_shared<NavButtons>(services_->gpios()));
break;
case drivers::NvsStorage::ButtonInputModes::kVolumeOnly:
default:
ret.push_back(std::make_shared<VolumeButtons>(services_->gpios()));
break;
}
ret.push_back(reset_);
return ret;
}
auto DeviceFactory::createFeedbacks()
-> std::vector<std::shared_ptr<IFeedbackDevice>> {
return {
std::make_shared<Haptics>(services_->haptics(), services_),
std::make_shared<TextToSpeech>(services_->tts()),
};
}
} // namespace input
|