From b1496ee9bd97ff8c34a67a49ec4ecdc6cfbd9436 Mon Sep 17 00:00:00 2001 From: Milk-Cool <43724263+Milk-Cool@users.noreply.github.com> Date: Mon, 30 Jan 2023 10:54:15 +0300 Subject: [PATCH 1/8] Furi: getter for current thread stdout write callback (#2344) --- firmware/targets/f7/api_symbols.csv | 5 +++-- furi/core/thread.c | 6 ++++++ furi/core/thread.h | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index a75e88bad..7b247daed 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,11.8,, +Version,+,11.9,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -1389,8 +1389,8 @@ Function,+,furi_hal_version_uid_size,size_t, Function,-,furi_hal_vibro_init,void, Function,+,furi_hal_vibro_on,void,_Bool Function,-,furi_init,void, -Function,+,furi_kernel_is_irq_or_masked,_Bool, Function,+,furi_kernel_get_tick_frequency,uint32_t, +Function,+,furi_kernel_is_irq_or_masked,_Bool, Function,+,furi_kernel_lock,int32_t, Function,+,furi_kernel_restore_lock,int32_t,int32_t Function,+,furi_kernel_unlock,int32_t, @@ -1515,6 +1515,7 @@ Function,+,furi_thread_get_name,const char*,FuriThreadId Function,+,furi_thread_get_return_code,int32_t,FuriThread* Function,+,furi_thread_get_stack_space,uint32_t,FuriThreadId Function,+,furi_thread_get_state,FuriThreadState,FuriThread* +Function,+,furi_thread_get_stdout_callback,FuriThreadStdoutWriteCallback, Function,+,furi_thread_is_suspended,_Bool,FuriThreadId Function,+,furi_thread_join,_Bool,FuriThread* Function,+,furi_thread_mark_as_service,void,FuriThread* diff --git a/furi/core/thread.c b/furi/core/thread.c index c966dd572..ef9560b4a 100644 --- a/furi/core/thread.c +++ b/furi/core/thread.c @@ -530,6 +530,12 @@ bool furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback) { return true; } +FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback() { + FuriThread* thread = furi_thread_get_current(); + + return thread->output.write_callback; +} + size_t furi_thread_stdout_write(const char* data, size_t size) { FuriThread* thread = furi_thread_get_current(); diff --git a/furi/core/thread.h b/furi/core/thread.h index c2f5a9130..1542d5bf0 100644 --- a/furi/core/thread.h +++ b/furi/core/thread.h @@ -227,6 +227,12 @@ const char* furi_thread_get_name(FuriThreadId thread_id); uint32_t furi_thread_get_stack_space(FuriThreadId thread_id); +/** Get STDOUT callback for thead + * + * @return STDOUT callback + */ +FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(); + /** Set STDOUT callback for thread * * @param callback callback or NULL to clear From 5db7fdf9852ec4a412765e265cd10d39c02305b7 Mon Sep 17 00:00:00 2001 From: Noam Drong Date: Mon, 30 Jan 2023 09:03:10 +0100 Subject: [PATCH 2/8] Add support for `GUI-CTRL` in bad_usb (#2315) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- applications/main/bad_usb/bad_usb_script.c | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/main/bad_usb/bad_usb_script.c b/applications/main/bad_usb/bad_usb_script.c index bbd721ed2..e2281133f 100644 --- a/applications/main/bad_usb/bad_usb_script.c +++ b/applications/main/bad_usb/bad_usb_script.c @@ -50,6 +50,7 @@ static const DuckyKey ducky_keys[] = { {"ALT-SHIFT", KEY_MOD_LEFT_ALT | KEY_MOD_LEFT_SHIFT}, {"ALT-GUI", KEY_MOD_LEFT_ALT | KEY_MOD_LEFT_GUI}, {"GUI-SHIFT", KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT}, + {"GUI-CTRL", KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_CTRL}, {"CTRL", KEY_MOD_LEFT_CTRL}, {"CONTROL", KEY_MOD_LEFT_CTRL}, From 7f3ebcd110e57193d903fed588920402952b0d0d Mon Sep 17 00:00:00 2001 From: Konstantin Volkov <72250702+doomwastaken@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:59:45 +0700 Subject: [PATCH 3/8] Changed bench target, stlink serial and added error for testing the run (#2275) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * changed bench target, stlink serial and added error for testing the run * changed flipper name for macos and changed serial aquisition for device manager * tested broken pipeline, reverting test data * added timeout-minutes, testing if its int or float Co-authored-by: Konstantin Volkov Co-authored-by: あく --- .github/workflows/unit_tests.yml | 1 + .github/workflows/updater_test.yml | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index ac3fc3684..7e625229a 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -56,6 +56,7 @@ jobs: - name: 'Run units and validate results' id: run_units if: steps.copy.outcome == 'success' + timeout-minutes: 2.5 run: | source scripts/toolchain/fbtenv.sh python3 scripts/testing/units.py ${{steps.device.outputs.flipper}} diff --git a/.github/workflows/updater_test.yml b/.github/workflows/updater_test.yml index d4ca56fad..0b02920fa 100644 --- a/.github/workflows/updater_test.yml +++ b/.github/workflows/updater_test.yml @@ -10,7 +10,7 @@ env: jobs: test_updater_on_bench: - runs-on: [self-hosted, FlipperZeroTest] # currently on same bench as units, needs different bench + runs-on: [self-hosted, FlipperZeroTestMac1] steps: - name: 'Decontaminate previous build leftovers' run: | @@ -27,7 +27,8 @@ jobs: - name: 'Get flipper from device manager (mock)' id: device run: | - echo "flipper=/dev/ttyACM0" >> $GITHUB_OUTPUT + echo "flipper=/dev/tty.usbmodemflip_Rekigyn1" >> $GITHUB_OUTPUT + echo "stlink=0F020D026415303030303032" >> $GITHUB_OUTPUT - name: 'Flashing target firmware' id: first_full_flash @@ -67,7 +68,7 @@ jobs: - name: 'Flash last release' if: failure() run: | - ./fbt flash OPENOCD_ADAPTER_SERIAL=2A0906016415303030303032 FORCE=1 + ./fbt flash OPENOCD_ADAPTER_SERIAL=${{steps.device.outputs.stlink}} FORCE=1 - name: 'Wait for flipper and format ext' if: failure() From d9be81588955812942c13eda2d58864fc282b4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Such=C3=A1nek?= Date: Mon, 30 Jan 2023 10:14:30 +0100 Subject: [PATCH 4/8] Print card CID in storage info (#2227) --- applications/services/storage/storage_cli.c | 16 +++++++- .../scenes/storage_settings_scene_sd_info.c | 19 +++++++-- firmware/targets/f7/fatfs/stm32_adafruit_sd.c | 41 ++++++++++--------- firmware/targets/f7/fatfs/stm32_adafruit_sd.h | 21 +++++----- 4 files changed, 62 insertions(+), 35 deletions(-) diff --git a/applications/services/storage/storage_cli.c b/applications/services/storage/storage_cli.c index c83f16499..eeaa7fce8 100644 --- a/applications/services/storage/storage_cli.c +++ b/applications/services/storage/storage_cli.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -60,17 +61,28 @@ static void storage_cli_info(Cli* cli, FuriString* path) { } } else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) { SDInfo sd_info; + SD_CID sd_cid; FS_Error error = storage_sd_info(api, &sd_info); + BSP_SD_GetCIDRegister(&sd_cid); if(error != FSE_OK) { storage_cli_print_error(error); } else { printf( - "Label: %s\r\nType: %s\r\n%luKiB total\r\n%luKiB free\r\n", + "Label: %s\r\nType: %s\r\n%luKiB total\r\n%luKiB free\r\n" + "%02x%2.2s %5.5s %i.%i\r\nSN:%04lx %02i/%i\r\n", sd_info.label, sd_api_get_fs_type_text(sd_info.fs_type), sd_info.kb_total, - sd_info.kb_free); + sd_info.kb_free, + sd_cid.ManufacturerID, + sd_cid.OEM_AppliID, + sd_cid.ProdName, + sd_cid.ProdRev >> 4, + sd_cid.ProdRev & 0xf, + sd_cid.ProdSN, + sd_cid.ManufactMonth, + sd_cid.ManufactYear + 2000); } } else { storage_cli_print_usage(); diff --git a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c index 0c398ed5b..a7991bc19 100644 --- a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c +++ b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c @@ -1,4 +1,5 @@ #include "../storage_settings.h" +#include static void storage_settings_scene_sd_info_dialog_callback(DialogExResult result, void* context) { StorageSettings* app = context; @@ -11,7 +12,10 @@ void storage_settings_scene_sd_info_on_enter(void* context) { DialogEx* dialog_ex = app->dialog_ex; SDInfo sd_info; + SD_CID sd_cid; FS_Error sd_status = storage_sd_info(app->fs_api, &sd_info); + BSP_SD_GetCIDRegister(&sd_cid); + scene_manager_set_scene_state(app->scene_manager, StorageSettingsSDInfo, sd_status); dialog_ex_set_context(dialog_ex, app); @@ -26,13 +30,22 @@ void storage_settings_scene_sd_info_on_enter(void* context) { } else { furi_string_printf( app->text_string, - "Label: %s\nType: %s\n%lu KiB total\n%lu KiB free", + "Label: %s\nType: %s\n%lu KiB total\n%lu KiB free\n" + "%02X%2.2s %5.5s %i.%i\nSN:%04lX %02i/%i", sd_info.label, sd_api_get_fs_type_text(sd_info.fs_type), sd_info.kb_total, - sd_info.kb_free); + sd_info.kb_free, + sd_cid.ManufacturerID, + sd_cid.OEM_AppliID, + sd_cid.ProdName, + sd_cid.ProdRev >> 4, + sd_cid.ProdRev & 0xf, + sd_cid.ProdSN, + sd_cid.ManufactMonth, + sd_cid.ManufactYear + 2000); dialog_ex_set_text( - dialog_ex, furi_string_get_cstr(app->text_string), 4, 4, AlignLeft, AlignTop); + dialog_ex, furi_string_get_cstr(app->text_string), 4, 1, AlignLeft, AlignTop); } view_dispatcher_switch_to_view(app->view_dispatcher, StorageSettingsViewDialogEx); diff --git a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c index b9b65f06a..998adee29 100644 --- a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c +++ b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c @@ -779,25 +779,10 @@ uint8_t SD_GetCIDRegister(SD_CID* Cid) { Cid->ManufacturerID = CID_Tab[0]; /* Byte 1 */ - Cid->OEM_AppliID = CID_Tab[1] << 8; - - /* Byte 2 */ - Cid->OEM_AppliID |= CID_Tab[2]; + memcpy(Cid->OEM_AppliID, CID_Tab + 1, 2); /* Byte 3 */ - Cid->ProdName1 = CID_Tab[3] << 24; - - /* Byte 4 */ - Cid->ProdName1 |= CID_Tab[4] << 16; - - /* Byte 5 */ - Cid->ProdName1 |= CID_Tab[5] << 8; - - /* Byte 6 */ - Cid->ProdName1 |= CID_Tab[6]; - - /* Byte 7 */ - Cid->ProdName2 = CID_Tab[7]; + memcpy(Cid->ProdName, CID_Tab + 3, 5); /* Byte 8 */ Cid->ProdRev = CID_Tab[8]; @@ -815,11 +800,12 @@ uint8_t SD_GetCIDRegister(SD_CID* Cid) { Cid->ProdSN |= CID_Tab[12]; /* Byte 13 */ - Cid->Reserved1 |= (CID_Tab[13] & 0xF0) >> 4; - Cid->ManufactDate = (CID_Tab[13] & 0x0F) << 8; + Cid->Reserved1 = (CID_Tab[13] & 0xF0) >> 4; + Cid->ManufactYear = (CID_Tab[13] & 0x0F) << 4; /* Byte 14 */ - Cid->ManufactDate |= CID_Tab[14]; + Cid->ManufactYear |= (CID_Tab[14] & 0xF0) >> 4; + Cid->ManufactMonth = (CID_Tab[14] & 0x0F); /* Byte 15 */ Cid->CID_CRC = (CID_Tab[15] & 0xFE) >> 1; @@ -837,6 +823,21 @@ uint8_t SD_GetCIDRegister(SD_CID* Cid) { return retr; } +uint8_t BSP_SD_GetCIDRegister(SD_CID* Cid) { + uint8_t retr = BSP_SD_ERROR; + + /* Slow speed init */ + furi_hal_spi_acquire(&furi_hal_spi_bus_handle_sd_slow); + furi_hal_sd_spi_handle = &furi_hal_spi_bus_handle_sd_slow; + + memset(Cid, 0, sizeof(SD_CID)); + retr = SD_GetCIDRegister(Cid); + + furi_hal_sd_spi_handle = NULL; + furi_hal_spi_release(&furi_hal_spi_bus_handle_sd_slow); + return retr; +} + /** * @brief Sends 5 bytes command to the SD card and get response * @param Cmd: The user expected command to send to SD card. diff --git a/firmware/targets/f7/fatfs/stm32_adafruit_sd.h b/firmware/targets/f7/fatfs/stm32_adafruit_sd.h index e0c5e3bef..a133c5922 100644 --- a/firmware/targets/f7/fatfs/stm32_adafruit_sd.h +++ b/firmware/targets/f7/fatfs/stm32_adafruit_sd.h @@ -133,16 +133,16 @@ typedef struct { * @brief Card Identification Data: CID Register */ typedef struct { - __IO uint8_t ManufacturerID; /* ManufacturerID */ - __IO uint16_t OEM_AppliID; /* OEM/Application ID */ - __IO uint32_t ProdName1; /* Product Name part1 */ - __IO uint8_t ProdName2; /* Product Name part2*/ - __IO uint8_t ProdRev; /* Product Revision */ - __IO uint32_t ProdSN; /* Product Serial Number */ - __IO uint8_t Reserved1; /* Reserved1 */ - __IO uint16_t ManufactDate; /* Manufacturing Date */ - __IO uint8_t CID_CRC; /* CID CRC */ - __IO uint8_t Reserved2; /* always 1 */ + uint8_t ManufacturerID; /* ManufacturerID */ + char OEM_AppliID[2]; /* OEM/Application ID */ + char ProdName[5]; /* Product Name */ + uint8_t ProdRev; /* Product Revision */ + uint32_t ProdSN; /* Product Serial Number */ + uint8_t Reserved1; /* Reserved1 */ + uint8_t ManufactYear; /* Manufacturing Year */ + uint8_t ManufactMonth; /* Manufacturing Month */ + uint8_t CID_CRC; /* CID CRC */ + uint8_t Reserved2; /* always 1 */ } SD_CID; /** @@ -207,6 +207,7 @@ uint8_t uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr); uint8_t BSP_SD_GetCardState(void); uint8_t BSP_SD_GetCardInfo(SD_CardInfo* pCardInfo); +uint8_t BSP_SD_GetCIDRegister(SD_CID* Cid); /* Link functions for SD Card peripheral*/ void SD_SPI_Slow_Init(void); From 01a9854f8af8898a9a1138f1e1f496ff74b51b8d Mon Sep 17 00:00:00 2001 From: Giacomo Ferretti Date: Mon, 30 Jan 2023 10:49:51 +0100 Subject: [PATCH 5/8] Documentation: add BadUSB GUI-CTRL #2347 --- documentation/file_formats/BadUsbScriptFormat.md | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/file_formats/BadUsbScriptFormat.md b/documentation/file_formats/BadUsbScriptFormat.md index fa5038742..2ef1d3135 100644 --- a/documentation/file_formats/BadUsbScriptFormat.md +++ b/documentation/file_formats/BadUsbScriptFormat.md @@ -67,6 +67,7 @@ Can be combined with a special key command or a single character. |ALT-SHIFT|ALT+SHIFT| |ALT-GUI|ALT+WIN| |GUI-SHIFT|WIN+SHIFT| +|GUI-CTRL|WIN+CTRL| ## String From de01e377659f32c84ccc6380ae2f46645cb74915 Mon Sep 17 00:00:00 2001 From: VerstreuteSeele Date: Mon, 30 Jan 2023 23:22:22 +0100 Subject: [PATCH 6/8] Update Unitemp --- applications/plugins/unitemp/README.md | 28 +- applications/plugins/unitemp/Sensors.c | 90 ++-- applications/plugins/unitemp/Sensors.h | 14 +- .../plugins/unitemp/interfaces/I2CSensor.c | 2 +- .../plugins/unitemp/interfaces/I2CSensor.h | 2 +- .../unitemp/interfaces/OneWireSensor.c | 31 +- .../unitemp/interfaces/OneWireSensor.h | 2 +- .../plugins/unitemp/interfaces/SPISensor.c | 89 ++++ .../plugins/unitemp/interfaces/SPISensor.h | 66 +++ .../unitemp/interfaces/SingleWireSensor.c | 8 +- .../unitemp/interfaces/SingleWireSensor.h | 2 +- applications/plugins/unitemp/sensors/AM2320.c | 2 +- applications/plugins/unitemp/sensors/AM2320.h | 2 +- applications/plugins/unitemp/sensors/BME680.c | 431 ++++++++++++++++++ applications/plugins/unitemp/sensors/BME680.h | 112 +++++ applications/plugins/unitemp/sensors/BMP180.c | 172 +++++++ applications/plugins/unitemp/sensors/BMP180.h | 62 +++ applications/plugins/unitemp/sensors/BMx280.c | 19 +- applications/plugins/unitemp/sensors/BMx280.h | 2 +- applications/plugins/unitemp/sensors/DHT20.c | 154 +++++++ applications/plugins/unitemp/sensors/DHT20.h | 63 +++ .../plugins/unitemp/sensors/HDC1080.c | 94 ++++ .../plugins/unitemp/sensors/HDC1080.h | 62 +++ applications/plugins/unitemp/sensors/HTU21x.c | 107 +++++ applications/plugins/unitemp/sensors/HTU21x.h | 62 +++ applications/plugins/unitemp/sensors/LM75.c | 2 +- applications/plugins/unitemp/sensors/LM75.h | 2 +- .../plugins/unitemp/sensors/MAX31855.c | 93 ++++ .../plugins/unitemp/sensors/MAX31855.h | 65 +++ .../plugins/unitemp/sensors/MAX6675.c | 81 ++++ .../plugins/unitemp/sensors/MAX6675.h | 65 +++ applications/plugins/unitemp/sensors/SHT30.c | 90 ++++ applications/plugins/unitemp/sensors/SHT30.h | 70 +++ .../plugins/unitemp/sensors/Sensors.xlsx | Bin 11864 -> 12642 bytes applications/plugins/unitemp/unitemp.c | 11 +- applications/plugins/unitemp/unitemp.h | 14 +- .../plugins/unitemp/views/General_view.c | 41 +- .../plugins/unitemp/views/MainMenu_view.c | 2 +- .../plugins/unitemp/views/Popup_view.c | 3 +- .../unitemp/views/SensorActions_view.c | 2 +- .../plugins/unitemp/views/SensorEdit_view.c | 47 +- .../unitemp/views/SensorNameEdit_view.c | 3 +- .../plugins/unitemp/views/SensorsList_view.c | 9 +- .../plugins/unitemp/views/Settings_view.c | 2 +- .../plugins/unitemp/views/UnitempViews.h | 2 +- .../plugins/unitemp/views/Widgets_view.c | 7 +- 46 files changed, 2149 insertions(+), 140 deletions(-) create mode 100644 applications/plugins/unitemp/interfaces/SPISensor.c create mode 100644 applications/plugins/unitemp/interfaces/SPISensor.h create mode 100644 applications/plugins/unitemp/sensors/BME680.c create mode 100644 applications/plugins/unitemp/sensors/BME680.h create mode 100644 applications/plugins/unitemp/sensors/BMP180.c create mode 100644 applications/plugins/unitemp/sensors/BMP180.h create mode 100644 applications/plugins/unitemp/sensors/DHT20.c create mode 100644 applications/plugins/unitemp/sensors/DHT20.h create mode 100644 applications/plugins/unitemp/sensors/HDC1080.c create mode 100644 applications/plugins/unitemp/sensors/HDC1080.h create mode 100644 applications/plugins/unitemp/sensors/HTU21x.c create mode 100644 applications/plugins/unitemp/sensors/HTU21x.h create mode 100644 applications/plugins/unitemp/sensors/MAX31855.c create mode 100644 applications/plugins/unitemp/sensors/MAX31855.h create mode 100644 applications/plugins/unitemp/sensors/MAX6675.c create mode 100644 applications/plugins/unitemp/sensors/MAX6675.h create mode 100644 applications/plugins/unitemp/sensors/SHT30.c create mode 100644 applications/plugins/unitemp/sensors/SHT30.h diff --git a/applications/plugins/unitemp/README.md b/applications/plugins/unitemp/README.md index 2f753faea..436f3600e 100644 --- a/applications/plugins/unitemp/README.md +++ b/applications/plugins/unitemp/README.md @@ -1,10 +1,24 @@ -![Flipper usage](https://user-images.githubusercontent.com/10090793/206618263-c1e212e4-58dc-432e-87a8-5c19fd835b35.png) +![Flipper usage](https://user-images.githubusercontent.com/10090793/211182642-e41919c5-3091-4125-815a-2d6a77a859f6.png) # Unitemp - Universal temperature sensor reader [![GitHub release](https://img.shields.io/github/release/quen0n/unitemp-flipperzero?include_prereleases=&sort=semver&color=blue)](https://github.com/quen0n/unitemp-flipperzero/releases/) -[![GitHub all releases](https://img.shields.io/github/downloads/quen0n/unitemp-flipperzero/total)]() -[![GitHub](https://img.shields.io/github/license/quen0n/unitemp-flipperzero)](https://github.com/quen0n/unitemp-flipperzero/blob/dev/LICENSE.md) -[Flipper Zero](https://flipperzero.one/) application for reading temperature, humidity and pressure sensors using Onewire, Singlewire, I2C protocols. -## List of supported sensors (supplemented) -![image](https://user-images.githubusercontent.com/10090793/208480561-e98a6192-d44d-4ad9-8692-a91ccaae47c7.png) +[![GitHub](https://img.shields.io/github/license/quen0n/unitemp-flipperzero)](https://github.com/quen0n/unitemp-flipperzero/blob/dev/LICENSE.md) +[![Build dev](https://github.com/quen0n/unitemp-flipperzero/actions/workflows/build_dev.yml/badge.svg?branch=dev)](https://github.com/quen0n/unitemp-flipperzero/actions/workflows/build_dev.yml) +[Flipper Zero](https://flipperzero.one/) application for reading temperature, humidity and pressure sensors like a DHT11/22, DS18B20, BMP280, HTU21 and more. +## List of supported sensors +![image](https://user-images.githubusercontent.com/10090793/215605424-54b1c08c-e41b-4fb4-b966-dd959507200b.png) + ## Installation -Copy the contents of the repository to the `applications/plugins/unitemp` folder and build the project. Flash FZ along with resources. [More...](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/fbt.md) +1) Download [latest version](https://cloud.quenon.ru/index.php/s/h98rT9UnaOL4wxR/download?path=%2F&files=unitemp-latest.fap) +2) Copy `unitemp-latest.fap` to `SD card/apps/GPIO` with qFlipper or mobile application +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) +## Gratitudes +Thanks to [@Svaarich](https://github.com/Svaarich) for the UI design and to the Unleashed firmware community for sensors testing and feedbacks. + +## Some community photos +![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 diff --git a/applications/plugins/unitemp/Sensors.c b/applications/plugins/unitemp/Sensors.c index d35e31931..2fca40b53 100644 --- a/applications/plugins/unitemp/Sensors.c +++ b/applications/plugins/unitemp/Sensors.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,7 +17,6 @@ */ #include "Sensors.h" #include -#include //Порты ввода/вывода, которые не были обозначены в общем списке const GpioPin SWC_10 = {.pin = LL_GPIO_PIN_14, .port = GPIOA}; @@ -67,12 +66,36 @@ const Interface ONE_WIRE = { .allocator = unitemp_onewire_sensor_alloc, .mem_releaser = unitemp_onewire_sensor_free, .updater = unitemp_onewire_sensor_update}; +const Interface SPI = { + .name = "SPI", + .allocator = unitemp_spi_sensor_alloc, + .mem_releaser = unitemp_spi_sensor_free, + .updater = unitemp_spi_sensor_update}; //Перечень интерфейсов подключения -//static const Interface* interfaces[] = {&SINGLE_WIRE, &I2C, &ONE_WIRE}; +//static const Interface* interfaces[] = {&SINGLE_WIRE, &I2C, &ONE_WIRE, &SPI}; //Перечень датчиков -static const SensorType* sensorTypes[] = - {&DHT11, &DHT12_SW, &DHT21, &DHT22, &AM2320_SW, &AM2320_I2C, &LM75, &BMP280, &BME280, &Dallas}; +static const SensorType* sensorTypes[] = { + &DHT11, + &DHT12_SW, + &DHT20, + &DHT21, + &DHT22, + &Dallas, + &AM2320_SW, + &AM2320_I2C, + &HTU21x, + &AHT10, + &SHT30, + &GXHT30, + &LM75, + &HDC1080, + &BMP180, + &BMP280, + &BME280, + &BME680, + &MAX31855, + &MAX6675}; const SensorType* unitemp_sensors_getTypeFromInt(uint8_t index) { if(index > SENSOR_TYPES_COUNT) return NULL; @@ -151,7 +174,7 @@ uint8_t unitemp_gpio_getAviablePortsCount(const Interface* interface, const GPIO } //Проверка для single wire - if(interface == &SINGLE_WIRE) { + if(interface == &SINGLE_WIRE || interface == &SPI) { if(gpio_interfaces_list[i] == NULL || (unitemp_gpio_getFromIndex(i) == extraport)) { aviable_ports_count++; } @@ -190,6 +213,13 @@ const GPIO* return NULL; } } + if(interface == &SPI) { + if(!((gpio_interfaces_list[0] == NULL || gpio_interfaces_list[0] == &SPI) && + (gpio_interfaces_list[1] == NULL || gpio_interfaces_list[1] == &SPI) && + (gpio_interfaces_list[3] == NULL || gpio_interfaces_list[3] == &SPI))) { + return NULL; + } + } uint8_t aviable_index = 0; for(uint8_t i = 0; i < GPIO_ITEMS; i++) { @@ -207,7 +237,7 @@ const GPIO* } } //Проверка для single wire - if(interface == &SINGLE_WIRE) { + if(interface == &SINGLE_WIRE || interface == &SPI) { if(gpio_interfaces_list[i] == NULL || unitemp_gpio_getFromIndex(i) == extraport) { if(aviable_index == index) { return unitemp_gpio_getFromIndex(i); @@ -268,9 +298,7 @@ void unitemp_sensors_add(Sensor* sensor) { } bool unitemp_sensors_load(void) { -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Loading sensors..."); -#endif + UNITEMP_DEBUG("Loading sensors..."); //Выделение памяти на поток app->file_stream = file_stream_alloc(app->storage); @@ -331,7 +359,7 @@ bool unitemp_sensors_load(void) { //Сколько байт до конца строки size_t line_end = 0; - while(line_end != STRING_FAILURE && line_end != (size_t)(file_size - 1)) { + while(line_end != ((size_t)-1) && line_end != (size_t)(file_size - 1)) { //Имя датчика char name[11] = {0}; //Тип датчика @@ -379,9 +407,7 @@ bool unitemp_sensors_load(void) { } bool unitemp_sensors_save(void) { -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Saving sensors..."); -#endif + UNITEMP_DEBUG("Saving sensors..."); //Выделение памяти для потока app->file_stream = file_stream_alloc(app->storage); @@ -424,6 +450,11 @@ bool unitemp_sensors_save(void) { stream_write_format( app->file_stream, "%d\n", unitemp_singlewire_sensorGetGPIO(sensor)->num); } + if(sensor->type->interface == &SPI) { + uint8_t gpio_num = ((SPISensor*)sensor->instance)->CS_pin->num; + stream_write_format(app->file_stream, "%d\n", gpio_num); + } + if(sensor->type->interface == &I2C) { stream_write_format( app->file_stream, "%X\n", ((I2CSensor*)sensor->instance)->currentI2CAdr); @@ -501,7 +532,7 @@ Sensor* unitemp_sensor_alloc(char* name, const SensorType* type, char* args) { //Выход если датчик успешно развёрнут if(status) { - FURI_LOG_I(APP_NAME, "Sensor %s allocated", name); + UNITEMP_DEBUG("Sensor %s allocated", name); return sensor; } //Выход с очисткой если память для датчика не была выделена @@ -527,17 +558,13 @@ void unitemp_sensor_free(Sensor* sensor) { bool status = false; //Высвобождение памяти под инстанс status = sensor->type->interface->mem_releaser(sensor); - UNUSED(status); -#ifdef UNITEMP_DEBUG if(status) { - FURI_LOG_D(APP_NAME, "Sensor %s memory successfully released", sensor->name); + UNITEMP_DEBUG("Sensor %s memory successfully released", sensor->name); } else { FURI_LOG_E(APP_NAME, "Sensor %s memory is not released", sensor->name); } -#endif free(sensor->name); - //free(sensor); } void unitemp_sensors_free(void) { @@ -556,9 +583,7 @@ bool unitemp_sensors_init(void) { //Может пропасть при отключении USB if(furi_hal_power_is_otg_enabled() != true) { furi_hal_power_enable_otg(); -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "OTG enabled"); -#endif + UNITEMP_DEBUG("OTG enabled"); } if(!(*app->sensors[i]->type->initializer)(app->sensors[i])) { FURI_LOG_E( @@ -567,9 +592,7 @@ bool unitemp_sensors_init(void) { app->sensors[i]->name); result = false; } -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Sensor %s successfully initialized", app->sensors[i]->name); -#endif + FURI_LOG_I(APP_NAME, "Sensor %s successfully initialized", app->sensors[i]->name); } app->sensors_ready = true; return result; @@ -580,9 +603,7 @@ bool unitemp_sensors_deInit(void) { //Выключение 5 В если до этого оно не было включено if(app->settings.lastOTGState != true) { furi_hal_power_disable_otg(); -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "OTG disabled"); -#endif + UNITEMP_DEBUG("OTG disabled"); } //Перебор датчиков из списка @@ -618,13 +639,14 @@ UnitempStatus unitemp_sensor_updateData(Sensor* sensor) { sensor->status = sensor->type->interface->updater(sensor); -#ifdef UNITEMP_DEBUG - if(sensor->status != UT_SENSORSTATUS_OK && sensor->status != UT_SENSORSTATUS_POLLING) - FURI_LOG_D(APP_NAME, "Sensor %s update status %d", sensor->name, sensor->status); -#endif + if(sensor->status != UT_SENSORSTATUS_OK && sensor->status != UT_SENSORSTATUS_POLLING) { + UNITEMP_DEBUG("Sensor %s update status %d", sensor->name, sensor->status); + } - if(app->settings.temp_unit == UT_TEMP_FAHRENHEIT && sensor->status == UT_SENSORSTATUS_OK) + if(app->settings.temp_unit == UT_TEMP_FAHRENHEIT && sensor->status == UT_SENSORSTATUS_OK) { uintemp_celsiumToFarengate(sensor); + } + if(sensor->status == UT_SENSORSTATUS_OK) { sensor->temp += sensor->temp_offset / 10.f; if(app->settings.pressure_unit == UT_PRESSURE_MM_HG) { diff --git a/applications/plugins/unitemp/Sensors.h b/applications/plugins/unitemp/Sensors.h index 52e6165f5..d2b7c07af 100644 --- a/applications/plugins/unitemp/Sensors.h +++ b/applications/plugins/unitemp/Sensors.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -136,7 +136,7 @@ typedef struct Sensor { extern const Interface SINGLE_WIRE; //Собственный однопроводной протокол датчиков DHTXX и AM23XX extern const Interface ONE_WIRE; //Однопроводной протокол Dallas extern const Interface I2C; //I2C_2 (PC0, PC1) -//extern const Interface SPI; +extern const Interface SPI; //SPI_1 (MOSI - 2, MISO - 3, CS - 4, SCK - 5) /* ============================= Датчик(и) ============================= */ /** @@ -318,7 +318,15 @@ const GPIO* //DS18x2x #include "./interfaces/OneWireSensor.h" #include "./sensors/LM75.h" -//BMP280, BME280 +//BMP280, BME280, BME680 #include "./sensors/BMx280.h" +#include "./sensors/BME680.h" #include "./sensors/AM2320.h" +#include "./sensors/DHT20.h" +#include "./sensors/SHT30.h" +#include "./sensors/BMP180.h" +#include "./sensors/HTU21x.h" +#include "./sensors/HDC1080.h" +#include "./sensors/MAX31855.h" +#include "./sensors/MAX6675.h" #endif diff --git a/applications/plugins/unitemp/interfaces/I2CSensor.c b/applications/plugins/unitemp/interfaces/I2CSensor.c index 72d959e27..e5901c282 100644 --- a/applications/plugins/unitemp/interfaces/I2CSensor.c +++ b/applications/plugins/unitemp/interfaces/I2CSensor.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/interfaces/I2CSensor.h b/applications/plugins/unitemp/interfaces/I2CSensor.h index 3df709d9a..4d468aae1 100644 --- a/applications/plugins/unitemp/interfaces/I2CSensor.h +++ b/applications/plugins/unitemp/interfaces/I2CSensor.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/interfaces/OneWireSensor.c b/applications/plugins/unitemp/interfaces/OneWireSensor.c index 740ba3365..f4f3ebcdc 100644 --- a/applications/plugins/unitemp/interfaces/OneWireSensor.c +++ b/applications/plugins/unitemp/interfaces/OneWireSensor.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -58,9 +58,7 @@ OneWireBus* uintemp_onewire_bus_alloc(const GPIO* gpio) { bus->device_count = 0; bus->gpio = gpio; bus->powerMode = PWR_PASSIVE; -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "one wire bus (port %d) allocated", gpio->num); -#endif + UNITEMP_DEBUG("one wire bus (port %d) allocated", gpio->num); return bus; } @@ -84,9 +82,7 @@ bool unitemp_onewire_bus_init(OneWireBus* bus) { return true; } bool unitemp_onewire_bus_deinit(OneWireBus* bus) { -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "devices on wire %d: %d", bus->gpio->num, bus->device_count); -#endif + UNITEMP_DEBUG("devices on wire %d: %d", bus->gpio->num, bus->device_count); bus->device_count--; if(bus->device_count <= 0) { bus->device_count = 0; @@ -236,15 +232,11 @@ void unitemp_onewire_bus_enum_init(void) { uint8_t* unitemp_onewire_bus_enum_next(OneWireBus* bus) { furi_delay_ms(10); if(!onewire_enum_fork_bit) { // Если на предыдущем шаге уже не было разногласий -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "All devices on wire %d is found", unitemp_gpio_toInt(bus->gpio)); -#endif + UNITEMP_DEBUG("All devices on wire %d is found", unitemp_gpio_toInt(bus->gpio)); return 0; // то просто выходим ничего не возвращая } if(!unitemp_onewire_bus_start(bus)) { -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Wire %d is empty", unitemp_gpio_toInt(bus->gpio)); -#endif + UNITEMP_DEBUG("Wire %d is empty", unitemp_gpio_toInt(bus->gpio)); return 0; } uint8_t bp = 8; @@ -278,9 +270,8 @@ uint8_t* unitemp_onewire_bus_enum_next(OneWireBus* bus) { if(!not1) { // Присутствует единица next |= 0x80; } else { // Нет ни нулей ни единиц - ошибочная ситуация -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Wrong wire %d situation", unitemp_gpio_toInt(bus->gpio)); -#endif + + UNITEMP_DEBUG("Wrong wire %d situation", unitemp_gpio_toInt(bus->gpio)); return 0; } } @@ -421,9 +412,7 @@ UnitempStatus unitemp_onewire_sensor_update(Sensor* sensor) { unitemp_onewire_bus_send_byte(instance->bus, 0xBE); // Read Scratch-pad unitemp_onewire_bus_read_byteArray(instance->bus, buff, 9); if(!unitemp_onewire_CRC_check(buff, 9)) { -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Sensor %s is not found", sensor->name); -#endif + UNITEMP_DEBUG("Sensor %s is not found", sensor->name); return UT_SENSORSTATUS_TIMEOUT; } } @@ -462,9 +451,7 @@ UnitempStatus unitemp_onewire_sensor_update(Sensor* sensor) { unitemp_onewire_bus_send_byte(instance->bus, 0xBE); // Read Scratch-pad unitemp_onewire_bus_read_byteArray(instance->bus, buff, 9); if(!unitemp_onewire_CRC_check(buff, 9)) { -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Failed CRC check: %s", sensor->name); -#endif + UNITEMP_DEBUG("Failed CRC check: %s", sensor->name); return UT_SENSORSTATUS_BADCRC; } int16_t raw = buff[0] | ((int16_t)buff[1] << 8); diff --git a/applications/plugins/unitemp/interfaces/OneWireSensor.h b/applications/plugins/unitemp/interfaces/OneWireSensor.h index f2b148535..ef94db820 100644 --- a/applications/plugins/unitemp/interfaces/OneWireSensor.h +++ b/applications/plugins/unitemp/interfaces/OneWireSensor.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/interfaces/SPISensor.c b/applications/plugins/unitemp/interfaces/SPISensor.c new file mode 100644 index 000000000..b53aed28d --- /dev/null +++ b/applications/plugins/unitemp/interfaces/SPISensor.c @@ -0,0 +1,89 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include "SPISensor.h" + +static uint8_t sensors_count = 0; + +bool unitemp_spi_sensor_alloc(Sensor* sensor, char* args) { + if(args == NULL) return false; + + //Создание инстанса датчика SPI + SPISensor* instance = malloc(sizeof(SPISensor)); + if(instance == NULL) { + FURI_LOG_E(APP_NAME, "Sensor %s instance allocation error", sensor->name); + return false; + } + sensor->instance = instance; + + //Определение GPIO chip select + int gpio = 255; + sscanf(args, "%d", &gpio); + instance->CS_pin = unitemp_gpio_getFromInt(gpio); + if(instance->CS_pin == NULL) { + FURI_LOG_E(APP_NAME, "Sensor %s GPIO setting error", sensor->name); + free(instance); + return false; + } + + instance->spi = malloc(sizeof(FuriHalSpiBusHandle)); + memcpy(instance->spi, &furi_hal_spi_bus_handle_external, sizeof(FuriHalSpiBusHandle)); + + instance->spi->cs = instance->CS_pin->pin; + + bool status = sensor->type->allocator(sensor, args); + + //Блокировка портов GPIO + sensors_count++; + unitemp_gpio_lock(unitemp_gpio_getFromInt(2), &SPI); + unitemp_gpio_lock(unitemp_gpio_getFromInt(3), &SPI); + unitemp_gpio_lock(unitemp_gpio_getFromInt(5), &SPI); + unitemp_gpio_lock(instance->CS_pin, &SPI); + return status; +} + +bool unitemp_spi_sensor_free(Sensor* sensor) { + bool status = sensor->type->mem_releaser(sensor); + unitemp_gpio_unlock(((SPISensor*)sensor->instance)->CS_pin); + free(((SPISensor*)(sensor->instance))->spi); + free(sensor->instance); + + if(--sensors_count == 0) { + unitemp_gpio_unlock(unitemp_gpio_getFromInt(2)); + unitemp_gpio_unlock(unitemp_gpio_getFromInt(3)); + unitemp_gpio_unlock(unitemp_gpio_getFromInt(5)); + } + + return status; +} + +bool unitemp_spi_sensor_init(Sensor* sensor) { + return sensor->type->initializer(sensor); +} + +bool unitemp_spi_sensor_deinit(Sensor* sensor) { + UNUSED(sensor); + + return true; +} + +UnitempStatus unitemp_spi_sensor_update(Sensor* sensor) { + return sensor->type->updater(sensor); +} \ No newline at end of file diff --git a/applications/plugins/unitemp/interfaces/SPISensor.h b/applications/plugins/unitemp/interfaces/SPISensor.h new file mode 100644 index 000000000..40f284b04 --- /dev/null +++ b/applications/plugins/unitemp/interfaces/SPISensor.h @@ -0,0 +1,66 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_SPI +#define UNITEMP_SPI + +#include "../unitemp.h" +#include + +//Структура SPI датчика +typedef struct SPISensor { + //Указатель на интерфейс SPI + FuriHalSpiBusHandle* spi; + //Порт подключения CS + const GPIO* CS_pin; +} SPISensor; + +/** + * @brief Выделение памяти для датчика с интерфейсом SPI + * @param sensor Указатель на датчик + * @param args Указатель на массив аргументов с параметрами датчика + * @return Истина если всё ок + */ +bool unitemp_spi_sensor_alloc(Sensor* sensor, char* args); + +/** + * @brief Высвобождение памяти инстанса датчика + * @param sensor Указатель на датчик + */ +bool unitemp_spi_sensor_free(Sensor* sensor); + +/** + * @brief Инициализации датчика с интерфейсом one wire + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_spi_sensor_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * @param sensor Указатель на датчик + */ +bool unitemp_spi_sensor_deinit(Sensor* sensor); + +/** + * @brief Обновить значение с датчка + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_spi_sensor_update(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/interfaces/SingleWireSensor.c b/applications/plugins/unitemp/interfaces/SingleWireSensor.c index 183bfc872..d6d1b092b 100644 --- a/applications/plugins/unitemp/interfaces/SingleWireSensor.c +++ b/applications/plugins/unitemp/interfaces/SingleWireSensor.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,7 +43,7 @@ const SensorType DHT12_SW = { .updater = unitemp_singlewire_update}; const SensorType DHT21 = { .typename = "DHT21", - .altname = "DHT21 (AM2301)", + .altname = "DHT21/AM2301", .interface = &SINGLE_WIRE, .datatype = UT_DATA_TYPE_TEMP_HUM, .pollingInterval = 1000, @@ -54,7 +54,7 @@ const SensorType DHT21 = { .updater = unitemp_singlewire_update}; const SensorType DHT22 = { .typename = "DHT22", - .altname = "DHT22 (AM2302)", + .altname = "DHT22/AM2302", .interface = &SINGLE_WIRE, .datatype = UT_DATA_TYPE_TEMP_HUM, .pollingInterval = 2000, @@ -262,7 +262,7 @@ UnitempStatus unitemp_singlewire_update(Sensor* sensor) { //Проверка на отрицательность температуры if(READ_BIT(raw, 1 << 15)) { //Проверка на способ кодирования данных - if(READ_BIT(raw, 0x60)) { + if(READ_BIT(raw, 0x6000)) { //Не оригинал sensor->temp = (float)((int16_t)raw) / 10; } else { diff --git a/applications/plugins/unitemp/interfaces/SingleWireSensor.h b/applications/plugins/unitemp/interfaces/SingleWireSensor.h index f5bc74734..c762ff0aa 100644 --- a/applications/plugins/unitemp/interfaces/SingleWireSensor.h +++ b/applications/plugins/unitemp/interfaces/SingleWireSensor.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/sensors/AM2320.c b/applications/plugins/unitemp/sensors/AM2320.c index e77707005..29b255e1d 100644 --- a/applications/plugins/unitemp/sensors/AM2320.c +++ b/applications/plugins/unitemp/sensors/AM2320.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/sensors/AM2320.h b/applications/plugins/unitemp/sensors/AM2320.h index f13105470..fa5f502d4 100644 --- a/applications/plugins/unitemp/sensors/AM2320.h +++ b/applications/plugins/unitemp/sensors/AM2320.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/sensors/BME680.c b/applications/plugins/unitemp/sensors/BME680.c new file mode 100644 index 000000000..397e702cb --- /dev/null +++ b/applications/plugins/unitemp/sensors/BME680.c @@ -0,0 +1,431 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + Contributed by g0gg0 (https://github.com/g3gg0) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "BME680.h" + +const SensorType BME680 = { + .typename = "BME680", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_HUMIDITY | UT_PRESSURE, + .pollingInterval = 500, + .allocator = unitemp_BME680_alloc, + .mem_releaser = unitemp_BME680_free, + .initializer = unitemp_BME680_init, + .deinitializer = unitemp_BME680_deinit, + .updater = unitemp_BME680_update}; + +//Интервал обновления калибровочных значений +#define BOSCH_CAL_UPDATE_INTERVAL 60000 + +#define BME680_ID 0x61 + +#define BME680_I2C_ADDR_MIN (0x76 << 1) +#define BME680_I2C_ADDR_MAX (0x77 << 1) + +#define BME680_REG_STATUS 0x1D +#define BME680_REG_CTRL_MEAS 0x74 +#define BME680_REG_CONFIG 0x75 +#define BME680_REG_CTRL_HUM 0x72 +//Преддескретизация температуры +#define BME680_TEMP_OVERSAMPLING_SKIP 0b00000000 +#define BME680_TEMP_OVERSAMPLING_1 0b00100000 +#define BME680_TEMP_OVERSAMPLING_2 0b01000000 +#define BME680_TEMP_OVERSAMPLING_4 0b01100000 +#define BME680_TEMP_OVERSAMPLING_8 0b10000000 +#define BME680_TEMP_OVERSAMPLING_16 0b10100000 +//Преддескретизация давления +#define BME680_PRESS_OVERSAMPLING_SKIP 0b00000000 +#define BME680_PRESS_OVERSAMPLING_1 0b00000100 +#define BME680_PRESS_OVERSAMPLING_2 0b00001000 +#define BME680_PRESS_OVERSAMPLING_4 0b00001100 +#define BME680_PRESS_OVERSAMPLING_8 0b00010000 +#define BME680_PRESS_OVERSAMPLING_16 0b00010100 +//Преддескретизация влажности +#define BME680_HUM_OVERSAMPLING_SKIP 0b00000000 +#define BME680_HUM_OVERSAMPLING_1 0b00000001 +#define BME680_HUM_OVERSAMPLING_2 0b00000010 +#define BME680_HUM_OVERSAMPLING_4 0b00000011 +#define BME680_HUM_OVERSAMPLING_8 0b00000100 +#define BME680_HUM_OVERSAMPLING_16 0b00000101 +//Режимы работы датчика +#define BME680_MODE_SLEEP 0b00000000 //Наелся и спит +#define BME680_MODE_FORCED 0b00000001 //Обновляет значения 1 раз, после чего уходит в сон +//Коэффициент фильтрации значений +#define BME680_FILTER_COEFF_1 0b00000000 +#define BME680_FILTER_COEFF_2 0b00000100 +#define BME680_FILTER_COEFF_4 0b00001000 +#define BME680_FILTER_COEFF_8 0b00001100 +#define BME680_FILTER_COEFF_16 0b00010000 +//Разрешить работу по SPI +#define BME680_SPI_3W_ENABLE 0b00000001 +#define BME680_SPI_3W_DISABLE 0b00000000 + +/* https://github.com/boschsensortec/BME680_driver/blob/master/bme680.c or + https://github.com/boschsensortec/BME68x-Sensor-API */ +static float BME680_compensate_temperature(I2CSensor* i2c_sensor, int32_t temp_adc) { + BME680_instance* bme680_instance = (BME680_instance*)i2c_sensor->sensorInstance; + float var1 = 0; + float var2 = 0; + float calc_temp = 0; + + /* calculate var1 data */ + var1 = + ((((float)temp_adc / 16384.0f) - ((float)bme680_instance->temp_cal.dig_T1 / 1024.0f)) * + ((float)bme680_instance->temp_cal.dig_T2)); + + /* calculate var2 data */ + var2 = + (((((float)temp_adc / 131072.0f) - ((float)bme680_instance->temp_cal.dig_T1 / 8192.0f)) * + (((float)temp_adc / 131072.0f) - ((float)bme680_instance->temp_cal.dig_T1 / 8192.0f))) * + ((float)bme680_instance->temp_cal.dig_T3 * 16.0f)); + + /* t_fine value*/ + bme680_instance->t_fine = (var1 + var2); + + /* compensated temperature data*/ + calc_temp = ((bme680_instance->t_fine) / 5120.0f); + + return calc_temp; +} + +static float BME680_compensate_pressure(I2CSensor* i2c_sensor, int32_t pres_adc) { + BME680_instance* bme680_instance = (BME680_instance*)i2c_sensor->sensorInstance; + + float var1; + float var2; + float var3; + float calc_pres; + + var1 = (((float)bme680_instance->t_fine / 2.0f) - 64000.0f); + var2 = var1 * var1 * (((float)bme680_instance->press_cal.dig_P6) / (131072.0f)); + var2 = var2 + (var1 * ((float)bme680_instance->press_cal.dig_P5) * 2.0f); + var2 = (var2 / 4.0f) + (((float)bme680_instance->press_cal.dig_P4) * 65536.0f); + var1 = + (((((float)bme680_instance->press_cal.dig_P3 * var1 * var1) / 16384.0f) + + ((float)bme680_instance->press_cal.dig_P2 * var1)) / + 524288.0f); + var1 = ((1.0f + (var1 / 32768.0f)) * ((float)bme680_instance->press_cal.dig_P1)); + calc_pres = (1048576.0f - ((float)pres_adc)); + + /* Avoid exception caused by division by zero */ + if((int)var1 != 0) { + calc_pres = (((calc_pres - (var2 / 4096.0f)) * 6250.0f) / var1); + var1 = + (((float)bme680_instance->press_cal.dig_P9) * calc_pres * calc_pres) / 2147483648.0f; + var2 = calc_pres * (((float)bme680_instance->press_cal.dig_P8) / 32768.0f); + var3 = + ((calc_pres / 256.0f) * (calc_pres / 256.0f) * (calc_pres / 256.0f) * + (bme680_instance->press_cal.dig_P10 / 131072.0f)); + calc_pres = + (calc_pres + + (var1 + var2 + var3 + ((float)bme680_instance->press_cal.dig_P7 * 128.0f)) / 16.0f); + } else { + calc_pres = 0; + } + + return calc_pres; +} + +static float BME680_compensate_humidity(I2CSensor* i2c_sensor, int32_t hum_adc) { + BME680_instance* bme680_instance = (BME680_instance*)i2c_sensor->sensorInstance; + float calc_hum; + float var1; + float var2; + float var3; + float var4; + float temp_comp; + + /* compensated temperature data*/ + temp_comp = ((bme680_instance->t_fine) / 5120.0f); + var1 = + (float)((float)hum_adc) - (((float)bme680_instance->hum_cal.dig_H1 * 16.0f) + + (((float)bme680_instance->hum_cal.dig_H3 / 2.0f) * temp_comp)); + var2 = var1 * + ((float)(((float)bme680_instance->hum_cal.dig_H2 / 262144.0f) * + (1.0f + (((float)bme680_instance->hum_cal.dig_H4 / 16384.0f) * temp_comp) + + (((float)bme680_instance->hum_cal.dig_H5 / 1048576.0f) * temp_comp * temp_comp)))); + var3 = (float)bme680_instance->hum_cal.dig_H6 / 16384.0f; + var4 = (float)bme680_instance->hum_cal.dig_H7 / 2097152.0f; + calc_hum = var2 + ((var3 + (var4 * temp_comp)) * var2 * var2); + if(calc_hum > 100.0f) { + calc_hum = 100.0f; + } else if(calc_hum < 0.0f) { + calc_hum = 0.0f; + } + + return calc_hum; +} + +/* https://github.com/boschsensortec/BME680_driver/blob/master/bme680_defs.h */ +#define BME680_COEFF_SIZE UINT8_C(41) +#define BME680_COEFF_ADDR1_LEN UINT8_C(25) +#define BME680_COEFF_ADDR2_LEN UINT8_C(16) +#define BME680_COEFF_ADDR1 UINT8_C(0x89) +#define BME680_COEFF_ADDR2 UINT8_C(0xe1) +#define BME680_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb) +#define BME680_T2_LSB_REG (1) +#define BME680_T2_MSB_REG (2) +#define BME680_T3_REG (3) +#define BME680_P1_LSB_REG (5) +#define BME680_P1_MSB_REG (6) +#define BME680_P2_LSB_REG (7) +#define BME680_P2_MSB_REG (8) +#define BME680_P3_REG (9) +#define BME680_P4_LSB_REG (11) +#define BME680_P4_MSB_REG (12) +#define BME680_P5_LSB_REG (13) +#define BME680_P5_MSB_REG (14) +#define BME680_P7_REG (15) +#define BME680_P6_REG (16) +#define BME680_P8_LSB_REG (19) +#define BME680_P8_MSB_REG (20) +#define BME680_P9_LSB_REG (21) +#define BME680_P9_MSB_REG (22) +#define BME680_P10_REG (23) +#define BME680_H2_MSB_REG (25) +#define BME680_H2_LSB_REG (26) +#define BME680_H1_LSB_REG (26) +#define BME680_H1_MSB_REG (27) +#define BME680_H3_REG (28) +#define BME680_H4_REG (29) +#define BME680_H5_REG (30) +#define BME680_H6_REG (31) +#define BME680_H7_REG (32) +#define BME680_T1_LSB_REG (33) +#define BME680_T1_MSB_REG (34) +#define BME680_GH2_LSB_REG (35) +#define BME680_GH2_MSB_REG (36) +#define BME680_GH1_REG (37) +#define BME680_GH3_REG (38) +#define BME680_HUM_REG_SHIFT_VAL UINT8_C(4) +#define BME680_BIT_H1_DATA_MSK UINT8_C(0x0F) + +static bool BME680_readCalValues(I2CSensor* i2c_sensor) { + BME680_instance* bme680_instance = (BME680_instance*)i2c_sensor->sensorInstance; + uint8_t coeff_array[BME680_COEFF_SIZE] = {0}; + + if(!unitemp_i2c_readRegArray( + i2c_sensor, BME680_COEFF_ADDR1, BME680_COEFF_ADDR1_LEN, &coeff_array[0])) + return false; + if(!unitemp_i2c_readRegArray( + i2c_sensor, + BME680_COEFF_ADDR2, + BME680_COEFF_ADDR2_LEN, + &coeff_array[BME680_COEFF_ADDR1_LEN])) + return false; + + /* Temperature related coefficients */ + bme680_instance->temp_cal.dig_T1 = (uint16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_T1_MSB_REG], coeff_array[BME680_T1_LSB_REG])); + bme680_instance->temp_cal.dig_T2 = (int16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_T2_MSB_REG], coeff_array[BME680_T2_LSB_REG])); + bme680_instance->temp_cal.dig_T3 = (int8_t)(coeff_array[BME680_T3_REG]); + + /* Pressure related coefficients */ + bme680_instance->press_cal.dig_P1 = (uint16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_P1_MSB_REG], coeff_array[BME680_P1_LSB_REG])); + bme680_instance->press_cal.dig_P2 = (int16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_P2_MSB_REG], coeff_array[BME680_P2_LSB_REG])); + bme680_instance->press_cal.dig_P3 = (int8_t)coeff_array[BME680_P3_REG]; + bme680_instance->press_cal.dig_P4 = (int16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_P4_MSB_REG], coeff_array[BME680_P4_LSB_REG])); + bme680_instance->press_cal.dig_P5 = (int16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_P5_MSB_REG], coeff_array[BME680_P5_LSB_REG])); + bme680_instance->press_cal.dig_P6 = (int8_t)(coeff_array[BME680_P6_REG]); + bme680_instance->press_cal.dig_P7 = (int8_t)(coeff_array[BME680_P7_REG]); + bme680_instance->press_cal.dig_P8 = (int16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_P8_MSB_REG], coeff_array[BME680_P8_LSB_REG])); + bme680_instance->press_cal.dig_P9 = (int16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_P9_MSB_REG], coeff_array[BME680_P9_LSB_REG])); + bme680_instance->press_cal.dig_P10 = (uint8_t)(coeff_array[BME680_P10_REG]); + + /* Humidity related coefficients */ + bme680_instance->hum_cal.dig_H1 = + (uint16_t)(((uint16_t)coeff_array[BME680_H1_MSB_REG] << BME680_HUM_REG_SHIFT_VAL) | (coeff_array[BME680_H1_LSB_REG] & BME680_BIT_H1_DATA_MSK)); + bme680_instance->hum_cal.dig_H2 = + (uint16_t)(((uint16_t)coeff_array[BME680_H2_MSB_REG] << BME680_HUM_REG_SHIFT_VAL) | ((coeff_array[BME680_H2_LSB_REG]) >> BME680_HUM_REG_SHIFT_VAL)); + bme680_instance->hum_cal.dig_H3 = (int8_t)coeff_array[BME680_H3_REG]; + bme680_instance->hum_cal.dig_H4 = (int8_t)coeff_array[BME680_H4_REG]; + bme680_instance->hum_cal.dig_H5 = (int8_t)coeff_array[BME680_H5_REG]; + bme680_instance->hum_cal.dig_H6 = (uint8_t)coeff_array[BME680_H6_REG]; + bme680_instance->hum_cal.dig_H7 = (int8_t)coeff_array[BME680_H7_REG]; + + /* Gas heater related coefficients */ + bme680_instance->gas_cal.dig_GH1 = (int8_t)coeff_array[BME680_GH1_REG]; + bme680_instance->gas_cal.dig_GH2 = (int16_t)(BME680_CONCAT_BYTES( + coeff_array[BME680_GH2_MSB_REG], coeff_array[BME680_GH2_LSB_REG])); + bme680_instance->gas_cal.dig_GH3 = (int8_t)coeff_array[BME680_GH3_REG]; + +#ifdef UNITEMP_DEBUG + FURI_LOG_D( + APP_NAME, + "Sensor BME680 T1-T3: %d, %d, %d", + bme680_instance->temp_cal.dig_T1, + bme680_instance->temp_cal.dig_T2, + bme680_instance->temp_cal.dig_T3); + + FURI_LOG_D( + APP_NAME, + "Sensor BME680: P1-P10: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", + bme680_instance->press_cal.dig_P1, + bme680_instance->press_cal.dig_P2, + bme680_instance->press_cal.dig_P3, + bme680_instance->press_cal.dig_P4, + bme680_instance->press_cal.dig_P5, + bme680_instance->press_cal.dig_P6, + bme680_instance->press_cal.dig_P7, + bme680_instance->press_cal.dig_P8, + bme680_instance->press_cal.dig_P9, + bme680_instance->press_cal.dig_P10); + + FURI_LOG_D( + APP_NAME, + "Sensor BME680: H1-H7: %d, %d, %d, %d, %d, %d, %d", + bme680_instance->hum_cal.dig_H1, + bme680_instance->hum_cal.dig_H2, + bme680_instance->hum_cal.dig_H3, + bme680_instance->hum_cal.dig_H4, + bme680_instance->hum_cal.dig_H5, + bme680_instance->hum_cal.dig_H6, + bme680_instance->hum_cal.dig_H7); + + FURI_LOG_D( + APP_NAME, + "Sensor BME680 GH1-GH3: %d, %d, %d", + bme680_instance->gas_cal.dig_GH1, + bme680_instance->gas_cal.dig_GH2, + bme680_instance->gas_cal.dig_GH3); + +#endif + + bme680_instance->last_cal_update_time = furi_get_tick(); + return true; +} +static bool BME680_isMeasuring(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + return (bool)(unitemp_i2c_readReg(i2c_sensor, BME680_REG_STATUS) & 0x20); +} + +bool unitemp_BME680_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + BME680_instance* bme680_instance = malloc(sizeof(BME680_instance)); + if(bme680_instance == NULL) { + FURI_LOG_E(APP_NAME, "Failed to allocation sensor %s instance", sensor->name); + return false; + } + + if(sensor->type == &BME680) bme680_instance->chip_id = BME680_ID; + + i2c_sensor->sensorInstance = bme680_instance; + + i2c_sensor->minI2CAdr = BME680_I2C_ADDR_MIN; + i2c_sensor->maxI2CAdr = BME680_I2C_ADDR_MAX; + return true; +} + +bool unitemp_BME680_init(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + //Перезагрузка + unitemp_i2c_writeReg(i2c_sensor, 0xE0, 0xB6); + //Чтение ID датчика + uint8_t id = unitemp_i2c_readReg(i2c_sensor, 0xD0); + if(id != BME680_ID) { + FURI_LOG_E( + APP_NAME, + "Sensor %s returned wrong ID 0x%02X, expected 0x%02X", + sensor->name, + id, + BME680_ID); + return false; + } + + unitemp_i2c_writeReg( + i2c_sensor, + BME680_REG_CTRL_HUM, + (unitemp_i2c_readReg(i2c_sensor, BME680_REG_CTRL_HUM) & ~7) | BME680_HUM_OVERSAMPLING_1); + unitemp_i2c_writeReg( + i2c_sensor, + BME680_REG_CTRL_MEAS, + BME680_TEMP_OVERSAMPLING_2 | BME680_PRESS_OVERSAMPLING_4 | BME680_MODE_FORCED); + //Настройка периода опроса и фильтрации значений + unitemp_i2c_writeReg( + i2c_sensor, BME680_REG_CONFIG, BME680_FILTER_COEFF_16 | BME680_SPI_3W_DISABLE); + //Чтение калибровочных значений + if(!BME680_readCalValues(i2c_sensor)) { + FURI_LOG_E(APP_NAME, "Failed to read calibration values sensor %s", sensor->name); + return false; + } + return true; +} + +bool unitemp_BME680_deinit(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + //Перевод в сон + unitemp_i2c_writeReg(i2c_sensor, BME680_REG_CTRL_MEAS, BME680_MODE_SLEEP); + return true; +} + +UnitempStatus unitemp_BME680_update(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + BME680_instance* instance = i2c_sensor->sensorInstance; + + uint32_t t = furi_get_tick(); + + uint8_t buff[3]; + //Проверка инициализированности датчика + unitemp_i2c_readRegArray(i2c_sensor, 0xF4, 2, buff); + if(buff[0] == 0) { + FURI_LOG_W(APP_NAME, "Sensor %s is not initialized!", sensor->name); + return UT_SENSORSTATUS_ERROR; + } + + unitemp_i2c_writeReg( + i2c_sensor, + BME680_REG_CTRL_MEAS, + unitemp_i2c_readReg(i2c_sensor, BME680_REG_CTRL_MEAS) | 1); + + while(BME680_isMeasuring(sensor)) { + if(furi_get_tick() - t > 100) { + return UT_SENSORSTATUS_TIMEOUT; + } + } + + if(furi_get_tick() - instance->last_cal_update_time > BOSCH_CAL_UPDATE_INTERVAL) { + BME680_readCalValues(i2c_sensor); + } + + if(!unitemp_i2c_readRegArray(i2c_sensor, 0x1F, 3, buff)) return UT_SENSORSTATUS_TIMEOUT; + int32_t adc_P = ((int32_t)buff[0] << 12) | ((int32_t)buff[1] << 4) | ((int32_t)buff[2] >> 4); + if(!unitemp_i2c_readRegArray(i2c_sensor, 0x22, 3, buff)) return UT_SENSORSTATUS_TIMEOUT; + int32_t adc_T = ((int32_t)buff[0] << 12) | ((int32_t)buff[1] << 4) | ((int32_t)buff[2] >> 4); + if(!unitemp_i2c_readRegArray(i2c_sensor, 0x25, 2, buff)) return UT_SENSORSTATUS_TIMEOUT; + int32_t adc_H = ((uint16_t)buff[0] << 8) | buff[1]; + + sensor->temp = BME680_compensate_temperature(i2c_sensor, adc_T); + sensor->pressure = BME680_compensate_pressure(i2c_sensor, adc_P); + sensor->hum = BME680_compensate_humidity(i2c_sensor, adc_H); + + return UT_SENSORSTATUS_OK; +} + +bool unitemp_BME680_free(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + free(i2c_sensor->sensorInstance); + return true; +} \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/BME680.h b/applications/plugins/unitemp/sensors/BME680.h new file mode 100644 index 000000000..b126c7c84 --- /dev/null +++ b/applications/plugins/unitemp/sensors/BME680.h @@ -0,0 +1,112 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + Contributed by g0gg0 (https://github.com/g3gg0) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_BME680 +#define UNITEMP_BME680 + +#include "../unitemp.h" +#include "../Sensors.h" +#include "../interfaces/I2CSensor.h" + +typedef struct { + uint16_t dig_T1; + int16_t dig_T2; + int16_t dig_T3; +} BME680_temp_cal; + +typedef struct { + uint16_t dig_GH1; + int16_t dig_GH2; + int16_t dig_GH3; +} BME680_gas_cal; + +typedef struct { + uint16_t dig_P1; + int16_t dig_P2; + int16_t dig_P3; + int16_t dig_P4; + int16_t dig_P5; + int16_t dig_P6; + int16_t dig_P7; + int16_t dig_P8; + int16_t dig_P9; + int16_t dig_P10; +} BME680_press_cal; + +typedef struct { + uint16_t dig_H1; + uint16_t dig_H2; + int8_t dig_H3; + int8_t dig_H4; + int8_t dig_H5; + uint8_t dig_H6; + int8_t dig_H7; +} BME680_hum_cal; + +typedef struct { + //Калибровочные значения температуры + BME680_temp_cal temp_cal; + //Калибровочные значения давления + BME680_press_cal press_cal; + //Калибровочные значения влажности воздуха + BME680_hum_cal hum_cal; + BME680_gas_cal gas_cal; + //Время последнего обновления калибровочных значений + uint32_t last_cal_update_time; + //Индификатор датчика + uint8_t chip_id; + //Корректировочное значение температуры + int32_t t_fine; +} BME680_instance; + +extern const SensorType BMP280; +extern const SensorType BME680; +/** + * @brief Выделение памяти и установка начальных значений датчика BMP280 + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_BME680_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика BMP280 + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_BME680_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * @param sensor Указатель на датчик + */ +bool unitemp_BME680_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * @param sensor Указатель на датчик + * @return Статус опроса датчика + */ +UnitempStatus unitemp_BME680_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * @param sensor Указатель на датчик + */ +bool unitemp_BME680_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/BMP180.c b/applications/plugins/unitemp/sensors/BMP180.c new file mode 100644 index 000000000..e94f38044 --- /dev/null +++ b/applications/plugins/unitemp/sensors/BMP180.c @@ -0,0 +1,172 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "BMP180.h" +#include "../interfaces/I2CSensor.h" + +typedef struct { + int16_t AC1; + int16_t AC2; + int16_t AC3; + uint16_t AC4; + uint16_t AC5; + uint16_t AC6; + int16_t B1; + int16_t B2; + int16_t MB; + int16_t MC; + int16_t MD; +} BMP180_cal; + +typedef struct { + //Калибровочные значения + BMP180_cal bmp180_cal; +} BMP180_instance; + +const SensorType BMP180 = { + .typename = "BMP180", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_PRESSURE, + .pollingInterval = 1000, + .allocator = unitemp_BMP180_I2C_alloc, + .mem_releaser = unitemp_BMP180_I2C_free, + .initializer = unitemp_BMP180_init, + .deinitializer = unitemp_BMP180_I2C_deinit, + .updater = unitemp_BMP180_I2C_update}; + +bool unitemp_BMP180_I2C_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Адреса на шине I2C (7 бит) + i2c_sensor->minI2CAdr = 0x77 << 1; + i2c_sensor->maxI2CAdr = 0x77 << 1; + + BMP180_instance* bmx280_instance = malloc(sizeof(BMP180_instance)); + i2c_sensor->sensorInstance = bmx280_instance; + return true; +} + +bool unitemp_BMP180_I2C_free(Sensor* sensor) { + UNUSED(sensor); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + free(i2c_sensor->sensorInstance); + return true; +} + +bool unitemp_BMP180_init(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Перезагрузка + if(!unitemp_i2c_writeReg(i2c_sensor, 0xE0, 0xB6)) return false; + furi_delay_ms(100); + + //Проверка ID + uint8_t id = unitemp_i2c_readReg(i2c_sensor, 0xD0); + if(id != 0x55) { + FURI_LOG_E( + APP_NAME, "Sensor %s returned wrong ID 0x%02X, expected 0x55", sensor->name, id); + return false; + } + + BMP180_instance* bmp180_instance = i2c_sensor->sensorInstance; + + uint8_t buff[22] = {0}; + + //Чтение калибровочных значений + if(!unitemp_i2c_readRegArray(i2c_sensor, 0xAA, 22, buff)) return false; + bmp180_instance->bmp180_cal.AC1 = (buff[0] << 8) | buff[1]; + bmp180_instance->bmp180_cal.AC2 = (buff[2] << 8) | buff[3]; + bmp180_instance->bmp180_cal.AC3 = (buff[4] << 8) | buff[5]; + bmp180_instance->bmp180_cal.AC4 = (buff[6] << 8) | buff[7]; + bmp180_instance->bmp180_cal.AC5 = (buff[8] << 8) | buff[9]; + bmp180_instance->bmp180_cal.AC6 = (buff[10] << 8) | buff[11]; + bmp180_instance->bmp180_cal.B1 = (buff[12] << 8) | buff[13]; + bmp180_instance->bmp180_cal.B2 = (buff[14] << 8) | buff[15]; + bmp180_instance->bmp180_cal.MB = (buff[16] << 8) | buff[17]; + bmp180_instance->bmp180_cal.MC = (buff[18] << 8) | buff[19]; + bmp180_instance->bmp180_cal.MD = (buff[20] << 8) | buff[21]; + + +UNITEMP_DEBUG( + "Sensor BMP180 (0x%02X) calibration values: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", + i2c_sensor->currentI2CAdr, + bmp180_instance->bmp180_cal.AC1, + bmp180_instance->bmp180_cal.AC2, + bmp180_instance->bmp180_cal.AC3, + bmp180_instance->bmp180_cal.AC4, + bmp180_instance->bmp180_cal.AC5, + bmp180_instance->bmp180_cal.AC6, + bmp180_instance->bmp180_cal.B1, + bmp180_instance->bmp180_cal.B2, + bmp180_instance->bmp180_cal.MB, + bmp180_instance->bmp180_cal.MC, + bmp180_instance->bmp180_cal.MD); + return true; +} + +bool unitemp_BMP180_I2C_deinit(Sensor* sensor) { + //Нечего деинициализировать + UNUSED(sensor); + return true; +} + +UnitempStatus unitemp_BMP180_I2C_update(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + BMP180_instance* bmp180_instance = i2c_sensor->sensorInstance; + + //Чтение температуры + if(!unitemp_i2c_writeReg(i2c_sensor, 0xF4, 0x2E)) return UT_SENSORSTATUS_TIMEOUT; + furi_delay_ms(5); + uint8_t buff[3] = {0}; + if(!unitemp_i2c_readRegArray(i2c_sensor, 0xF6, 2, buff)) return UT_SENSORSTATUS_TIMEOUT; + int32_t UT = ((uint16_t)buff[0] << 8) + buff[1]; + int32_t X1 = (UT - bmp180_instance->bmp180_cal.AC6) * bmp180_instance->bmp180_cal.AC5 >> 15; + int32_t X2 = (bmp180_instance->bmp180_cal.MC << 11) / (X1 + bmp180_instance->bmp180_cal.MD); + int32_t B5 = X1 + X2; + sensor->temp = ((B5 + 8) / 16) * 0.1f; + + //Чтение давления + if(!unitemp_i2c_writeReg(i2c_sensor, 0xF4, 0x34 + (0b11 << 6))) return UT_SENSORSTATUS_TIMEOUT; + furi_delay_ms(26); + if(!unitemp_i2c_readRegArray(i2c_sensor, 0xF6, 3, buff)) return UT_SENSORSTATUS_TIMEOUT; + uint32_t UP = ((buff[0] << 16) + (buff[1] << 8) + buff[2]) >> (8 - 0b11); + + int32_t B6, X3, B3, P; + uint32_t B4, B7; + B6 = B5 - 4000; + X1 = (bmp180_instance->bmp180_cal.B2 * ((B6 * B6) >> 12)) >> 11; + X2 = (bmp180_instance->bmp180_cal.AC2 * B6) >> 11; + X3 = X1 + X2; + B3 = (((bmp180_instance->bmp180_cal.AC1 * 4 + X3) << 0b11) + 2) >> 2; + X1 = (bmp180_instance->bmp180_cal.AC3 * B6) >> 13; + X2 = (bmp180_instance->bmp180_cal.B1 * ((B6 * B6) >> 12)) >> 16; + X3 = ((X1 + X2) + 2) >> 2; + B4 = (bmp180_instance->bmp180_cal.AC4 * (unsigned long)(X3 + 32768)) >> 15; + B7 = ((unsigned long)UP - B3) * (50000 >> 0b11); + if(B7 < 0x80000000) + P = (B7 * 2) / B4; + else + P = (B7 / B4) * 2; + X1 = (P >> 8) * (P >> 8); + X1 = (X1 * 3038) >> 16; + X2 = (-7357 * (P)) >> 16; + P = P + ((X1 + X2 + 3791) >> 4); + sensor->pressure = P; + + return UT_SENSORSTATUS_OK; +} diff --git a/applications/plugins/unitemp/sensors/BMP180.h b/applications/plugins/unitemp/sensors/BMP180.h new file mode 100644 index 000000000..ce2569092 --- /dev/null +++ b/applications/plugins/unitemp/sensors/BMP180.h @@ -0,0 +1,62 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_BMP180 +#define UNITEMP_BMP180 + +#include "../unitemp.h" +#include "../Sensors.h" +extern const SensorType BMP180; +/** + * @brief Выделение памяти и установка начальных значений датчика BMP180 + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_BMP180_I2C_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика BMP180 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_BMP180_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_BMP180_I2C_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_BMP180_I2C_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_BMP180_I2C_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/BMx280.c b/applications/plugins/unitemp/sensors/BMx280.c index a64daaa1d..db445d330 100644 --- a/applications/plugins/unitemp/sensors/BMx280.c +++ b/applications/plugins/unitemp/sensors/BMx280.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -180,22 +180,19 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) { if(!unitemp_i2c_readRegArray( i2c_sensor, TEMP_CAL_START_ADDR, 6, (uint8_t*)&bmx280_instance->temp_cal)) return false; -#ifdef UNITEMP_DEBUG - FURI_LOG_D( - APP_NAME, + + UNITEMP_DEBUG( "Sensor BMx280 (0x%02X) T1-T3: %d, %d, %d", i2c_sensor->currentI2CAdr, bmx280_instance->temp_cal.dig_T1, bmx280_instance->temp_cal.dig_T2, bmx280_instance->temp_cal.dig_T3); -#endif if(!unitemp_i2c_readRegArray( i2c_sensor, PRESS_CAL_START_ADDR, 18, (uint8_t*)&bmx280_instance->press_cal)) return false; -#ifdef UNITEMP_DEBUG - FURI_LOG_D( - APP_NAME, + + UNITEMP_DEBUG( "Sensor BMx280 (0x%02X): P1-P9: %d, %d, %d, %d, %d, %d, %d, %d, %d", i2c_sensor->currentI2CAdr, bmx280_instance->press_cal.dig_P1, @@ -207,7 +204,6 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) { bmx280_instance->press_cal.dig_P7, bmx280_instance->press_cal.dig_P8, bmx280_instance->press_cal.dig_P9); -#endif if(bmx280_instance->chip_id == BME280_ID) { uint8_t buff[7] = {0}; @@ -221,9 +217,7 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) { bmx280_instance->hum_cal.dig_H5 = (buff[4] & 0x0F) | ((int16_t)buff[5] << 4); bmx280_instance->hum_cal.dig_H6 = buff[6]; -#ifdef UNITEMP_DEBUG - FURI_LOG_D( - APP_NAME, + UNITEMP_DEBUG( "Sensor BMx280 (0x%02X): H1-H6: %d, %d, %d, %d, %d, %d", i2c_sensor->currentI2CAdr, bmx280_instance->hum_cal.dig_H1, @@ -232,7 +226,6 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) { bmx280_instance->hum_cal.dig_H4, bmx280_instance->hum_cal.dig_H5, bmx280_instance->hum_cal.dig_H6); -#endif } bmx280_instance->last_cal_update_time = furi_get_tick(); diff --git a/applications/plugins/unitemp/sensors/BMx280.h b/applications/plugins/unitemp/sensors/BMx280.h index fe52a364e..32027f285 100644 --- a/applications/plugins/unitemp/sensors/BMx280.h +++ b/applications/plugins/unitemp/sensors/BMx280.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/sensors/DHT20.c b/applications/plugins/unitemp/sensors/DHT20.c new file mode 100644 index 000000000..ce11fe3d6 --- /dev/null +++ b/applications/plugins/unitemp/sensors/DHT20.c @@ -0,0 +1,154 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "DHT20.h" +#include "../interfaces/I2CSensor.h" + +const SensorType DHT20 = { + .typename = "DHT20", + .altname = "DHT20/AM2108/AHT20", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_HUMIDITY, + .pollingInterval = 1000, + .allocator = unitemp_DHT20_I2C_alloc, + .mem_releaser = unitemp_DHT20_I2C_free, + .initializer = unitemp_DHT20_init, + .deinitializer = unitemp_DHT20_I2C_deinit, + .updater = unitemp_DHT20_I2C_update}; +const SensorType AHT10 = { + .typename = "AHT10", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_HUMIDITY, + .pollingInterval = 1000, + .allocator = unitemp_DHT20_I2C_alloc, + .mem_releaser = unitemp_DHT20_I2C_free, + .initializer = unitemp_DHT20_init, + .deinitializer = unitemp_DHT20_I2C_deinit, + .updater = unitemp_DHT20_I2C_update}; + +static uint8_t DHT20_get_status(I2CSensor* i2c_sensor) { + uint8_t status[1] = {0}; + unitemp_i2c_readArray(i2c_sensor, 1, status); + return status[0]; +} + +static uint8_t DHT20_calc_CRC8(uint8_t* message, uint8_t Num) { + uint8_t i; + uint8_t byte; + uint8_t crc = 0xFF; + for(byte = 0; byte < Num; byte++) { + crc ^= (message[byte]); + for(i = 8; i > 0; --i) { + if(crc & 0x80) + crc = (crc << 1) ^ 0x31; + else + crc = (crc << 1); + } + } + return crc; +} + +static void DHT20_reset_reg(I2CSensor* i2c_sensor, uint8_t addr) { + uint8_t data[3] = {addr, 0x00, 0x00}; + + unitemp_i2c_writeArray(i2c_sensor, 3, data); + + furi_delay_ms(5); + + unitemp_i2c_readArray(i2c_sensor, 3, data); + + furi_delay_ms(10); + + data[0] = 0xB0 | addr; + unitemp_i2c_writeArray(i2c_sensor, 3, data); +} + +bool unitemp_DHT20_I2C_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Адреса на шине I2C (7 бит) + i2c_sensor->minI2CAdr = 0x38 << 1; + i2c_sensor->maxI2CAdr = (sensor->type == &DHT20) ? (0x38 << 1) : (0x39 << 1); + return true; +} + +bool unitemp_DHT20_I2C_free(Sensor* sensor) { + //Нечего высвобождать, так как ничего не было выделено + UNUSED(sensor); + return true; +} + +bool unitemp_DHT20_init(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + uint8_t data[3] = {0xA8, 0x00, 0x00}; + if(!unitemp_i2c_writeArray(i2c_sensor, 3, data)) return false; + furi_delay_ms(10); + data[0] = (sensor->type == &DHT20) ? 0xBE : 0xE1; + data[1] = 0x08; + if(!unitemp_i2c_writeArray(i2c_sensor, 3, data)) return false; + furi_delay_ms(10); + + return true; +} + +bool unitemp_DHT20_I2C_deinit(Sensor* sensor) { + //Нечего деинициализировать + UNUSED(sensor); + return true; +} + +UnitempStatus unitemp_DHT20_I2C_update(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + if(DHT20_get_status(i2c_sensor) != 0x18) { + DHT20_reset_reg(i2c_sensor, 0x1B); + DHT20_reset_reg(i2c_sensor, 0x1C); + DHT20_reset_reg(i2c_sensor, 0x1E); + } + furi_delay_ms(10); + + uint8_t data[7] = {0xAC, 0x33, 0x00}; + if(!unitemp_i2c_writeArray(i2c_sensor, 3, data)) return UT_SENSORSTATUS_TIMEOUT; + furi_delay_ms(80); + uint32_t t = furi_get_tick(); + while(DHT20_get_status(i2c_sensor) == 0x80) { + if(furi_get_tick() - t > 10) return UT_SENSORSTATUS_TIMEOUT; + } + + if(!unitemp_i2c_readArray(i2c_sensor, 7, data)) return UT_SENSORSTATUS_TIMEOUT; + + if(DHT20_calc_CRC8(data, 6) != data[6]) { + return UT_SENSORSTATUS_BADCRC; + } + uint32_t RetuData = 0; + RetuData = (RetuData | data[1]) << 8; + RetuData = (RetuData | data[2]) << 8; + RetuData = (RetuData | data[3]); + RetuData = RetuData >> 4; + sensor->hum = RetuData * 100 * 10 / 1024.0f / 1024.0f / 10.0f; + + RetuData = 0; + RetuData = (RetuData | data[3]) << 8; + RetuData = (RetuData | data[4]) << 8; + RetuData = (RetuData | data[5]); + RetuData = RetuData & 0xfffff; + sensor->temp = (RetuData * 200 * 10.0f / 1024.0f / 1024.0f - 500) / 10.0f; + + return UT_SENSORSTATUS_OK; +} diff --git a/applications/plugins/unitemp/sensors/DHT20.h b/applications/plugins/unitemp/sensors/DHT20.h new file mode 100644 index 000000000..417b0ed1d --- /dev/null +++ b/applications/plugins/unitemp/sensors/DHT20.h @@ -0,0 +1,63 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_DHT20 +#define UNITEMP_DHT20 + +#include "../unitemp.h" +#include "../Sensors.h" +extern const SensorType DHT20; +extern const SensorType AHT10; +/** + * @brief Выделение памяти и установка начальных значений датчика DHT20 + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_DHT20_I2C_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика DHT20 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_DHT20_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_DHT20_I2C_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_DHT20_I2C_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_DHT20_I2C_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/HDC1080.c b/applications/plugins/unitemp/sensors/HDC1080.c new file mode 100644 index 000000000..5f2c59b24 --- /dev/null +++ b/applications/plugins/unitemp/sensors/HDC1080.c @@ -0,0 +1,94 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "HDC1080.h" +#include "../interfaces/I2CSensor.h" + +const SensorType HDC1080 = { + .typename = "HDC1080", + .interface = &I2C, + .datatype = UT_DATA_TYPE_TEMP_HUM, + .pollingInterval = 250, + .allocator = unitemp_HDC1080_alloc, + .mem_releaser = unitemp_HDC1080_free, + .initializer = unitemp_HDC1080_init, + .deinitializer = unitemp_HDC1080_deinit, + .updater = unitemp_HDC1080_update}; + +bool unitemp_HDC1080_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Адреса на шине I2C (7 бит) + i2c_sensor->minI2CAdr = 0x40 << 1; + i2c_sensor->maxI2CAdr = 0x40 << 1; + return true; +} + +bool unitemp_HDC1080_free(Sensor* sensor) { + //Нечего высвобождать, так как ничего не было выделено + UNUSED(sensor); + return true; +} + +bool unitemp_HDC1080_init(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + uint8_t data[2]; + if(!unitemp_i2c_readRegArray(i2c_sensor, 0xFF, 2, data)) return UT_SENSORSTATUS_TIMEOUT; + uint16_t device_id = ((uint16_t)data[0] << 8) | data[1]; + if(device_id != 0x1050) { + FURI_LOG_E( + APP_NAME, + "Sensor %s returned wrong ID 0x%02X, expected 0x1050", + sensor->name, + device_id); + return false; + } + data[0] = 0b0001000; + data[1] = 0; + //Установка режима работы и разрядности измерений + if(!unitemp_i2c_writeRegArray(i2c_sensor, 0x02, 2, data)) return UT_SENSORSTATUS_TIMEOUT; + + return true; +} + +bool unitemp_HDC1080_deinit(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + UNUSED(i2c_sensor); + return true; +} + +UnitempStatus unitemp_HDC1080_update(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + uint8_t data[2] = {0}; + //Запуск измерения + if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT; + furi_delay_ms(10); + if(!unitemp_i2c_readArray(i2c_sensor, 2, data)) return UT_SENSORSTATUS_TIMEOUT; + + sensor->temp = ((float)(((uint16_t)data[0] << 8) | data[1]) / 65536) * 165 - 40; + + data[0] = 1; + if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT; + furi_delay_ms(10); + if(!unitemp_i2c_readArray(i2c_sensor, 2, data)) return UT_SENSORSTATUS_TIMEOUT; + sensor->hum = ((float)(((uint16_t)data[0] << 8) | data[1]) / 65536) * 100; + + return UT_SENSORSTATUS_OK; +} diff --git a/applications/plugins/unitemp/sensors/HDC1080.h b/applications/plugins/unitemp/sensors/HDC1080.h new file mode 100644 index 000000000..59ba0673c --- /dev/null +++ b/applications/plugins/unitemp/sensors/HDC1080.h @@ -0,0 +1,62 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_HDC1080 +#define UNITEMP_HDC1080 + +#include "../unitemp.h" +#include "../Sensors.h" +extern const SensorType HDC1080; +/** + * @brief Выделение памяти и установка начальных значений датчика HDC1080 + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_HDC1080_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика HDC1080 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_HDC1080_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_HDC1080_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_HDC1080_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_HDC1080_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/HTU21x.c b/applications/plugins/unitemp/sensors/HTU21x.c new file mode 100644 index 000000000..2e7222bc4 --- /dev/null +++ b/applications/plugins/unitemp/sensors/HTU21x.c @@ -0,0 +1,107 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "HTU21x.h" +#include "../interfaces/I2CSensor.h" + +const SensorType HTU21x = { + .typename = "HTU21x", + .altname = "HTU21x/SI70xx/SHT2x", + .interface = &I2C, + .datatype = UT_DATA_TYPE_TEMP_HUM, + .pollingInterval = 250, + .allocator = unitemp_HTU21x_alloc, + .mem_releaser = unitemp_HTU21x_free, + .initializer = unitemp_HTU21x_init, + .deinitializer = unitemp_HTU21x_deinit, + .updater = unitemp_HTU21x_update}; + +static uint8_t checkCRC(uint16_t data) { + for(uint8_t i = 0; i < 16; i++) { + if(data & 0x8000) + data = (data << 1) ^ 0x13100; + else + data <<= 1; + } + return (data >> 8); +} + +bool unitemp_HTU21x_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Адреса на шине I2C (7 бит) + i2c_sensor->minI2CAdr = 0x40 << 1; + i2c_sensor->maxI2CAdr = 0x41 << 1; + return true; +} + +bool unitemp_HTU21x_free(Sensor* sensor) { + //Нечего высвобождать, так как ничего не было выделено + UNUSED(sensor); + return true; +} + +bool unitemp_HTU21x_init(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + UNUSED(i2c_sensor); + return true; +} + +bool unitemp_HTU21x_deinit(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + UNUSED(i2c_sensor); + return true; +} + +UnitempStatus unitemp_HTU21x_update(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Датчик может быть всего один, так что норм + static bool temp_hum = false; + + uint8_t data[3]; + + if(sensor->status == UT_SENSORSTATUS_POLLING) { + if(!unitemp_i2c_readArray(i2c_sensor, 3, data)) return UT_SENSORSTATUS_TIMEOUT; + + uint16_t raw = ((uint16_t)data[0] << 8) | data[1]; + if(checkCRC(raw) != data[2]) return UT_SENSORSTATUS_BADCRC; + + if(temp_hum) { + sensor->temp = (0.002681f * raw - 46.85f); + } else { + sensor->hum = ((0.001907 * (raw ^ 0x02)) - 6); + } + temp_hum = !temp_hum; + if(temp_hum) return UT_SENSORSTATUS_EARLYPOOL; + return UT_SENSORSTATUS_OK; + } + + if(temp_hum) { + //Запрос температуры + data[0] = 0xF3; + if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT; + } else { + //Запрос влажности + data[0] = 0xF5; + if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT; + } + + return UT_SENSORSTATUS_POLLING; +} diff --git a/applications/plugins/unitemp/sensors/HTU21x.h b/applications/plugins/unitemp/sensors/HTU21x.h new file mode 100644 index 000000000..ffe062a24 --- /dev/null +++ b/applications/plugins/unitemp/sensors/HTU21x.h @@ -0,0 +1,62 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_HTU21x +#define UNITEMP_HTU21x + +#include "../unitemp.h" +#include "../Sensors.h" +extern const SensorType HTU21x; +/** + * @brief Выделение памяти и установка начальных значений датчика HTU21x + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_HTU21x_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика HTU21x + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_HTU21x_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_HTU21x_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_HTU21x_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_HTU21x_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/LM75.c b/applications/plugins/unitemp/sensors/LM75.c index e71376404..a9c8df84e 100644 --- a/applications/plugins/unitemp/sensors/LM75.c +++ b/applications/plugins/unitemp/sensors/LM75.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/sensors/LM75.h b/applications/plugins/unitemp/sensors/LM75.h index dc1fb791c..d5397b178 100644 --- a/applications/plugins/unitemp/sensors/LM75.h +++ b/applications/plugins/unitemp/sensors/LM75.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/sensors/MAX31855.c b/applications/plugins/unitemp/sensors/MAX31855.c new file mode 100644 index 000000000..2411eb09e --- /dev/null +++ b/applications/plugins/unitemp/sensors/MAX31855.c @@ -0,0 +1,93 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "MAX31855.h" + +const SensorType MAX31855 = { + .typename = "MAX31855", + .altname = "MAX31855 (Thermocouple)", + .interface = &SPI, + .datatype = UT_TEMPERATURE, + .pollingInterval = 500, + .allocator = unitemp_MAX31855_alloc, + .mem_releaser = unitemp_MAX31855_free, + .initializer = unitemp_MAX31855_init, + .deinitializer = unitemp_MAX31855_deinit, + .updater = unitemp_MAX31855_update}; + +bool unitemp_MAX31855_alloc(Sensor* sensor, char* args) { + UNUSED(sensor); + UNUSED(args); + return true; +} + +bool unitemp_MAX31855_free(Sensor* sensor) { + UNUSED(sensor); + return true; +} + +bool unitemp_MAX31855_init(Sensor* sensor) { + SPISensor* instance = sensor->instance; + furi_hal_spi_bus_handle_init(instance->spi); + UNUSED(instance); + return true; +} + +bool unitemp_MAX31855_deinit(Sensor* sensor) { + UNUSED(sensor); + return true; +} + +UnitempStatus unitemp_MAX31855_update(Sensor* sensor) { + SPISensor* instance = sensor->instance; + + furi_hal_spi_acquire(instance->spi); + furi_hal_gpio_write(instance->CS_pin->pin, false); + + uint8_t buff[4] = {0}; + + furi_hal_spi_bus_rx(instance->spi, buff, 4, 0xFF); + furi_hal_spi_release(instance->spi); + + uint32_t raw = (buff[0] << 24) | (buff[1] << 16) | (buff[2] << 8) | buff[3]; + + if(raw == 0xFFFFFFFF || raw == 0) return UT_SENSORSTATUS_TIMEOUT; + + //Определение состояния термопары + uint8_t state = raw & 0b111; + //Обрыв + if(state == 0x01) { + UNITEMP_DEBUG("%s has thermocouple open circuit", sensor->name); + return UT_SENSORSTATUS_ERROR; + } + //Короткое замыкание к земле + if(state == 0x02) { + UNITEMP_DEBUG("%s has thermocouple short to GND", sensor->name); + return UT_SENSORSTATUS_ERROR; + } + //Короткое замыкание к питанию + if(state == 0x04) { + UNITEMP_DEBUG("%s has thermocouple short to VCC", sensor->name); + return UT_SENSORSTATUS_ERROR; + } + + raw = (raw >> 16) & 0xFFFC; + + sensor->temp = (int16_t)(raw) / 16.0f; + + return UT_SENSORSTATUS_OK; +} diff --git a/applications/plugins/unitemp/sensors/MAX31855.h b/applications/plugins/unitemp/sensors/MAX31855.h new file mode 100644 index 000000000..d63c39885 --- /dev/null +++ b/applications/plugins/unitemp/sensors/MAX31855.h @@ -0,0 +1,65 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_MAX31855 +#define UNITEMP_MAX31855 + +#include "../unitemp.h" +#include "../Sensors.h" +#include "../interfaces/SPISensor.h" + +extern const SensorType MAX31855; + +/** + * @brief Выделение памяти и установка начальных значений датчика MAX31855 + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_MAX31855_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика MAX31855 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_MAX31855_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_MAX31855_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_MAX31855_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_MAX31855_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/MAX6675.c b/applications/plugins/unitemp/sensors/MAX6675.c new file mode 100644 index 000000000..e97a96eb5 --- /dev/null +++ b/applications/plugins/unitemp/sensors/MAX6675.c @@ -0,0 +1,81 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "MAX6675.h" + +const SensorType MAX6675 = { + .typename = "MAX6675", + .altname = "MAX6675 (Thermocouple)", + .interface = &SPI, + .datatype = UT_TEMPERATURE, + .pollingInterval = 500, + .allocator = unitemp_MAX6675_alloc, + .mem_releaser = unitemp_MAX6675_free, + .initializer = unitemp_MAX6675_init, + .deinitializer = unitemp_MAX6675_deinit, + .updater = unitemp_MAX6675_update}; + +bool unitemp_MAX6675_alloc(Sensor* sensor, char* args) { + UNUSED(sensor); + UNUSED(args); + return true; +} + +bool unitemp_MAX6675_free(Sensor* sensor) { + UNUSED(sensor); + return true; +} + +bool unitemp_MAX6675_init(Sensor* sensor) { + SPISensor* instance = sensor->instance; + furi_hal_spi_bus_handle_init(instance->spi); + UNUSED(instance); + return true; +} + +bool unitemp_MAX6675_deinit(Sensor* sensor) { + UNUSED(sensor); + return true; +} + +UnitempStatus unitemp_MAX6675_update(Sensor* sensor) { + SPISensor* instance = sensor->instance; + + furi_hal_spi_acquire(instance->spi); + furi_hal_gpio_write(instance->CS_pin->pin, false); + + uint8_t buff[2] = {0}; + + furi_hal_spi_bus_rx(instance->spi, buff, 2, 0xFF); + furi_hal_spi_release(instance->spi); + + uint32_t raw = (buff[0] << 8) | buff[1]; + + if(raw == 0xFFFFFFFF || raw == 0) return UT_SENSORSTATUS_TIMEOUT; + + //Определение состояния термопары + uint8_t state = raw & 0b100; + //Обрыв + if(state == 0b100) { + UNITEMP_DEBUG("%s has thermocouple open circuit", sensor->name); + return UT_SENSORSTATUS_ERROR; + } + + sensor->temp = (int16_t)(raw) / 32.0f; + + return UT_SENSORSTATUS_OK; +} diff --git a/applications/plugins/unitemp/sensors/MAX6675.h b/applications/plugins/unitemp/sensors/MAX6675.h new file mode 100644 index 000000000..cce346590 --- /dev/null +++ b/applications/plugins/unitemp/sensors/MAX6675.h @@ -0,0 +1,65 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_MAX6675 +#define UNITEMP_MAX6675 + +#include "../unitemp.h" +#include "../Sensors.h" +#include "../interfaces/SPISensor.h" + +extern const SensorType MAX6675; + +/** + * @brief Выделение памяти и установка начальных значений датчика MAX6675 + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_MAX6675_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика MAX6675 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_MAX6675_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_MAX6675_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_MAX6675_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_MAX6675_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/SHT30.c b/applications/plugins/unitemp/sensors/SHT30.c new file mode 100644 index 000000000..dd43e80af --- /dev/null +++ b/applications/plugins/unitemp/sensors/SHT30.c @@ -0,0 +1,90 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "SHT30.h" +#include "../interfaces/I2CSensor.h" + +const SensorType SHT30 = { + .typename = "SHT30", + .altname = "SHT30/31/35", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_HUMIDITY, + .pollingInterval = 1000, + .allocator = unitemp_SHT30_I2C_alloc, + .mem_releaser = unitemp_SHT30_I2C_free, + .initializer = unitemp_SHT30_init, + .deinitializer = unitemp_SHT30_I2C_deinit, + .updater = unitemp_SHT30_I2C_update}; +const SensorType GXHT30 = { + .typename = "GXHT30", + .altname = "GXHT30/31/35", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_HUMIDITY, + .pollingInterval = 1000, + .allocator = unitemp_SHT30_I2C_alloc, + .mem_releaser = unitemp_SHT30_I2C_free, + .initializer = unitemp_GXHT30_init, + .deinitializer = unitemp_SHT30_I2C_deinit, + .updater = unitemp_SHT30_I2C_update}; + +bool unitemp_SHT30_I2C_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Адреса на шине I2C (7 бит) + i2c_sensor->minI2CAdr = 0x44 << 1; + i2c_sensor->maxI2CAdr = 0x45 << 1; + return true; +} + +bool unitemp_SHT30_I2C_free(Sensor* sensor) { + //Нечего высвобождать, так как ничего не было выделено + UNUSED(sensor); + return true; +} + +bool unitemp_SHT30_init(Sensor* sensor) { + UNUSED(sensor); + return true; +} + +bool unitemp_GXHT30_init(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + //Включение режима автоматического преобразования 2 раза в сек + uint8_t data[2] = {0x22, 0x36}; + if(!unitemp_i2c_writeArray(i2c_sensor, 2, data)) return false; + return true; +} + +bool unitemp_SHT30_I2C_deinit(Sensor* sensor) { + //Нечего деинициализировать + UNUSED(sensor); + return true; +} + +UnitempStatus unitemp_SHT30_I2C_update(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + //Получение данных + uint8_t data[6] = {0xE0, 0x00}; + if(!unitemp_i2c_writeArray(i2c_sensor, 2, data)) return UT_SENSORSTATUS_TIMEOUT; + if(!unitemp_i2c_readArray(i2c_sensor, 6, data)) return UT_SENSORSTATUS_TIMEOUT; + + sensor->temp = -45 + 175 * (((uint16_t)(data[0] << 8) | data[1]) / 65535.0f); + sensor->hum = 100 * (((uint16_t)(data[3] << 8) | data[4]) / 65535.0f); + + return UT_SENSORSTATUS_OK; +} diff --git a/applications/plugins/unitemp/sensors/SHT30.h b/applications/plugins/unitemp/sensors/SHT30.h new file mode 100644 index 000000000..4b5b74411 --- /dev/null +++ b/applications/plugins/unitemp/sensors/SHT30.h @@ -0,0 +1,70 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_SHT30 +#define UNITEMP_SHT30 + +#include "../unitemp.h" +#include "../Sensors.h" +extern const SensorType SHT30; +extern const SensorType GXHT30; +/** + * @brief Выделение памяти и установка начальных значений датчика SHT30 + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_SHT30_I2C_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика SHT30 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_SHT30_init(Sensor* sensor); +/** + * @brief Инициализации датчика GXHT30 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_GXHT30_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_SHT30_I2C_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_SHT30_I2C_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_SHT30_I2C_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/Sensors.xlsx b/applications/plugins/unitemp/sensors/Sensors.xlsx index 2b6578e0ecc66d8bd41e911ea600061bc3c70de0..c314098a88c2bbc3d75fcc900815cfbdf5bb4772 100644 GIT binary patch delta 7810 zcmZ8mWl$W-vff1kY=Gb{!QE|x1X|09^9P}5+uPL5=d}&3-0!E?yY*K z-kTp&Gt=EQRp0dV^n5*MxbdN3;T4o}zV=Z75dgqJ0RY|r0018c4sT~S`wz~}_Ut~6 z4mDbfPPu}3f%P8Gz`ML)Vs;+Jk`coq+)5Go#g;VYk`W+}uDOF<&e)b@pbfNG^yj3_ zOT{8q3jIZju{8RCL$j{^N$dFfv{7%KLKQEZ8glzh1`|JmHA~le@9Hi_2r8AxFPR#y zAkO0<#pmaDISKEr)y#R#B!CG(&HK2J$$uqmG}A(LFZM}OtR$t1>Q$ND@xHd2`a!n( zvRVTYA*v&MLEr6n*U-Kw)RdWq#0+Khdhf zcPCMlBnU`EiX*Fbos9+mg}(ZhfTatu_nETTtU>!E4KL*;$L0rH8-Sc#JAPUq%#-}* zrx)0Ob}UU4uA?>`Ps^Apf<}AkjZ;Nko_9QiH`?kup07-s*Lw|RIVj6dS9eTliuI2? z8$JY*UUWp8nWR-nTpm;rK+2W9dyUDfxj6mM-n@)U$RJ+C00J~b8w{tWBfO8#T-e8( zoT45#u}?1O-m6HaHc{{7Y8qEr*~YhaRQUCxDcAO)Y92?*T^8HAe~Q_6^eZ2(;0aPm zrLDVCM0)TQym~n3HS{U8Ud{}@E&l11RPR;qSO{lY;))2*NXX&zHc!PWiyPW6q{&o) z@gUH45B#P`l_>}+5|aVHqmEy;;7(Y=I@p^~4xPi;g%wD~Kyzuo%U~66v?Q1CTqUTn zdPGXN^c(NJn@_+#Dko<-u`zrQ5S>kYqilXujPKCaClK#+1|+GS1sCSbtzw`bs=2m)|DEzYtNSX zBzgS+drmNFIZ5$&!$tEAoWpikx~Cckmq$+YGt1g5|2{;A{c>igg3r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49nnTr2M~C)PL6qQNVt3Qd9n4 za{KRsQEC{NOA4`{4z|n4_!kW;;vhY2pNR$bjSG+RpX1^1SLTWP%ZvE`wfQ@0WQ5&w Si6d$=!$i30P$;4QO#To4U`1&F diff --git a/applications/plugins/unitemp/unitemp.c b/applications/plugins/unitemp/unitemp.c index ce1cd1dc9..181de0e78 100644 --- a/applications/plugins/unitemp/unitemp.c +++ b/applications/plugins/unitemp/unitemp.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,7 +21,6 @@ #include "./views/UnitempViews.h" #include -#include /* Переменные */ //Данные приложения @@ -79,9 +78,7 @@ bool unitemp_saveSettings(void) { } bool unitemp_loadSettings(void) { -#ifdef UNITEMP_DEBUG - FURI_LOG_D(APP_NAME, "Loading settings..."); -#endif + UNITEMP_DEBUG("Loading settings..."); //Выделение памяти на поток app->file_stream = file_stream_alloc(app->storage); @@ -147,7 +144,7 @@ bool unitemp_loadSettings(void) { //Сколько байт до конца строки size_t line_end = 0; - while(line_end != STRING_FAILURE && line_end != (size_t)(file_size - 1)) { + while(line_end != ((size_t)-1) && line_end != (size_t)(file_size - 1)) { char buff[20] = {0}; sscanf(((char*)(file_buf + line_end)), "%s", buff); @@ -236,6 +233,8 @@ static bool unitemp_alloc(void) { */ static void unitemp_free(void) { popup_free(app->popup); + //Удаление вида после обработки + view_dispatcher_remove_view(app->view_dispatcher, UnitempViewPopup); unitemp_widgets_free(); unitemp_SensorActions_free(); diff --git a/applications/plugins/unitemp/unitemp.h b/applications/plugins/unitemp/unitemp.h index 144780968..bde8b0c17 100644 --- a/applications/plugins/unitemp/unitemp.h +++ b/applications/plugins/unitemp/unitemp.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,19 +39,25 @@ /* Объявление макроподстановок */ //Имя приложения #define APP_NAME "Unitemp" +//Версия приложения +#define UNITEMP_APP_VER "1.2" //Путь хранения файлов плагина #define APP_PATH_FOLDER "/ext/unitemp" //Имя файла с настройками #define APP_FILENAME_SETTINGS "settings.cfg" //Имя файла с датчиками #define APP_FILENAME_SENSORS "sensors.cfg" -//Версия приложения -#define UNITEMP_APP_VER "1.0" //Размер буффера текста #define BUFF_SIZE 32 -#define UNITEMP_DEBUG +#define UNITEMP_D + +#ifdef FURI_DEBUG +#define UNITEMP_DEBUG(msg, ...) FURI_LOG_D(APP_NAME, msg, ##__VA_ARGS__) +#else +#define UNITEMP_DEBUG(msg, ...) +#endif /* Объявление перечислений */ //Единицы измерения температуры diff --git a/applications/plugins/unitemp/views/General_view.c b/applications/plugins/unitemp/views/General_view.c index e21b04de2..dcf8420d9 100644 --- a/applications/plugins/unitemp/views/General_view.c +++ b/applications/plugins/unitemp/views/General_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,9 @@ #include "UnitempViews.h" #include "unitemp_icons.h" -#include +extern const Icon I_ButtonRight_4x7; +extern const Icon I_ButtonLeft_4x7; +extern const Icon I_Ok_btn_9x9; static View* view; @@ -74,7 +76,7 @@ static void _draw_temperature(Canvas* canvas, Sensor* sensor, uint8_t x, uint8_t app->buff[0] = '-'; offset = 1; } - snprintf((char*)(app->buff + offset), BUFF_SIZE, "%d", (int8_t)sensor->temp); + snprintf((char*)(app->buff + offset), BUFF_SIZE, "%d", (int16_t)sensor->temp); canvas_set_font(canvas, FontBigNumbers); canvas_draw_str_aligned( canvas, @@ -235,6 +237,7 @@ static void _draw_carousel_values(Canvas* canvas) { canvas_draw_icon(canvas, 34, 23, frames[furi_get_tick() % 2250 / 750]); canvas_set_font(canvas, FontSecondary); + //TODO: Оптимизировать эту срань if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &SINGLE_WIRE) { snprintf( app->buff, @@ -254,6 +257,9 @@ static void _draw_carousel_values(Canvas* canvas) { if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &I2C) { snprintf(app->buff, BUFF_SIZE, "Waiting for module on I2C pins"); } + if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &SPI) { + snprintf(app->buff, BUFF_SIZE, "Waiting for module on SPI pins"); + } canvas_draw_str_aligned(canvas, 64, 19, AlignCenter, AlignCenter, app->buff); return; } @@ -302,6 +308,8 @@ static void _draw_carousel_values(Canvas* canvas) { break; } } + +//TODO: Оптимизировать вывод информации static void _draw_carousel_info(Canvas* canvas) { canvas_set_font(canvas, FontPrimary); canvas_draw_str(canvas, 10, 23, "Type:"); @@ -349,6 +357,25 @@ static void _draw_carousel_info(Canvas* canvas) { ->gpio->name); } + if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &SPI) { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, 10, 35, "MISO pin:"); + canvas_draw_str(canvas, 10, 46, "CS pin:"); + canvas_draw_str(canvas, 10, 58, "SCK pin:"); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str( + canvas, 41, 23, unitemp_sensor_getActive(generalview_sensor_index)->type->typename); + canvas_draw_str(canvas, 60, 35, unitemp_gpio_getFromInt(3)->name); + canvas_draw_str( + canvas, + 47, + 46, + ((SPISensor*)unitemp_sensor_getActive(generalview_sensor_index)->instance) + ->CS_pin->name); + canvas_draw_str(canvas, 54, 58, unitemp_gpio_getFromInt(5)->name); + } + if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &I2C) { canvas_set_font(canvas, FontPrimary); canvas_draw_str(canvas, 10, 35, "I2C addr:"); @@ -362,7 +389,8 @@ static void _draw_carousel_info(Canvas* canvas) { BUFF_SIZE, "0x%02X", ((I2CSensor*)unitemp_sensor_getActive(generalview_sensor_index)->instance) - ->currentI2CAdr); + ->currentI2CAdr >> + 1); canvas_draw_str(canvas, 57, 35, app->buff); canvas_draw_str(canvas, 54, 46, "15 (C0)"); canvas_draw_str(canvas, 54, 58, "16 (C1)"); @@ -539,6 +567,10 @@ static bool _input_callback(InputEvent* event, void* context) { return true; } } + //Обработка длинного нажатия "Ок" + if(event->key == InputKeyOk && event->type == InputTypeLong) { + app->settings.temp_unit = !app->settings.temp_unit; + } return true; } @@ -558,5 +590,6 @@ void unitemp_General_switch(void) { } void unitemp_General_free(void) { + view_dispatcher_remove_view(app->view_dispatcher, UnitempViewGeneral); view_free(view); } diff --git a/applications/plugins/unitemp/views/MainMenu_view.c b/applications/plugins/unitemp/views/MainMenu_view.c index 4b2820eee..bfd0cb0cf 100644 --- a/applications/plugins/unitemp/views/MainMenu_view.c +++ b/applications/plugins/unitemp/views/MainMenu_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/views/Popup_view.c b/applications/plugins/unitemp/views/Popup_view.c index d495462b2..efa7e7ffa 100644 --- a/applications/plugins/unitemp/views/Popup_view.c +++ b/applications/plugins/unitemp/views/Popup_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,6 @@ #include "UnitempViews.h" #include #include -#include uint32_t _prev_view_id; diff --git a/applications/plugins/unitemp/views/SensorActions_view.c b/applications/plugins/unitemp/views/SensorActions_view.c index 6f375a50a..1d1a83076 100644 --- a/applications/plugins/unitemp/views/SensorActions_view.c +++ b/applications/plugins/unitemp/views/SensorActions_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/views/SensorEdit_view.c b/applications/plugins/unitemp/views/SensorEdit_view.c index 4d5bc17db..ccb07a48e 100644 --- a/applications/plugins/unitemp/views/SensorEdit_view.c +++ b/applications/plugins/unitemp/views/SensorEdit_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -63,13 +63,9 @@ bool _onewire_id_exist(uint8_t* id) { static void _onewire_scan(void) { OneWireSensor* ow_sensor = editable_sensor->instance; -#ifdef UNITEMP_DEBUG - FURI_LOG_D( - APP_NAME, - "devices on wire %d: %d", - ow_sensor->bus->gpio->num, - ow_sensor->bus->device_count); -#endif + + UNITEMP_DEBUG( + "devices on wire %d: %d", ow_sensor->bus->gpio->num, ow_sensor->bus->device_count); //Сканирование шины one wire unitemp_onewire_bus_init(ow_sensor->bus); @@ -101,9 +97,8 @@ static void _onewire_scan(void) { memcpy(ow_sensor->deviceID, id, 8); ow_sensor->familyCode = id[0]; -#ifdef UNITEMP_DEBUG - FURI_LOG_D( - APP_NAME, + + UNITEMP_DEBUG( "Found sensor's ID: %02X%02X%02X%02X%02X%02X%02X%02X", id[0], id[1], @@ -113,7 +108,6 @@ static void _onewire_scan(void) { id[5], id[6], id[7]); -#endif if(ow_sensor->familyCode != 0) { char id_buff[10]; @@ -199,6 +193,12 @@ static void _gpio_change_callback(VariableItem* item) { unitemp_gpio_getAviablePort(editable_sensor->type->interface, index, initial_gpio); variable_item_set_current_value_text(item, instance->gpio->name); } + if(editable_sensor->type->interface == &SPI) { + SPISensor* instance = editable_sensor->instance; + instance->CS_pin = + unitemp_gpio_getAviablePort(editable_sensor->type->interface, index, initial_gpio); + variable_item_set_current_value_text(item, instance->CS_pin->name); + } if(editable_sensor->type->interface == &ONE_WIRE) { OneWireSensor* instance = editable_sensor->instance; instance->bus->gpio = @@ -214,9 +214,9 @@ static void _gpio_change_callback(VariableItem* item) { static void _i2caddr_change_callback(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); ((I2CSensor*)editable_sensor->instance)->currentI2CAdr = - ((I2CSensor*)editable_sensor->instance)->minI2CAdr + index; + ((I2CSensor*)editable_sensor->instance)->minI2CAdr + index * 2; char buff[5]; - snprintf(buff, 5, "0x%2X", ((I2CSensor*)editable_sensor->instance)->currentI2CAdr); + snprintf(buff, 5, "0x%2X", ((I2CSensor*)editable_sensor->instance)->currentI2CAdr >> 1); variable_item_set_current_value_text(item, buff); } /** @@ -302,12 +302,15 @@ void unitemp_SensorEdit_switch(Sensor* sensor) { offset_buff, OFFSET_BUFF_SIZE, "%+1.1f", (double)(editable_sensor->temp_offset / 10.0)); variable_item_set_current_value_text(temp_offset_item, offset_buff); - //Порт подключения датчка (для one wire и single wire) - if(sensor->type->interface == &ONE_WIRE || sensor->type->interface == &SINGLE_WIRE) { + //Порт подключения датчка (для one wire, SPI и single wire) + if(sensor->type->interface == &ONE_WIRE || sensor->type->interface == &SINGLE_WIRE || + sensor->type->interface == &SPI) { if(sensor->type->interface == &ONE_WIRE) { initial_gpio = ((OneWireSensor*)editable_sensor->instance)->bus->gpio; - } else { + } else if(sensor->type->interface == &SINGLE_WIRE) { initial_gpio = ((SingleWireSensor*)editable_sensor->instance)->gpio; + } else if(sensor->type->interface == &SPI) { + initial_gpio = ((SPISensor*)editable_sensor->instance)->CS_pin; } uint8_t aviable_gpio_count = @@ -335,11 +338,15 @@ void unitemp_SensorEdit_switch(Sensor* sensor) { VariableItem* item = variable_item_list_add( variable_item_list, "I2C address", - ((I2CSensor*)sensor->instance)->maxI2CAdr - ((I2CSensor*)sensor->instance)->minI2CAdr + - 1, + (((I2CSensor*)sensor->instance)->maxI2CAdr >> 1) - + (((I2CSensor*)sensor->instance)->minI2CAdr >> 1) + 1, _i2caddr_change_callback, app); - snprintf(app->buff, 5, "0x%2X", ((I2CSensor*)sensor->instance)->currentI2CAdr); + snprintf(app->buff, 5, "0x%2X", ((I2CSensor*)sensor->instance)->currentI2CAdr >> 1); + variable_item_set_current_value_index( + item, + (((I2CSensor*)sensor->instance)->currentI2CAdr >> 1) - + (((I2CSensor*)sensor->instance)->minI2CAdr >> 1)); variable_item_set_current_value_text(item, app->buff); } diff --git a/applications/plugins/unitemp/views/SensorNameEdit_view.c b/applications/plugins/unitemp/views/SensorNameEdit_view.c index 1d36ac142..19df76edf 100644 --- a/applications/plugins/unitemp/views/SensorNameEdit_view.c +++ b/applications/plugins/unitemp/views/SensorNameEdit_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -42,5 +42,6 @@ void unitemp_SensorNameEdit_switch(Sensor* sensor) { view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID); } void unitemp_SensorNameEdit_free(void) { + view_dispatcher_remove_view(app->view_dispatcher, VIEW_ID); text_input_free(text_input); } \ No newline at end of file diff --git a/applications/plugins/unitemp/views/SensorsList_view.c b/applications/plugins/unitemp/views/SensorsList_view.c index a7d3d5556..716ec260b 100644 --- a/applications/plugins/unitemp/views/SensorsList_view.c +++ b/applications/plugins/unitemp/views/SensorsList_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,8 @@ #include "UnitempViews.h" #include #include -#include + +extern const Icon I_Cry_dolph_55x52; //Текущий вид static View* view; @@ -85,8 +86,8 @@ static void _enter_callback(void* context, uint32_t index) { return; } - //Выбор первого доступного порта для датчика single wire - if(type->interface == &SINGLE_WIRE) { + //Выбор первого доступного порта для датчика single wire и SPI + if(type->interface == &SINGLE_WIRE || type->interface == &SPI) { snprintf( args, 4, diff --git a/applications/plugins/unitemp/views/Settings_view.c b/applications/plugins/unitemp/views/Settings_view.c index c3f82c14e..bff169129 100644 --- a/applications/plugins/unitemp/views/Settings_view.c +++ b/applications/plugins/unitemp/views/Settings_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/views/UnitempViews.h b/applications/plugins/unitemp/views/UnitempViews.h index b7c2467e0..b78cf2b28 100644 --- a/applications/plugins/unitemp/views/UnitempViews.h +++ b/applications/plugins/unitemp/views/UnitempViews.h @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/applications/plugins/unitemp/views/Widgets_view.c b/applications/plugins/unitemp/views/Widgets_view.c index 6d8702ca1..97505d925 100644 --- a/applications/plugins/unitemp/views/Widgets_view.c +++ b/applications/plugins/unitemp/views/Widgets_view.c @@ -1,6 +1,6 @@ /* Unitemp - Universal temperature reader - Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ #include "UnitempViews.h" #include "unitemp_icons.h" -#include +extern const Icon I_DolphinCommon_56x48; void unitemp_widgets_alloc(void) { app->widget = widget_alloc(); @@ -27,6 +27,7 @@ void unitemp_widgets_alloc(void) { } void unitemp_widgets_free(void) { + view_dispatcher_remove_view(app->view_dispatcher, UnitempViewWidget); widget_free(app->widget); } @@ -132,7 +133,7 @@ void unitemp_widget_delete_switch(Sensor* sensor) { app->buff, BUFF_SIZE, "\e#I2C addr:\e# 0x%02X", - ((I2CSensor*)current_sensor->instance)->currentI2CAdr); + ((I2CSensor*)current_sensor->instance)->currentI2CAdr >> 1); widget_add_text_box_element( app->widget, 0, 28, 128, 23, AlignLeft, AlignTop, app->buff, false); } From 66eb191a599687606bc67758a85d8410163c87ee Mon Sep 17 00:00:00 2001 From: VerstreuteSeele Date: Mon, 30 Jan 2023 23:29:08 +0100 Subject: [PATCH 7/8] Fix build | update storage_settings_scene_sd_info.c --- .../scenes/storage_settings_scene_sd_info.c | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c index f900d5c8c..f69f6c7ef 100644 --- a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c +++ b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c @@ -28,33 +28,6 @@ void storage_settings_scene_sd_info_on_enter(void* context) { dialog_ex, "Try to reinsert\nor format SD\ncard.", 3, 19, AlignLeft, AlignTop); dialog_ex_set_center_button_text(dialog_ex, "Ok"); } else { - char unit_kb[] = "KB"; - char unit_mb[] = "MB"; - char unit_gb[] = "GB"; - - double sd_total_val = (double)sd_info.kb_total; - char* sd_total_unit = unit_kb; - double sd_free_val = (double)sd_info.kb_free; - char* sd_free_unit = unit_kb; - - if(sd_total_val > 1024) { - sd_total_val /= 1024; - sd_total_unit = unit_mb; - } - if(sd_total_val > 1024) { - sd_total_val /= 1024; - sd_total_unit = unit_gb; - } - - if(sd_free_val > 1024) { - sd_free_val /= 1024; - sd_free_unit = unit_mb; - } - if(sd_free_val > 1024) { - sd_free_val /= 1024; - sd_free_unit = unit_gb; - } - furi_string_printf( app->text_string, "Label: %s\nType: %s\n%lu KiB total\n%lu KiB free\n" @@ -109,4 +82,4 @@ void storage_settings_scene_sd_info_on_exit(void* context) { dialog_ex_reset(dialog_ex); furi_string_reset(app->text_string); -} +} \ No newline at end of file From 2354b51d30d11a8877a58682fe3975194c2161c8 Mon Sep 17 00:00:00 2001 From: Clara K Date: Tue, 31 Jan 2023 11:41:42 +0100 Subject: [PATCH 8/8] Update ReadMe.md --- ReadMe.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 58123126d..bb167c543 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -4,7 +4,7 @@

-[Intro](https://github.com/ClaraCrazy/Flipper-Xtreme#What-makes-it-special) | [Animations](https://github.com/ClaraCrazy/Flipper-Xtreme#Animations--Asset-Packs) | [Docs](https://github.com/ClaraCrazy/Flipper-Xtreme/wiki) | [Changelog](https://github.com/ClaraCrazy/Flipper-Xtreme#list-of-changes) | [Known bugs](https://github.com/ClaraCrazy/Flipper-Xtreme#Known-bugs) | [Install](https://github.com/ClaraCrazy/Flipper-Xtreme#Install) | [Build](https://github.com/ClaraCrazy/Flipper-Xtreme#build-it-yourself) | [Discord](https://discord.gg/flipper-xtreme) +[Intro](https://github.com/ClaraCrazy/Flipper-Xtreme#What-makes-it-special) | [Animations](https://github.com/ClaraCrazy/Flipper-Xtreme#Animations--Asset-Packs) | [Docs](https://github.com/ClaraCrazy/Flipper-Xtreme/wiki) | [Changelog](https://github.com/ClaraCrazy/Flipper-Xtreme#list-of-changes) | [Known bugs](https://github.com/ClaraCrazy/Flipper-Xtreme/issues?q=is%3Aissue+is%3Aopen+label%3Arelease-pending) | [Install](https://github.com/ClaraCrazy/Flipper-Xtreme#Install) | [Build](https://github.com/ClaraCrazy/Flipper-Xtreme#build-it-yourself) | [Discord](https://discord.gg/flipper-xtreme) ----- This firmware is a complete overhaul of the [Official Firmware](https://github.com/flipperdevices/flipperzero-firmware), it also features lots of awesome code-bits from [Unleashed](https://github.com/DarkFlippers/unleashed-firmware). @@ -147,14 +147,6 @@ Note: This repo is always updated with OFW & Unleashed. No need to mention all t - Tons of unused code from FAPs and system calls ``` ----- -
-

Known Bugs:

- -```txt -- Nothing rn. Hopefully that wont change -``` - ----

Install: