Skip to content

Commit

Permalink
Merge pull request #49 from vortigont/eff_flags
Browse files Browse the repository at this point in the history
Eff flags
  • Loading branch information
vortigont authored Jan 4, 2024
2 parents 5f88746 + 7b08a23 commit 6be8dd1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
26 changes: 12 additions & 14 deletions src/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7555,16 +7555,25 @@ void EffectStarShips::draw(float x, float y, CRGB color) {
// (c) Stepko + kostyamat
// 17.03.21
// https://editor.soulmatelights.com/gallery/739-flags
EffectFlags::EffectFlags(LedFB<CRGB> *framebuffer) : EffectCalc(framebuffer){
switcher.set(CHANGE_FLAG_TIME * TASK_SECOND, TASK_FOREVER, [this](){ flag = random(total_flags); });
ts.addTask(switcher);
}

String EffectFlags::setDynCtrl(UIControl*_val){
if (_val->getId()==1)
_speed = map(EffectCalc::setDynCtrl(_val).toInt(), 1, 255, 1, 16);
else if (_val->getId()==3) _flag = EffectCalc::setDynCtrl(_val).toInt();
else if (_val->getId()==3) flag = EffectCalc::setDynCtrl(_val).toInt();
else if (_val->getId()==4) EffectCalc::setDynCtrl(_val).toInt() == 1 ? switcher.enableDelayed() : switcher.disable(); // random flag switch
else EffectCalc::setDynCtrl(_val).toInt(); // для всех других не перечисленных контролов просто дергаем функцию базового класса (если это контролы палитр, микрофона и т.д.)
return String();
}

EffectFlags::~EffectFlags(){
ts.deleteTask(switcher);
}

bool EffectFlags::run() {
changeFlags();
fb->fade(32);
for (uint8_t i = 0; i < fb->w(); i++) {
thisVal = inoise8((float) i * DEVIATOR, counter, (int)count/*(float)i * SPEED_ADJ/2*/);
Expand Down Expand Up @@ -7603,7 +7612,7 @@ bool EffectFlags::run() {
break;

default:
break;
russia(i);
}

}
Expand All @@ -7612,17 +7621,6 @@ bool EffectFlags::run() {
return true;
}

void EffectFlags::changeFlags() {
if (!_flag) {
EVERY_N_SECONDS(CHANGE_FLAG) {
count++;
flag = count % 10;
}
}
else
flag = _flag - 1;
}

#ifdef MIC_EFFECTS
/* -------------- эффект "VU-Meter"
(c) G6EJD, https://www.youtube.com/watch?v=OStljy_sUVg&t=0s
Expand Down
13 changes: 8 additions & 5 deletions src/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1809,17 +1809,19 @@ class EffectMagma: public EffectCalc {
// https://editor.soulmatelights.com/gallery/739-flags
class EffectFlags: public EffectCalc {
private:
const int total_flags = 10;
const float DEVIATOR = 512. / fb->w();
float counter;
uint8_t flag = 0;
uint8_t _flag;
uint8_t flag = 0; // which flag is currently running
uint8_t count;
uint8_t _speed; // 1 - 16
const uint8_t CHANGE_FLAG = 30; // >= 10 Autochange
const uint8_t CHANGE_FLAG_TIME = 30;

uint8_t thisVal;
uint8_t thisMax;

Task switcher; // flag changer

//Germany
void germany(uint8_t i);
//Ukraine
Expand All @@ -1845,7 +1847,8 @@ class EffectFlags: public EffectCalc {
String setDynCtrl(UIControl*_val) override;

public:
EffectFlags(LedFB<CRGB> *framebuffer) : EffectCalc(framebuffer){}
EffectFlags(LedFB<CRGB> *framebuffer);
~EffectFlags();
//void load () override;
bool run() override;
};
Expand Down Expand Up @@ -2193,7 +2196,7 @@ class EffectFlower : public EffectCalc {
};
#include "log.h"
/*
Effect "Tetsrik clock"
Effect "Tetris clock"
based on https://github.com/witnessmenow/WiFi-Tetris-Clock
*/
class TetrisClock : public EffectCalc {
Expand Down
9 changes: 4 additions & 5 deletions src/effects_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static constexpr uint8_t T_EFFVER[] = {
0, 6, 6, 4, 4, 1, 3, 3, 3, 5, 3, 6, 5, 3, 5, 10, // 0-15
1, 1, 3, 1, 3, 7, 5, 2, 1, 5, 5, 7, 7, 2, 1, 5, // 16-31
5, 5, 5, 3, 7, 3, 4, 3, 3, 1, 4, 5, 7, 1, 1, 3, // 32 - 47
1, 6, 6, 6, 4, 7, 5, 4, 1, 5, 6, 3, 1, 5, 7, 6, // 48 - 63
3, 6, 6, 6, 4, 7, 5, 4, 1, 5, 6, 3, 1, 5, 7, 6, // 48 - 63
5, 1, 1, 5, 4, 1,11, 1, 3, 1, 1, 1, 1, 0, 0, 0, // 64 - 79
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80 - 95
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 96 - 111
Expand Down Expand Up @@ -261,10 +261,9 @@ typedef enum : uint8_t {RANGE=0,EDIT,CHECKBOX} CONTROL_TYPE; // младшие 4
* Полный формат для пользовательского (id=0...7) параметра имеет вид: {"id":0,"type":0,"name":"Параметр","val":"127","min":"1","max":"255","step":"1"}
* если какой-то из параметров стандартный из этого списка, то его можно опустить и не указывать
* @nb@ - будет заменен на реальный номер эффекта, @name@ - на дефолтное имя эффекта, @ver@ - версия
* https://community.alexgyver.ru/threads/wifi-lampa-budilnik-proshivka-firelamp_jeeui-gpl.2739/post-48813
* https://community.alexgyver.ru/threads/wifi-lampa-budilnik-proshivka-firelamp_jeeui-gpl.2739/post-48848
*
* P.S. этот безумный бред нужно убрать
*/

#define COTNROLS_PREFIX "\"nb\":@nb@,\"name\":\"@name@\",\"ver\":@ver@,\"flags\":"

// Дефолтные контролы
Expand Down Expand Up @@ -302,7 +301,7 @@ static constexpr const char* E_DRIFT = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLA
static constexpr const char* E_F2012_MIC = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":2,\"type\":48}, {\"id\":3,\"val\":64,\"max\":128,\"name\":\"" DFTINTF_088 "\"}, {\"id\":4,\"val\":6,\"max\":10,\"name\":\"" DFTINTF_084 "\"}, {\"id\":7,\"type\":18,\"val\":1,\"name\":\"" DFTINTF_020 "\"}]}";
static constexpr const char* E_F2018 = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":2,\"name\":\"" DFTINTF_0D7 "\"}, {\"id\":3,\"type\":2,\"val\":1,\"name\":\"" DFTINTF_0E4 "\"}, {\"id\":7,\"type\":18,\"val\":1,\"name\":\"" DFTINTF_020 "\"}]}";
static constexpr const char* E_FAIRY = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":3,\"type\":2,\"val\":1,\"name\":\"" DFTINTF_0F9 "\"}]}";
static constexpr const char* E_FLAGS = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":2,\"type\":48}, {\"id\":3,\"min\":0,\"val\":0,\"max\":10,\"name\":\"" DFTINTF_00A "\"}]}";
static constexpr const char* E_FLAGS = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":2,\"type\":48}, {\"id\":3,\"min\":0,\"val\":0,\"max\":9,\"name\":\"" DFTINTF_00A "\"}, {\"id\":4,\"type\":2,\"val\":0,\"name\":\"" DFTINTF_0E5 "\"} ]}";
static constexpr const char* E_FLOCK = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":2,\"type\":48}, {\"id\":3,\"max\":" SF(FASTLED_PALETTS_COUNT) ",\"name\":\"" DFTINTF_084 "\"}, {\"id\":4,\"type\":2,\"val\":1,\"name\":\"" DFTINTF_0E8 "\"}]}";
static constexpr const char* E_FLYING = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":2,\"type\":48}, {\"id\":3,\"max\":128,\"name\":\"" DFTINTF_0DE "\"}, {\"id\":4,\"val\":7,\"max\":" SF(FASTLED_PALETTS_COUNT) ",\"name\":\"" DFTINTF_084 "\"}, {\"id\":5,\"type\":2,\"val\":1,\"name\":\"" DFTINTF_107 "\"}]}";
static constexpr const char* E_FOUNT = "{" COTNROLS_PREFIX SF(SET_ALL_EFFFLAGS) ",\"ctrls\":[{\"id\":3,\"type\":2,\"val\":1,\"name\":\"" DFTINTF_0FA "\"}, {\"id\":4,\"val\":0,\"min\":0,\"max\":10,\"name\":\"" DFTINTF_103 "\"}, {\"id\":5,\"type\":16,\"val\":127,\"min\":0,\"max\":255,\"name\":\"" DFTINTF_0DB "\"}, {\"id\":7,\"type\":18,\"val\":1,\"name\":\"" DFTINTF_020 "\"}]}";
Expand Down
17 changes: 8 additions & 9 deletions src/effectworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool Effcfg::loadeffconfig(uint16_t nb, const char *folder){
else
soundfile.clear();

brt = doc["brt"];
//brt = doc["brt"];
curve = doc[A_dev_lcurve] ? static_cast<luma::curve>(doc[A_dev_lcurve].as<int>()) : luma::curve::cie1931;


Expand All @@ -166,9 +166,8 @@ void Effcfg::create_eff_default_cfg_file(uint16_t nb, String &filename){
void Effcfg::_savecfg(char *folder){
File configFile;
String filename = fshlpr::getEffectCfgPath(num, folder);
LOG(printf_P,PSTR("Writing eff #%d cfg: %s\n"), num, filename.c_str());
configFile = LittleFS.open(filename, "w"); // PSTR("w") использовать нельзя, будет исключение!
//configFile.w
LOG(printf, "Writing eff #%d cfg: %s\n", num, filename.c_str());
configFile = LittleFS.open(filename, "w");
configFile.print(getSerializedEffConfig());
configFile.close();
}
Expand Down Expand Up @@ -202,7 +201,7 @@ String Effcfg::getSerializedEffConfig(uint8_t replaceBright) const {
doc["flags"] = flags.mask;
doc["name"] = effectName;
doc["ver"] = version;
if (brt) doc["brt"] = brt;
//if (brt) doc["brt"] = brt;
if (curve != luma::curve::cie1931) doc[A_dev_lcurve] = e2int(curve);
doc["snd"] = soundfile;
JsonArray arr = doc.createNestedArray("ctrls");
Expand Down Expand Up @@ -905,14 +904,14 @@ uint16_t EffectWorker::effIndexByList(uint16_t val) {
}

bool Effcfg::_eff_ctrls_load_from_jdoc(DynamicJsonDocument &effcfg, LList<std::shared_ptr<UIControl>> &ctrls){
LOG(print, PSTR("_eff_ctrls_load_from_jdoc(), "));
LOG(print, "_eff_ctrls_load_from_jdoc(), ");
//LOG(printf_P, PSTR("Load MEM: %s - CFG: %s - DEF: %s\n"), effectName.c_str(), doc["name"].as<String>().c_str(), worker->getName().c_str());
// вычитываею список контроллов
// повторные - скипаем, нехватающие - создаем
// обязательные контролы 0, 1, 2 - яркость, скорость, масштаб, остальные пользовательские
JsonArray arr = effcfg["ctrls"].as<JsonArray>();
if (!arr) return false;
LOG(printf_P, PSTR("got arr of %u controls\n"), arr.size());
LOG(printf, "got arr of %u controls\n", arr.size());

ctrls.clear();
uint8_t id_tst = 0x0; // пустой
Expand Down Expand Up @@ -942,12 +941,12 @@ bool Effcfg::_eff_ctrls_load_from_jdoc(DynamicJsonDocument &effcfg, LList<std::s
}

// тест стандартных контроллов
for(int8_t id=0;id<3;id++){
for(int8_t id=1;id<3;id++){ // 0-й пропускаем, это бывшая "индивидуальная яркость"
if(!((id_tst>>id)&1)){ // не найден контрол, нужно создать
auto c = std::make_shared<UIControl>(
id, // id
CONTROL_TYPE::RANGE, // type
id==0 ? TINTF_00D : id==1 ? TINTF_087 : TINTF_088, // name
/*id==0 ? TINTF_00D :*/ id==1 ? TINTF_087 : TINTF_088, // name
"127", // value
"1", // min
"255", // max
Expand Down
4 changes: 2 additions & 2 deletions src/effectworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Effcfg {
/**
* получить версию эффекта из "прошивки" по его ENUM
*/
inline static uint8_t geteffcodeversion(uint8_t id) { return pgm_read_byte(T_EFFVER + id); };
static uint8_t geteffcodeversion(uint8_t id) { return *(T_EFFVER + id); };

/**
* @brief deserialise effect configuration from a file based on eff number
Expand Down Expand Up @@ -223,7 +223,7 @@ class Effcfg {
uint16_t num = 0; // номер эффекта
uint8_t version = 0; // версия эффекта
EFFFLAGS flags; // effect flags
uint8_t brt{0}; // effect's private brightness
//uint8_t brt{0}; // effect's private brightness
luma::curve curve{luma::curve::cie1931};
String effectName; // имя эффекта (предварительно заданное или из конфига)
String soundfile; // имя/путь к звуковому файлу (DF Player Mini)
Expand Down

0 comments on commit 6be8dd1

Please sign in to comment.