-
Notifications
You must be signed in to change notification settings - Fork 17
/
MsgSetColorSettings.h
72 lines (57 loc) · 2.09 KB
/
MsgSetColorSettings.h
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
#pragma once
#include "MsgHandlerBase.h"
#include "MsgFrameBuffer.h"
#include "Logging.h"
#include "MathUtils.h"
#include "Preferences.h"
#include "TrapezoidSampler.h"
class MsgSetColorSettings : public MsgHandlerBase
{
public:
virtual bool Read(Connection* sender, NetIncomingMessage& msg)
{
if (msg.BodyLength() == 0)
return false;
// Read the body as json
json_error_t error;
json_t* root = json_loads(msg.Body(), 0, &error);
if (!root)
{
LOG_ERROR("MsgSetColorSettings.Read: error on line " << error.line << ":" << error.text);
return false;
}
LOG_INFO("Processing MsgSetColorSettings message");
Preferences* prefs = Preferences::Instance;
// TotalFadeTimeMS
json_t* totalFadeTimeMS = json_object_get(root, "totalFadeTimeMS");
if (json_is_integer(totalFadeTimeMS))
prefs->TotalFadeTimeMS = (int)json_integer_value(totalFadeTimeMS);
// Fixed Color settings
json_t* fixedColorEnabled = json_object_get(root, "fixedColorEnabled");
if (json_is_boolean(fixedColorEnabled))
prefs->FixedColorEnabled = json_is_true(fixedColorEnabled);
json_t* fixedColor = json_object_get(root, "fixedColor");
if (json_is_color(fixedColor))
prefs->FixedColor = json_color_value(fixedColor);
// Camera settings
json_t* camSaturation = json_object_get(root, "camSaturation");
if (json_is_integer(camSaturation))
prefs->CamSaturation = (uint8_t)json_integer_value(camSaturation);
json_t* camBrightness = json_object_get(root, "camBrightness");
if (json_is_integer(camBrightness))
prefs->CamBrightness = (uint8_t)json_integer_value(camBrightness);
json_t* camContrast = json_object_get(root, "camContrast");
if (json_is_integer(camContrast))
prefs->CamContrast = (uint8_t)json_integer_value(camContrast);
json_t* camGain = json_object_get(root, "camGain");
if (json_is_integer(camGain))
prefs->CamGain = (uint8_t)json_integer_value(camGain);
// Update camera
CameraController::Instance->UpdateSettings(prefs->CamSaturation, prefs->CamBrightness, prefs->CamContrast, prefs->CamGain);
// Save
prefs->Save();
// Cleanup
json_decref(root);
return true;
}
};