-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhw_ds_board.cs
139 lines (123 loc) · 3.61 KB
/
hw_ds_board.cs
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.IO;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace guardian_server {
public class DS_Board {
Hardware hw;
Dictionary<string, dynamic> state;
public void update_sensors() {
hw.server.sensors["fans"] = state["fans"];
hw.server.sensors["strips"] = state["strips"];
hw.server.sensors["uv_strips"] = state["uv_strips"];
}
public Dictionary<string, dynamic> save() {
return state;
}
public List<double?> default_color() {
return new List<double?> { 0, 1, 0.5 };
}
public List<double?> default_beg_color() {
return new List<double?> { 240, 1, 0.5 };
}
public List<double?> default_end_color() {
return new List<double?> { 0, 1, 0.5 };
}
public dynamic as_fan_color(dynamic color) {
color[1] = null;
color[2] = null;
return color;
}
public dynamic as_uv_color(dynamic color) {
color[0] = null;
color[2] = null;
return color;
}
public void set_default_state() {
int i;
state = new Dictionary<string, dynamic>();
state["fans"] = new List<Dictionary<string, dynamic>>();
state["strips"] = new List<Dictionary<string, dynamic>>();
state["uv_strips"] = new List<Dictionary<string, dynamic>>();
for (i = 0; i < 7; i += 1) {
var fan = new Dictionary<string, dynamic>();
fan["name"] = "Fan " + (i + 1);
fan["effect"] = "none";
fan["color"] = as_fan_color(default_color());
fan["beg_color"] = as_fan_color(default_beg_color());
fan["end_color"] = as_fan_color(default_end_color());
fan["pwm"] = 0;
fan["rpm"] = 0;
fan["auto"] = 0;
fan["temp"] = 40;
state["fans"].Add(fan);
}
for (i = 0; i < 4; i += 1) {
var strip = new Dictionary<string, dynamic>();
strip["name"] = "Strip " + (i + 1);
strip["effect"] = "none";
strip["color"] = default_color();
strip["beg_color"] = default_beg_color();
strip["end_color"] = default_end_color();
state["strips"].Add(strip);
}
for (i = 0; i < 2; i += 1) {
var uv = new Dictionary<string, dynamic>();
uv["name"] = "UV Strip " + (i + 1);
uv["effect"] = "none";
uv["color"] = as_uv_color(default_color());
uv["beg_color"] = as_uv_color(default_beg_color());
uv["end_color"] = as_uv_color(default_end_color());
state["uv_strips"].Add(uv);
}
}
void update_obj(dynamic from, dynamic to) {
foreach (JProperty x in from) {
to[x.Name] = x.Value;
}
}
public void update_fan(dynamic fan) {
int i;
for (i = 0; i < state["fans"].Count; i += 1) {
var x = state["fans"][i];
if (fan["name"] == x["name"]) {
update_obj(fan, x);
as_fan_color(x["color"]);
as_fan_color(x["beg_color"]);
as_fan_color(x["end_color"]);
}
}
}
public void update_strip(dynamic strip) {
int i;
for (i = 0; i < state["strips"].Count; i += 1) {
var x = state["strips"][i];
if (strip["name"] == x["name"]) {
update_obj(strip, x);
}
}
}
public void update_uv_strip(dynamic uv_strip) {
int i;
for (i = 0; i < state["uv_strips"].Count; i += 1) {
var x = state["uv_strips"][i];
if (uv_strip["name"] == x["name"]) {
update_obj(uv_strip, x);
as_uv_color(x["color"]);
as_uv_color(x["beg_color"]);
as_uv_color(x["end_color"]);
}
}
}
public DS_Board(Hardware h) {
Program.log.add("DS_Board: ");
hw = h;
set_default_state();
if (hw.state["ds_board"] != null) {
update_obj(hw.state["ds_board"], state);
}
Program.log.add_line("ok");
}
}
}