From ee41413c6aa7d24f41f0172d505f0326255b7640 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 9 Mar 2023 04:47:33 +0300 Subject: [PATCH] Update unitemp --- CHANGELOG.md | 2 + applications/plugins/unitemp/README.md | 4 +- applications/plugins/unitemp/Sensors.c | 7 +- .../unitemp/interfaces/OneWireSensor.c | 156 +++--------------- .../unitemp/interfaces/OneWireSensor.h | 7 +- applications/plugins/unitemp/unitemp.c | 5 +- applications/plugins/unitemp/unitemp.h | 9 +- .../plugins/unitemp/views/General_view.c | 20 ++- .../plugins/unitemp/views/SensorEdit_view.c | 2 +- .../plugins/unitemp/views/Settings_view.c | 4 +- 10 files changed, 66 insertions(+), 150 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f55ad7fb6..1d75cab2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ * If you have copied apps into `apps` folder - remove `apps` folder on your microSD before installing this release to avoid issues! * SubGHz: Default custom buttons layout for non standard remotes (for example your remote has broken buttons and transmit only 0xC, now you can use other buttons) * SubGHz: Fix issues with external module 5v power (now all works automatically, enabling +5v manually not required) (**Only for modules that work with 5v->3.3v converter!!!!!**) +* SubGHz: Option to disable automatic 5v power for external modules - (5v is enabled by default, if you are using module without converter you can set this option to OFF) * SubGHz: Fix and update subghz protocols to use new error system * SubGHz: Fix default frequency being overwritten bug (Add manually fixes) * SubGHz: Fix 464Mhz and (390MHz for external module only) was showing up in Frequency analyzer all the time due to noise * iButton: Fix ibutton app - add manually - duplicate names * Plugins: NFC Magic fix - reinit nfc at app start +* Plugins: Update **Unitemp - Temperature sensors reader** (DHT11/22, DS18B20, BMP280, HTU21x and more) [(by quen0n)](https://github.com/quen0n/unitemp-flipperzero) * Plugins: Update **SWD Probe** [(by g3gg0)](https://github.com/g3gg0/flipper-swd_probe) * Plugins: Massive plugins refactoring - not full refactoring, only small issues is fixed and moved all plugins to furi mutex instead of valuemutex * Plugins: Many small issues was found and fixed due mutex upgrade diff --git a/applications/plugins/unitemp/README.md b/applications/plugins/unitemp/README.md index 436f3600e..2da78d2bd 100644 --- a/applications/plugins/unitemp/README.md +++ b/applications/plugins/unitemp/README.md @@ -13,7 +13,7 @@ 3) Open application on your Flipper: `Applications->GPIO->Temp sensors reader` Note: If you get the message "API version mismatch" after updating the firmware, download and install Unitemp again ## Need help? Discussions? -Join the discussion, ask a question or just send a photo of the flipper with sensors to [Discord](https://discord.com/channels/740930220399525928/1056727938747351060) +Join the discussion, ask a question or just send a photo of the flipper with sensors to [Discord](https://discord.com/channels/740930220399525928/1056727938747351060). [Invite link](https://discord.com/invite/flipper) ## Gratitudes Thanks to [@Svaarich](https://github.com/Svaarich) for the UI design and to the Unleashed firmware community for sensors testing and feedbacks. @@ -21,4 +21,4 @@ Thanks to [@Svaarich](https://github.com/Svaarich) for the UI design and to the ![image](https://user-images.githubusercontent.com/10090793/210120132-7ddbc937-0a6b-4472-bd1c-7fbc3ecdf2ad.png) ![image](https://user-images.githubusercontent.com/10090793/210120135-12fc5810-77ff-49db-b799-e9479e1f57a7.png) ![image](https://user-images.githubusercontent.com/10090793/210120143-a2bae3ce-4190-421f-8c4f-c7c744903bd6.png) -![image](https://user-images.githubusercontent.com/10090793/215224085-8099408e-b3de-4a0c-854e-fe4e4faa8ea3.png) \ No newline at end of file +![image](https://user-images.githubusercontent.com/10090793/215224085-8099408e-b3de-4a0c-854e-fe4e4faa8ea3.png) diff --git a/applications/plugins/unitemp/Sensors.c b/applications/plugins/unitemp/Sensors.c index d9304ab32..30419a929 100644 --- a/applications/plugins/unitemp/Sensors.c +++ b/applications/plugins/unitemp/Sensors.c @@ -149,8 +149,7 @@ uint8_t unitemp_gpio_getAviablePortsCount(const Interface* interface, const GPIO for(uint8_t i = 0; i < GPIO_ITEMS; i++) { //Проверка для one wire if(interface == &ONE_WIRE) { - if(((gpio_interfaces_list[i] == NULL || gpio_interfaces_list[i] == &ONE_WIRE) && - (i != 12)) || //Почему-то не работает на 17 порте + if(((gpio_interfaces_list[i] == NULL || gpio_interfaces_list[i] == &ONE_WIRE)) || (unitemp_gpio_getFromIndex(i) == extraport)) { aviable_ports_count++; } @@ -208,9 +207,7 @@ const GPIO* for(uint8_t i = 0; i < GPIO_ITEMS; i++) { //Проверка для one wire if(interface == &ONE_WIRE) { - //Почему-то не работает на 17 порте - if(((gpio_interfaces_list[i] == NULL || gpio_interfaces_list[i] == &ONE_WIRE) && - (i != 12)) || //Почему-то не работает на 17 порте + if(((gpio_interfaces_list[i] == NULL || gpio_interfaces_list[i] == &ONE_WIRE)) || (unitemp_gpio_getFromIndex(i) == extraport)) { if(aviable_index == index) { return unitemp_gpio_getFromIndex(i); diff --git a/applications/plugins/unitemp/interfaces/OneWireSensor.c b/applications/plugins/unitemp/interfaces/OneWireSensor.c index f4f3ebcdc..b951fc55b 100644 --- a/applications/plugins/unitemp/interfaces/OneWireSensor.c +++ b/applications/plugins/unitemp/interfaces/OneWireSensor.c @@ -20,7 +20,6 @@ #include "OneWireSensor.h" #include #include -#include const SensorType Dallas = { .typename = "Dallas", @@ -37,8 +36,6 @@ const SensorType Dallas = { // Переменные для хранения промежуточного результата сканирования шины // найденный восьмибайтовый адрес static uint8_t onewire_enum[8] = {0}; -// последний нулевой бит, где была неоднозначность (нумеруя с единицы) -static uint8_t onewire_enum_fork_bit = 65; OneWireBus* uintemp_onewire_bus_alloc(const GPIO* gpio) { if(gpio == NULL) { @@ -55,9 +52,11 @@ OneWireBus* uintemp_onewire_bus_alloc(const GPIO* gpio) { } OneWireBus* bus = malloc(sizeof(OneWireBus)); + bus->device_count = 0; bus->gpio = gpio; bus->powerMode = PWR_PASSIVE; + UNITEMP_DEBUG("one wire bus (port %d) allocated", gpio->num); return bus; @@ -69,6 +68,8 @@ bool unitemp_onewire_bus_init(OneWireBus* bus) { //Выход если шина уже была инициализирована if(bus->device_count > 1) return true; + bus->host = onewire_host_alloc(bus->gpio->pin); + unitemp_gpio_lock(bus->gpio, &ONE_WIRE); //Высокий уровень по умолчанию furi_hal_gpio_write(bus->gpio->pin, true); @@ -81,6 +82,7 @@ bool unitemp_onewire_bus_init(OneWireBus* bus) { return true; } + bool unitemp_onewire_bus_deinit(OneWireBus* bus) { UNITEMP_DEBUG("devices on wire %d: %d", bus->gpio->num, bus->device_count); bus->device_count--; @@ -100,84 +102,34 @@ bool unitemp_onewire_bus_deinit(OneWireBus* bus) { return false; } } -bool unitemp_onewire_bus_start(OneWireBus* bus) { - furi_hal_gpio_write(bus->gpio->pin, false); - furi_delay_us(500); - - furi_hal_gpio_write(bus->gpio->pin, true); - - //Ожидание подъёма шины - uint32_t t = furi_get_tick(); - while(!furi_hal_gpio_read(bus->gpio->pin)) { - //Выход если шина не поднялась - if(furi_get_tick() - t > 10) return false; - } - - furi_delay_us(100); - bool status = !furi_hal_gpio_read(bus->gpio->pin); - furi_delay_us(400); - return status; +inline bool unitemp_onewire_bus_start(OneWireBus* bus) { + return onewire_host_reset(bus->host); } -void unitemp_onewire_bus_send_bit(OneWireBus* bus, bool state) { - //Необходимо для стабильной работы при пассивном питании - if(bus->powerMode == PWR_PASSIVE) furi_delay_us(100); - - if(state) { - // write 1 - furi_hal_gpio_write(bus->gpio->pin, false); - furi_delay_us(1); - furi_hal_gpio_write(bus->gpio->pin, true); - furi_delay_us(90); - } else { - furi_hal_gpio_write(bus->gpio->pin, false); - furi_delay_us(90); - furi_hal_gpio_write(bus->gpio->pin, true); - //Ожидание подъёма шины - uint32_t t = furi_get_tick(); - while(!furi_hal_gpio_read(bus->gpio->pin)) { - //Выход если шина не поднялась - if(furi_get_tick() - t > 10) return; - } - } +inline void unitemp_onewire_bus_send_bit(OneWireBus* bus, bool state) { + onewire_host_write_bit(bus->host, state); } -void unitemp_onewire_bus_send_byte(OneWireBus* bus, uint8_t data) { - for(int i = 0; i < 8; i++) { - unitemp_onewire_bus_send_bit(bus, (data & (1 << i)) != 0); - } +inline void unitemp_onewire_bus_send_byte(OneWireBus* bus, uint8_t data) { + onewire_host_write(bus->host, data); } void unitemp_onewire_bus_send_byteArray(OneWireBus* bus, uint8_t* data, uint8_t len) { for(uint8_t i = 0; i < len; i++) { - unitemp_onewire_bus_send_byte(bus, data[i]); + onewire_host_write(bus->host, data[i]); } } -bool unitemp_onewire_bus_read_bit(OneWireBus* bus) { - furi_delay_ms(1); - furi_hal_gpio_write(bus->gpio->pin, false); - furi_delay_us(2); // Длительность низкого уровня, минимум 1 мкс - furi_hal_gpio_write(bus->gpio->pin, true); - furi_delay_us(8); // Пауза до момента сэмплирования, всего не более 15 мкс - bool r = furi_hal_gpio_read(bus->gpio->pin); - furi_delay_us(80); // Ожидание до следующего тайм-слота, минимум 60 мкс с начала низкого уровня - return r; +inline bool unitemp_onewire_bus_read_bit(OneWireBus* bus) { + return onewire_host_read_bit(bus->host); } -uint8_t unitemp_onewire_bus_read_byte(OneWireBus* bus) { - uint8_t r = 0; - for(uint8_t p = 8; p; p--) { - r >>= 1; - if(unitemp_onewire_bus_read_bit(bus)) r |= 0x80; - } - return r; +inline uint8_t unitemp_onewire_bus_read_byte(OneWireBus* bus) { + return onewire_host_read(bus->host); } void unitemp_onewire_bus_read_byteArray(OneWireBus* bus, uint8_t* data, uint8_t len) { - for(uint8_t i = 0; i < len; i++) { - data[i] = unitemp_onewire_bus_read_byte(bus); - } + onewire_host_read_bytes(bus->host, data, len); } static uint8_t onewire_CRC_update(uint8_t crc, uint8_t b) { @@ -222,77 +174,16 @@ bool unitemp_onewire_sensor_readID(OneWireSensor* instance) { return true; } -void unitemp_onewire_bus_enum_init(void) { - for(uint8_t p = 0; p < 8; p++) { - onewire_enum[p] = 0; - } - onewire_enum_fork_bit = 65; // правее правого +void unitemp_onewire_bus_enum_init(OneWireBus* bus) { + onewire_host_reset_search(bus->host); } uint8_t* unitemp_onewire_bus_enum_next(OneWireBus* bus) { - furi_delay_ms(10); - if(!onewire_enum_fork_bit) { // Если на предыдущем шаге уже не было разногласий - UNITEMP_DEBUG("All devices on wire %d is found", unitemp_gpio_toInt(bus->gpio)); - return 0; // то просто выходим ничего не возвращая + if(onewire_host_search(bus->host, onewire_enum, NORMAL_SEARCH)) { + return onewire_enum; + } else { + return NULL; } - if(!unitemp_onewire_bus_start(bus)) { - UNITEMP_DEBUG("Wire %d is empty", unitemp_gpio_toInt(bus->gpio)); - return 0; - } - uint8_t bp = 8; - uint8_t* pprev = &onewire_enum[0]; - uint8_t prev = *pprev; - uint8_t next = 0; - - uint8_t p = 1; - unitemp_onewire_bus_send_byte(bus, 0xF0); - uint8_t newfork = 0; - for(;;) { - uint8_t not0 = unitemp_onewire_bus_read_bit(bus); - uint8_t not1 = unitemp_onewire_bus_read_bit(bus); - if(!not0) { // Если присутствует в адресах бит ноль - if(!not1) { // Но также присустствует бит 1 (вилка) - if(p < - onewire_enum_fork_bit) { // Если мы левее прошлого правого конфликтного бита, - if(prev & 1) { - next |= 0x80; // то копируем значение бита из прошлого прохода - } else { - newfork = p; // если ноль, то запомним конфликтное место - } - } else if(p == onewire_enum_fork_bit) { - next |= - 0x80; // если на этом месте в прошлый раз был правый конфликт с нулём, выведем 1 - } else { - newfork = p; // правее - передаём ноль и запоминаем конфликтное место - } - } // в противном случае идём, выбирая ноль в адресе - } else { - if(!not1) { // Присутствует единица - next |= 0x80; - } else { // Нет ни нулей ни единиц - ошибочная ситуация - - UNITEMP_DEBUG("Wrong wire %d situation", unitemp_gpio_toInt(bus->gpio)); - return 0; - } - } - unitemp_onewire_bus_send_bit(bus, next & 0x80); - bp--; - if(!bp) { - *pprev = next; - if(p >= 64) break; - next = 0; - pprev++; - prev = *pprev; - bp = 8; - } else { - if(p >= 64) break; - prev >>= 1; - next >>= 1; - } - p++; - } - onewire_enum_fork_bit = newfork; - return &onewire_enum[0]; } void unitemp_onewire_bus_select_sensor(OneWireSensor* instance) { @@ -364,7 +255,6 @@ bool unitemp_onewire_sensor_init(Sensor* sensor) { } unitemp_onewire_bus_init(instance->bus); - furi_delay_ms(1); if(instance->familyCode == FC_DS18B20 || instance->familyCode == FC_DS1822) { //Установка разрядности в 10 бит diff --git a/applications/plugins/unitemp/interfaces/OneWireSensor.h b/applications/plugins/unitemp/interfaces/OneWireSensor.h index ef94db820..cb031d161 100644 --- a/applications/plugins/unitemp/interfaces/OneWireSensor.h +++ b/applications/plugins/unitemp/interfaces/OneWireSensor.h @@ -19,6 +19,7 @@ #define UNITEMP_OneWire #include "../unitemp.h" +#include //Коды семейства устройств typedef enum DallasFamilyCode { @@ -42,6 +43,8 @@ typedef struct { int8_t device_count; //Режим питания датчиков на шине PowerMode powerMode; + + OneWireHost* host; } OneWireBus; //Инстанс датчика one wire @@ -155,7 +158,7 @@ bool unitemp_onewire_bus_read_bit(OneWireBus* bus); * * @param bus Указатель на шину one wire * @return Байт информации - */ + **/ uint8_t unitemp_onewire_bus_read_byte(OneWireBus* bus); /** @@ -201,7 +204,7 @@ void unitemp_onewire_bus_select_sensor(OneWireSensor* instance); /** * @brief Инициализация процесса поиска адресов на шине one wire */ -void unitemp_onewire_bus_enum_init(void); +void unitemp_onewire_bus_enum_init(OneWireBus* bus); /** * @brief Перечисляет устройства на шине one wire и получает очередной адрес diff --git a/applications/plugins/unitemp/unitemp.c b/applications/plugins/unitemp/unitemp.c index 181de0e78..fbf9eca55 100644 --- a/applications/plugins/unitemp/unitemp.c +++ b/applications/plugins/unitemp/unitemp.c @@ -36,6 +36,9 @@ void unitemp_pascalToMmHg(Sensor* sensor) { void unitemp_pascalToKPa(Sensor* sensor) { sensor->pressure = sensor->pressure / 1000.0f; } +void unitemp_pascalToHPa(Sensor* sensor) { + sensor->pressure = sensor->pressure / 100.0f; +} void unitemp_pascalToInHg(Sensor* sensor) { sensor->pressure = sensor->pressure * 0.0002953007; } @@ -306,4 +309,4 @@ int32_t unitemp_app() { unitemp_free(); //Выход return 0; -} \ No newline at end of file +} diff --git a/applications/plugins/unitemp/unitemp.h b/applications/plugins/unitemp/unitemp.h index bde8b0c17..4d184b2c3 100644 --- a/applications/plugins/unitemp/unitemp.h +++ b/applications/plugins/unitemp/unitemp.h @@ -67,6 +67,7 @@ typedef enum { UT_PRESSURE_MM_HG, UT_PRESSURE_IN_HG, UT_PRESSURE_KPA, + UT_PRESSURE_HPA, UT_PRESSURE_COUNT } pressureMeasureUnit; @@ -135,6 +136,12 @@ void unitemp_pascalToKPa(Sensor* sensor); * * @param sensor Указатель на датчик */ +void unitemp_pascalToHPa(Sensor* sensor); +/** + * + * Mod BySepa - linktr.ee/BySepa + * + */ void unitemp_pascalToInHg(Sensor* sensor); /** @@ -151,4 +158,4 @@ bool unitemp_saveSettings(void); bool unitemp_loadSettings(void); extern Unitemp* app; -#endif \ No newline at end of file +#endif diff --git a/applications/plugins/unitemp/views/General_view.c b/applications/plugins/unitemp/views/General_view.c index dcf8420d9..2c8d389bf 100644 --- a/applications/plugins/unitemp/views/General_view.c +++ b/applications/plugins/unitemp/views/General_view.c @@ -116,14 +116,20 @@ static void _draw_humidity(Canvas* canvas, Sensor* sensor, const uint8_t pos[2]) static void _draw_pressure(Canvas* canvas, Sensor* sensor) { const uint8_t x = 29, y = 39; //Рисование рамки - canvas_draw_rframe(canvas, x, y, 69, 20, 3); - canvas_draw_rframe(canvas, x, y, 69, 19, 3); + if(app->settings.pressure_unit == UT_PRESSURE_HPA) { + canvas_draw_rframe(canvas, x, y, 84, 20, 3); + canvas_draw_rframe(canvas, x, y, 84, 19, 3); + } else { + canvas_draw_rframe(canvas, x, y, 69, 20, 3); + canvas_draw_rframe(canvas, x, y, 69, 19, 3); + } //Рисование иконки canvas_draw_icon(canvas, x + 3, y + 4, &I_pressure_7x13); int16_t press_int = sensor->pressure; - int8_t press_dec = (int16_t)(sensor->temp * 10) % 10; + // Change Temp for Pressure + int8_t press_dec = (int16_t)(sensor->pressure * 10) % 10; //Целая часть давления snprintf(app->buff, BUFF_SIZE, "%d", press_int); @@ -136,15 +142,23 @@ static void _draw_pressure(Canvas* canvas, Sensor* sensor) { snprintf(app->buff, BUFF_SIZE, ".%d", press_dec); canvas_set_font(canvas, FontPrimary); canvas_draw_str(canvas, x + 27 + int_len / 2 + 2, y + 10 + 7, app->buff); + } else if(app->settings.pressure_unit == UT_PRESSURE_HPA) { + uint8_t int_len = canvas_string_width(canvas, app->buff); + snprintf(app->buff, BUFF_SIZE, ".%d", press_dec); + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, x + 32 + int_len / 2 + 2, y + 10 + 7, app->buff); } canvas_set_font(canvas, FontSecondary); //Единица измерения + if(app->settings.pressure_unit == UT_PRESSURE_MM_HG) { canvas_draw_icon(canvas, x + 50, y + 2, &I_mm_hg_15x15); } else if(app->settings.pressure_unit == UT_PRESSURE_IN_HG) { canvas_draw_icon(canvas, x + 50, y + 2, &I_in_hg_15x15); } else if(app->settings.pressure_unit == UT_PRESSURE_KPA) { canvas_draw_str(canvas, x + 52, y + 13, "kPa"); + } else if(app->settings.pressure_unit == UT_PRESSURE_HPA) { + canvas_draw_str(canvas, x + 67, y + 13, "hPa"); } } diff --git a/applications/plugins/unitemp/views/SensorEdit_view.c b/applications/plugins/unitemp/views/SensorEdit_view.c index ccb07a48e..c1ac4c028 100644 --- a/applications/plugins/unitemp/views/SensorEdit_view.c +++ b/applications/plugins/unitemp/views/SensorEdit_view.c @@ -75,7 +75,7 @@ static void _onewire_scan(void) { } while(_onewire_id_exist(id)); if(id == NULL) { - unitemp_onewire_bus_enum_init(); + unitemp_onewire_bus_enum_init(ow_sensor->bus); id = unitemp_onewire_bus_enum_next(ow_sensor->bus); if(_onewire_id_exist(id)) { do { diff --git a/applications/plugins/unitemp/views/Settings_view.c b/applications/plugins/unitemp/views/Settings_view.c index bff169129..e61c6cad6 100644 --- a/applications/plugins/unitemp/views/Settings_view.c +++ b/applications/plugins/unitemp/views/Settings_view.c @@ -25,7 +25,7 @@ static VariableItemList* variable_item_list; static const char states[2][9] = {"Auto", "Infinity"}; static const char temp_units[UT_TEMP_COUNT][3] = {"*C", "*F"}; -static const char pressure_units[UT_PRESSURE_COUNT][6] = {"mm Hg", "in Hg", "kPa"}; +static const char pressure_units[UT_PRESSURE_COUNT][6] = {"mm Hg", "in Hg", "kPa", "hPA"}; //Элемент списка - бесконечная подсветка VariableItem* infinity_backlight_item; @@ -149,4 +149,4 @@ void unitemp_Settings_free(void) { view_free(view); //Удаление вида после обработки view_dispatcher_remove_view(app->view_dispatcher, VIEW_ID); -} \ No newline at end of file +}