Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 3d635c9

Browse files
ilcatoaentinger
authored andcommitted
First draft TV type support
1 parent 79cbe30 commit 3d635c9

File tree

1 file changed

+226
-0
lines changed

1 file changed

+226
-0
lines changed
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
//
2+
// This file is part of ArduinoCloudThing
3+
//
4+
// Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
5+
//
6+
// This software is released under the GNU General Public License version 3,
7+
// which covers the main part of ArduinoCloudThing.
8+
// The terms of this license can be found at:
9+
// https://www.gnu.org/licenses/gpl-3.0.en.html
10+
//
11+
// You can be released from the requirements of the above licenses by purchasing
12+
// a commercial license. Buying such a license is mandatory if you want to modify or
13+
// otherwise use the software for commercial activities involving the Arduino
14+
// software without disclosing the source code of your own applications. To purchase
15+
// a commercial license, send an email to license@arduino.cc.
16+
//
17+
18+
#ifndef CLOUDTELEVISION_H_
19+
#define CLOUDTELEVISION_H_
20+
21+
/******************************************************************************
22+
INCLUDE
23+
******************************************************************************/
24+
25+
#include <Arduino.h>
26+
#include "../../ArduinoCloudProperty.h"
27+
28+
/******************************************************************************
29+
ENUM
30+
******************************************************************************/
31+
enum class PlaybackCommands : u_int8_t {
32+
FastForward = 0,
33+
Next = 1,
34+
Pause = 2,
35+
Play = 3,
36+
Previous = 4,
37+
Rewind = 5,
38+
StartOver = 6,
39+
Stop = 7,
40+
None = 255
41+
};
42+
enum class InputValue : u_int8_t {
43+
AUX1 = 0,
44+
AUX2 = 1,
45+
AUX3 = 2,
46+
AUX4 = 3,
47+
AUX5 = 4,
48+
AUX6 = 5,
49+
AUX7 = 6,
50+
BLURAY = 7,
51+
CABLE = 8,
52+
CD = 9,
53+
COAX1 = 10,
54+
COAX2 = 11,
55+
COMPOSITE1 = 12,
56+
DVD = 13,
57+
GAME = 14,
58+
HDRADIO = 15,
59+
HDMI1 = 16,
60+
HDMI2 = 17,
61+
HDMI3 = 18,
62+
HDMI4 = 19,
63+
HDMI5 = 20,
64+
HDMI6 = 21,
65+
HDMI7 = 22,
66+
HDMI8 = 23,
67+
HDMI9 = 24,
68+
HDMI10 = 25,
69+
HDMIARC = 26,
70+
INPUT1 = 27,
71+
INPUT2 = 28,
72+
INPUT3 = 29,
73+
INPUT4 = 30,
74+
INPUT5 = 31,
75+
INPUT6 = 32,
76+
INPUT7 = 33,
77+
INPUT8 = 34,
78+
INPUT9 = 35,
79+
INPUT10 = 36,
80+
IPOD = 37,
81+
LINE1 = 38,
82+
LINE2 = 39,
83+
LINE3 = 40,
84+
LINE4 = 41,
85+
LINE5 = 42,
86+
LINE6 = 43,
87+
LINE7 = 44,
88+
MEDIAPLAYER = 45,
89+
OPTICAL1 = 46,
90+
OPTICAL2 = 47,
91+
PHONO = 48,
92+
PLAYSTATION = 49,
93+
PLAYSTATION3 = 50,
94+
PLAYSTATION4 = 51,
95+
SATELLITE = 52,
96+
SMARTCAST = 53,
97+
TUNER = 54,
98+
TV = 55,
99+
USBDAC = 56,
100+
VIDEO1 = 57,
101+
VIDEO2 = 58,
102+
VIDEO3 = 59,
103+
XBOX = 60
104+
};
105+
106+
/******************************************************************************
107+
CLASS DECLARATION
108+
******************************************************************************/
109+
110+
class Television {
111+
public:
112+
bool swi;
113+
u_int8_t vol;
114+
bool mut;
115+
PlaybackCommands pbc;
116+
InputValue inp;
117+
u_int16_t cha;
118+
119+
120+
Television(bool swi, u_int8_t vol, bool mut, PlaybackCommands pbc, InputValue inp, u_int16_t cha):
121+
swi(swi),
122+
vol(vol),
123+
mut(mut),
124+
pbc(pbc),
125+
inp(inp),
126+
cha(cha)
127+
{
128+
}
129+
130+
bool operator==(Television & aTV) {
131+
return
132+
aTV.swi == swi &&
133+
aTV.vol == vol &&
134+
aTV.mut == mut &&
135+
aTV.pbc == pbc &&
136+
aTV.inp == inp &&
137+
aTV.cha == cha;
138+
}
139+
140+
bool operator!=(Television & aTV) {
141+
return !(operator==(aTV));
142+
}
143+
144+
};
145+
146+
class CloudTelevision : public ArduinoCloudProperty {
147+
private:
148+
Television _value,
149+
_cloud_value;
150+
public:
151+
CloudTelevision() : _value(false, 0, false, PlaybackCommands::None, InputValue::TV, 0), _cloud_value(false, 0, false, PlaybackCommands::None, InputValue::TV, 0) {}
152+
CloudTelevision(bool swi, u_int8_t vol, bool mut, PlaybackCommands pbc, InputValue inp, u_int16_t cha) : _value(swi, vol, mut, pbc, inp, cha), _cloud_value(swi, vol, mut, pbc, inp, cha) {}
153+
154+
virtual bool isDifferentFromCloud() {
155+
156+
return _value != _cloud_value;
157+
}
158+
159+
CloudTelevision& operator=(Television aTV) {
160+
_value.swi = aTV.swi;
161+
_value.vol = aTV.vol;
162+
_value.mut = aTV.mut;
163+
_value.pbc = aTV.pbc;
164+
_value.inp = aTV.inp;
165+
_value.cha = aTV.cha;
166+
updateLocalTimestamp();
167+
return *this;
168+
}
169+
170+
Television getCloudValue() {
171+
return _cloud_value;
172+
}
173+
174+
Television getValue() {
175+
return _value;
176+
}
177+
178+
bool getSwitch() {
179+
return _value.swi;
180+
}
181+
182+
u_int8_t getVolume() {
183+
return _value.vol;
184+
}
185+
186+
bool getMute() {
187+
return _value.mut;
188+
}
189+
190+
PlaybackCommands getPlaybackCommand() {
191+
return _value.pbc;
192+
}
193+
194+
InputValue getInputValue() {
195+
return _value.inp;
196+
}
197+
198+
u_int16_t getChannel() {
199+
return _value.cha;
200+
}
201+
202+
virtual void fromCloudToLocal() {
203+
_value = _cloud_value;
204+
}
205+
virtual void fromLocalToCloud() {
206+
_cloud_value = _value;
207+
}
208+
virtual void appendAttributesToCloud() {
209+
appendAttribute(_value.swi);
210+
appendAttribute(_value.vol);
211+
appendAttribute(_value.mut);
212+
appendAttribute((int)_value.pbc);
213+
appendAttribute((int)_value.inp);
214+
appendAttribute(_value.cha);
215+
}
216+
virtual void setAttributesFromCloud() {
217+
setAttribute(_cloud_value.swi);
218+
setAttribute((int&)_cloud_value.vol);
219+
setAttribute(_cloud_value.mut);
220+
setAttribute((int&)_cloud_value.pbc);
221+
setAttribute((int&)_cloud_value.inp);
222+
setAttribute((int&)_cloud_value.cha);
223+
}
224+
};
225+
226+
#endif /* CLOUDTELEVISION_H_ */

0 commit comments

Comments
 (0)