forked from PlummersSoftwareLLC/NightDriverStrip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremotecontrol.cpp
More file actions
146 lines (128 loc) · 4.5 KB
/
remotecontrol.cpp
File metadata and controls
146 lines (128 loc) · 4.5 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
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
144
145
146
//+--------------------------------------------------------------------------
//
// File: remotecontrol.cpp
//
// NightDriverStrip - (c) 2018 Plummer's Software LLC. All Rights Reserved.
//
// This file is part of the NightDriver software project.
//
// NightDriver is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// NightDriver is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Nightdriver. It is normally found in copying.txt
// If not, see <https://www.gnu.org/licenses/>.
//
//
// Description:
//
// Handles a simple IR remote for changing effects, brightness, etc.
//
// History: Jun-14-2023 Rbergen Extracted handle() from header
//---------------------------------------------------------------------------
#include "globals.h"
#if ENABLE_REMOTE
#include "systemcontainer.h"
#define BRIGHTNESS_STEP 20
void RemoteControl::handle()
{
decode_results results;
static uint lastResult = 0;
if (!_IR_Receive.decode(&results))
return;
uint result = results.value;
_IR_Receive.resume();
debugI("Received IR Remote Code: 0x%08X, Decode: %08X\n", result, results.decode_type);
if (0xFFFFFFFF == result || result == lastResult)
{
static uint lastRepeatTime = millis();
// Only the OFF key runs at the full unbounded speed, so you can rapidly dim. But everything
// else has its repeat rate clamped here.
auto kMinRepeatms = 200;
if (result == IR_OFF)
kMinRepeatms = 0; // Dim as fast as the remote sends it
else if (result == 0xFFFFFFFF)
kMinRepeatms = 500; // Repeats happen at 500ms
else if (result == lastResult)
kMinRepeatms = 50; // Manual presses get debounced to at least 50ms
if (millis() - lastRepeatTime > kMinRepeatms)
{
debugV("Remote Repeat; lastResult == %08x, elapsed = %lu\n", lastResult, millis()-lastRepeatTime);
result = lastResult;
lastRepeatTime = millis();
}
else
{
return;
}
}
lastResult = result;
auto &effectManager = g_ptrSystem->EffectManager();
auto &deviceConfig = g_ptrSystem->DeviceConfig();
if (IR_ON == result)
{
debugV("Turning ON via remote");
effectManager.ClearRemoteColor();
effectManager.SetInterval(0);
effectManager.StartEffect();
deviceConfig.SetBrightness(BRIGHTNESS_MAX);
return;
}
else if (IR_OFF == result)
{
deviceConfig.SetBrightness((int)deviceConfig.GetBrightness() - BRIGHTNESS_STEP);
return;
}
else if (IR_BPLUS == result)
{
effectManager.SetInterval(DEFAULT_EFFECT_INTERVAL, true);
if (deviceConfig.ApplyGlobalColors())
effectManager.ClearRemoteColor();
else
effectManager.NextEffect();
return;
}
else if (IR_BMINUS == result)
{
effectManager.SetInterval(DEFAULT_EFFECT_INTERVAL, true);
if (deviceConfig.ApplyGlobalColors())
effectManager.ClearRemoteColor();
else
effectManager.PreviousEffect();
return;
}
else if (IR_SMOOTH == result)
{
effectManager.ClearRemoteColor();
effectManager.SetInterval(EffectManager::csSmoothButtonSpeed);
}
else if (IR_STROBE == result)
{
effectManager.NextPalette();
}
else if (IR_FLASH == result)
{
effectManager.PreviousPalette();
}
else if (IR_FADE == result)
{
effectManager.ShowVU( !effectManager.IsVUVisible() );
}
for (int i = 0; i < ARRAYSIZE(RemoteColorCodes); i++)
{
if (RemoteColorCodes[i].code == result)
{
debugV("Changing Color via remote: %08X\n", (uint) RemoteColorCodes[i].color);
effectManager.ApplyGlobalColor(RemoteColorCodes[i].color);
return;
}
}
}
#endif