From 52871cc1491faf356002eb6183d30ddf726e9d21 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Tue, 14 Feb 2023 20:07:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B8=D0=B3=D1=80=D0=B8=D1=80=D1=83?= =?UTF-8?q?=D0=B5=D1=82=20=D1=81=20raw=20=D0=BD=D0=B0=20nec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/IRLight.h | 33 +++++++-------------------------- src/IRLight.cpp | 16 ++++++++-------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/include/IRLight.h b/include/IRLight.h index 7baa893..e76c432 100644 --- a/include/IRLight.h +++ b/include/IRLight.h @@ -13,38 +13,19 @@ private: IRsend *irsend; - const uint16_t RDOn[67] = { - 9080,4270, 680,470, 680,420, 680,420, 680,470, 680,420, 680,420, 680,420, 730,1470, 730,1520, 680,1520, 730,1470, 730,1470, 730,1520, 680,1520, 730,1470, 730,420, 680,1520, 730,420, 680,420, 680,420, 730,420, 680,420, 680,420, 730,420, 680,420, 680,1520, 680,1520, 730,1470, 730,1470, 730,1520, 730,1470, 730,1470, 730}; + const uint32_t RDOn = irsend->encodeNEC(0x80, 0x1); - const uint16_t RDOff[67] = { - 9030,4320, 630,470, 680,420, 680,470, 630,470, 680,420, 680,470, 630,470, 680,1520, 680,1570, 630,1570, 630,1570, 680,1520, 680,1570, 630,1570, 680,1520, 680,470, 630,470, 680,1520, 680,370, 730,1570, 630,1570, 680,420, 680,470, 630,470, 680,1520, 680,470, 630,1570, 680,420, 680,470, 630,1570, 680,1520, 680,1570, 630}; + const uint32_t RDOff = irsend->encodeNEC(0x80, 0x1A); - const uint16_t RDButtonCenter[67] = { - 9030, 4320, 680, 470, 630, 470, 680, 420, 680, 470, 630, 470, - 680, 420, 680, 470, 630, 1570, 680, 1520, 680, 1520, 680, 1520, - 730, 1520, 680, 1520, 680, 1520, 680, 1570, 680, 420, 680, 1520, - 680, 470, 680, 1520, 680, 470, 630, 470, 680, 420, 680, 470, - 630, 470, 630, 470, 680, 1520, 680, 470, 680, 1520, 630, 1570, - 680, 1520, 680, 1570, 680, 1520, 680}; + const uint32_t RDButtonCenter = irsend->encodeNEC(0x80, 0x5); - const uint16_t RDBrightnessUp[67] = { - 9080,4270, 730,420, 680,420, 680,420, 730,420, 680,420, 680,420, 730,420, - 680,1520, 680,1520, 730,1470, 730,1470, 730,1520, 680,1520, 730,1470, - 730,1520, 680,420, 680,470, 580,1620, 580,520, 630,520, 580,1620, 580,520, - 630,520, 580,520, 630,1570, 580,570, 580,1570, 630,1620, 630,520, 580,1570, - 730,1520, 680,1520, 730}; + const uint32_t RDBrightnessUp = irsend->encodeNEC(0x80, 0x12); - const uint16_t RDBrightnessDown[67] = { - 9030, 4320, 630, 520, 630, 470, 630, 470, 630, 520, 630, 470, - 630, 470, 630, 520, 630, 1570, 630, 1570, 630, 1620, 630, 1570, - 630, 1570, 630, 1620, 630, 1570, 630, 1570, 630, 470, 680, 470, - 630, 1570, 630, 1570, 680, 1570, 630, 1570, 630, 470, 680, 470, - 630, 470, 630, 1570, 680, 470, 630, 470, 630, 470, 680, 470, - 630, 1570, 630, 1570, 680, 1570, 630}; + const uint32_t RDBrightnessDown = irsend->encodeNEC(0x80, 0x1E); - const uint16_t RDButtonA[67] = {8980,4370, 630,470, 680,470, 630,470, 630,470, 630,520, 630,470, 630,470, 630,1620, 630,1570, 630,1620, 580,1570, 630,1620, 630,1570, 630,1570, 630,1570, 680,470, 630,1570, 630,1570, 630,1620, 630,470, 630,470, 630,470, 680,470, 630,470, 630,470, 680,470, 630,470, 630,1570, 630,1620, 630,1570, 630,1570, 630,1570, 630}; + const uint32_t RDButtonA = irsend->encodeNEC(0x80, 0x7); - const uint16_t RDButtonB[67] = {9030,4320, 630,520, 580,520, 630,470, 630,470, 680,470, 580,520, 630,470, 680,1570, 630,1570, 630,1570, 630,1570, 630,1620, 580,1620, 630,1570, 630,1620, 580,520, 580,520, 630,470, 680,470, 630,1570, 630,470, 630,520, 580,520, 630,470, 630,1620, 630,1570, 630,1570, 630,470, 680,1570, 630,1570, 630,1570, 630,1570, 680}; + const uint32_t RDButtonB = irsend->encodeNEC(0x80, 0x8); public: explicit IRLight(int pin); diff --git a/src/IRLight.cpp b/src/IRLight.cpp index a775d2d..4c27088 100644 --- a/src/IRLight.cpp +++ b/src/IRLight.cpp @@ -19,12 +19,12 @@ void IRLight::setState(bool state) { void IRLight::on() { state = true; - irsend->sendRaw(RDOn, 67, 38); + irsend->sendNEC(RDOn); } void IRLight::off() { state = false; - irsend->sendRaw(RDOff, 67, 38); + irsend->sendNEC(RDOff); } void IRLight::setBrightness(int newBrightness) { @@ -46,15 +46,15 @@ void IRLight::setColorTemperature(int color) { if (color < 208) { color_temp = 2; brightness = 14; - irsend->sendRaw(RDButtonB, 67, 38); + irsend->sendNEC(RDButtonB); } else if (color < 294) { color_temp = 1; brightness = 14; - irsend->sendRaw(RDButtonCenter, 67, 38); + irsend->sendNEC(RDButtonCenter); } else { color_temp = 0; brightness = 14; - irsend->sendRaw(RDButtonA, 67, 38); + irsend->sendNEC(RDButtonA); } } @@ -74,14 +74,14 @@ int IRLight::getColorTemperature() { void IRLight::brightnessUp() { if (brightness < getBrightnessScale()) { brightness++; - irsend->sendRaw(RDBrightnessUp, 67, 38); + irsend->sendNEC(RDBrightnessUp); } } void IRLight::brightnessDown() { if (brightness > 0) { brightness--; - irsend->sendRaw(RDBrightnessDown, 67, 38); + irsend->sendNEC(RDBrightnessDown); } } @@ -89,7 +89,7 @@ void IRLight::begin() { irsend->begin(); brightness = 14; color_temp = 1; - irsend->sendRaw(RDButtonCenter, 67, 38); + irsend->sendNEC(RDButtonCenter); delay(500); off(); }