Skip to content

Commit

Permalink
Fixed app touch logic and added tighter mode sync
Browse files Browse the repository at this point in the history
  • Loading branch information
connornishijima committed May 11, 2024
1 parent 219c547 commit f949ec3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 70 deletions.
79 changes: 16 additions & 63 deletions data/js/websockets_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ let touch_high = [
got_touch_vals = true;

let auto_response_table = {
"welcome":"get|config",
"config_ready":"get|modes",
"modes_ready":"get|sliders",
"welcome" :"get|config",
"config_ready" :"get|modes",
"modes_ready" :"get|sliders",
"sliders_ready":"get|toggles",
"toggles_ready":"get|menu_toggles",
"mode_selected":"get|config",
"reload_config":"get|config",
};

function check_connection_timeout(){
Expand Down Expand Up @@ -306,6 +306,10 @@ function set_mode(mode_name){
transmit(`set|mode|${mode_name}`);
}

function increment_mode(){
transmit(`increment_mode`);
}

function send_slider_change(slider_name){
let new_value = document.getElementById(slider_name).value;
transmit(`set|${slider_name}|${new_value}`);
Expand All @@ -327,58 +331,9 @@ function transmit(message){
ws.send(message);
}

// Function to transmit events
//function transmit(event_name) {
// console.log(event_name); // Replace this with the actual implementation
//}

// Function to handle touch events on the header logo
function setup_header_logo_touch() {
const header_logo = document.getElementById('header_logo');
let touch_timer = null;
let touch_active = false;

header_logo.addEventListener('touchstart', function(e) {
if (touch_active) return; // Ignore if another touch is already active
touch_active = true;
touch_timer = setTimeout(function() {
transmit('button_hold');
trigger_vibration(100);

if(standby_mode == false){
//console.log("ENTERING STANDBY");
standby_mode = true;
document.getElementById("header_logo").style.color = "#5495d761";
}
else if(standby_mode == true){
//console.log("EXITING STANDBY");
standby_mode = false;
document.getElementById("header_logo").style.color = "var(--primary)";
}

touch_timer = null; // Clear the timer once the function is called
}, 500); // Set timeout for 500ms
});

header_logo.addEventListener('touchend', function(e) {
if (touch_timer) {
clearTimeout(touch_timer); // Clear the timer if the touch ends before 500ms
transmit('button_tap');

var num_modes = modes.length;
let next_mode = (configuration.current_mode + 1) % num_modes;
configuration.current_mode = next_mode;
let next_mode_name = modes[next_mode];
document.getElementById("current_mode").innerHTML = next_mode_name;

}
touch_active = false; // Allow new touches
});
}

// Function to handle touch events on the device icon
function setup_device_icon_touch() {
const device_icon = document.getElementById('device_icon');
function setup_top_touch_listener(div_id) {
const device_icon = document.getElementById(div_id);
let touch_timer = null;
let touch_active = false;

Expand Down Expand Up @@ -409,12 +364,10 @@ function setup_device_icon_touch() {
clearTimeout(touch_timer); // Clear the timer if the touch ends before 500ms
transmit('button_tap');

var num_modes = modes.length;
let next_mode = (configuration.current_mode + 1) % num_modes;
configuration.current_mode = next_mode;
let next_mode_name = modes[next_mode];
document.getElementById("current_mode").innerHTML = next_mode_name;

if(standby_mode == true){
standby_mode = false;
document.getElementById("header_logo").style.color = "var(--primary)";
}
}
touch_active = false; // Allow new touches
});
Expand Down Expand Up @@ -489,8 +442,8 @@ function open_websockets_connection_to_device(){
if(first_load == true){
first_load = false;
console.log("APP_LOADED websockets_connection.js");
setup_header_logo_touch();
setup_device_icon_touch();
setup_top_touch_listener("header_logo");
setup_top_touch_listener("device_icon");

open_websockets_connection_to_device();
}
Expand Down
13 changes: 11 additions & 2 deletions src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void parse_command(uint32_t t_now_ms, command com) {
else{
load_sliders_relevant_to_mode(mode_index);
load_toggles_relevant_to_mode(mode_index);
transmit_to_client_in_slot("mode_selected", com.origin_client_slot);
broadcast("reload_config");
}
}
else{
Expand Down Expand Up @@ -286,7 +286,10 @@ void parse_command(uint32_t t_now_ms, command com) {
else if (fastcmp(substring, "button_tap")) {
printf("REMOTE TAP TRIGGER\n");
if(EMOTISCOPE_ACTIVE == true){
increment_mode();
int16_t next_mode_index = increment_mode();
load_sliders_relevant_to_mode(next_mode_index);
load_toggles_relevant_to_mode(next_mode_index);
broadcast("reload_config");
}
else{
toggle_standby();
Expand Down Expand Up @@ -336,6 +339,12 @@ void parse_command(uint32_t t_now_ms, command com) {
}
}
}
else if(fastcmp(substring, "increment_mode")){
int16_t next_mode_index = increment_mode();
load_sliders_relevant_to_mode(next_mode_index);
load_toggles_relevant_to_mode(next_mode_index);
broadcast("reload_config");
}
else if (fastcmp(substring, "start_debug_recording")) {
audio_recording_index = 0;
memset(audio_debug_recording, 0, sizeof(int16_t)*MAX_AUDIO_RECORDING_SAMPLES);
Expand Down
4 changes: 3 additions & 1 deletion src/light_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ int16_t set_light_mode_by_name(const char* name){
return mode_index;
}

void increment_mode(){
int16_t increment_mode(){
int16_t next_mode_index = (configuration.current_mode + 1) % NUM_LIGHT_MODES;
set_light_mode_by_index(next_mode_index);

return next_mode_index;
}

void enter_queued_light_mode(){
Expand Down
2 changes: 2 additions & 0 deletions src/light_modes/active/analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ void draw_analog(){
);

if(configuration.mirror_mode == true){
dot_pos = 0.1 + dot_pos * 0.9;

draw_dot(leds, NUM_RESERVED_DOTS+0, dot_color, 0.5 + (dot_pos* 0.5), 1.0);
draw_dot(leds, NUM_RESERVED_DOTS+1, dot_color, 0.5 + (dot_pos*-0.5), 1.0);
}
Expand Down
6 changes: 3 additions & 3 deletions src/tempo.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ float calculate_magnitude_of_tempo(uint16_t tempo_bin) {
float window_pos = 0.0;

for (uint16_t i = 0; i < block_size; i++) {
float sample_novelty = novelty_curve_normalized[((NOVELTY_HISTORY_LENGTH - 1) - block_size) + i];
//float sample_vu = vu_curve[((NOVELTY_HISTORY_LENGTH - 1) - block_size) + i];
//float sample_novelty = novelty_curve_normalized[((NOVELTY_HISTORY_LENGTH - 1) - block_size) + i];
float sample_vu = vu_curve[((NOVELTY_HISTORY_LENGTH - 1) - block_size) + i];
//float sample = (sample_novelty + sample_vu) / 2.0;

float q0 = tempi[tempo_bin].coeff * q1 - q2 + (sample_novelty * window_lookup[uint32_t(window_pos)]);
float q0 = tempi[tempo_bin].coeff * q1 - q2 + (sample_vu * window_lookup[uint32_t(window_pos)]);
q2 = q1;
q1 = q0;

Expand Down
3 changes: 2 additions & 1 deletion src/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ volatile bool slider_touch_active = false;
volatile bool device_touch_active = false;

extern void toggle_standby();
extern void increment_mode();
extern int16_t increment_mode();
extern uint8_t hold_blinks_queued;
extern bool hold_blink_state;

Expand Down Expand Up @@ -165,6 +165,7 @@ void read_touch(){
else if(touch_pins[t].pin == TOUCH_CENTER_PIN){
if(EMOTISCOPE_ACTIVE == true){
increment_mode();
broadcast("reload_config");
save_config_delayed();
}
else{
Expand Down

0 comments on commit f949ec3

Please sign in to comment.