Skip to content

Commit

Permalink
Reduce S2L meters appearing on menu randomly
Browse files Browse the repository at this point in the history
Mutex for scene number was being taken for too long when changing screen; should fix most instances - still one race condition left (see #13 comments)
Also correct some indentation
  • Loading branch information
jevans3142 committed Feb 25, 2024
1 parent 06542e4 commit ce7d8ba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
16 changes: 8 additions & 8 deletions src/main/dmx_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ void dmx_input_task(void)
// if not 0, then RDM or custom protocol
if(dtmp[0] == 0)
{
dmx_state = DMX_DATA;
// reset dmx adress to 0
current_rx_addr = 0;
//xSemaphoreTake(DMX_Input_Buffer_Mutex, ( TickType_t ) 10 );
// store received timestamp
//TODO - this is the timing thing
last_dmx_packet = xTaskGetTickCount();
//xSemaphoreGive(DMX_Input_Buffer_Mutex);
dmx_state = DMX_DATA;
// reset dmx adress to 0
current_rx_addr = 0;
//xSemaphoreTake(DMX_Input_Buffer_Mutex, ( TickType_t ) 10 );
// store received timestamp
//TODO - this is the timing thing
last_dmx_packet = xTaskGetTickCount();
//xSemaphoreGive(DMX_Input_Buffer_Mutex);
}
}
// check if in data receive mode
Expand Down
10 changes: 9 additions & 1 deletion src/main/redraw_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
#include "freertos/task.h"
#include "driver/adc.h"
#include "esp_timer.h"
#include "esp_err.h"
#include "esp_log.h"

#include "main.h"
#include "redraw_screen.h"
#include "screen_driver.h"
#include "scene_engine.h"

static const char *TAG = "redraw_screen";

//Define states and mutexs
SemaphoreHandle_t Screen_No_Mutex = NULL;
int Screen_No = 0;
Expand Down Expand Up @@ -138,8 +142,8 @@ void set_screen(int new_screen_no, int new_screen_selected)
{
set_screen_selected_value(new_screen_selected);
Screen_No = new_screen_no;
redraw_screen(new_screen_no);
xSemaphoreGive( Screen_No_Mutex );
redraw_screen(new_screen_no);
}
}
}
Expand All @@ -154,6 +158,10 @@ int get_screen(void)
xSemaphoreGive( Screen_No_Mutex );
return returnval;
}
else
{
ESP_LOGW(TAG, "Unable to take mutex in get_screen");
}
}
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/redraw_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

//Define screen IDs

#define SCREEN_MAIN_STATUS 0
#define SCREEN_MAIN_MENU 1
#define SCREEN_MAIN_STATUS 1
#define SCREEN_MAIN_MENU 2

#define SCREEN_RECALL_SCENE 10
#define SCREEN_RECORD_SCENE 11
Expand Down
47 changes: 27 additions & 20 deletions src/main/scene_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,33 +279,36 @@ void scene_calc_task(uint8_t *output)
}

// Colourfade effects

if ((Scene_Engine_Settings_temp.colourfade_enable[temp_scene_no - 1] == pdTRUE) && (Scene_Engine_Settings_temp.colourfade_mode == COLOURFADE_MODE_RGB))
{
// Colourfade is active on this scene
float time_proportion = 6 * (fmod((float) millis(),(float) (1000*Scene_Engine_Settings_temp.colourfade_time))) / ((float)(1000 * Scene_Engine_Settings_temp.colourfade_time));
if ((Scene_Engine_Settings_temp.colourfade_enable[temp_scene_no - 1] == pdTRUE) && (Scene_Engine_Settings_temp.colourfade_mode == COLOURFADE_MODE_RGB))
{
// Colourfade is active on this scene
float time_proportion = 6 * (fmod((float) millis(),(float) (1000*Scene_Engine_Settings_temp.colourfade_time))) / ((float)(1000 * Scene_Engine_Settings_temp.colourfade_time));

// Convert HSV to RBG (effectively...)
float x = 1 - fabs(fmod(time_proportion,2)-1);
float r = 0, g = 0, b = 0;
if ((0 <= time_proportion) && (time_proportion <= 1)) { r = 1; g = x; b = 0; }
if ((1 < time_proportion) && (time_proportion <= 2)) { r = x; g = 1; b = 0; }
if ((2 < time_proportion) && (time_proportion <= 3)) { r = 0; g = 1; b = x; }
if ((3 < time_proportion) && (time_proportion <= 4)) { r = 0; g = x; b = 1; }
if ((4 < time_proportion) && (time_proportion <= 5)) { r = x; g = 0; b = 1; }
if ((5 < time_proportion) && (time_proportion <= 6)) { r = 1; g = 0; b = x; }

// Convert HSV to RBG (effectively...)
float x = 1 - fabs(fmod(time_proportion,2)-1);
float r = 0, g = 0, b = 0;
if ((0 <= time_proportion) && (time_proportion <= 1)) { r = 1; g = x; b = 0; }
if ((1 < time_proportion) && (time_proportion <= 2)) { r = x; g = 1; b = 0; }
if ((2 < time_proportion) && (time_proportion <= 3)) { r = 0; g = 1; b = x; }
if ((3 < time_proportion) && (time_proportion <= 4)) { r = 0; g = x; b = 1; }
if ((4 < time_proportion) && (time_proportion <= 5)) { r = x; g = 0; b = 1; }
if ((5 < time_proportion) && (time_proportion <= 6)) { r = 1; g = 0; b = x; }

current_state[Scene_Engine_Settings_temp.colourfade_r_ch] = (uint8_t) 255 * r;
current_state[Scene_Engine_Settings_temp.colourfade_g_ch] = (uint8_t) 255 * g;
current_state[Scene_Engine_Settings_temp.colourfade_b_ch] = (uint8_t) 255 * b;

}
current_state[Scene_Engine_Settings_temp.colourfade_r_ch] = (uint8_t) 255 * r;
current_state[Scene_Engine_Settings_temp.colourfade_g_ch] = (uint8_t) 255 * g;
current_state[Scene_Engine_Settings_temp.colourfade_b_ch] = (uint8_t) 255 * b;

}

current_state[0] = 0x00; // Force the DMX start code to be 0x00 for 'dimmer data'
copy_513(current_state, output);
xSemaphoreGive(DMX_Buffer_Mutex);
}
else
{
// Can't get mutex
ESP_LOGW(TAG, "Can't take DMX buffer mutex in scene calc task");
}
}
}

Expand All @@ -332,5 +335,9 @@ void store_dmx_input_value(uint16_t address, uint8_t value)
dmx_in_buffer[address] = value;
xSemaphoreGive(DMX_Buffer_Mutex);
}
else
{
ESP_LOGW(TAG, "Can't take DMX store mutex");
}
}
}

0 comments on commit ce7d8ba

Please sign in to comment.