Skip to content

Commit

Permalink
Merge pull request #47 from vladin79/master
Browse files Browse the repository at this point in the history
Fix for issue #41
  • Loading branch information
quen0n authored Dec 28, 2024
2 parents 50d5615 + c6b0da4 commit ebec477
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
11 changes: 10 additions & 1 deletion Sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ void unitemp_sensors_free(void) {
bool unitemp_sensors_init(void) {
bool result = true;

app->sensors_ready = false;

//Перебор датчиков из списка
for(uint8_t i = 0; i < unitemp_sensors_getCount(); i++) {
//Включение 5V если на порту 1 FZ его нет
Expand All @@ -578,12 +580,15 @@ bool unitemp_sensors_init(void) {
}
FURI_LOG_I(APP_NAME, "Sensor %s successfully initialized", app->sensors[i]->name);
}

app->sensors_ready = true;

return result;
}

bool unitemp_sensors_deInit(void) {
bool result = true;

//Выключение 5 В если до этого оно не было включено
if(app->settings.lastOTGState != true) {
furi_hal_power_disable_otg();
Expand All @@ -600,11 +605,14 @@ bool unitemp_sensors_deInit(void) {
result = false;
}
}

return result;
}

UnitempStatus unitemp_sensor_updateData(Sensor* sensor) {
if(sensor == NULL) return UT_SENSORSTATUS_ERROR;
if(sensor == NULL) {
return UT_SENSORSTATUS_ERROR;
}

//Проверка на допустимость опроса датчика
if(furi_get_tick() - sensor->lastPollingTime < sensor->type->pollingInterval) {
Expand Down Expand Up @@ -641,6 +649,7 @@ UnitempStatus unitemp_sensor_updateData(Sensor* sensor) {
unitemp_pascalToKPa(sensor);
}
}

return sensor->status;
}

Expand Down
8 changes: 4 additions & 4 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ App(
],
stack_size=2 * 1024,
order=100,
fap_description = "Application for reading temperature, humidity and pressure sensors like a DHT11/22, DS18B20, BMP280, HTU21 and more",
fap_author = "Quenon",
fap_weburl = "https://github.com/quen0n/Unitemp-Flipper-Zero-Plugin",
fap_description="Application for reading temperature, humidity and pressure sensors like a DHT11/22, DS18B20, BMP280, HTU21 and more",
fap_author="Quenon",
fap_weburl="https://github.com/quen0n/Unitemp-Flipper-Zero-Plugin",
fap_category="GPIO",
fap_icon="icon.png",
fap_icon_assets="assets",
fap_libs=["assets"],
fap_version="1.5"
fap_version="1.6"
)
31 changes: 23 additions & 8 deletions unitemp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "unitemp.h"
#include "interfaces/SingleWireSensor.h"
#include "Sensors.h"
#include "./views/UnitempViews.h"

Expand Down Expand Up @@ -178,6 +177,14 @@ bool unitemp_loadSettings(void) {
return true;
}

static void view_dispatcher_tick_event_callback(void* context) {
UNUSED(context);

if((app->sensors_ready) && (app->sensors_update)) {
unitemp_sensors_updateValues();
}
}

/**
* @brief Выделение места под переменные плагина
*
Expand All @@ -187,8 +194,8 @@ bool unitemp_loadSettings(void) {
static bool unitemp_alloc(void) {
//Выделение памяти под данные приложения
app = malloc(sizeof(Unitemp));
//Разрешение работы приложения
app->processing = true;

app->sensors_ready = false;

//Открытие хранилища (?)
app->storage = furi_record_open(RECORD_STORAGE);
Expand All @@ -202,6 +209,7 @@ static bool unitemp_alloc(void) {
app->settings.pressure_unit = UT_PRESSURE_MM_HG; //Единица измерения давления - мм рт. ст.

app->gui = furi_record_open(RECORD_GUI);

//Диспетчер окон
app->view_dispatcher = view_dispatcher_alloc();

Expand All @@ -223,6 +231,9 @@ static bool unitemp_alloc(void) {
app->popup = popup_alloc();
view_dispatcher_add_view(app->view_dispatcher, UnitempViewPopup, popup_get_view(app->popup));

view_dispatcher_set_tick_event_callback(
app->view_dispatcher, view_dispatcher_tick_event_callback, furi_ms_to_ticks(100));

view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);

return true;
Expand Down Expand Up @@ -279,31 +290,35 @@ int32_t unitemp_app() {

//Загрузка настроек из SD-карты
unitemp_loadSettings();

//Применение настроек
if(app->settings.infinityBacklight == true) {
//Постоянное свечение подсветки
notification_message(app->notifications, &sequence_display_backlight_enforce_on);
}

app->settings.lastOTGState = furi_hal_power_is_otg_enabled();

//Загрузка датчиков из SD-карты
unitemp_sensors_load();

//Инициализация датчиков
unitemp_sensors_init();

unitemp_General_switch();

while(app->processing) {
if(app->sensors_ready) unitemp_sensors_updateValues();
furi_delay_ms(100);
}
view_dispatcher_run(app->view_dispatcher);

//Деинициализация датчиков
unitemp_sensors_deInit();

//Автоматическое управление подсветкой
if(app->settings.infinityBacklight == true)
notification_message(app->notifications, &sequence_display_backlight_enforce_auto);

//Освобождение памяти
unitemp_free();

//Выход
return 0;
}
}
6 changes: 3 additions & 3 deletions unitemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//Имя приложения
#define APP_NAME "Unitemp"
//Версия приложения
#define UNITEMP_APP_VER "1.4-store"
#define UNITEMP_APP_VER "1.6"
//Путь хранения файлов плагина
#define APP_PATH_FOLDER "/ext/unitemp"
//Имя файла с настройками
Expand Down Expand Up @@ -86,8 +86,8 @@ typedef struct {
//Основная структура плагина
typedef struct {
//Система
bool processing; //Флаг работы приложения. При ложном значении приложение закрывается
bool sensors_ready; //Флаг готовности датчиков к опросу
bool sensors_update; // Флаг допустимости опроса датчиков
//Основные настройки
UnitempSettings settings;
//Массив указателей на датчики
Expand Down Expand Up @@ -151,4 +151,4 @@ bool unitemp_saveSettings(void);
bool unitemp_loadSettings(void);

extern Unitemp* app;
#endif
#endif
13 changes: 6 additions & 7 deletions views/General_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ static void _draw_view_sensorsCarousel(Canvas* canvas) {
static void _draw_callback(Canvas* canvas, void* _model) {
UNUSED(_model);

app->sensors_ready = true;
app->sensors_update = true;

uint8_t sensors_count = unitemp_sensors_getActiveCount();

if(generalview_sensor_index + 1 > sensors_count) generalview_sensor_index = 0;
if(generalview_sensor_index >= sensors_count) generalview_sensor_index = 0;

if(sensors_count == 0) {
current_view = G_NO_SENSORS_VIEW;
Expand All @@ -462,14 +462,14 @@ static bool _input_callback(InputEvent* event, void* context) {
if(event->key == InputKeyOk && event->type == InputTypeShort) {
//Меню добавления датчика при их отсутствии
if(current_view == G_NO_SENSORS_VIEW) {
app->sensors_ready = false;
app->sensors_update = false;
unitemp_SensorsList_switch();
} else if(current_view == G_LIST_VIEW) {
//Переход в главное меню при выключенном селекторе
app->sensors_ready = false;
app->sensors_update = false;
unitemp_MainMenu_switch();
} else if(current_view == G_CAROUSEL_VIEW) {
app->sensors_ready = false;
app->sensors_update = false;
unitemp_SensorActions_switch(unitemp_sensor_getActive(generalview_sensor_index));
}
}
Expand Down Expand Up @@ -553,7 +553,7 @@ static bool _input_callback(InputEvent* event, void* context) {
//Выход из приложения при карусели или отсутствии датчиков
if(current_view == G_NO_SENSORS_VIEW ||
((current_view == G_CAROUSEL_VIEW) && (carousel_info_selector == CAROUSEL_VALUES))) {
app->processing = false;
view_dispatcher_stop(app->view_dispatcher);
return true;
}
//Переключение селектора вида карусели
Expand Down Expand Up @@ -585,7 +585,6 @@ void unitemp_General_alloc(void) {
}

void unitemp_General_switch(void) {
app->sensors_ready = true;
view_dispatcher_switch_to_view(app->view_dispatcher, UnitempViewGeneral);
}

Expand Down

0 comments on commit ebec477

Please sign in to comment.