MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / load

Function load

Tactility/Source/settings/DisplaySettings.cpp:107–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107bool load(DisplaySettings& settings) {
108 std::map<std::string, std::string> map;
109 if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
110 return false;
111 }
112
113 auto orientation_entry = map.find(SETTINGS_KEY_ORIENTATION);
114 Orientation orientation;
115 if (orientation_entry == map.end() || !fromString(orientation_entry->second, orientation)) {
116 orientation = getDefaultOrientation();
117 }
118
119 auto gamma_entry = map.find(SETTINGS_KEY_GAMMA_CURVE);
120 int gamma_curve = 0;
121 if (gamma_entry != map.end()) {
122 gamma_curve = atoi(gamma_entry->second.c_str());
123 }
124
125 auto backlight_duty_entry = map.find(SETTINGS_KEY_BACKLIGHT_DUTY);
126 int backlight_duty = 200; // default
127 if (backlight_duty_entry != map.end()) {
128 backlight_duty = atoi(backlight_duty_entry->second.c_str());
129 if (backlight_duty_entry->second != "0" && backlight_duty == 0) {
130 backlight_duty = 200;
131 }
132 }
133
134 bool timeout_enabled = false;
135 auto timeout_enabled_entry = map.find(SETTINGS_KEY_TIMEOUT_ENABLED);
136 if (timeout_enabled_entry != map.end()) {
137 timeout_enabled = (timeout_enabled_entry->second == "1" || timeout_enabled_entry->second == "true" || timeout_enabled_entry->second == "True");
138 }
139
140 uint32_t timeout_ms = 60000; // default 60s
141 auto timeout_ms_entry = map.find(SETTINGS_KEY_TIMEOUT_MS);
142 if (timeout_ms_entry != map.end()) {
143 timeout_ms = static_cast<uint32_t>(std::strtoul(timeout_ms_entry->second.c_str(), nullptr, 10));
144 }
145
146 auto screensaver_entry = map.find(SETTINGS_KEY_SCREENSAVER_TYPE);
147 ScreensaverType screensaver_type = ScreensaverType::BouncingBalls;
148 if (screensaver_entry != map.end()) {
149 fromString(screensaver_entry->second, screensaver_type);
150 }
151
152 settings.orientation = orientation;
153 settings.gammaCurve = gamma_curve;
154 settings.backlightDuty = backlight_duty;
155 settings.backlightTimeoutEnabled = timeout_enabled;
156 settings.backlightTimeoutMs = timeout_ms;
157 settings.screensaverType = screensaver_type;
158
159 return true;
160}
161
162DisplaySettings getDefault() {
163 return DisplaySettings {

Callers 10

loadOrGetDefaultFunction · 0.70
DOCTEST_DEFINE_DECORATORFunction · 0.50
onConnectFunction · 0.50
onToggleAutoConnectMethod · 0.50
onPressConnectMethod · 0.50
onShowMethod · 0.50
setupDisplayMethod · 0.50
onToggleAutoConnectMethod · 0.50
onCreateMethod · 0.50
onShowMethod · 0.50

Calls 3

loadPropertiesFileFunction · 0.85
getDefaultOrientationFunction · 0.85
fromStringFunction · 0.70

Tested by 1

DOCTEST_DEFINE_DECORATORFunction · 0.40