-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIV3.cpp
165 lines (132 loc) · 2.63 KB
/
IV3.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "IV3.h"
#include "Wire.h"
void IV3_clock::i2c_trans(uint8_t* data, uint8_t length)
{
Wire.begin();
Wire.beginTransmission(I2C_address);
for(int i=0;i<length;i++)
Wire.write(data[i]);
Wire.endTransmission();
}
void IV3_clock::set_time(void)
{
uint8_t TX[7] = {SET_TIME, this->time.year, this->time.month, this->time.day, this->time.hour, this->time.minute, this->time.second};
i2c_trans(TX, 7);
}
void IV3_clock::get_time(void)
{
uint8_t RX[6];
uint8_t TX[1]={READ_TIME};
uint8_t i=0;
i2c_trans(TX, 1);
delay(1);
Wire.requestFrom(I2C_address, 6);
while(Wire.available())
{
RX[i] = Wire.read();
i++;
}
this->time.year = RX[0];
this->time.month = RX[1];
this->time.day = RX[2];
this->time.hour = RX[3];
this->time.minute = RX[4];
this->time.second = RX[5];
}
void IV3_clock::print_time(void)
{
Serial.print(this->time.day);
Serial.print(":");
Serial.print(this->time.month);
Serial.print(":");
Serial.print(20);
Serial.print(this->time.year);
Serial.print(" ");
Serial.print(this->time.hour);
Serial.print(":");
Serial.print(this->time.minute);
Serial.print(":");
Serial.print(this->time.second);
Serial.println("");
}
void IV3_clock::clock_mode(void)
{
uint8_t TX[1]={CLOCK_MODE};
i2c_trans(TX, 1);
}
void IV3_clock::user_display(uint8_t *data)
{
uint8_t TX[5];
uint8_t i;
TX[0] = USER_DISPLAY;
for(i=0;i<4;i++)
TX[i+1] = data[i];
i2c_trans(TX, 5);
}
void IV3_clock::set_hour_mode(bool mode)
{
uint8_t TX[2];
TX[0] = HOUR_MODE;
if(mode == true)
TX[1] = 1;
else
TX[1] = 0;
i2c_trans(TX, 2);
}
void IV3_clock::set_brightness(uint8_t brightness)
{
uint8_t TX[2];
if(brightness>MAX_TUBE_BRIGHTNESS)
brightness = MAX_TUBE_BRIGHTNESS;
TX[0] = SET_BRIGHTNESS;
TX[1] = brightness;
i2c_trans(TX, 2);
}
void IV3_clock::set_night_fade(bool mode)
{
uint8_t TX[2];
TX[0] = NIGHT_FADE;
if(mode == true)
TX[1] = 1;
else
TX[1] = 0;
i2c_trans(TX, 2);
}
void IV3_clock::reset(void)
{
uint8_t TX[1] = {SFT_RST};
i2c_trans(TX, 1);
}
void IV3_clock::get_status(void)
{
uint8_t TX[1] = {GET_STATUS};
i2c_trans(TX, 2);
delay(10);
Wire.requestFrom(I2C_address, 1);
while(Wire.available())
{
IV3_status = Wire.read();
}
}
bool IV3_clock::get_hour_mode(void)
{
this->get_status();
if((IV3_status & 0x80) == 0x80)
return true;
else
return false;
}
bool IV3_clock::get_fade_mode(void)
{
this->get_status();
if((IV3_status & 0x40) == 0x40)
return true;
else
return false;
}
uint8_t IV3_clock::get_brightness(void)
{
this->get_status();
IV3_status &= 0x1F;
return IV3_status;
}