Skip to content

Commit

Permalink
add full logic in led settings
Browse files Browse the repository at this point in the history
  • Loading branch information
progzone122 committed Jun 2, 2024
1 parent ff929db commit f6b0606
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 83 deletions.
59 changes: 58 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
{
"nuxt.isNuxtApp": false
"nuxt.isNuxtApp": false,
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
8 changes: 0 additions & 8 deletions firmware/lib/Led/Led.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ class Led {
int _pin; // Пин, к которому подключена лента
int _count; // Количество светодиодов в ленте

unsigned long lastUpdate = 0; // Время последнего обновления анимации
const int animationSteps = 50; // Количество шагов в анимации
const int animationDelay = 20; // Задержка в миллисекундах между шагами
int currentStep = 0; // Текущий шаг анимации
bool animating = false; // Флаг анимации
int startColor[3]; // Начальный цвет
int endColor[3]; // Конечный цвет

public:
Adafruit_NeoPixel strip; // Объект управления лентой
int brightness[5] = {100, 100, 100, 100, 100}; // Яркость
Expand Down
30 changes: 27 additions & 3 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void loop()
button_index = col.toInt32();
}
if (col.index() > 1) {
// Serial.println(col);
switch (button_index) {
case 1:
strcat(settings.b1_hotkeys, ",");
Expand All @@ -113,6 +112,31 @@ void loop()
}

}
} else if (command == "wl") {
for (su::TextParser col(message_row, ','); col.parse();) {
Serial.println(col);
switch (col.index())
{
case 0:
button_index = col.toInt32();
break;

case 1:
settings.colors[button_index - 1][0] = col.toInt32();
break;

case 2:
settings.colors[button_index - 1][1] = col.toInt32();
break;

case 3:
settings.colors[button_index - 1][2] = col.toInt32();
break;

default:
break;
}
}
}
}
}
Expand Down Expand Up @@ -154,7 +178,7 @@ void loop()
}
}
if(button1.pressing()) {
led.setPixelsInRange(1, 2, led.strip.Color(settings.colors[0][0], settings.colors[0][1], settings.colors[0][2]));
led.setPixelsInRange(1, 2, led.strip.Color(settings.colors[1][0], settings.colors[1][1], settings.colors[1][2]));
led.setBrightness(1, 2, 100);

String value[10] = {};
Expand All @@ -179,7 +203,7 @@ void loop()
}
}
if(button2.pressing()) {
led.setPixelsInRange(0, 0, led.strip.Color(settings.colors[0][0], settings.colors[0][1], settings.colors[0][2]));
led.setPixelsInRange(0, 0, led.strip.Color(settings.colors[2][0], settings.colors[2][1], settings.colors[2][2]));
led.setBrightness(0, 0, 100);

String value[10] = {};
Expand Down
149 changes: 104 additions & 45 deletions micropad_engine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ mod hotkeys;

use std::rc::Rc;
use std::time::Duration;
use serde_json::Value;
use serialport::SerialPort;
use serialport::SerialPortType::{Unknown};
use slint::VecModel;
use slint::{VecModel, Weak};
use slint::SharedString;
slint::include_modules!();
// fn main() {
Expand All @@ -28,6 +30,96 @@ fn get_ports() -> Vec<SharedString> {
ports
}

fn write_hotkeys(app_weak: &Weak<AppWindow>, hotkeys: &Value) -> String {
let box1_1: usize = app_weak.unwrap().get_box1_1_current_index() as usize;
let box1_2: usize = app_weak.unwrap().get_box1_2_current_index() as usize;
let box1_3: usize = app_weak.unwrap().get_box1_3_current_index() as usize;
let box2_1: usize = app_weak.unwrap().get_box2_1_current_index() as usize;
let box2_2: usize = app_weak.unwrap().get_box2_2_current_index() as usize;
let box2_3: usize = app_weak.unwrap().get_box2_3_current_index() as usize;
let box3_1: usize = app_weak.unwrap().get_box3_1_current_index() as usize;
let box3_2: usize = app_weak.unwrap().get_box3_2_current_index() as usize;
let box3_3: usize = app_weak.unwrap().get_box3_3_current_index() as usize;

// convert value to key
let box1_1 = hotkeys::find_key_by_index(&hotkeys, box1_1).unwrap();
let box1_2 = hotkeys::find_key_by_index(&hotkeys, box1_2).unwrap();
let box1_3 = hotkeys::find_key_by_index(&hotkeys, box1_3).unwrap();
let box2_1 = hotkeys::find_key_by_index(&hotkeys, box2_1).unwrap();
let box2_2 = hotkeys::find_key_by_index(&hotkeys, box2_2).unwrap();
let box2_3 = hotkeys::find_key_by_index(&hotkeys, box2_3).unwrap();
let box3_1 = hotkeys::find_key_by_index(&hotkeys, box3_1).unwrap();
let box3_2 = hotkeys::find_key_by_index(&hotkeys, box3_2).unwrap();
let box3_3 = hotkeys::find_key_by_index(&hotkeys, box3_3).unwrap();

let mut message: String = String::new();
let mut message_b1: String = String::from("wh;1,press");
let mut message_b2: String = String::from("2,press");
let mut message_b3: String = String::from("3,press");

for key in [box1_1, box1_2, box1_3] {
if key != "none" {
message_b1.push_str(&format!(",{}", key));
}
}
for key in [box2_1, box2_2, box2_3] {
if key != "none" {
message_b2.push_str(&format!(",{}", key));
}
}
for key in [box3_1, box3_2, box3_3] {
if key != "none" {
message_b3.push_str(&format!(",{}", key));
}
}
message.push_str(&format!("{};{};{}", message_b1, message_b2, message_b3));
println!("{}", message);

message
}

fn write_backlight(app_weak: &Weak<AppWindow>) -> String {
// let message: String = String::from("wl;1,0,86,222");
let lineEdit1_color_red_value: SharedString = app_weak.unwrap().get_lineEdit1_color_red_value();
let lineEdit1_color_green_value: SharedString = app_weak.unwrap().get_lineEdit1_color_green_value();
let lineEdit1_color_blue_value: SharedString = app_weak.unwrap().get_lineEdit1_color_blue_value();

let lineEdit2_color_red_value: SharedString = app_weak.unwrap().get_lineEdit2_color_red_value();
let lineEdit2_color_green_value: SharedString = app_weak.unwrap().get_lineEdit2_color_green_value();
let lineEdit2_color_blue_value: SharedString = app_weak.unwrap().get_lineEdit2_color_blue_value();

let lineEdit3_color_red_value: SharedString = app_weak.unwrap().get_lineEdit3_color_red_value();
let lineEdit3_color_green_value: SharedString = app_weak.unwrap().get_lineEdit3_color_green_value();
let lineEdit3_color_blue_value: SharedString = app_weak.unwrap().get_lineEdit3_color_blue_value();

let mut message: String = String::new();
let mut message_b1: String = String::from("wl;1");
let mut message_b2: String = String::from("2");
let mut message_b3: String = String::from("3");


for value in [lineEdit1_color_red_value, lineEdit1_color_green_value, lineEdit1_color_blue_value] {
if value != "" {
message_b1.push_str(&format!(",{}", value));
}
}
for value in [lineEdit2_color_red_value, lineEdit2_color_green_value, lineEdit2_color_blue_value] {
if value != "" {
message_b2.push_str(&format!(",{}", value));
}
}
for value in [lineEdit3_color_red_value, lineEdit3_color_green_value, lineEdit3_color_blue_value] {
if value != "" {
message_b3.push_str(&format!(",{}", value));
}
}

message.push_str(&format!("{};{};{}", message_b1, message_b2, message_b3));
println!("{}", message);

message
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let hotkeys = hotkeys::get_json();

Expand All @@ -48,56 +140,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// callbacks
let app_weak = app.as_weak();
app.on_cl(move || {
let box1_1: usize = app_weak.unwrap().get_box1_1_current_index() as usize;
let box1_2: usize = app_weak.unwrap().get_box1_2_current_index() as usize;
let box1_3: usize = app_weak.unwrap().get_box1_3_current_index() as usize;
let box2_1: usize = app_weak.unwrap().get_box2_1_current_index() as usize;
let box2_2: usize = app_weak.unwrap().get_box2_2_current_index() as usize;
let box2_3: usize = app_weak.unwrap().get_box2_3_current_index() as usize;
let box3_1: usize = app_weak.unwrap().get_box3_1_current_index() as usize;
let box3_2: usize = app_weak.unwrap().get_box3_2_current_index() as usize;
let box3_3: usize = app_weak.unwrap().get_box3_3_current_index() as usize;

// convert value to key
let box1_1 = hotkeys::find_key_by_index(&hotkeys, box1_1).unwrap();
let box1_2 = hotkeys::find_key_by_index(&hotkeys, box1_2).unwrap();
let box1_3 = hotkeys::find_key_by_index(&hotkeys, box1_3).unwrap();
let box2_1 = hotkeys::find_key_by_index(&hotkeys, box2_1).unwrap();
let box2_2 = hotkeys::find_key_by_index(&hotkeys, box2_2).unwrap();
let box2_3 = hotkeys::find_key_by_index(&hotkeys, box2_3).unwrap();
let box3_1 = hotkeys::find_key_by_index(&hotkeys, box3_1).unwrap();
let box3_2 = hotkeys::find_key_by_index(&hotkeys, box3_2).unwrap();
let box3_3 = hotkeys::find_key_by_index(&hotkeys, box3_3).unwrap();

let mut message: String = String::new();
let mut message_b1: String = String::from("wh;1,press");
let mut message_b2: String = String::from("2,press");
let mut message_b3: String = String::from("3,press");

for key in [box1_1, box1_2, box1_3] {
if key != "none" {
message_b1.push_str(&format!(",{}", key));
}
}
for key in [box2_1, box2_2, box2_3] {
if key != "none" {
message_b2.push_str(&format!(",{}", key));
}
}
for key in [box3_1, box3_2, box3_3] {
if key != "none" {
message_b3.push_str(&format!(",{}", key));
}
}
message.push_str(&format!("{};{};{}", message_b1, message_b2, message_b3));
println!("{}", message);

let mut port = serialport::new(app_weak.unwrap().get_ports_combo_value().as_str(), 9600)
.timeout(Duration::from_millis(10))
.open()
.expect("Failed to open port");

port.write(message.as_ref()).expect("Failed to send Serial message");
let tab_index: i32 = app_weak.unwrap().get_tab_current_index();

match tab_index {
0 => message = String::from(write_hotkeys(&app_weak, &hotkeys)),
1 => message = String::from(write_backlight(&app_weak)),
_ => {}
}

if !message.is_empty() {
port.write(message.as_ref()).expect("Failed to send Serial message");
}
});

app.set_window_title(SharedString::from("Pad Engine"));
Expand Down
19 changes: 15 additions & 4 deletions micropad_engine/ui/app.slint
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export component AppWindow inherits Window {
// Device port lists
in property <[string]> ports_combo_model;
in-out property <string> ports_combo_value <=> tm.combo_value;
// Tabs
in-out property <int> tab_current_index <=> tab.current-index;
// Hotkeys actions
in property <[string]> actions;
in-out property <int> box1_1_current_index <=> ht.box1_1_current_index;
Expand All @@ -21,9 +23,18 @@ export component AppWindow inherits Window {
in-out property <int> box3_2_current_index <=> ht.box3_2_current_index;
in-out property <int> box3_3_current_index <=> ht.box3_3_current_index;
// Backlight actions
in-out property <string> lineEdit_color_red_value <=> bl.lineEdit_color_red_value;
in-out property <string> lineEdit_color_green_value <=> bl.lineEdit_color_green_value;
in-out property <string> lineEdit_color_blue_value <=> bl.lineEdit_color_blue_value;
in-out property <string> lineEdit1_color_red_value <=> bl.lineEdit1_color_red_value;
in-out property <string> lineEdit1_color_green_value <=> bl.lineEdit1_color_green_value;
in-out property <string> lineEdit1_color_blue_value <=> bl.lineEdit1_color_blue_value;

in-out property <string> lineEdit2_color_red_value <=> bl.lineEdit2_color_red_value;
in-out property <string> lineEdit2_color_green_value <=> bl.lineEdit2_color_green_value;
in-out property <string> lineEdit2_color_blue_value <=> bl.lineEdit2_color_blue_value;

in-out property <string> lineEdit3_color_red_value <=> bl.lineEdit3_color_red_value;
in-out property <string> lineEdit3_color_green_value <=> bl.lineEdit3_color_green_value;
in-out property <string> lineEdit3_color_blue_value <=> bl.lineEdit3_color_blue_value;
// Callbacks
callback cl <=> tm.clicked;

min-width: 400px;
Expand All @@ -36,7 +47,7 @@ export component AppWindow inherits Window {
combo_model: ports_combo_model;
}
Rectangle {
TabWidget {
tab := TabWidget {
Tab {
title: "Hotkeys";
ht := HotkeysTab {
Expand Down
Loading

0 comments on commit f6b0606

Please sign in to comment.