-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Управление светомузыкой с ПК #13
Open
TsSaltan
wants to merge
5
commits into
AlexGyver:master
Choose a base branch
from
TsSaltan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
// ***************************** НАСТРОЙКИ ***************************** | ||
|
||
// ----- настройка ИК пульта | ||
#define REMOTE_TYPE 1 // 0 - без пульта, 1 - пульт от WAVGAT, 2 - пульт от KEYES, 3 - кастомный пульт | ||
#define REMOTE_TYPE 4 // 0 - без пульта, 1 - пульт от WAVGAT, 2 - пульт от KEYES, 3 - кастомный пульт, 4 - управление с ПК | ||
// система может работать С ЛЮБЫМ ИК ПУЛЬТОМ (практически). Коды для своего пульта можно задать начиная со строки 160 в прошивке. Коды пультов определяются скетчем IRtest_2.0, читай инструкцию | ||
|
||
// ----- настройки параметров | ||
|
@@ -177,6 +177,29 @@ byte HUE_STEP = 5; | |
#define BUTT_HASH 0x38379AD // # | ||
#endif | ||
|
||
// ----- Управление командами с ПК ----- | ||
// В общем-то не важно, какой код будет у кнопок | ||
#if REMOTE_TYPE == 4 | ||
#include <CommandLine.h> | ||
#define BUTT_UP 0xE51CA6AD | ||
#define BUTT_DOWN 0xD22353AD | ||
#define BUTT_LEFT 0x517068AD | ||
#define BUTT_RIGHT 0xAC2A56AD | ||
#define BUTT_OK 0x1B92DDAD | ||
#define BUTT_1 0x68E456AD | ||
#define BUTT_2 0xF08A26AD | ||
#define BUTT_3 0x151CD6AD | ||
#define BUTT_4 0x18319BAD | ||
#define BUTT_5 0xF39EEBAD | ||
#define BUTT_6 0x4AABDFAD | ||
#define BUTT_7 0xE25410AD | ||
#define BUTT_8 0x297C76AD | ||
#define BUTT_9 0x14CE54AD | ||
#define BUTT_0 0xC089F6AD | ||
#define BUTT_STAR 0xAF3F1BAD // * | ||
#define BUTT_HASH 0x38379AD // # | ||
#endif | ||
Comment on lines
+194
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это кнопки с клавы? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А, понял, это ж .ino, пульт |
||
|
||
|
||
// ------------------------------ ДЛЯ РАЗРАБОТЧИКОВ -------------------------------- | ||
#define MODE_AMOUNT 9 // количество режимов | ||
|
@@ -305,6 +328,10 @@ void setup() { | |
readEEPROM(); | ||
} | ||
} | ||
|
||
#if REMOTE_TYPE == 4 | ||
Serial.println("ColorMusic is ready"); // Приветствие в консоль | ||
#endif | ||
} | ||
|
||
void loop() { | ||
|
@@ -656,11 +683,152 @@ float smartIncrFloat(float value, float incr_step, float mininmum, float maximum | |
|
||
#if REMOTE_TYPE != 0 | ||
void remoteTick() { | ||
|
||
#if REMOTE_TYPE != 4 | ||
// Управление с пульта | ||
if (IRLremote.available()) { | ||
auto data = IRLremote.read(); | ||
IRdata = data.command; | ||
ir_flag = true; | ||
} | ||
#else | ||
// Управление с ПК | ||
ir_flag = hasCommand(); | ||
if(ir_flag){ | ||
const char *cmdName = getCommand(); | ||
IRdata = -1; | ||
|
||
// mode {mode_№} - изменение режима | ||
if(strcmp(cmdName, "mode") == 0){ | ||
int mode = getArgInt(); | ||
|
||
if(mode > 0 && mode <= MODE_AMOUNT){ | ||
this_mode = mode-1; | ||
} | ||
|
||
Serial.print("Current mode: "); | ||
Serial.println(mode); | ||
} | ||
|
||
// submode - изменение подрежима, имитируем нажатие кнопки # | ||
else if(strcmp(cmdName, "submode") == 0){ | ||
IRdata = BUTT_HASH; | ||
Serial.println("Submode changed"); | ||
} | ||
|
||
// calibrate - калибровка шума, имитируем нажатие на кнопку 0 | ||
else if (0 == strcmp(cmdName, "calibrate")){ | ||
IRdata = BUTT_0; | ||
Serial.println("Noise calibrated"); | ||
} | ||
|
||
// power - вкл/выкл ленты, имитируем нажатие на * | ||
else if (0 == strcmp(cmdName, "power")){ | ||
IRdata = BUTT_STAR; | ||
if(ONstate){ | ||
Serial.println("LEDs off"); | ||
} else { | ||
Serial.println("LEDs on"); | ||
} | ||
} | ||
|
||
// bright+ - увеличение яркости горящих диодов | ||
else if (0 == strcmp(cmdName, "bright+")){ | ||
BRIGHTNESS = smartIncr(BRIGHTNESS, 10, 0, 255); | ||
FastLED.setBrightness(BRIGHTNESS); | ||
cmdName = "bright"; | ||
} | ||
|
||
// bright- - уменьшение яркости горящих диодов | ||
else if (0 == strcmp(cmdName, "bright-")){ | ||
BRIGHTNESS = smartIncr(BRIGHTNESS, -10, 0, 255); | ||
FastLED.setBrightness(BRIGHTNESS); | ||
cmdName = "bright"; | ||
} | ||
|
||
// bright {bright_level} - изменение уровня яркости горящих диодов | ||
// bright - без аргумента показывает текущий уровень яркости | ||
else if (0 == strcmp(cmdName, "bright")){ | ||
int level = getArgInt(); | ||
if(level > 0 && level <= 255){ | ||
BRIGHTNESS = level; | ||
FastLED.setBrightness(BRIGHTNESS); | ||
Serial.print("Brightness changed to: "); | ||
Serial.println(BRIGHTNESS); | ||
} else { | ||
Serial.print("Current brightness: "); | ||
Serial.println(BRIGHTNESS); | ||
} | ||
} | ||
|
||
// backlight+ - увеличение яркости негорящих светодиодов | ||
else if (0 == strcmp(cmdName, "backlight+")){ | ||
EMPTY_BRIGHT = smartIncr(EMPTY_BRIGHT, 5, 0, 255); | ||
cmdName = "backlight"; | ||
} | ||
|
||
// backlight- - уменьшение яркости негорящих светодиодов | ||
else if (0 == strcmp(cmdName, "backlight-")){ | ||
EMPTY_BRIGHT = smartIncr(EMPTY_BRIGHT, -5, 0, 255); | ||
cmdName = "backlight"; | ||
} | ||
|
||
// backlight {bright_level} - изменение яркости негорящих светодиодов | ||
// backlight - без аргумента - текущий уровень фоновой подсветки | ||
else if (0 == strcmp(cmdName, "backlight")){ | ||
int level = getArgInt(); | ||
if(level > 0 && level <= 255){ | ||
EMPTY_BRIGHT = level; | ||
Serial.print("Backlight brightness changed to: "); | ||
Serial.println(EMPTY_BRIGHT); | ||
} else { | ||
Serial.print("Current backlight brightness: "); | ||
Serial.println(EMPTY_BRIGHT); | ||
} | ||
} | ||
|
||
// lightmode {mode_№} - изменение подрежима у режима №7 (постоянная подсветка) | ||
else if (0 == strcmp(cmdName, "lightmode")){ | ||
int mode = getArgInt(); | ||
light_mode = mode; | ||
|
||
Serial.print("Current light mode: "); | ||
Serial.println(light_mode); | ||
} | ||
|
||
// Команды для настройки, кнопки вверх, вниз, влево, вправо - up, down, left, right соответственно | ||
else if (0 == strcmp(cmdName, "up")){ | ||
settings_mode = false; | ||
IRdata = BUTT_UP; | ||
} | ||
else if (0 == strcmp(cmdName, "down")){ | ||
settings_mode = false; | ||
IRdata = BUTT_DOWN; | ||
} | ||
else if (0 == strcmp(cmdName, "left")){ | ||
settings_mode = false; | ||
IRdata = BUTT_LEFT; | ||
} | ||
else if (0 == strcmp(cmdName, "right")){ | ||
settings_mode = false; | ||
IRdata = BUTT_RIGHT; | ||
} | ||
|
||
// handshake - "рукопожатие", устройство должно вернуть своё название, чтоб программа смогла найти "своё" Arduino для управления | ||
else if (0 == strcmp(cmdName, "handshake")){ | ||
Serial.println("<Arduino> ColorMusic"); | ||
} | ||
|
||
// Обработка неподдерживаемых команд | ||
else { | ||
Serial.print("Invalid command '"); | ||
Serial.print(cmdName); | ||
Serial.println("'"); | ||
} | ||
|
||
} | ||
#endif | ||
|
||
if (ir_flag) { // если данные пришли | ||
eeprom_timer = millis(); | ||
eeprom_flag = true; | ||
|
@@ -831,6 +999,9 @@ void remoteTick() { | |
} | ||
} | ||
break; | ||
case -1: // кейс для управление с ПК, когда нужно сохранить настройки | ||
eeprom_flag = true; | ||
break; | ||
default: eeprom_flag = false; // если не распознали кнопку, не обновляем настройки! | ||
break; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#define COMMAND_BUFFER_LENGTH 100 // Максикмальная длина команды. MAX: 255 | ||
|
||
#define CR '\r' | ||
#define LF '\n' | ||
#define BS '\b' | ||
#define NULLCHAR '\0' | ||
#define SPACE ' ' | ||
|
||
const char *delimiters = ", \n"; // Разделитель команд | ||
char commandLine[COMMAND_BUFFER_LENGTH + 1]; // Буфер для команды | ||
|
||
/** | ||
* hasCommand() | ||
* Считывает данные с порта в буфер | ||
* @return bool true - поступила новая команда, false - в буфере пусто | ||
*/ | ||
bool hasCommand(){ | ||
static uint8_t charsRead = 0; | ||
|
||
while (Serial.available()) { | ||
char c; | ||
|
||
if(Serial.available()){ | ||
c = Serial.read(); | ||
} | ||
|
||
switch (c){ | ||
case CR: // команда заканчивается символом CR и/или LS | ||
case LF: | ||
commandLine[charsRead] = NULLCHAR; | ||
if (charsRead > 0) { | ||
charsRead = 0; | ||
Serial.println(commandLine); | ||
return true; | ||
} | ||
break; | ||
default: | ||
c = tolower(c); | ||
if (charsRead < COMMAND_BUFFER_LENGTH) { | ||
commandLine[charsRead++] = c; | ||
} | ||
commandLine[charsRead] = NULLCHAR; //just in case | ||
break; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* getCommand() | ||
* Получить текст команды | ||
*/ | ||
char * getCommand() { | ||
char * word = strtok(commandLine, delimiters); | ||
return word; | ||
} | ||
|
||
/** | ||
* getArg() | ||
* Получить следующий аргумент | ||
*/ | ||
char * getArg() { | ||
char * word = strtok(NULL, delimiters); | ||
return word; | ||
} | ||
|
||
/** | ||
* getArgInt() | ||
* Получить следующий числовой аргумент | ||
*/ | ||
long getArgInt() { | ||
char * numTextPtr = strtok(NULL, delimiters); | ||
return atol(numTextPtr); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не лучший варик менять значение, лучше просто оставить коммент для параметра. Если ветку сольют, то невнимательные прошивальщики начнут жаловаться, что не работает пульт 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, изменения не должны менять настройки предыдущего конфига.. Надо чтоб опция только в комментарии появилась.