-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsydeDCHU.cpp
More file actions
89 lines (76 loc) · 2.55 KB
/
InsydeDCHU.cpp
File metadata and controls
89 lines (76 loc) · 2.55 KB
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
#include "InsydeDCHU.hpp"
#include <Windows.h>
#include <sstream>
using std::stringstream;
bool InsydeDCHU::init()
{
auto MHID = LoadLibraryA("InsydeDCHU.dll");
if (MHID == NULL) {
return false;
}
SetDCHU_Data = (int (*)(int command, byte * buffer, int length))GetProcAddress(MHID, "SetDCHU_Data");
WriteAppSettings = (int (*)(int page, int offset, int length, byte * buffer))GetProcAddress(MHID, "WriteAppSettings");
ReadAppSettings = (int (*)(int page, int offset, int length, byte * buffer))GetProcAddress(MHID, "ReadAppSettings");
return true;
}
std::string InsydeDCHU::getStatus()
{
stringstream ss;
byte brightness = 0;
ReadAppSettings(2, 35, 1, &brightness);
byte color[3] = { 0 };
ReadAppSettings(2, 81, 3, color);
ss << "RGB: " << "(" << (int)color[0] << ", " << (int)color[1] << ", " << (int)color[2] << ")\n";
ss << "亮度: " << (int)brightness << "\n";
byte mode = 0;
ReadAppSettings(2, 32, 1, &mode);
byte status = 0;
ReadAppSettings(2, 84, 1, &status);
ss << "灯光状态: " << (status == 0 ? "关" : "开") << '\n';
ss << "灯光模式: " << (int) mode<< '\n';
byte booteffect = 0;
ReadAppSettings(2, 7, 1, &booteffect);
ss << "引导覆盖: " << (booteffect == 0 ? "默认" : "覆盖") << "\n";
byte sleep[3] = { 0 };
ReadAppSettings(2, 37, 3, sleep);
int sleepsec = sleep[0] * 3600 + sleep[1] * 60 + sleep[2];
byte sleepstatus = 0;
ReadAppSettings(2, 36, 1, &sleepstatus);
ss << "睡眠状态: " << (sleepstatus == 0 ? "未睡眠" : "正在睡眠") << "\n";
ss << "睡眠时间: " << sleepsec << "秒\n";
return ss.str();
}
void InsydeDCHU::setMode(Mode mode)
{
byte data[] = { 255,255,255,(byte)mode };
SetDCHU_Data(103, data, 4);
//byte data2 = getModeNum(mode);
//WriteAppSettings(2, 32, 1, &data2);
}
byte InsydeDCHU::getModeNum(Mode mode)
{
switch (mode) {
case Mode::Random:return 0;
case Mode::Breath:return 2;
case Mode::Cycle: return 3;
case Mode::Wave: return 4;
case Mode::Dance: return 5;
case Mode::Tempo: return 6;
case Mode::Flash: return 7;
case Mode::AllRGB: return 8;
default: throw 0;
};
}
void InsydeDCHU::setColor(byte r, byte g, byte b)
{
byte rgb[] = { r,g,b,240 };
SetDCHU_Data(103, rgb, 4);
//WriteAppSettings(2, 81, 3, rgb);
}
void InsydeDCHU::SetBrightness(byte a)
{
byte data[] = { a, 0, 0, 244 };
SetDCHU_Data(103,data , 4);
//TODO: express the setting as a value in [0-4] as they do in their code
// WriteAppSettings(2, 35, 1, ref new byte[1]{ value } [0] );
}