Skip to content

Commit ff97b9a

Browse files
committed
add new library and update microphone library
1 parent 9057fdf commit ff97b9a

File tree

23 files changed

+647
-1203
lines changed

23 files changed

+647
-1203
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#######################################
2+
# Syntax Coloring Map ColorConverter
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
ColorConverter KEYWORD1
9+
10+
#######################################
11+
# Methods and Functions (KEYWORD2)
12+
#######################################
13+
RgbToHsl KEYWORD2
14+
HslToRgb KEYWORD2
15+
RgbToHsv KEYWORD2
16+
HsvToRgb KEYWORD2
17+
TemperatureToRgb KEYWORD2
18+
19+
#######################################
20+
# Constants (LITERAL1)
21+
#######################################
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/***************************************************
2+
Copyright (c) 2017 Luis Llamas
3+
(www.luisllamas.es)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
8+
****************************************************/
9+
10+
#include "ColorConverterLib.h"
11+
12+
void ColorConverter::RgbToHsv(uint8_t red, uint8_t green, uint8_t blue, double& hue, double& saturation, double& value)
13+
{
14+
auto rd = static_cast<double>(red) / 255;
15+
auto gd = static_cast<double>(green) / 255;
16+
auto bd = static_cast<double>(blue) / 255;
17+
auto max = threeway_max(rd, gd, bd), min = threeway_min(rd, gd, bd);
18+
19+
value = max;
20+
21+
auto d = max - min;
22+
saturation = max == 0 ? 0 : d / max;
23+
24+
hue = 0;
25+
if (max != min)
26+
{
27+
if (max == rd)
28+
{
29+
hue = (gd - bd) / d + (gd < bd ? 6 : 0);
30+
}
31+
else if (max == gd)
32+
{
33+
hue = (bd - rd) / d + 2;
34+
}
35+
else if (max == bd)
36+
{
37+
hue = (rd - gd) / d + 4;
38+
}
39+
hue /= 6;
40+
}
41+
}
42+
43+
44+
void ColorConverter::RgbToHsl(uint8_t red, uint8_t green, uint8_t blue, double& hue, double& saturation, double& lighting)
45+
{
46+
auto rd = static_cast<double>(red) / 255;
47+
auto gd = static_cast<double>(green) / 255;
48+
auto bd = static_cast<double>(blue) / 255;
49+
50+
auto max = threeway_max(rd, gd, bd);
51+
auto min = threeway_min(rd, gd, bd);
52+
53+
double h, s, l = (max + min) / 2;
54+
55+
if (max == min)
56+
{
57+
h = s = 0; // achromatic
58+
}
59+
else
60+
{
61+
auto d = max - min;
62+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
63+
if (max == rd)
64+
{
65+
h = (gd - bd) / d + (gd < bd ? 6 : 0);
66+
}
67+
else if (max == gd)
68+
{
69+
h = (bd - rd) / d + 2;
70+
}
71+
else if (max == bd)
72+
{
73+
h = (rd - gd) / d + 4;
74+
}
75+
h /= 6;
76+
}
77+
78+
hue = h;
79+
saturation = s;
80+
lighting = l;
81+
}
82+
83+
void ColorConverter::HsvToRgb(double hue, double saturation, double value, uint8_t& red, uint8_t& green, uint8_t& blue)
84+
{
85+
double r, g, b;
86+
87+
auto i = static_cast<int>(hue * 6);
88+
auto f = hue * 6 - i;
89+
auto p = value * (1 - saturation);
90+
auto q = value * (1 - f * saturation);
91+
auto t = value * (1 - (1 - f) * saturation);
92+
93+
switch (i % 6)
94+
{
95+
case 0: r = value , g = t , b = p;
96+
break;
97+
case 1: r = q , g = value , b = p;
98+
break;
99+
case 2: r = p , g = value , b = t;
100+
break;
101+
case 3: r = p , g = q , b = value;
102+
break;
103+
case 4: r = t , g = p , b = value;
104+
break;
105+
case 5: r = value , g = p , b = q;
106+
break;
107+
}
108+
109+
red = static_cast<uint8_t>(r * 255);
110+
green = static_cast<uint8_t>(g * 255);
111+
blue = static_cast<uint8_t>(b * 255);
112+
}
113+
114+
115+
void ColorConverter::HslToRgb(double hue, double saturation, double lightness, uint8_t& red, uint8_t& green, uint8_t& blue)
116+
{
117+
double r, g, b;
118+
119+
if (saturation == 0)
120+
{
121+
r = g = b = lightness; // achromatic
122+
}
123+
else
124+
{
125+
auto q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
126+
auto p = 2 * lightness - q;
127+
r = hue2rgb(p, q, hue + 1 / 3.0);
128+
g = hue2rgb(p, q, hue);
129+
b = hue2rgb(p, q, hue - 1 / 3.0);
130+
}
131+
132+
red = static_cast<uint8_t>(r * 255);
133+
green = static_cast<uint8_t>(g * 255);
134+
blue = static_cast<uint8_t>(b * 255);
135+
}
136+
137+
void ColorConverter::TemperatureToRgb(int kelvin, uint8_t& red, uint8_t& green, uint8_t& blue)
138+
{
139+
auto temp = kelvin / 100;
140+
141+
if (temp <= 66)
142+
{
143+
red = 255;
144+
green = 99.4708025861 * log(temp) - 161.1195681661;
145+
146+
if (temp <= 19)
147+
{
148+
blue = 0;
149+
}
150+
else
151+
{
152+
blue = 138.5177312231 * log(temp - 10) - 305.0447927307;
153+
}
154+
}
155+
else
156+
{
157+
red = 329.698727446 * pow(temp - 60, -0.1332047592);
158+
green = 288.1221695283 * pow(temp - 60, -0.0755148492);
159+
blue = 255;
160+
}
161+
}
162+
163+
void ColorConverter::HexToRgb(String hex, uint8_t& red, uint8_t& green, uint8_t& blue)
164+
{
165+
long number;
166+
if(hex[0] == '#') number = strtol(&hex[1], nullptr, 16);
167+
else number = strtol(&hex[0], nullptr, 16);
168+
red = number >> 16;
169+
green = number >> 8 & 0xFF;
170+
blue = number & 0xFF;
171+
}
172+
173+
void ColorConverter::RgbToHex(uint8_t red, uint8_t green, uint8_t blue, String &hex)
174+
{
175+
char hexArray[6] = { 0 };
176+
sprintf(hexArray, "%02X%02X%02X", red, green, blue);
177+
hex = hexArray;
178+
}
179+
180+
181+
double inline ColorConverter::threeway_max(double a, double b, double c)
182+
{
183+
return max(a, max(b, c));
184+
}
185+
186+
double inline ColorConverter::threeway_min(double a, double b, double c)
187+
{
188+
return min(a, min(b, c));
189+
}
190+
191+
double ColorConverter::hue2rgb(double p, double q, double t)
192+
{
193+
if (t < 0) t += 1;
194+
if (t > 1) t -= 1;
195+
if (t < 1 / 6.0) return p + (q - p) * 6 * t;
196+
if (t < 1 / 2.0) return q;
197+
if (t < 2 / 3.0) return p + (q - p) * (2 / 3.0 - t) * 6;
198+
return p;
199+
}
200+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/***************************************************
2+
Copyright (c) 2017 Luis Llamas
3+
(www.luisllamas.es)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
8+
****************************************************/
9+
10+
#ifndef _COLOERCONVERTER_h
11+
#define _COLOERCONVERTER_h
12+
13+
#if defined(ARDUINO) && ARDUINO >= 100
14+
#include "Arduino.h"
15+
#else
16+
#include "WProgram.h"
17+
#endif
18+
19+
class ColorConverter
20+
{
21+
22+
public:
23+
static void RgbToHsv(uint8_t r, uint8_t g, uint8_t b, double &hue, double &saturation, double &value);
24+
25+
static void RgbToHsl(uint8_t red, uint8_t green, uint8_t blue, double &hue, double &saturation, double &lighting);
26+
27+
static void HsvToRgb(double hue, double saturation, double value, uint8_t & red, uint8_t & green, uint8_t & blue);
28+
29+
static void HslToRgb(double hue, double saturation, double lightness, uint8_t &red, uint8_t &green, uint8_t &blue);
30+
31+
static void TemperatureToRgb(int kelvin, uint8_t & red, uint8_t & green, uint8_t & blue);
32+
33+
static void HexToRgb(String hex, uint8_t& r, uint8_t& g, uint8_t& b);
34+
35+
static void RgbToHex(uint8_t r, uint8_t g, uint8_t b, String &hex);
36+
37+
private:
38+
static double threeway_max(double a, double b, double c);
39+
static double threeway_min(double a, double b, double c);
40+
static double hue2rgb(double p, double q, double t);
41+
};
42+
#endif
43+
44+

libraries/00_DHT/keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Datatypes (KEYWORD1)
77
###########################################
88

9-
DHT KEYWORD1
9+
DHT KEYWORD1 DHT
1010

1111
###########################################
1212
# Methods and Functions (KEYWORD2)

libraries/00_IMU/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
####################################
66
# Datatypes (KEYWORD1)
77
####################################
8+
lsm6dsm KEYWORD1 lsm6dsm
89
LSM6DSM KEYWORD1 LSM6DSM
910

1011
####################################

libraries/00_IRremote/keywords.txt

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#######################################
2+
# Syntax Coloring Map For IRremote
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
decode_results KEYWORD1
10+
IRrecv KEYWORD1
11+
IRsend KEYWORD1
12+
IrReceiver KEYWORD1
13+
IrSender KEYWORD1
14+
decodedIRData KEYWORD1
15+
16+
#######################################
17+
# Methods and Functions (KEYWORD2)
18+
#######################################
19+
20+
setFeedbackLED KEYWORD2
21+
enableLEDFeedback KEYWORD2
22+
enableLEDFeedbackForSend KEYWORD2
23+
disableLEDFeedback KEYWORD2
24+
disableLEDFeedbackForSend KEYWORD2
25+
printIRResultShort KEYWORD2
26+
begin KEYWORD2
27+
start KEYWORD2
28+
available KEYWORD2
29+
read KEYWORD2
30+
stop KEYWORD2
31+
end KEYWORD2
32+
enableLEDFeedback KEYWORD2
33+
decode KEYWORD2
34+
resume KEYWORD2
35+
enableIRIn KEYWORD2
36+
disableIRIn KEYWORD2
37+
sendNEC KEYWORD2
38+
setSendPin KEYWORD2
39+
write KEYWORD2
40+
enableIROut KEYWORD2
41+
IRLedOff KEYWORD2
42+
sendRaw KEYWORD2
43+
sendJVC KEYWORD2
44+
sendLG KEYWORD2
45+
sendLGRepeat KEYWORD2
46+
sendLGRaw KEYWORD2
47+
sendNEC KEYWORD2
48+
sendNECRepeat KEYWORD2
49+
sendNECRaw KEYWORD2
50+
sendOnkyo KEYWORD2
51+
sendApple KEYWORD2
52+
sendPanasonic KEYWORD2
53+
sendKaseikyo KEYWORD2
54+
sendKaseikyo_Denon KEYWORD2
55+
sendKaseikyo_Sharp KEYWORD2
56+
sendKaseikyo_JVC KEYWORD2
57+
sendKaseikyo_Mitsubishi KEYWORD2
58+
sendRC5 KEYWORD2
59+
sendRC6 KEYWORD2
60+
sendSamsungRepeat KEYWORD2
61+
sendSamsung KEYWORD2
62+
sendSharp KEYWORD2
63+
sendSony KEYWORD2
64+
sendSharpRaw KEYWORD2
65+
sendLegoPowerFunctions KEYWORD2
66+
sendMagiQuest KEYWORD2
67+
sendPronto KEYWORD2
68+
sendMagiQuest KEYWORD2
69+
70+
#######################################
71+
# Constants (LITERAL1)
72+
#######################################
73+
74+
PULSE_DISTANCE LITERAL1
75+
PULSE_WIDTH LITERAL1
76+
DENON LITERAL1
77+
DISH LITERAL1
78+
JVC LITERAL1
79+
LG LITERAL1
80+
LG2 LITERAL1
81+
NEC LITERAL1
82+
PANASONIC LITERAL1
83+
KASEIKYO LITERAL1
84+
KASEIKYO_JVC LITERAL1
85+
KASEIKYO_DENON LITERAL1
86+
KASEIKYO_SHARP LITERAL1
87+
KASEIKYO_MITSUBISHI LITERAL1
88+
RC5 LITERAL1
89+
RC6 LITERAL1
90+
SAMSUNG LITERAL1
91+
SHARP LITERAL1
92+
SONY LITERAL1
93+
ONKYO LITERAL1
94+
APPLE LITERAL1
95+
BOSEWAVE LITERAL1
96+
LEGO_PF LITERAL1
97+
MAGIQUEST LITERAL1
98+
WHYNTER LITERAL1
99+
UNKNOWN LITERAL1
100+
IR_RECEIVE_PIN LITERAL1
101+
IR_SEND_PIN LITERAL1
102+
FEEDBACK_LED_IS_ACTIVE_LOW LITERAL1

0 commit comments

Comments
 (0)