forked from Duet3D/T113_Screen_for_RepRapFirmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeatObservers.cpp
143 lines (139 loc) · 4.75 KB
/
HeatObservers.cpp
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
140
141
142
143
/*
* HeatObservers.cpp
*
* Created on: 19 Dec 2023
* Author: Andy Everitt
*/
#include "Debug.h"
#include "Configuration.h"
#include "UI/Logic/Sidebar.h"
#include "UI/OmObserver.h"
#include "UI/UserInterface.h"
#include "ObjectModel/BedOrChamber.h"
#include "ObjectModel/Heat.h"
/*
* These functions are run when the OM field is received.
* The function takes 2 arguments:
* - val data from the OM where the type is automatically converted based on the chosen macro
* - indices is an array of the indicies for the OM key
* The _IF_CHANGED suffix only runs the function if the data is different from the previous
* time function was called. This is unique to each combination of indices.
*/
static UI::Observer<UI::ui_field_update_cb> HeatObserversField[] = {
OBSERVER_CHAR("heat:heaters^", [](OBSERVER_CHAR_ARGS) { OM::Heat::RemoveHeater(indices[0], false); }),
/* Update heaters current reading */
OBSERVER_FLOAT("heat:heaters^:current",
[](OBSERVER_FLOAT_ARGS) {
if (!OM::Heat::UpdateHeaterTemp(indices[0], val))
{
error("Failed to update heater temperature; heater %d = %fC", indices[0], val);
return;
}
UI::ToolsList::RefreshAllToolLists(false);
UI::Sidebar::UpdateTemperatureSnapshot();
}), /* Update what tool heaters active temperature */
OBSERVER_INT("heat:heaters^:active",
[](OBSERVER_INT_ARGS) {
if (!OM::Heat::UpdateHeaterTarget(indices[0], val, true))
{
error("Failed to update heater %d active temperature to %d", indices[0], val);
return;
}
UI::ToolsList::RefreshAllToolLists(false);
}),
/* Update what tool heaters standby temperature */
OBSERVER_INT("heat:heaters^:standby",
[](OBSERVER_INT_ARGS) {
if (!OM::Heat::UpdateHeaterTarget(indices[0], val, false))
{
error("Failed to update heater %d standby temperature to %d", indices[0], val);
return;
}
UI::ToolsList::RefreshAllToolLists(false);
}),
OBSERVER_FLOAT("heat:heaters^:avgPwm",
[](OBSERVER_FLOAT_ARGS) {
if (!OM::Heat::UpdateHeaterPwm(indices[0], val))
{
error("Failed to update heater %d avgPwm to %.3f", indices[0], val);
return;
}
UI::ToolsList::RefreshAllToolLists(false);
}),
OBSERVER_FLOAT("heat:heaters^:min",
[](OBSERVER_FLOAT_ARGS) {
if (!OM::Heat::UpdateHeaterMin(indices[0], val))
{
error("Failed to update heater %d min to %.3f", indices[0], val);
return;
}
UI::ToolsList::RefreshAllToolLists(false);
}),
OBSERVER_FLOAT("heat:heaters^:max",
[](OBSERVER_FLOAT_ARGS) {
if (!OM::Heat::UpdateHeaterMax(indices[0], val))
{
error("Failed to update heater %d max to %.3f", indices[0], val);
return;
}
UI::ToolsList::RefreshAllToolLists(false);
}),
OBSERVER_INT("heat:heaters^:sensor",
[](OBSERVER_INT_ARGS) {
if (!OM::Heat::UpdateHeaterSensor(indices[0], val))
{
error("Failed to update heater %d sensor to %d", indices[0], val);
return;
}
}),
OBSERVER_CHAR("heat:heaters^:state", [](OBSERVER_CHAR_ARGS) { OM::Heat::UpdateHeaterStatus(indices[0], val); }),
OBSERVER_INT("heat:bedHeaters^",
[](OBSERVER_INT_ARGS) {
if (val > -1)
{
OM::SetBedHeater(indices[0], val);
for (size_t i = OM::g_lastBed + 1; i < indices[0]; ++i)
{
OM::RemoveBed(i, false);
}
OM::g_lastBed = indices[0];
dbg("g_lastBed=%d", OM::g_lastBed);
}
}),
OBSERVER_INT("heat:chamberHeaters^",
[](OBSERVER_INT_ARGS) {
if (val > -1)
{
OM::SetChamberHeater(indices[0], val);
for (size_t i = OM::g_lastChamber + 1; i < indices[0]; ++i)
{
OM::RemoveChamber(i, false);
}
OM::g_lastChamber = indices[0];
dbg("g_lastChamber=%d", OM::g_lastChamber);
}
}),
};
/*
* These functions are run when the end of an array has been received from the OM
* The function needs to take in an array containing the indices of the OM key
*/
static UI::Observer<UI::ui_array_end_update_cb> HeatObserversArrayEnd[] = {
OBSERVER_ARRAY_END("heaters^",
[](OBSERVER_ARRAY_END_ARGS) {
if (OM::Heat::RemoveHeater(indices[0], true))
UI::ToolsList::RefreshAllToolLists();
}),
OBSERVER_ARRAY_END("heat:bedHeaters^",
[](OBSERVER_ARRAY_END_ARGS) {
OM::RemoveBed(OM::g_lastBed + 1, true);
OM::g_lastBed = -1;
UI::ToolsList::RefreshAllToolLists();
}),
OBSERVER_ARRAY_END("heat:chamberHeaters^",
[](OBSERVER_ARRAY_END_ARGS) {
OM::RemoveChamber(OM::g_lastChamber + 1, true);
OM::g_lastChamber = -1;
UI::ToolsList::RefreshAllToolLists();
}),
};