Browse Source

Add uv_meter_as7331 from https://github.com/michaelbaisch/uv_meter

git-subtree-dir: uv_meter_as7331
git-subtree-mainline: 5fed652ef9f9144727e6aa4764feffbddd81347a
git-subtree-split: 4c32e20ca842201191fb77ded98b1c0b8dbc81f0
Michael Baisch 9 months ago
parent
commit
530cc5a132
44 changed files with 4216 additions and 0 deletions
  1. 53 0
      uv_meter_as7331/.github/workflows/build.yml
  2. 7 0
      uv_meter_as7331/.gitignore
  3. 1 0
      uv_meter_as7331/.gitsubtree
  4. 1149 0
      uv_meter_as7331/AS7331.cpp
  5. 731 0
      uv_meter_as7331/AS7331.hpp
  6. 2 0
      uv_meter_as7331/CHANGELOG.md
  7. 37 0
      uv_meter_as7331/DESCRIPTION.md
  8. 674 0
      uv_meter_as7331/LICENSE
  9. 44 0
      uv_meter_as7331/README.md
  10. 16 0
      uv_meter_as7331/application.fam
  11. BIN
      uv_meter_as7331/assets/Alert_9x8.png
  12. BIN
      uv_meter_as7331/assets/ButtonCenter_7x7.png
  13. BIN
      uv_meter_as7331/assets/ButtonLeftSmall_3x5.png
  14. BIN
      uv_meter_as7331/assets/ButtonRightSmall_3x5.png
  15. BIN
      uv_meter_as7331/assets/Glasses_24x8.png
  16. BIN
      uv_meter_as7331/assets/Sun_15x16.png
  17. BIN
      uv_meter_as7331/assets/Sunglasses_24x8.png
  18. BIN
      uv_meter_as7331/assets/Unit_W_m2_22x11.png
  19. BIN
      uv_meter_as7331/assets/Unit_mW_m2_28x11.png
  20. BIN
      uv_meter_as7331/assets/Unit_uW_cm2_34x11.png
  21. BIN
      uv_meter_as7331/assets/Wiring_128x64.png
  22. 0 0
      uv_meter_as7331/images/.gitkeep
  23. BIN
      uv_meter_as7331/images/flipper_with_sensor.jpeg
  24. 30 0
      uv_meter_as7331/scenes/uv_meter_scene.cpp
  25. 29 0
      uv_meter_as7331/scenes/uv_meter_scene.hpp
  26. 41 0
      uv_meter_as7331/scenes/uv_meter_scene_about.cpp
  27. 5 0
      uv_meter_as7331/scenes/uv_meter_scene_config.hpp
  28. 116 0
      uv_meter_as7331/scenes/uv_meter_scene_data.cpp
  29. 49 0
      uv_meter_as7331/scenes/uv_meter_scene_help.cpp
  30. 105 0
      uv_meter_as7331/scenes/uv_meter_scene_settings.cpp
  31. 87 0
      uv_meter_as7331/scenes/uv_meter_scene_wiring.cpp
  32. BIN
      uv_meter_as7331/screenshots/data_1.png
  33. BIN
      uv_meter_as7331/screenshots/data_2.png
  34. BIN
      uv_meter_as7331/screenshots/settings.png
  35. BIN
      uv_meter_as7331/screenshots/wiring.png
  36. BIN
      uv_meter_as7331/uv_meter.png
  37. 115 0
      uv_meter_as7331/uv_meter_app.cpp
  38. 30 0
      uv_meter_as7331/uv_meter_app.hpp
  39. 56 0
      uv_meter_as7331/uv_meter_app_i.hpp
  40. 7 0
      uv_meter_as7331/uv_meter_event.hpp
  41. 693 0
      uv_meter_as7331/views/uv_meter_data.cpp
  42. 46 0
      uv_meter_as7331/views/uv_meter_data.hpp
  43. 78 0
      uv_meter_as7331/views/uv_meter_wiring.cpp
  44. 15 0
      uv_meter_as7331/views/uv_meter_wiring.hpp

+ 53 - 0
uv_meter_as7331/.github/workflows/build.yml

@@ -0,0 +1,53 @@
+name: "UV Meter: Build for multiple SDK sources"
+# This will build your app for dev and release channels on GitHub. 
+# It will also build your app every day to make sure it's up to date with the latest SDK changes.
+# See https://github.com/marketplace/actions/build-flipper-application-package-fap for more information
+
+on:
+  push:
+    branches: 
+      - main 
+  pull_request:
+    branches:
+      - '**'
+  schedule: 
+    # do a build every day
+    - cron: "1 1 * * *"
+
+jobs:
+  ufbt-build:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        include:
+          - name: Official Dev channel
+            sdk-channel: dev
+          - name: Official Release channel
+            sdk-channel: release
+          - name: Unleashed Dev
+            sdk-index-url: https://up.unleashedflip.com/directory.json
+            sdk-channel: dev
+          - name: Unleashed Release
+            sdk-index-url: https://up.unleashedflip.com/directory.json
+            sdk-channel: release
+          - name: Momentum Dev
+            sdk-index-url: https://up.momentum-fw.dev/firmware/directory.json
+            sdk-channel: dev
+          - name: Momentum Release
+            sdk-index-url: https://up.momentum-fw.dev/firmware/directory.json
+            sdk-channel: release
+    name: 'ufbt: Build for ${{ matrix.name }}'
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+      - name: Build with ufbt
+        uses: flipperdevices/flipperzero-ufbt-action@v0.1.3
+        id: build-app
+        with:
+          sdk-channel: ${{ matrix.sdk-channel }}
+          sdk-index-url: ${{ matrix.sdk-index-url }}
+      - name: Upload app artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: ${{ github.event.repository.name }}-${{ steps.build-app.outputs.suffix }}
+          path: ${{ steps.build-app.outputs.fap-artifacts }}

+ 7 - 0
uv_meter_as7331/.gitignore

@@ -0,0 +1,7 @@
+dist/*
+.vscode
+.clang-format
+.clangd
+.editorconfig
+.env
+.ufbt

+ 1 - 0
uv_meter_as7331/.gitsubtree

@@ -0,0 +1 @@
+https://github.com/michaelbaisch/uv_meter main /

+ 1149 - 0
uv_meter_as7331/AS7331.cpp

@@ -0,0 +1,1149 @@
+/**
+ * @file AS7331.cpp
+ * @brief Implementation of AS7331 UV Spectral Sensor Driver
+ */
+
+#include "AS7331.hpp"
+#include <furi_hal_i2c.h>
+#include <furi_hal.h>
+#include <cmath> // For pow()
+
+// Prevent compiler optimization, for debugging.
+// #pragma GCC optimize("O0")
+
+// Timeout value for I2C operations (in milliseconds)
+#define AS7331_I2C_TIMEOUT 100
+
+// Constructor
+AS7331::AS7331(uint8_t i2c_address_7bit)
+    // Convert 7-bit to 8-bit address
+    : _i2c_addr_8bit(i2c_address_7bit << 1)
+    // Initialize to invalid mode to force first-time setup
+    , _deviceMode(static_cast<as7331_device_mode_t>(0x00))
+    , _power_down(true)
+    , _gain(GAIN_2)
+    , _integration_time(TIME_64MS)
+    , _enable_divider(false)
+    , _divider(DIV_2)
+    , _clock_frequency(CCLK_1_024_MHZ)
+    , _standby(false)
+    , _measurement_mode(MEASUREMENT_MODE_COMMAND) {
+}
+
+// Initialize the sensor
+bool AS7331::init(const uint8_t& i2c_address_7bit) {
+    uint8_t detected_address_7bit = 0;
+
+    if(i2c_address_7bit == 0x0) {
+        // Scan I2C bus for AS7331 device
+        detected_address_7bit = scan_i2c_bus();
+        if(detected_address_7bit == 0x0) {
+            FURI_LOG_E(
+                "AS7331",
+                "Failed to find an AS7331 device with one of the four valid addresses on the I2C bus.");
+            return false;
+        }
+    } else {
+        if(deviceReady(i2c_address_7bit)) {
+            detected_address_7bit = i2c_address_7bit;
+        } else {
+            FURI_LOG_E("AS7331", "No device found at I2C address 0x%02X.", i2c_address_7bit);
+            return false;
+        }
+    }
+    // Set the I2C address (7-Bit to 8-Bit)
+    _i2c_addr_8bit = detected_address_7bit << 1;
+
+    // Wake up the device from power-down mode
+    if(!setPowerDown(false)) {
+        FURI_LOG_E("AS7331", "Failed to wake up the device from power-down mode.");
+        return false;
+    }
+
+    // Set the device into configuration mode
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+    bool success = setDeviceMode(DEVICE_MODE_CONFIG);
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+    if(!success) {
+        FURI_LOG_E("AS7331", "Failed to set the device into configuration mode.");
+        return false;
+    }
+
+    // Populate local configuration variables from device registers
+    if(!updateLocalConfig()) {
+        FURI_LOG_E("AS7331", "Failed to read device configuration registers.");
+        return false;
+    }
+
+    // Read the device ID
+    as7331_agen_reg_t deviceID;
+    if(!getDeviceID(deviceID)) {
+        FURI_LOG_E("AS7331", "Failed to read device ID.");
+        return false;
+    }
+    // Compare with expected Device ID
+    if(deviceID.byte != ExpectedAGENContent) {
+        FURI_LOG_E(
+            "AS7331",
+            "Device ID mismatch: expected 0x%02X, got 0x%02X.",
+            ExpectedAGENContent,
+            deviceID.byte);
+        return false;
+    }
+
+    return true;
+}
+
+// Set sensor gain (CREG1:GAIN)
+bool AS7331::setGain(const as7331_gain_t& gain) {
+    if(gain > GAIN_1) {
+        FURI_LOG_E("AS7331", "Invalid gain value: %d.", gain);
+        return false;
+    }
+
+    as7331_creg1_reg_t creg1;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in configuration mode
+    if(!setDeviceMode(DEVICE_MODE_CONFIG)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed set device mode to configuration.");
+        return false;
+    }
+
+    // Read CREG1
+    if(!readRegister(RegCfgCreg1, creg1.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read CREG1 register from device.");
+        return false;
+    }
+
+    // Write new gain value
+    creg1.gain = gain;
+    if(!writeRegister(RegCfgCreg1, creg1.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to write gain value to device: %d.", creg1.gain);
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Update local config
+    _gain = gain;
+
+    return true;
+}
+
+// Set integration time (CREG1:TIME)
+bool AS7331::setIntegrationTime(const as7331_integration_time_t& time) {
+    // Validate integration time value
+    if(time > TIME_16384MS) {
+        FURI_LOG_E("AS7331", "Invalid integration time value: %d.", time);
+        return false;
+    }
+
+    // Automatically set divider depending on ADC resolution to prevent overflow
+    // Since this voids advantages of higher integration times, remove once overflow checking is implemented.
+    /*
+    int adc_resolution;
+    if(time == 15) {
+        // Special case: Same as TIME 0
+        adc_resolution = 10;
+    } else {
+        adc_resolution = 10 + time;
+    }
+    if(adc_resolution > 16) {
+        as7331_divider_t divider = static_cast<as7331_divider_t>(adc_resolution - 17);
+        setDivider(divider, true);
+    } else if(_enable_divider) {
+        setDivider(DIV_2, false);
+    }
+    */
+
+    as7331_creg1_reg_t creg1;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in configuration mode
+    if(!setDeviceMode(DEVICE_MODE_CONFIG)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to configuration.");
+        return false;
+    }
+
+    // Read CREG1
+    if(!readRegister(RegCfgCreg1, creg1.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read CREG1 register from device.");
+        return false;
+    }
+
+    // Write new integration time value
+    creg1.integration_time = time;
+    if(!writeRegister(RegCfgCreg1, creg1.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E(
+            "AS7331",
+            "Failed to write integration time value to device: %d.",
+            creg1.integration_time);
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Update local config
+    _integration_time = time;
+
+    return true;
+}
+
+// Set output divider (CREG2:DIV)
+bool AS7331::setDivider(const as7331_divider_t& divider, const bool enable) {
+    // Validate divider value
+    if(divider > DIV_256) {
+        FURI_LOG_E("AS7331", "Invalid divider value: %d.", divider);
+        return false;
+    }
+
+    as7331_creg2_reg_t creg2;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in configuration mode
+    if(!setDeviceMode(DEVICE_MODE_CONFIG)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to configuration.");
+        return false;
+    }
+
+    // Read CREG2
+    if(!readRegister(RegCfgCreg2, creg2.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read CREG2 register from device.");
+        return false;
+    }
+
+    // Write new divider value and enable/disable it
+    creg2.divider = divider;
+    creg2.enable_divider = enable;
+    if(!writeRegister(RegCfgCreg2, creg2.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E(
+            "AS7331",
+            "Failed to write divider settings to device: DIV=%d, ENABLE=%d.",
+            creg2.divider,
+            creg2.enable_divider);
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Update local config
+    _enable_divider = enable;
+    _divider = divider;
+
+    return true;
+}
+
+// Set clock frequency (CREG3:CCLK)
+bool AS7331::setClockFrequency(const as7331_clock_frequency_t& frequency) {
+    // Validate clock frequency value
+    if(frequency > CCLK_8_192_MHZ) {
+        FURI_LOG_E("AS7331", "Invalid clock frequency value: %d.", frequency);
+        return false;
+    }
+
+    as7331_creg3_reg_t creg3;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in configuration mode
+    if(!setDeviceMode(DEVICE_MODE_CONFIG)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to configuration.");
+        return false;
+    }
+
+    // Read CREG3
+    if(!readRegister(RegCfgCreg3, creg3.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read CREG3 register from device.");
+        return false;
+    }
+
+    // Write new clock frequency value
+    creg3.clock_frequency = frequency;
+    if(!writeRegister(RegCfgCreg3, creg3.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E(
+            "AS7331",
+            "Failed to write clock frequency value to device: %d.",
+            creg3.clock_frequency);
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Update local config
+    _clock_frequency = frequency;
+
+    return true;
+}
+
+// Set measurement mode (CREG3:MMODE)
+bool AS7331::setMeasurementMode(const as7331_measurement_mode_t& mode) {
+    // Validate measurement mode value
+    if(mode > MEASUREMENT_MODE_SYNC_START_END) {
+        FURI_LOG_E("AS7331", "Invalid measurement mode value: %d.", mode);
+        return false;
+    }
+
+    as7331_creg3_reg_t creg3;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in configuration mode
+    if(!setDeviceMode(DEVICE_MODE_CONFIG)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to configuration.");
+        return false;
+    }
+
+    // Read CREG3
+    if(!readRegister(RegCfgCreg3, creg3.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read CREG3 register from device.");
+        return false;
+    }
+
+    // Write new measurement mode value
+    creg3.measurement_mode = mode;
+    if(!writeRegister(RegCfgCreg3, creg3.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E(
+            "AS7331", "Failed to write measurement mode to device: %d.", creg3.measurement_mode);
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Update local config
+    _measurement_mode = mode;
+
+    return true;
+}
+
+// Enable or disable power down state (OSR:PD)
+bool AS7331::setPowerDown(const bool& power_down) {
+    // The power-down feature affects both operational states: configuration and measurement.
+    // When the power-down state is activated while the device is in a measurement cycle,
+    // the power-down action is only executed during the intervals between consecutive conversions.
+
+    // Power Down Current Consumption: max 1µA
+    // Startup Time after Power Down state: 1.2-2ms
+
+    as7331_osr_reg_t osr;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // OSR is accessible in any mode
+    // Read OSR register
+    if(!readOSRRegister(osr)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read OSR register from device.");
+        return false;
+    }
+
+    // Check if the desired power down state is already set
+    if(osr.power_down != power_down) {
+        osr.power_down = power_down; // Set PD bit
+
+        // Write back the OSR register
+        // Local configuration (_power_down) is updated in writeOSRRegister
+        if(!writeOSRRegister(osr)) {
+            furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+            FURI_LOG_E("AS7331", "Failed to write power down state to device: %d.", power_down);
+            return false;
+        }
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    return true;
+}
+
+// Put the sensor in standby mode or wake it up (CREG3:SB)
+bool AS7331::setStandby(const bool& standby) {
+    // Standby Current Consumption: max 970 µA
+    // Startup Time after Standby state: 4-5 µs
+
+    as7331_creg3_reg_t creg3;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in configuration mode
+    if(!setDeviceMode(DEVICE_MODE_CONFIG)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to configuration.");
+        return false;
+    }
+
+    // Read CREG3
+    if(!readRegister(RegCfgCreg3, creg3.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read CREG3 register from device.");
+        return false;
+    }
+
+    // Check if the desired standby state is already set
+    if(creg3.standby != standby) {
+        creg3.standby = standby; // Set SB bit
+
+        // Write back the CREG3 register
+        if(!writeRegister(RegCfgCreg3, creg3.byte)) {
+            furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+            FURI_LOG_E("AS7331", "Failed to write standby state to device: %d.", standby);
+            return false;
+        }
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Update local config
+    _standby = standby;
+
+    return true;
+}
+
+// Start the measurement (OSR:SS = 1)
+bool AS7331::startMeasurement() {
+    as7331_osr_reg_t osr;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in measurement mode
+    if(!setDeviceMode(DEVICE_MODE_MEASURE)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to measurement.");
+        return false;
+    }
+
+    // Read OSR register
+    if(!readOSRRegister(osr)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read OSR register from device.");
+        return false;
+    }
+
+    // Check if measurement is already started
+    if(osr.start_state != 1) {
+        osr.start_state = 1; // Set SS bit to start measurement
+
+        // Write back OSR register
+        if(!writeOSRRegister(osr)) {
+            furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+            FURI_LOG_E("AS7331", "Failed to write OSR register to start measurement.");
+            return false;
+        }
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    return true;
+}
+
+// Stop the measurement (OSR:SS = 0)
+bool AS7331::stopMeasurement() {
+    as7331_osr_reg_t osr;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Read OSR register
+    if(!readOSRRegister(osr)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read OSR register from device.");
+        return false;
+    }
+
+    // Check if measurement is already stopped
+    if(osr.start_state != 0) {
+        osr.start_state = 0; // Clear SS bit to stop measurement
+
+        // Write back OSR register
+        if(!writeOSRRegister(osr)) {
+            furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+            FURI_LOG_E("AS7331", "Failed to write OSR register to stop measurement.");
+            return false;
+        }
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    return true;
+}
+
+// Wait for measurement to complete based on conversion time
+void AS7331::waitForMeasurement() {
+    double TCONV = getConversionTime();
+
+    if(TCONV > 0) {
+        // Wait for TCONV time, adding a small buffer
+        furi_delay_ms(static_cast<uint32_t>(TCONV * 1000) + 1); // Add 1 ms to ensure completion
+    }
+}
+
+// Get raw measurement results
+bool AS7331::getRawResults(RawResults& rawResults) {
+    uint8_t buffer[6]; // Each result is 2 bytes, so 3 results * 2 bytes = 6 bytes
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in measurement mode
+    if(!setDeviceMode(DEVICE_MODE_MEASURE)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to measurement.");
+        return false;
+    }
+
+    // Read all measurement results in one I²C transaction
+    if(!readRegisters(RegMeasResultA, buffer, 6)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read measurement results from device.");
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Combine the bytes into 16-bit values (LSB first)
+    rawResults.uv_a = (static_cast<uint16_t>(buffer[1]) << 8) | buffer[0];
+    rawResults.uv_b = (static_cast<uint16_t>(buffer[3]) << 8) | buffer[2];
+    rawResults.uv_c = (static_cast<uint16_t>(buffer[5]) << 8) | buffer[4];
+
+    return true;
+}
+
+// Get processed measurement results with raw data
+bool AS7331::getResults(Results& results, RawResults& rawResults) {
+    bool success = true;
+
+    // Get the raw measurement results
+    success &= getRawResults(rawResults);
+
+    if(!success) {
+        return false;
+    }
+
+    // Calculate FSREe for each channel
+    double FSREe_A = calculateFSREe(UV_A, false);
+    double FSREe_B = calculateFSREe(UV_B, false);
+    double FSREe_C = calculateFSREe(UV_C, false);
+    FURI_LOG_I("AS7331", "FSREe_A: %f", FSREe_B);
+    FURI_LOG_I("AS7331", "FSREe_B: %f", FSREe_C);
+    FURI_LOG_I("AS7331", "FSREe_C: %f", FSREe_C);
+
+    if(FSREe_A < 0 || FSREe_B < 0 || FSREe_C < 0) {
+        // Invalid FSREe calculation
+        return false;
+    }
+
+    // Adjust FSREe for clock frequency
+    // Since FSREe is inversely proportional to fCLK,
+    // we adjust FSREe by dividing by the clock frequency ratio
+    double fCLK_ratio = static_cast<double>(1 << _clock_frequency); // fCLK_actual / fCLK_base
+
+    FSREe_A /= fCLK_ratio;
+    FSREe_B /= fCLK_ratio;
+    FSREe_C /= fCLK_ratio;
+
+    // Get NCLK from TIME_code
+    uint32_t NCLK;
+    if(_integration_time == 15) {
+        NCLK = 1024;
+    } else if(_integration_time <= 14) {
+        NCLK = 1 << (10 + _integration_time);
+    } else {
+        return false; // Invalid TIME_code
+    }
+
+    // Adjust NCLK and FSREe for Divider if enabled
+    if(_enable_divider) {
+        int divider_factor = 1 << (_divider + 1); // Divider factor is 2^(DIV + 1)
+        NCLK /= divider_factor; // Adjust NCLK
+        // Alternatively, we could adjust MRES, but adjusting NCLK is equivalent and simpler
+    }
+
+    // Calculate LSB for each channel
+    double LSB_A = FSREe_A / NCLK;
+    double LSB_B = FSREe_B / NCLK;
+    double LSB_C = FSREe_C / NCLK;
+
+    // Calculate Ee (Irradiance in µW/cm²) for each channel
+    results.uv_a = rawResults.uv_a * LSB_A;
+    results.uv_b = rawResults.uv_b * LSB_B;
+    results.uv_c = rawResults.uv_c * LSB_C;
+
+    return true;
+}
+
+// Get processed measurement results
+bool AS7331::getResults(Results& results) {
+    RawResults rawResults; // Temporary variable
+    return getResults(results, rawResults); // Call the core function
+}
+
+// Read temperature measurement (16-bit)
+bool AS7331::getTemperature(double& temperature) {
+    uint16_t temperature_raw;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in measurement mode
+    if(!setDeviceMode(DEVICE_MODE_MEASURE)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to measurement.");
+        return false;
+    }
+
+    // Read temperature register
+    if(!readRegister16(RegMeasTemp, temperature_raw)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read temperature register from device.");
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Calculate temperature in Celsius (Datasheet p. 42)
+    temperature = temperature_raw * 0.05 - 66.9; // [°C]
+
+    return true;
+}
+
+// Check if the device is ready
+bool AS7331::deviceReady(const uint8_t& i2c_address_7bit) {
+    uint8_t i2c_address_8bit;
+
+    if(i2c_address_7bit == 0) {
+        i2c_address_8bit = _i2c_addr_8bit;
+    } else {
+        i2c_address_8bit = i2c_address_7bit << 1; // Convert 7-bit to 8-bit address
+    }
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    bool ready = furi_hal_i2c_is_device_ready(
+        &furi_hal_i2c_handle_external, i2c_address_8bit, AS7331_I2C_TIMEOUT);
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    return ready;
+}
+
+// Perform a software reset (OSR:SW_RES = 1)
+bool AS7331::reset() {
+    // Setting SW_RES to '1' triggers a software reset of the AS7331.
+    as7331_osr_reg_t osr;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // OSR is accessible in any mode
+    if(!readOSRRegister(osr)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read OSR register from device.");
+        return false;
+    }
+
+    osr.software_reset = 1; // Set SW_RES bit
+
+    if(!writeOSRRegister(osr)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to write OSR register to reset device.");
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    // Update local configuration variables from device registers
+    _deviceMode = DEVICE_MODE_CONFIG;
+    if(!updateLocalConfig()) {
+        FURI_LOG_E("AS7331", "Failed to read device configuration registers.");
+        return false;
+    }
+
+    return true;
+}
+
+// Getter methods
+
+// Read device ID (including mutation number)
+bool AS7331::getDeviceID(as7331_agen_reg_t& deviceID) {
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    if(!readRegister(RegCfgAgen, deviceID.byte)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read device ID register from device.");
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    return true;
+}
+
+// Read status register in measurement mode
+bool AS7331::getStatus(as7331_osr_status_reg_t& status) {
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in measurement mode
+    if(!setDeviceMode(DEVICE_MODE_MEASURE)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to set device mode to measurement.");
+        return false;
+    }
+
+    if(!readRegister16(RegMeasOsrStatus, status.word)) {
+        furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+        FURI_LOG_E("AS7331", "Failed to read status register from device.");
+        return false;
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    return true;
+}
+
+// Local config getter methods
+
+// Getter for gain code
+as7331_gain_t AS7331::getGain() const {
+    return _gain;
+}
+
+// Getter for actual gain value
+int16_t AS7331::getGainValue() const {
+    // Gain value is calculated using the formula: gain = 2^(11 - gain_code)
+    return 1 << (11 - _gain);
+}
+
+// Getter for integration time code
+as7331_integration_time_t AS7331::getIntegrationTime() const {
+    return _integration_time;
+}
+
+// Get conversion time in seconds
+double AS7331::getConversionTime() const {
+    // Base clock frequency is 1.024 MHz
+    double fCLK_base = 1.024e6; // Hz
+
+    // Actual clock frequency based on CCLK code
+    double fCLK = fCLK_base * (1 << _clock_frequency);
+
+    // Calculate NCLK based on TIME code
+    uint32_t NCLK; // Number of clock cycles within conversion time
+    if(_integration_time == 15) {
+        NCLK = 1024; // Special case: Same as TIME 0
+    } else if(_integration_time <= 14) {
+        NCLK = 1 << (10 + _integration_time);
+    } else {
+        // Invalid TIME code
+        return -1.0;
+    }
+
+    // Conversion time TCONV
+    double TCONV = static_cast<double>(NCLK) / fCLK; // in seconds
+
+    return TCONV;
+}
+
+// Getter for divider code
+as7331_divider_t AS7331::getDivider() const {
+    return _divider;
+}
+
+// Getter for divider enabled state
+bool AS7331::isDividerEnabled() const {
+    return _enable_divider;
+}
+
+// Getter for actual divider value
+uint8_t AS7331::getDividerValue() const {
+    // Divider value is calculated using the formula: divider = 2^(1 + divider_code)
+    uint8_t divider_value = 1 << (1 + _divider);
+    return divider_value;
+}
+
+// Getter for clock frequency code
+as7331_clock_frequency_t AS7331::getClockFrequency() const {
+    return _clock_frequency;
+}
+
+// Getter for actual clock frequency value
+double AS7331::getClockFrequencyValue() const {
+    // Clock frequency is calculated using the formula: fCLK = 1.024 * 2^clock_frequency_code (in MHz)
+    uint32_t freq_multiplier = 1 << _clock_frequency; // 2^clock_frequency_code
+    double clock_frequency_value = 1.024 * freq_multiplier; // in MHz
+    return clock_frequency_value;
+}
+
+// Getter for measurement mode
+as7331_measurement_mode_t AS7331::getMeasurementMode() const {
+    return _measurement_mode;
+}
+
+// Getter for power down state
+bool AS7331::isPowerDown() const {
+    return _power_down;
+}
+
+// Getter for standby state
+bool AS7331::isStandby() const {
+    return _standby;
+}
+
+// Internal helper methods
+
+// Set the device mode
+bool AS7331::setDeviceMode(const as7331_device_mode_t& mode) {
+    if(mode != DEVICE_MODE_CONFIG && mode != DEVICE_MODE_MEASURE) {
+        FURI_LOG_E("AS7331", "Invalid device mode value: %d.", mode);
+        return false;
+    }
+    if(_deviceMode == mode) {
+        return true; // Already in desired mode
+    }
+
+    // Read OSR register
+    as7331_osr_reg_t osr;
+    if(!readOSRRegister(osr)) {
+        FURI_LOG_E("AS7331", "Failed to read OSR register from device.");
+        return false;
+    }
+
+    // Set operating state (DOS bits)
+    osr.operating_state = mode;
+
+    // If transitioning to Measurement state, ensure power-down is disabled
+    if(mode == DEVICE_MODE_MEASURE) {
+        osr.power_down = 0;
+    }
+
+    // Write back OSR register
+    // '_deviceMode' is updated in writeOSRRegister
+    if(!writeOSRRegister(osr)) {
+        FURI_LOG_E("AS7331", "Failed to write OSR register to set device mode.");
+        return false;
+    }
+
+    return true;
+}
+
+// Read OSR register and update local config
+bool AS7331::readOSRRegister(as7331_osr_reg_t& osr) {
+    if(!readRegister(RegCfgOsr, osr.byte)) {
+        FURI_LOG_E("AS7331", "Failed to read OSR Register from device.");
+        return false;
+    }
+
+    if(osr.operating_state != DEVICE_MODE_CONFIG && osr.operating_state != DEVICE_MODE_MEASURE) {
+        FURI_LOG_E(
+            "AS7331", "Invalid operating state value read from device: %d.", osr.operating_state);
+        return false;
+    }
+
+    // Update local config
+    _deviceMode = osr.operating_state;
+    _power_down = osr.power_down;
+
+    return true;
+}
+
+// Write OSR register and update local config
+bool AS7331::writeOSRRegister(const as7331_osr_reg_t& osr) {
+    if(osr.operating_state != DEVICE_MODE_CONFIG && osr.operating_state != DEVICE_MODE_MEASURE) {
+        FURI_LOG_E("AS7331", "Invalid device mode value: %d.", osr.operating_state);
+        return false;
+    }
+
+    // Write back OSR register
+    if(!writeRegister(RegCfgOsr, osr.byte)) {
+        FURI_LOG_E("AS7331", "Failed to write OSR to device: %d.", osr.byte);
+        return false;
+    }
+
+    // Update local config
+    _deviceMode = osr.operating_state;
+    _power_down = osr.power_down;
+
+    return true;
+}
+
+// Generalized method to read multiple bytes from consecutive registers
+bool AS7331::readRegisters(uint8_t start_register_addr, uint8_t* buffer, size_t length) {
+    bool success;
+
+    // Write Phase: Send the start register address, end with AwaitRestart
+    success = furi_hal_i2c_tx_ext(
+        &furi_hal_i2c_handle_external,
+        _i2c_addr_8bit,
+        false, // 7-bit address
+        &start_register_addr,
+        1,
+        FuriHalI2cBeginStart,
+        FuriHalI2cEndAwaitRestart, // Prepare for repeated start
+        AS7331_I2C_TIMEOUT);
+    if(!success) {
+        FURI_LOG_E("AS7331", "Failed to send start register address");
+        return false;
+    }
+
+    // Read Phase: Read the data, begin with Restart, end with Stop
+    success = furi_hal_i2c_rx_ext(
+        &furi_hal_i2c_handle_external,
+        _i2c_addr_8bit,
+        false, // 7-bit address
+        buffer,
+        length,
+        FuriHalI2cBeginRestart, // Repeated start
+        FuriHalI2cEndStop,
+        AS7331_I2C_TIMEOUT);
+    if(!success) {
+        FURI_LOG_E("AS7331", "Failed to read data");
+        return false;
+    }
+
+    return true;
+}
+
+// Function to read an 8-bit register
+bool AS7331::readRegister(uint8_t register_addr, uint8_t& data) {
+    return readRegisters(register_addr, &data, 1);
+}
+
+// Function to read a 16-bit register
+bool AS7331::readRegister16(uint8_t register_addr, uint16_t& data) {
+    uint8_t buffer[2];
+    bool success = readRegisters(register_addr, buffer, 2);
+    if(!success) {
+        return false;
+    }
+
+    // Combine the two bytes into a 16-bit value (LSB first)
+    data = (static_cast<uint16_t>(buffer[1]) << 8) | buffer[0];
+
+    return true;
+}
+
+// Function to write an 8-bit register
+bool AS7331::writeRegister(uint8_t register_addr, const uint8_t& data) {
+    bool success;
+    uint8_t buffer[2] = {register_addr, data};
+
+    // Write the register address and data in one transaction
+    success = furi_hal_i2c_tx_ext(
+        &furi_hal_i2c_handle_external,
+        _i2c_addr_8bit,
+        false, // 7-bit address
+        buffer,
+        2,
+        FuriHalI2cBeginStart,
+        FuriHalI2cEndStop,
+        AS7331_I2C_TIMEOUT);
+    if(!success) {
+        FURI_LOG_E("AS7331", "Failed to write data");
+        return false;
+    }
+
+    return true;
+}
+
+// Scan I2C bus for AS7331 device
+uint8_t AS7331::scan_i2c_bus() {
+    uint8_t addr_found = 0; // Will hold the address if found
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Iterate through possible I2C addresses
+    for(uint8_t addr_7bit = DefaultI2CAddr; addr_7bit <= QuaternaryI2CAddr; addr_7bit++) {
+        uint8_t addr_8bit = addr_7bit << 1;
+
+        // Check for device readiness
+        if(furi_hal_i2c_is_device_ready(
+               &furi_hal_i2c_handle_external, addr_8bit, AS7331_I2C_TIMEOUT)) {
+            addr_found = addr_7bit;
+            break;
+        }
+    }
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    if(addr_found == 0) {
+        FURI_LOG_E("AS7331", "No AS7331 device found on I²C bus.");
+    }
+
+    return addr_found;
+}
+
+// Update local configuration variables from device registers
+bool AS7331::updateLocalConfig() {
+    bool success = true;
+    as7331_creg1_reg_t creg1;
+    as7331_creg2_reg_t creg2;
+    as7331_creg3_reg_t creg3;
+
+    furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
+
+    // Ensure we are in configuration mode
+    success &= setDeviceMode(DEVICE_MODE_CONFIG);
+
+    // Read configuration registers
+    success &= readRegister(RegCfgCreg1, creg1.byte);
+    success &= readRegister(RegCfgCreg2, creg2.byte);
+    success &= readRegister(RegCfgCreg3, creg3.byte);
+
+    furi_hal_i2c_release(&furi_hal_i2c_handle_external);
+
+    if(!success) {
+        FURI_LOG_E("AS7331", "Failed to read configuration registers.");
+        return false;
+    }
+
+    // Validate and populate local configuration variables
+    if(creg1.gain <= GAIN_1) {
+        _gain = static_cast<as7331_gain_t>(creg1.gain);
+    } else {
+        FURI_LOG_E("AS7331", "Invalid gain value read from device: %d.", creg1.gain);
+        return false;
+    }
+
+    if(creg1.integration_time <= TIME_16384MS) {
+        _integration_time = static_cast<as7331_integration_time_t>(creg1.integration_time);
+    } else {
+        FURI_LOG_E(
+            "AS7331",
+            "Invalid integration time value read from device: %d.",
+            creg1.integration_time);
+        return false;
+    }
+
+    _enable_divider = creg2.enable_divider;
+
+    if(creg2.divider <= DIV_256) {
+        _divider = static_cast<as7331_divider_t>(creg2.divider);
+    } else {
+        FURI_LOG_E("AS7331", "Invalid divider value read from device: %d.", creg2.divider);
+        return false;
+    }
+
+    if(creg3.clock_frequency <= CCLK_8_192_MHZ) {
+        _clock_frequency = static_cast<as7331_clock_frequency_t>(creg3.clock_frequency);
+    } else {
+        FURI_LOG_E(
+            "AS7331",
+            "Invalid clock frequency value read from device: %d.",
+            creg3.clock_frequency);
+        return false;
+    }
+
+    _standby = creg3.standby;
+
+    if(creg3.measurement_mode <= MEASUREMENT_MODE_SYNC_START_END) {
+        _measurement_mode = static_cast<as7331_measurement_mode_t>(creg3.measurement_mode);
+    } else {
+        FURI_LOG_E(
+            "AS7331",
+            "Invalid measurement mode value read from device: %d.",
+            creg3.measurement_mode);
+        return false;
+    }
+
+    // _deviceMode and _power_down is updated in readOSRRegister()/writeOSRRegister()
+
+    return true;
+}
+
+/**
+ * @brief Calculates the Full-Scale Range irradiance (FSREe) for a given UV type.
+ *
+ * This function computes the FSREe, which is the maximum detectable irradiance (Ee) that the sensor can measure without saturating the ADC, based on the selected GAIN settings. Optionally, it can adjust FSREe for the integration TIME setting.
+ *
+ * **Definitions:**
+ * - **FSR (FSREe in equations)**: Full-Scale Range—the maximum detectable irradiance (Ee) the sensor can measure without saturating the ADC, given the selected GAIN (and optionally TIME) settings.
+ * - **LSB**: Least Significant Bit—the smallest change in irradiance that the sensor can detect with the selected settings. In the datasheet, it's given in nW/cm², but here we calculate it in µW/cm² (same as FSREe).
+ * - **NCLK**: Number of clock cycles during the conversion.
+ * - **MRES**: ADC count. The most straightforward way to get Ee is:
+ *   - *Ee = MRES × LSB* (ADC count times the value of a single step)
+ * - **LSB Calculation**:
+ *   - *LSB = FSR / NCLK*
+ *
+ * **Note:**
+ * - Both LSB and FSR depend on the clock frequency (fCLK); the tables in the datasheet assume an fCLK of 1.024 MHz.
+ * - When calculating LSB, FSREe should **not** be adjusted for integration TIME, as higher TIME values increase the resolution beyond 16 bits, and only the least 16 bits are stored in the result registers.
+ *
+ * @param uvType The type of UV measurement (UV_A, UV_B, or UV_C).
+ * @param adjustForIntegrationTime Optional. A boolean flag indicating whether to adjust FSREe for the integration TIME setting. Default is `true`.
+ * @return The calculated FSREe value in µW/cm², or `-1.0` if an error occurs.
+ */
+double AS7331::calculateFSREe(as7331_uv_type_t uvType, bool adjustForIntegrationTime) {
+    // Base FSREe at GAIN = 1x for each channel, from datasheet (p.32 - p.38)
+    double FSREe_gain1;
+    switch(uvType) {
+    case UV_A: // Channel A
+        FSREe_gain1 = 348160.0; // µW/cm² at GAIN=1x, TIME code 6
+        break;
+    case UV_B: // Channel B
+        FSREe_gain1 = 387072.0; // µW/cm² at GAIN=1x, TIME code 6
+        break;
+    case UV_C: // Channel C
+        FSREe_gain1 = 169984.0; // µW/cm² at GAIN=1x, TIME code 3
+        break;
+    default:
+        // Invalid UV type
+        return -1.0;
+    }
+
+    // Calculate the actual gain value
+    int GAIN_value = getGainValue();
+    if(GAIN_value <= 0) {
+        return -1.0; // Invalid GAIN
+    }
+
+    // Calculate the base FSREe for the current gain setting
+    double FSREe = FSREe_gain1 / GAIN_value;
+
+    if(adjustForIntegrationTime) {
+        // Adjust FSREe for integration TIME
+        if(uvType == UV_A || uvType == UV_B) {
+            if(_integration_time <= 6) {
+                // No adjustment needed for TIME codes 0-6
+            } else if(_integration_time <= 14) {
+                // For each TIME code above 6, FSREe halves
+                int time_diff = _integration_time - 6;
+                FSREe /= (1 << time_diff); // FSREe /= 2^(TIME_code - 6)
+            } else if(_integration_time == 15) {
+                // Special case: TIME code 15 is equivalent to TIME code 0
+                // No adjustment needed
+            } else {
+                return -1.0; // Invalid TIME code
+            }
+        } else if(uvType == UV_C) {
+            if(_integration_time <= 3) {
+                // No adjustment needed for TIME codes 0-3
+            } else if(_integration_time <= 7) {
+                // Divide FSREe by 2
+                FSREe /= 2;
+            } else if(_integration_time <= 14) {
+                // For each TIME code above 7, FSREe halves
+                int time_diff = _integration_time - 7;
+                FSREe /= (1 << time_diff); // FSREe /= 2^(TIME_code - 3)
+            } else if(_integration_time == 15) {
+                // Special case: TIME code 15 is equivalent to TIME code 0
+                // No adjustment needed
+            } else {
+                return -1.0; // Invalid TIME code
+            }
+        }
+    }
+
+    return FSREe;
+}

+ 731 - 0
uv_meter_as7331/AS7331.hpp

@@ -0,0 +1,731 @@
+/**
+ * @file AS7331.hpp
+ * @brief UV Spectral Sensor - AS7331 Driver
+ *
+ * This driver provides a communication interface for the AS7331 UV spectral sensor.
+ * It includes configurations for I2C addressing, device modes, gain, clock frequency,
+ * and measurement settings.
+ *
+ * Inspired by: https://github.com/sparkfun/SparkFun_AS7331_Arduino_Library/blob/main/src/sfeAS7331.h
+ * Datasheet: https://look.ams-osram.com/m/1856fd2c69c35605/original/AS7331-Spectral-UVA-B-C-Sensor.pdf
+ */
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <furi_hal_i2c_types.h>
+
+/**
+ * @defgroup AS7331_I2C_Addressing I2C Addressing
+ * @brief I2C address definitions for AS7331
+ *
+ * The 7-bit I2C address is defined as [1, 1, 1, 0, 1, A1, A0], where A1 and A0 are configurable address pins.
+ * @{
+ */
+
+/** Default I2C address when A1 = 0, A0 = 0 */
+const uint8_t DefaultI2CAddr = 0x74;
+
+/** Secondary I2C address when A1 = 0, A0 = 1 */
+const uint8_t SecondaryI2CAddr = 0x75;
+
+/** Tertiary I2C address when A1 = 1, A0 = 0 */
+const uint8_t TertiaryI2CAddr = 0x76;
+
+/** Quaternary I2C address when A1 = 1, A0 = 1 */
+const uint8_t QuaternaryI2CAddr = 0x77;
+
+/** Expected API Generation Register content (Device ID + Mutation number) */
+const uint8_t ExpectedAGENContent = 0x21;
+
+/** @} */ // End of AS7331_I2C_Addressing group
+
+/**
+ * @defgroup AS7331_Enums Enumerations
+ * @brief Enumerations for AS7331 settings
+ * @{
+ */
+
+/**
+ * @brief Device Operating Modes
+ */
+enum as7331_device_mode_t : uint8_t {
+    DEVICE_MODE_CONFIG = 0x2, /**< Configuration mode */
+    DEVICE_MODE_MEASURE = 0x3 /**< Measurement mode */
+};
+
+/**
+ * @brief Sensor Gain Settings (CREG1:GAIN)
+ *
+ * Default: GAIN_2 (1010)
+ *
+ * Gain value is calculated as:  
+ * **gain = 2<sup>(11 - gain_code)</sup>**
+ */
+enum as7331_gain_t : uint8_t {
+    GAIN_2048 = 0x0000,
+    GAIN_1024,
+    GAIN_512,
+    GAIN_256,
+    GAIN_128,
+    GAIN_64,
+    GAIN_32,
+    GAIN_16,
+    GAIN_8,
+    GAIN_4,
+    GAIN_2,
+    GAIN_1
+};
+
+/**
+ * @brief Integration Time Settings (CREG1:TIME)
+ *
+ * Default: TIME_64MS (0110)
+ *
+ * The conversion time in the enumerators (in milliseconds) is valid for a clock frequency of 1.024 MHz.
+ * For higher clock frequencies, the conversion time is divided by 2 each time the clock frequency is doubled.
+ *
+ * **Conversion Time [ms] = 2<sup>integration_time_code</sup>**
+ */
+enum as7331_integration_time_t : uint8_t {
+    TIME_1MS = 0x0,
+    TIME_2MS,
+    TIME_4MS,
+    TIME_8MS,
+    TIME_16MS,
+    TIME_32MS,
+    TIME_64MS,
+    TIME_128MS,
+    TIME_256MS,
+    TIME_512MS,
+    TIME_1024MS,
+    TIME_2048MS,
+    TIME_4096MS,
+    TIME_8192MS,
+    TIME_16384MS
+};
+
+/**
+ * @brief Divider Settings (CREG2:DIV)
+ *
+ * Default: DIV_2 (000)
+ *
+ * Divider value is calculated as:  
+ * **divider = 2<sup>(1 + divider_code)</sup>**
+ */
+enum as7331_divider_t : uint8_t {
+    DIV_2 = 0x0,
+    DIV_4,
+    DIV_8,
+    DIV_16,
+    DIV_32,
+    DIV_64,
+    DIV_128,
+    DIV_256
+};
+
+/**
+ * @brief Internal Clock Frequency Settings fCLK (CREG3:CCLK)
+ *
+ * Default: CCLK_1_024_MHZ
+ *
+ * Clock frequency is calculated as:  
+ * **clock_frequency = 1.024 × 2<sup>clock_frequency_code</sup>** (in MHz)
+ */
+enum as7331_clock_frequency_t : uint8_t {
+    CCLK_1_024_MHZ = 0x00, /**< 1.024 MHz: 1 - 16384 ms (Conversion Time) */
+    CCLK_2_048_MHZ,
+    CCLK_4_096_MHZ,
+    CCLK_8_192_MHZ /**< 8.192 MHz: 0.125 - 2048 ms (Conversion Time) */
+};
+
+/**
+ * @brief Measurement Modes (CREG3:MMODE)
+ *
+ * Default: MEASUREMENT_MODE_COMMAND (01)
+ */
+enum as7331_measurement_mode_t : uint8_t {
+    MEASUREMENT_MODE_CONTINUOUS = 0x0, /**< Continuous Measurement Mode (CONT) */
+    MEASUREMENT_MODE_COMMAND, /**< Command Measurement Mode (CMD) */
+    MEASUREMENT_MODE_SYNC_START, /**< Synchronous Measurement Mode (SYNS) - externally synchronized start of measurement */
+    MEASUREMENT_MODE_SYNC_START_END /**< Synchronous Measurement Start and End Mode (SYND) - start and end of measurement are externally synchronized */
+};
+
+/** @brief UV Type Selection */
+enum as7331_uv_type_t : uint8_t {
+    UV_A,
+    UV_B,
+    UV_C
+};
+
+/** @} */ // End of AS7331_Enums group
+
+/**
+ * @defgroup AS7331_Config_Registers Configuration Register Definitions
+ * @brief Definitions for configuration registers
+ *
+ * Registers are 8 bits long and can only be accessed in the configuration mode.
+ * @{
+ */
+
+/** @brief OSR configuration register address */
+const uint8_t RegCfgOsr = 0x00;
+
+/**
+ * @brief Operational State Register (OSR) Register Layout
+ */
+typedef union {
+    struct {
+        as7331_device_mode_t
+            operating_state    : 3; /**< DOS (010) - Device Operating State (OSR[2:0]) */
+        uint8_t software_reset : 1; /**< SW_RES (0) - Software Reset (OSR[3]) */
+        uint8_t reserved       : 2; /**< Reserved, do not write (OSR[5:4]) */
+        uint8_t power_down     : 1; /**< PD (1) - Power Down (OSR[6]) */
+        uint8_t start_state    : 1; /**< SS (0) - Start State (OSR[7]) */
+    };
+    uint8_t byte;
+} as7331_osr_reg_t;
+
+/** @brief AGEN register address */
+const uint8_t RegCfgAgen = 0x02;
+
+/**
+ * @brief AGEN Register Layout
+ */
+typedef union {
+    struct {
+        uint8_t
+            mutation : 4; /**< MUT (0001) - Mutation number of control register bank. Incremented when control registers change (AGEN[3:0]) */
+        uint8_t device_id : 4; /**< DEVID (0010) - Device ID number (AGEN[7:4]) */
+    };
+    uint8_t byte;
+} as7331_agen_reg_t;
+
+/** @brief CREG1 -- Configuration Register 1 address */
+const uint8_t RegCfgCreg1 = 0x06;
+
+/**
+ * @brief CREG1 Register Layout
+ */
+typedef union {
+    struct {
+        as7331_integration_time_t
+            integration_time : 4; /**< TIME (0110) - Integration time (CREG1[3:0]) */
+        as7331_gain_t gain   : 4; /**< GAIN (1010) - Sensor gain (CREG1[7:4]) */
+    };
+    uint8_t byte;
+} as7331_creg1_reg_t;
+
+/** @brief CREG2 -- Configuration Register 2 address */
+const uint8_t RegCfgCreg2 = 0x07;
+
+/**
+ * @brief CREG2 Register Layout
+ */
+typedef union {
+    struct {
+        as7331_divider_t divider : 3; /**< DIV (000) - Divider value (CREG2[2:0]) */
+        uint8_t enable_divider   : 1; /**< EN_DIV (0) - Divider enable (CREG2[3]) */
+        uint8_t reserved         : 2; /**< Reserved, do not write (CREG2[5:4]) */
+        uint8_t
+            enable_temp : 1; /**< EN_TM (1) - Temperature measurement enable in SYND mode (CREG2[6]) */
+        uint8_t reserved1 : 1; /**< Reserved, do not write (CREG2[7]) */
+    };
+    uint8_t byte;
+} as7331_creg2_reg_t;
+
+/** @brief CREG3 -- Configuration Register 3 address */
+const uint8_t RegCfgCreg3 = 0x08;
+
+/**
+ * @brief CREG3 Register Layout
+ */
+typedef union {
+    struct {
+        as7331_clock_frequency_t
+            clock_frequency : 2; /**< CCLK (00) - Internal clock frequency (CREG3[1:0]) */
+        uint8_t reserved    : 1; /**< Reserved, do not write (CREG3[2]) */
+        uint8_t ready_mode  : 1; /**< RDYOD (0) - Ready pin mode (CREG3[3]) */
+        uint8_t standby     : 1; /**< SB (0) - Standby mode (CREG3[4]) */
+        uint8_t reserved1   : 1; /**< Reserved, do not write (CREG3[5]) */
+        as7331_measurement_mode_t
+            measurement_mode : 2; /**< MMODE (01) - Measurement mode selection (CREG3[7:6]) */
+    };
+    uint8_t byte;
+} as7331_creg3_reg_t;
+
+/** @brief BREAK register address */
+const uint8_t RegCfgBreak =
+    0x09; /**< BREAK (0x19) - Break time TBREAK between two measurements (except CMD mode) */
+
+/** @brief EDGES register address */
+const uint8_t RegCfgEdges = 0x0A; /**< EDGES (0x1) - Number of SYN falling edges */
+
+/** @brief OPTREG - Option Register address */
+const uint8_t RegCfgOptReg = 0x0B;
+
+/**
+ * @brief OPTREG Register Layout
+ */
+typedef union {
+    struct {
+        uint8_t init_idx : 1; /**< INIT_IDX (1) - I2C repeat start mode flag (OPTREG[0]) */
+        uint8_t reserved : 7; /**< Reserved, do not write (OPTREG[7:1]) */
+    };
+    uint8_t byte;
+} as7331_optreg_reg_t;
+
+/** @} */ // End of AS7331_Config_Registers group
+
+/**
+ * @defgroup AS7331_Measurement_Registers Measurement Register Definitions
+ * @brief Definitions for measurement registers
+ *
+ * Registers are 16 bits long and read-only, except for the lower byte of the OSR/STATUS register.
+ * @{
+ */
+
+/** @brief OSR/Status register address */
+const uint8_t RegMeasOsrStatus = 0x00;
+
+/**
+ * @brief OSR/STATUS Register Layout
+ */
+typedef union {
+    struct {
+        as7331_osr_reg_t osr; /**< OSR settings (lower byte) (OSRSTAT[7:0]) */
+        uint8_t power_state   : 1; /**< POWERSTATE - Power Down state (OSRSTAT[8]) */
+        uint8_t standby_state : 1; /**< STANDBYSTATE - Standby mode state (OSRSTAT[9]) */
+        uint8_t not_ready     : 1; /**< NOTREADY - Inverted ready pin state (OSRSTAT[10]) */
+        uint8_t new_data      : 1; /**< NDATA - New data available (OSRSTAT[11]) */
+        uint8_t lost_data     : 1; /**< LDATA - Data overwritten before retrieval (OSRSTAT[12]) */
+        uint8_t adc_overflow  : 1; /**< ADCOF - Overflow of ADC channel (OSRSTAT[13]) */
+        uint8_t result_overflow : 1; /**< MRESOF - Overflow of MRES1...MRES3 (OSRSTAT[14]) */
+        uint8_t
+            out_conv_overflow : 1; /**< OUTCONVOF - Overflow of internal 24-bit OUTCONV (OSRSTAT[15]) */
+    };
+    uint16_t word;
+} as7331_osr_status_reg_t;
+
+/** @brief TEMP register address (12-bit temperature, MS 4 bits are 0) */
+const uint8_t RegMeasTemp = 0x01;
+
+/** @brief MRES1 register address - Measurement Result A */
+const uint8_t RegMeasResultA = 0x02;
+
+/** @brief MRES2 register address - Measurement Result B */
+const uint8_t RegMeasResultB = 0x03;
+
+/** @brief MRES3 register address - Measurement Result C */
+const uint8_t RegMeasResultC = 0x04;
+
+/** @brief OUTCONVL register address - First 16 bits of 24-bit OUTCONV */
+const uint8_t RegMeasOutConvL = 0x05;
+
+/** @brief OUTCONVH register address - Upper 8 bits of OUTCONV, MSB is 0 */
+const uint8_t RegMeasOutConvH = 0x06;
+
+/** @} */ // End of AS7331_Measurement_Registers group
+
+/**
+ * @brief AS7331 UV Spectral Sensor Driver
+ *
+ * This class provides an interface for the AS7331 UV spectral sensor,
+ * allowing configuration and measurement.
+ */
+class AS7331 {
+public:
+    /** @brief Struct to hold raw measurement results */
+    struct RawResults {
+        uint16_t uv_a; /**< Raw measurement for UV-A channel */
+        uint16_t uv_b; /**< Raw measurement for UV-B channel */
+        uint16_t uv_c; /**< Raw measurement for UV-C channel */
+    };
+
+    /** @brief Struct to hold processed measurement results */
+    struct Results {
+        double uv_a; /**< Irradiance for UV-A in µW/cm² */
+        double uv_b; /**< Irradiance for UV-B in µW/cm² */
+        double uv_c; /**< Irradiance for UV-C in µW/cm² */
+    };
+
+    /**
+     * @brief Constructs an AS7331 sensor object
+     *
+     * @param address I2C address of the sensor (default is DefaultI2CAddr)
+     */
+    AS7331(uint8_t address = DefaultI2CAddr);
+
+    /**
+     * @brief Initialize the sensor
+     *
+     * @param address I2C address in 7-bit format. If 0x0, scan the I2C bus to find the device.
+     * @return true if initialization is successful, false otherwise
+     */
+    bool init(const uint8_t& address = 0);
+
+    // Configuration methods
+
+    /**
+     * @brief Set sensor gain (CREG1:GAIN)
+     *
+     * @param gain Gain setting from as7331_gain_t
+     * @return true if successful, false otherwise
+     */
+    bool setGain(const as7331_gain_t& gain);
+
+    /**
+     * @brief Set integration time (CREG1:TIME)
+     *
+     * @param time Integration time setting from as7331_integration_time_t
+     * @return true if successful, false otherwise
+     */
+    bool setIntegrationTime(const as7331_integration_time_t& time);
+
+    /**
+     * @brief Set output divider (CREG2:DIV)
+     *
+     * @param divider Divider setting from as7331_divider_t
+     * @param enable Enable or disable the divider
+     * @return true if successful, false otherwise
+     */
+    bool setDivider(const as7331_divider_t& divider, const bool enable = true);
+
+    /**
+     * @brief Set clock frequency (CREG3:CCLK)
+     *
+     * @param freq Clock frequency setting from as7331_clock_frequency_t
+     * @return true if successful, false otherwise
+     */
+    bool setClockFrequency(const as7331_clock_frequency_t& freq);
+
+    /**
+     * @brief Set measurement mode (CREG3:MMODE)
+     *
+     * @param mode Measurement mode setting from as7331_measurement_mode_t
+     * @return true if successful, false otherwise
+     */
+    bool setMeasurementMode(const as7331_measurement_mode_t& mode);
+
+    // Power management
+
+    /**
+     * @brief Enable or disable power-down state (OSR:PD)
+     *
+     * @param power_down true to enable power-down, false to disable
+     * @return true if successful, false otherwise
+     */
+    bool setPowerDown(const bool& power_down);
+
+    /**
+     * @brief Enable or disable standby mode (CREG3:SB)
+     *
+     * @param standby true to enable standby, false to disable
+     * @return true if successful, false otherwise
+     */
+    bool setStandby(const bool& standby);
+
+    // Measurement methods
+
+    /**
+     * @brief Start the measurement (OSR:SS = 1)
+     *
+     * @return true if successful, false otherwise
+     */
+    bool startMeasurement();
+
+    /**
+     * @brief Stop the measurement (OSR:SS = 0)
+     *
+     * @return true if successful, false otherwise
+     */
+    bool stopMeasurement();
+
+    /**
+     * @brief Wait for the measurement to complete based on conversion time
+     */
+    void waitForMeasurement();
+
+    /**
+     * @brief Get raw measurement results
+     *
+     * Before reading results, wait an appropriate amount of time for the measurement to complete (TCONV).
+     *
+     * @param rawResults Struct to hold raw measurement results
+     * @return true if successful, false otherwise
+     */
+    bool getRawResults(RawResults& rawResults);
+
+    /**
+     * @brief Get processed measurement results
+     *
+     * Before reading results, wait an appropriate amount of time for the measurement to complete (TCONV).
+     *
+     * @param results Struct to hold processed measurement results
+     * @param rawResults Struct to hold raw measurement results
+     * @return true if successful, false otherwise
+     */
+    bool getResults(Results& results, RawResults& rawResults);
+
+    /**
+     * @brief Get processed measurement results
+     *
+     * Before reading results, wait an appropriate amount of time for the measurement to complete (TCONV).
+     *
+     * @param results Struct to hold processed measurement results
+     * @return true if successful, false otherwise
+     */
+    bool getResults(Results& results);
+
+    /**
+     * @brief Get temperature measurement
+     *
+     * Before reading results, wait an appropriate amount of time for the measurement to complete (TCONV).
+     *
+     * @param temperature Temperature in degrees Celsius
+     * @return true if successful, false otherwise
+     */
+    bool getTemperature(double& temperature);
+
+    // Utility methods
+
+    /**
+     * @brief Check if the device is ready
+     *
+     * @param i2c_address_7bit I2C address in 7-bit format (default uses internal address)
+     * @return true if device is ready, false otherwise
+     */
+    bool deviceReady(const uint8_t& i2c_address_7bit = 0);
+
+    /**
+     * @brief Perform a software reset
+     *
+     * This immediately stops any running measurements and resets the device to its configuration state,
+     * with all registers reverting to their initial values.
+     *
+     * @return true if the reset was successful, false otherwise
+     */
+    bool reset();
+
+    // Getter methods
+
+    /**
+     * @brief Get device ID (including mutation number)
+     *
+     * @param deviceID Struct to hold device ID
+     * @return true if successful, false otherwise
+     */
+    bool getDeviceID(as7331_agen_reg_t& deviceID);
+
+    /**
+     * @brief Get status register in measurement mode
+     *
+     * @param status Struct to hold status register data
+     * @return true if successful, false otherwise
+     */
+    bool getStatus(as7331_osr_status_reg_t& status);
+
+    // Local config getter methods
+
+    /**
+     * @brief Get current gain setting
+     *
+     * @return Current gain setting as as7331_gain_t
+     */
+    as7331_gain_t getGain() const;
+
+    /**
+     * @brief Get actual gain value
+     *
+     * @return Gain value as integer
+     */
+    int16_t getGainValue() const;
+
+    /**
+     * @brief Get current integration time setting
+     *
+     * @return Current integration time as as7331_integration_time_t
+     */
+    as7331_integration_time_t getIntegrationTime() const;
+
+    /**
+     * @brief Get current conversion time in seconds
+     *
+     * @return Conversion time in seconds
+     */
+    double getConversionTime() const;
+
+    /**
+     * @brief Get current divider setting
+     *
+     * @return Current divider setting as as7331_divider_t
+     */
+    as7331_divider_t getDivider() const;
+
+    /**
+     * @brief Check if divider is enabled
+     *
+     * @return true if divider is enabled, false otherwise
+     */
+    bool isDividerEnabled() const;
+
+    /**
+     * @brief Get actual divider value
+     *
+     * @return Divider value as integer
+     */
+    uint8_t getDividerValue() const;
+
+    /**
+     * @brief Get current clock frequency setting
+     *
+     * @return Current clock frequency as as7331_clock_frequency_t
+     */
+    as7331_clock_frequency_t getClockFrequency() const;
+
+    /**
+     * @brief Get actual clock frequency value
+     *
+     * @return Clock frequency in MHz
+     */
+    double getClockFrequencyValue() const;
+
+    /**
+     * @brief Get current measurement mode
+     *
+     * @return Current measurement mode as as7331_measurement_mode_t
+     */
+    as7331_measurement_mode_t getMeasurementMode() const;
+
+    /**
+     * @brief Check if power-down is enabled
+     *
+     * @return true if power-down is enabled, false otherwise
+     */
+    bool isPowerDown() const;
+
+    /**
+     * @brief Check if standby mode is enabled
+     *
+     * @return true if standby is enabled, false otherwise
+     */
+    bool isStandby() const;
+
+private:
+    // Internal helper methods
+
+    /**
+     * @brief Set the device mode
+     *
+     * @param mode Device mode to set
+     * @return true if successful, false otherwise
+     */
+    bool setDeviceMode(const as7331_device_mode_t& mode);
+
+    /**
+     * @brief Read OSR register and update local config
+     *
+     * @param osr Struct to hold OSR register data
+     * @return true if successful, false otherwise
+     */
+    bool readOSRRegister(as7331_osr_reg_t& osr);
+
+    /**
+     * @brief Write OSR register and update local config
+     *
+     * @param osr OSR register data to write
+     * @return true if successful, false otherwise
+     */
+    bool writeOSRRegister(const as7331_osr_reg_t& osr);
+
+    /**
+     * @defgroup AS7331_I2C_Methods AS7331 Custom I2C Methods
+     * @brief Custom I2C read and write functions for the AS7331 sensor.
+     *
+     * These functions utilize a "repeated start" condition instead of terminating each transaction with a STOP condition, as required by the AS7331.
+     * This is achieved using `FuriHalI2cEndAwaitRestart` and `FuriHalI2cBeginRestart`, despite their documentation referring to "Clock Stretching," which the AS7331 does not support.
+     *
+     * @note The caller is responsible for calling `furi_hal_i2c_acquire` and `furi_hal_i2c_release`.
+     * @{
+     */
+
+    /**
+     * @brief Read multiple bytes from consecutive registers
+     *
+     * @param start_register_addr Starting register address
+     * @param buffer Buffer to store read data
+     * @param length Number of bytes to read
+     * @return true if successful, false otherwise
+     * @ingroup AS7331_I2C_Methods
+     */
+    bool readRegisters(uint8_t start_register_addr, uint8_t* buffer, size_t length);
+
+    /**
+     * @brief Read an 8-bit register
+     *
+     * @param register_addr Register address to read
+     * @param data Variable to store read data
+     * @return true if successful, false otherwise
+     * @ingroup AS7331_I2C_Methods
+     */
+    bool readRegister(uint8_t register_addr, uint8_t& data);
+
+    /**
+     * @brief Read a 16-bit register
+     *
+     * @param register_addr Register address to read
+     * @param data Variable to store read data
+     * @return true if successful, false otherwise
+     * @ingroup AS7331_I2C_Methods
+     */
+    bool readRegister16(uint8_t register_addr, uint16_t& data);
+
+    /**
+     * @brief Write an 8-bit register
+     *
+     * @param register_addr Register address to write
+     * @param data Data to write
+     * @return true if successful, false otherwise
+     * @ingroup AS7331_I2C_Methods
+     */
+    bool writeRegister(uint8_t register_addr, const uint8_t& data);
+
+    /** @} */ // End of AS7331_I2C_Methods group
+
+    /**
+     * @brief Scan I2C bus for AS7331 device
+     *
+     * @return Found I2C address in 7-bit format, 0 if not found
+     */
+    uint8_t scan_i2c_bus();
+
+    /**
+     * @brief Update local configuration variables from device registers
+     *
+     * @return true if successful, false otherwise
+     */
+    bool updateLocalConfig();
+
+    /**
+     * @brief Calculate Full-Scale Range (FSREe) for a given UV type
+     *
+     * @param uvType UV type (UV_A, UV_B, UV_C)
+     * @param adjustForIntegrationTime Optional. A boolean flag indicating whether to adjust FSREe for the integration TIME setting. Default is `true`.
+     * @return FSREe value in µW/cm², `-1.0` if an error occurs
+     */
+    double calculateFSREe(as7331_uv_type_t uvType, bool adjustForIntegrationTime = true);
+
+    // Private member variables
+    uint8_t _i2c_addr_8bit;
+    as7331_device_mode_t _deviceMode;
+    bool _power_down;
+    as7331_gain_t _gain; /**< Gain code (0 to 11) */
+    as7331_integration_time_t _integration_time; /**< Integration time code (0 to 15) */
+    bool _enable_divider; /**< Divider enabled (CREG2:EN_DIV) */
+    as7331_divider_t _divider; /**< Divider value (CREG2:DIV) */
+    as7331_clock_frequency_t _clock_frequency; /**< Clock frequency code (0 to 3) */
+    bool _standby;
+    as7331_measurement_mode_t _measurement_mode;
+};

+ 2 - 0
uv_meter_as7331/CHANGELOG.md

@@ -0,0 +1,2 @@
+v1.0:
+Initial Release

+ 37 - 0
uv_meter_as7331/DESCRIPTION.md

@@ -0,0 +1,37 @@
+# UV Meter
+
+Application designed to measure ultraviolet (UV) radiation levels using the [AS7331](https://ams-osram.com/products/sensor-solutions/ambient-light-color-spectral-proximity-sensors/ams-as7331-spectral-uv-sensor) sensor. It supports individual measurements for UV-A, UV-B, and UV-C wavelengths. The easiest way to hook everything up is to use a breakout board, such as the one from [SparkFun](https://www.sparkfun.com/sparkfun-spectral-uv-sensor-as7331-qwiic.html).
+
+
+## Wiring
+
+Connect the AS7331 sensor to your Flipper Zero via I²C:
+
+| Sensor Pin | Flipper Zero Pin   |
+|------------|--------------------|
+| **SCL**    | C0 \[pin 16\]        |
+| **SDA**    | C1 \[pin 15\]        |
+| **3V3**    | 3V3 \[pin 9\]        |
+| **GND**    | GND \[pin 11 or 18\] |
+
+By default, the application scans all possible I²C addresses for the sensor. However, you can manually set a specific address in the settings menu, accessible by pressing the **Enter** button.
+
+
+## Usage
+
+Once connected, the application automatically displays real-time UV measurements. The main screen shows individual UV-A, UV-B, and UV-C readings. Beneath the numbers you see the currently used unit (µW/cm², W/m² or mW/m²).
+
+Next to each UV reading is a small meter indicating the raw sensor value. If this value is too high or too low, a warning symbol will appear, signaling potential sensor overexposure or underexposure. This condition will probably result in unreliable measurements. Adjusting the **Gain** and **Exposure Time** settings (similar to camera ISO and shutter speed) at the bottom of the screen can help correct this.
+
+In addition to direct sensor measurements, the application provides an interpretation of this irradiance data on human safety, displayed on the right side of the screen. The time (in minutes) indicates the recommended maximum daily exposure duration during an 8-hour work shift, based on the 2024 Threshold Limit Values (TLVs) and Biological Exposure Indices (BEIs) published by the [American Conference of Governmental Industrial Hygienists (ACGIH)](https://en.wikipedia.org/wiki/American_Conference_of_Governmental_Industrial_Hygienists).
+
+Since UV radiation poses greater risks to the eyes, the app includes a setting to specify whether your eyes are protected. This adjusts the maximum daily exposure duration according to ACGIH recommendations.
+
+The displayed percentages indicate how much each UV type (UV-A, UV-B, UV-C) contributes to the maximum daily exposure. This helps illustrate that higher sensor readings don't necessarily mean a greater health risk; for example, even though UV-A sensor values are typically higher, they usually contribute less to the recommended maximum exposure limit compared to UV-B or UV-C.
+
+When following the maximum daily exposure duration, the TLV/BEI guidelines ensure: “\[…\] nearly all healthy workers may be repeatedly exposed without acute adverse health effects such as erythema and photokeratitis.”
+
+
+## Disclaimer
+
+This application is provided for informational purposes only and should not be used as a sole basis for safety-critical decisions. Always follow official guidelines, regulations, and professional advice regarding UV exposure. The developer assumes no responsibility for any damages, injuries, or consequences arising from decisions or actions based on the information provided by this application.

+ 674 - 0
uv_meter_as7331/LICENSE

@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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 <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

+ 44 - 0
uv_meter_as7331/README.md

@@ -0,0 +1,44 @@
+# UV Meter
+
+A Flipper Zero application designed to measure ultraviolet (UV) radiation levels using the [AS7331](https://ams-osram.com/products/sensor-solutions/ambient-light-color-spectral-proximity-sensors/ams-as7331-spectral-uv-sensor) sensor. It supports individual measurements for UV-A, UV-B, and UV-C wavelengths. The easiest way to hook everything up is to use a breakout board, such as the one from [SparkFun](https://www.sparkfun.com/sparkfun-spectral-uv-sensor-as7331-qwiic.html).
+
+![wiring](images/flipper_with_sensor.jpeg)
+
+## Wiring
+
+Connect the AS7331 sensor to your Flipper Zero via I²C:
+
+![wiring](screenshots/wiring.png)
+
+| Sensor Pin | Flipper Zero Pin   |
+|------------|--------------------|
+| **SCL**    | C0 [pin 16]        |
+| **SDA**    | C1 [pin 15]        |
+| **3V3**    | 3V3 [pin 9]        |
+| **GND**    | GND [pin 11 or 18] |
+
+By default, the application scans all possible I²C addresses for the sensor. However, you can manually set a specific address in the settings menu, accessible by pressing the **Enter** button.
+
+
+## Usage
+
+Once connected, the application automatically displays real-time UV measurements. The main screen shows individual UV-A, UV-B, and UV-C readings. Beneath the numbers you see the currently used unit (µW/cm², W/m² or mW/m²).
+
+![wiring](screenshots/data_1.png)
+
+Next to each UV reading is a small meter indicating the raw sensor value. If this value is too high or too low, a warning symbol will appear, signaling potential sensor overexposure or underexposure. This condition will probably result in unreliable measurements. Adjusting the **Gain** and **Exposure Time** settings (similar to camera ISO and shutter speed) at the bottom of the screen can help correct this.
+
+In addition to direct sensor measurements, the application provides an interpretation of this irradiance data on human safety, displayed on the right side of the screen. The time (in minutes) indicates the recommended maximum daily exposure duration during an 8-hour work shift, based on the 2024 Threshold Limit Values (TLVs) and Biological Exposure Indices (BEIs) published by the [American Conference of Governmental Industrial Hygienists (ACGIH)](https://en.wikipedia.org/wiki/American_Conference_of_Governmental_Industrial_Hygienists).
+
+Since UV radiation poses greater risks to the eyes, the app includes a setting to specify whether your eyes are protected. This adjusts the maximum daily exposure duration according to ACGIH recommendations.
+
+The displayed percentages indicate how much each UV type (UV-A, UV-B, UV-C) contributes to the maximum daily exposure. This helps illustrate that higher sensor readings don't necessarily mean a greater health risk; for example, even though UV-A sensor values are typically higher, they usually contribute less to the recommended maximum exposure limit compared to UV-B or UV-C.
+
+When following the maximum daily exposure duration, the TLV/BEI guidelines ensure:
+
+> “[...] nearly all healthy workers may be repeatedly exposed without acute adverse health effects such as erythema and photokeratitis.”
+
+
+## Disclaimer
+
+This application is provided for informational purposes only and should not be used as a sole basis for safety-critical decisions. Always follow official guidelines, regulations, and professional advice regarding UV exposure. The developer assumes no responsibility for any damages, injuries, or consequences arising from decisions or actions based on the information provided by this application.

+ 16 - 0
uv_meter_as7331/application.fam

@@ -0,0 +1,16 @@
+App(
+    appid="uv_meter_as7331",
+    name="UV Meter",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="uv_meter_app",
+    requires=["gui"],
+    stack_size=2 * 1024,
+    fap_category="GPIO",
+    sources=["*.c*", "!documentation"],
+    fap_version="1.0",
+    fap_icon="uv_meter.png",
+    fap_description="Measure UV radiation using the AS7331 sensor",
+    fap_author="Michael Baisch",
+    fap_weburl="https://github.com/michaelbaisch/uv_meter",
+    fap_icon_assets="assets",
+)

BIN
uv_meter_as7331/assets/Alert_9x8.png


BIN
uv_meter_as7331/assets/ButtonCenter_7x7.png


BIN
uv_meter_as7331/assets/ButtonLeftSmall_3x5.png


BIN
uv_meter_as7331/assets/ButtonRightSmall_3x5.png


BIN
uv_meter_as7331/assets/Glasses_24x8.png


BIN
uv_meter_as7331/assets/Sun_15x16.png


BIN
uv_meter_as7331/assets/Sunglasses_24x8.png


BIN
uv_meter_as7331/assets/Unit_W_m2_22x11.png


BIN
uv_meter_as7331/assets/Unit_mW_m2_28x11.png


BIN
uv_meter_as7331/assets/Unit_uW_cm2_34x11.png


BIN
uv_meter_as7331/assets/Wiring_128x64.png


+ 0 - 0
uv_meter_as7331/images/.gitkeep


BIN
uv_meter_as7331/images/flipper_with_sensor.jpeg


+ 30 - 0
uv_meter_as7331/scenes/uv_meter_scene.cpp

@@ -0,0 +1,30 @@
+#include "uv_meter_scene.hpp"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
+void (*const uv_meter_scene_on_enter_handlers[])(void*) = {
+#include "uv_meter_scene_config.hpp"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
+bool (*const uv_meter_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
+#include "uv_meter_scene_config.hpp"
+};
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
+void (*const uv_meter_scene_on_exit_handlers[])(void* context) = {
+#include "uv_meter_scene_config.hpp"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers uv_meter_scene_handlers = {
+    .on_enter_handlers = uv_meter_scene_on_enter_handlers,
+    .on_event_handlers = uv_meter_scene_on_event_handlers,
+    .on_exit_handlers = uv_meter_scene_on_exit_handlers,
+    .scene_num = UVMeterSceneNum,
+};

+ 29 - 0
uv_meter_as7331/scenes/uv_meter_scene.hpp

@@ -0,0 +1,29 @@
+#pragma once
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(prefix, name, id) UVMeterScene##id,
+typedef enum {
+#include "uv_meter_scene_config.hpp"
+    UVMeterSceneNum,
+} UVMeterScene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers uv_meter_scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
+#include "uv_meter_scene_config.hpp"
+#undef ADD_SCENE
+
+// Generate scene on_event handlers declaration
+#define ADD_SCENE(prefix, name, id) \
+    bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
+#include "uv_meter_scene_config.hpp"
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
+#include "uv_meter_scene_config.hpp"
+#undef ADD_SCENE

+ 41 - 0
uv_meter_as7331/scenes/uv_meter_scene_about.cpp

@@ -0,0 +1,41 @@
+#include "uv_meter_app_i.hpp"
+
+#define UV_METER_VERSION_APP FAP_VERSION
+#define UV_METER_DEVELOPER "Michael Baisch"
+#define UV_METER_GITHUB "https://github.com/michaelbaisch/uv_meter"
+#define UV_METER_NAME "\e#\e!             UV Meter             \e!\n"
+#define UV_METER_BLANK_INV "\e#\e!                                                      \e!\n"
+
+void uv_meter_scene_about_on_enter(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    widget_reset(app->widget);
+    FuriString* tmp_string = furi_string_alloc();
+
+    widget_add_text_box_element(
+        app->widget, 0, 0, 128, 14, AlignCenter, AlignBottom, UV_METER_BLANK_INV, false);
+    widget_add_text_box_element(
+        app->widget, 0, 2, 128, 14, AlignCenter, AlignBottom, UV_METER_NAME, false);
+    furi_string_printf(tmp_string, "\e#Information\n");
+    furi_string_cat_printf(tmp_string, "Version: %s\n", UV_METER_VERSION_APP);
+    furi_string_cat_printf(tmp_string, "Developed by: %s\n", UV_METER_DEVELOPER);
+    furi_string_cat_printf(tmp_string, "Github: %s\n\n", UV_METER_GITHUB);
+    furi_string_cat_str(tmp_string, "\e#Description\n");
+    furi_string_cat_str(tmp_string, "Measure UV radiation using\n");
+    furi_string_cat_str(tmp_string, "the AS7331 sensor.\n");
+    widget_add_text_scroll_element(app->widget, 0, 16, 128, 50, furi_string_get_cstr(tmp_string));
+
+    furi_string_free(tmp_string);
+    view_dispatcher_switch_to_view(app->view_dispatcher, UVMeterViewWidget);
+}
+
+bool uv_meter_scene_about_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return false;
+}
+void uv_meter_scene_about_on_exit(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    widget_reset(app->widget);
+}

+ 5 - 0
uv_meter_as7331/scenes/uv_meter_scene_config.hpp

@@ -0,0 +1,5 @@
+ADD_SCENE(uv_meter, wiring, Wiring)
+ADD_SCENE(uv_meter, data, Data)
+ADD_SCENE(uv_meter, settings, Settings)
+ADD_SCENE(uv_meter, about, About)
+ADD_SCENE(uv_meter, help, Help)

+ 116 - 0
uv_meter_as7331/scenes/uv_meter_scene_data.cpp

@@ -0,0 +1,116 @@
+#include "uv_meter_app_i.hpp"
+#include "uv_meter_event.hpp"
+
+#include <gui/view_dispatcher.h>
+
+/**
+ * @brief Start a new measurement
+ *
+ * Initializes a new measurement and updates the measurement state.
+ *
+ * @param app_state Pointer to the shared app_state
+ */
+static void start_measurement(UVMeterAppState* app_state) {
+    // Start measurement
+    app_state->as7331.setMeasurementMode(MEASUREMENT_MODE_COMMAND);
+    app_state->as7331.startMeasurement();
+}
+
+/**
+ * @brief Process the measurement results
+ *
+ * Retrieves the measurement results and updates the application state.
+ *
+ * @param app Pointer to the app
+ */
+static void process_measurement_results(UVMeterApp* app) {
+    if(app->app_state->as7331.getResults(app->app_state->results, app->app_state->raw_results)) {
+        FURI_LOG_D(
+            "UV_Meter Data",
+            "Irradiance UVA: %.2f µW/cm² UVB: %.2f µW/cm² UVC: %.2f µW/cm²",
+            app->app_state->results.uv_a,
+            app->app_state->results.uv_b,
+            app->app_state->results.uv_c);
+        uv_meter_data_set_results(
+            app->uv_meter_data_view, &app->app_state->results, &app->app_state->raw_results);
+    } else {
+        FURI_LOG_E("UV_Meter Data", "Failed to get measurement results");
+    }
+}
+
+static void uv_meter_scene_data_enter_settings_callback(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    view_dispatcher_send_custom_event(app->view_dispatcher, UVMeterCustomEventSceneEnterSettings);
+}
+
+void uv_meter_scene_data_on_enter(void* context) {
+    auto* app = static_cast<UVMeterApp*>(context);
+
+    uv_meter_update_from_sensor(app->uv_meter_data_view);
+    uv_meter_data_set_unit(app->uv_meter_data_view, app->app_state->unit);
+
+    uv_meter_data_set_enter_settings_callback(
+        app->uv_meter_data_view, uv_meter_scene_data_enter_settings_callback, app);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, UVMeterViewData);
+}
+
+bool uv_meter_scene_data_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UVMeterCustomEventSceneEnterSettings) {
+            scene_manager_next_scene(app->scene_manager, UVMeterSceneSettings);
+            consumed = true;
+        }
+
+    } else if(event.type == SceneManagerEventTypeTick) {
+        furi_mutex_acquire(app->app_state->as7331_mutex, FuriWaitForever);
+
+        // Check if sensor got disconnected
+        if(!app->app_state->as7331_initialized || !app->app_state->as7331.deviceReady()) {
+            app->app_state->as7331_initialized = false;
+            scene_manager_search_and_switch_to_previous_scene(
+                app->scene_manager, UVMeterSceneWiring);
+        } else {
+            // Getting the status will put sensor into measurement state
+            as7331_osr_status_reg_t status;
+            app->app_state->as7331.getStatus(status);
+            // Check if measurement is complete
+            if(status.new_data) {
+                process_measurement_results(app);
+                start_measurement(app->app_state);
+            }
+            // This happens when measurement was interrupted by changing settings
+            else if(status.osr.start_state != 1) {
+                start_measurement(app->app_state);
+            }
+            // Handle overflows
+            if(status.adc_overflow || status.result_overflow || status.out_conv_overflow) {
+                FURI_LOG_E(
+                    "UV Meter Data",
+                    "Overflow detected! ADCOF (%d) MRESOF (%d) OUTCONVOF (%d)",
+                    status.adc_overflow,
+                    status.result_overflow,
+                    status.out_conv_overflow);
+            }
+        }
+        consumed = true;
+        furi_mutex_release(app->app_state->as7331_mutex);
+
+    } else if(event.type == SceneManagerEventTypeBack) {
+        // Always quit app in data scene
+        scene_manager_stop(app->scene_manager);
+        view_dispatcher_stop(app->view_dispatcher);
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void uv_meter_scene_data_on_exit(void* context) {
+    UNUSED(context);
+}

+ 49 - 0
uv_meter_as7331/scenes/uv_meter_scene_help.cpp

@@ -0,0 +1,49 @@
+#include "uv_meter_app_i.hpp"
+
+void uv_meter_scene_help_on_enter(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    widget_reset(app->widget);
+    FuriString* tmp_string = furi_string_alloc();
+
+    furi_string_cat_str(tmp_string, "\e#Wiring:\n");
+    furi_string_cat_str(
+        tmp_string,
+        "  SCL: 16 [C0]\n"
+        "  SDA: 15 [C1]\n"
+        "  3V3: 9 [3V3]\n"
+        "  GND: 11 or 18 [GND]\n");
+    furi_string_cat_str(tmp_string, "\e#Usage:\n");
+    furi_string_cat_str(
+        tmp_string,
+        "Main UV values shown with\n"
+        "raw value meters beside.\n"
+        "Avoid low/high warnings by\n"
+        "adjusting Gain/Exposure.\n"
+        "Right side: Max daily safe\n"
+        "UV exposure (minutes per\n"
+        "8h day).\n"
+        "Percentages indicates each\n"
+        "UV type's contribution.\n");
+    furi_string_cat_str(
+        tmp_string,
+        "\e#Disclaimer\n"
+        "Info provided as-is;\n"
+        "not liable for usage.\n");
+
+    widget_add_text_scroll_element(app->widget, 0, 0, 128, 64, furi_string_get_cstr(tmp_string));
+
+    furi_string_free(tmp_string);
+    view_dispatcher_switch_to_view(app->view_dispatcher, UVMeterViewWidget);
+}
+
+bool uv_meter_scene_help_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return false;
+}
+void uv_meter_scene_help_on_exit(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    widget_reset(app->widget);
+}

+ 105 - 0
uv_meter_as7331/scenes/uv_meter_scene_settings.cpp

@@ -0,0 +1,105 @@
+#include "uv_meter_app_i.hpp"
+#include "uv_meter_event.hpp"
+
+static const char* i2c_addresses[] = {
+    [UVMeterI2CAddressAuto] = "Auto",
+    [UVMeterI2CAddress74] = "0x74",
+    [UVMeterI2CAddress75] = "0x75",
+    [UVMeterI2CAddress76] = "0x76",
+    [UVMeterI2CAddress77] = "0x77",
+};
+
+static const char* units[] = {
+    [UVMeterUnituW_cm_2] = "uW/cm2",
+    [UVMeterUnitW_m_2] = "W/m2",
+    [UVMeterUnitmW_m_2] = "mW/m2",
+};
+
+static void i2c_address_change_callback(VariableItem* item) {
+    UVMeterApp* app = static_cast<UVMeterApp*>(variable_item_get_context(item));
+    uint8_t index = variable_item_get_current_value_index(item);
+
+    variable_item_set_current_value_text(item, i2c_addresses[index]);
+
+    app->app_state->i2c_address = static_cast<UVMeterI2CAddress>(index);
+}
+
+static void unit_change_callback(VariableItem* item) {
+    UVMeterApp* app = static_cast<UVMeterApp*>(variable_item_get_context(item));
+    uint8_t index = variable_item_get_current_value_index(item);
+
+    variable_item_set_current_value_text(item, units[index]);
+
+    app->app_state->unit = static_cast<UVMeterUnit>(index);
+}
+
+static void enter_callback(void* context, uint32_t index) {
+    auto* app = static_cast<UVMeterApp*>(context);
+    switch(index) {
+    // Update indices when adding new setting items
+    case 2:
+        scene_manager_handle_custom_event(app->scene_manager, UVMeterCustomEventSceneEnterHelp);
+        break;
+    case 3:
+        scene_manager_handle_custom_event(app->scene_manager, UVMeterCustomEventSceneEnterAbout);
+        break;
+    default:
+        break;
+    }
+}
+
+void uv_meter_scene_settings_on_enter(void* context) {
+    auto* app = static_cast<UVMeterApp*>(context);
+    variable_item_list_reset(app->variable_item_list);
+    VariableItem* item;
+
+    item = variable_item_list_add(
+        app->variable_item_list,
+        "I2C Address",
+        COUNT_OF(i2c_addresses),
+        i2c_address_change_callback,
+        app);
+    variable_item_set_current_value_index(item, app->app_state->i2c_address);
+    variable_item_set_current_value_text(item, i2c_addresses[app->app_state->i2c_address]);
+
+    item = variable_item_list_add(
+        app->variable_item_list, "Unit", COUNT_OF(units), unit_change_callback, app);
+    variable_item_set_current_value_index(item, app->app_state->unit);
+    variable_item_set_current_value_text(item, units[app->app_state->unit]);
+
+    // Be aware when adding new items before "Help" to change index in `enter_callback()`
+    variable_item_list_add(app->variable_item_list, "Help", 0, NULL, NULL);
+    variable_item_list_add(app->variable_item_list, "About", 0, NULL, NULL);
+
+    variable_item_list_set_enter_callback(app->variable_item_list, enter_callback, app);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, UVMeterViewVariableItemList);
+}
+
+bool uv_meter_scene_settings_on_event(void* context, SceneManagerEvent event) {
+    auto* app = static_cast<UVMeterApp*>(context);
+    bool consumed = false;
+
+    switch(event.type) {
+    case SceneManagerEventTypeCustom:
+        switch(event.event) {
+        case UVMeterCustomEventSceneEnterHelp:
+            scene_manager_next_scene(app->scene_manager, UVMeterSceneHelp);
+            consumed = true;
+            break;
+        case UVMeterCustomEventSceneEnterAbout:
+            scene_manager_next_scene(app->scene_manager, UVMeterSceneAbout);
+            consumed = true;
+            break;
+        }
+        break;
+    default:
+        break;
+    }
+    return consumed;
+}
+
+void uv_meter_scene_settings_on_exit(void* context) {
+    auto* app = static_cast<UVMeterApp*>(context);
+    variable_item_list_reset(app->variable_item_list);
+}

+ 87 - 0
uv_meter_as7331/scenes/uv_meter_scene_wiring.cpp

@@ -0,0 +1,87 @@
+#include "uv_meter_app_i.hpp"
+#include "uv_meter_event.hpp"
+
+static void uv_meter_scene_wiring_enter_settings_callback(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    view_dispatcher_send_custom_event(app->view_dispatcher, UVMeterCustomEventSceneEnterSettings);
+}
+
+void uv_meter_scene_wiring_on_enter(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+
+    uv_meter_wiring_set_enter_settings_callback(
+        app->uv_meter_wiring_view, uv_meter_scene_wiring_enter_settings_callback, app);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, UVMeterViewWiring);
+}
+
+bool uv_meter_scene_wiring_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UVMeterCustomEventSceneEnterSettings) {
+            scene_manager_next_scene(app->scene_manager, UVMeterSceneSettings);
+            consumed = true;
+        }
+    } else if(event.type == SceneManagerEventTypeTick) {
+        uint32_t current_time = furi_get_tick();
+
+        // Check once per second if AS7331 sensor is available
+        if(current_time - app->app_state->last_sensor_check_timestamp >= furi_ms_to_ticks(1000)) {
+            furi_mutex_acquire(app->app_state->as7331_mutex, FuriWaitForever);
+
+            if(!app->app_state->as7331_initialized) {
+                // Initialize the sensor, also wake it up if in power down mode
+                uint8_t i2c_address = 0x0;
+                switch(app->app_state->i2c_address) {
+                case UVMeterI2CAddressAuto:
+                    break;
+                case UVMeterI2CAddress74:
+                    i2c_address = DefaultI2CAddr;
+                    break;
+                case UVMeterI2CAddress75:
+                    i2c_address = SecondaryI2CAddr;
+                    break;
+                case UVMeterI2CAddress76:
+                    i2c_address = TertiaryI2CAddr;
+                    break;
+                case UVMeterI2CAddress77:
+                    i2c_address = QuaternaryI2CAddr;
+                    break;
+                }
+                app->app_state->as7331_initialized = app->app_state->as7331.init(i2c_address);
+            }
+            if(!app->app_state->as7331_initialized || !app->app_state->as7331.deviceReady()) {
+                app->app_state->as7331_initialized = false;
+            } else {
+                // Set default Gain and Integration Time
+                app->app_state->as7331.setGain(GAIN_8);
+                app->app_state->as7331.setIntegrationTime(TIME_128MS);
+            }
+            furi_mutex_release(app->app_state->as7331_mutex);
+
+            if(app->app_state->as7331_initialized) {
+                scene_manager_next_scene(app->scene_manager, UVMeterSceneData);
+                consumed = true;
+            }
+
+            app->app_state->last_sensor_check_timestamp = current_time;
+        }
+
+    } else if(event.type == SceneManagerEventTypeBack) {
+        // Always quit app in wiring scene
+        scene_manager_stop(app->scene_manager);
+        view_dispatcher_stop(app->view_dispatcher);
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void uv_meter_scene_wiring_on_exit(void* context) {
+    UNUSED(context);
+}

BIN
uv_meter_as7331/screenshots/data_1.png


BIN
uv_meter_as7331/screenshots/data_2.png


BIN
uv_meter_as7331/screenshots/settings.png


BIN
uv_meter_as7331/screenshots/wiring.png


BIN
uv_meter_as7331/uv_meter.png


+ 115 - 0
uv_meter_as7331/uv_meter_app.cpp

@@ -0,0 +1,115 @@
+
+#include "uv_meter_app_i.hpp"
+
+// Forward events from View Dispatcher to Scene Manager
+static bool uv_meter_app_custom_callback(void* context, uint32_t custom_event) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    return scene_manager_handle_custom_event(app->scene_manager, custom_event);
+}
+
+static bool uv_meter_app_back_event_callback(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    bool value = scene_manager_handle_back_event(app->scene_manager);
+    return value;
+}
+
+static void uv_meter_app_tick_callback(void* context) {
+    furi_assert(context);
+    auto* app = static_cast<UVMeterApp*>(context);
+    scene_manager_handle_tick_event(app->scene_manager);
+}
+
+static UVMeterApp* uv_meter_app_alloc() {
+    UVMeterApp* app = new UVMeterApp();
+
+    app->app_state = new UVMeterAppState();
+    app->app_state->as7331_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    app->app_state->results.uv_a = 0;
+    app->app_state->results.uv_b = 0;
+    app->app_state->results.uv_c = 0;
+    app->app_state->raw_results.uv_a = 0;
+    app->app_state->raw_results.uv_b = 0;
+    app->app_state->raw_results.uv_c = 0;
+    app->app_state->last_sensor_check_timestamp = 0;
+    app->app_state->as7331_initialized = false;
+    app->app_state->i2c_address = UVMeterI2CAddressAuto;
+    app->app_state->unit = UVMeterUnituW_cm_2;
+
+    app->scene_manager = scene_manager_alloc(&uv_meter_scene_handlers, app);
+    app->view_dispatcher = view_dispatcher_alloc();
+    view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
+    view_dispatcher_set_custom_event_callback(app->view_dispatcher, uv_meter_app_custom_callback);
+    view_dispatcher_set_navigation_event_callback(
+        app->view_dispatcher, uv_meter_app_back_event_callback);
+    view_dispatcher_set_tick_event_callback(
+        app->view_dispatcher, uv_meter_app_tick_callback, furi_ms_to_ticks(150));
+
+    app->uv_meter_wiring_view = uv_meter_wiring_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        UVMeterViewWiring,
+        uv_meter_wiring_get_view(app->uv_meter_wiring_view));
+    app->variable_item_list = variable_item_list_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        UVMeterViewVariableItemList,
+        variable_item_list_get_view(app->variable_item_list));
+    app->uv_meter_data_view = uv_meter_data_alloc();
+    uv_meter_data_set_sensor(
+        app->uv_meter_data_view, &app->app_state->as7331, app->app_state->as7331_mutex);
+    view_dispatcher_add_view(
+        app->view_dispatcher, UVMeterViewData, uv_meter_data_get_view(app->uv_meter_data_view));
+    app->widget = widget_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher, UVMeterViewWidget, widget_get_view(app->widget));
+
+    app->gui = static_cast<Gui*>(furi_record_open(RECORD_GUI));
+    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
+    scene_manager_next_scene(app->scene_manager, UVMeterViewWiring);
+
+    return app;
+}
+
+static void uv_meter_app_free(UVMeterApp* app) {
+    furi_assert(app);
+    furi_record_close(RECORD_GUI);
+    view_dispatcher_remove_view(app->view_dispatcher, UVMeterViewWidget);
+    widget_free(app->widget);
+    view_dispatcher_remove_view(app->view_dispatcher, UVMeterViewData);
+    uv_meter_data_free(app->uv_meter_data_view);
+    view_dispatcher_remove_view(app->view_dispatcher, UVMeterViewVariableItemList);
+    variable_item_list_free(app->variable_item_list);
+    view_dispatcher_remove_view(app->view_dispatcher, UVMeterViewWiring);
+    uv_meter_wiring_free(app->uv_meter_wiring_view);
+
+    view_dispatcher_free(app->view_dispatcher);
+    scene_manager_free(app->scene_manager);
+
+    furi_mutex_free(app->app_state->as7331_mutex);
+    delete app->app_state;
+    delete app;
+}
+
+/**
+ * @brief Main application entry point
+ *
+ * @param p Unused parameter
+ * @return Exit code
+ */
+extern "C" int32_t uv_meter_app(void* p) {
+    UNUSED(p);
+    UVMeterApp* app = uv_meter_app_alloc();
+
+    view_dispatcher_run(app->view_dispatcher);
+
+    // Power down the sensor before exiting
+    if(app->app_state->as7331_initialized) {
+        app->app_state->as7331.setPowerDown(true);
+        app->app_state->as7331_initialized = false;
+    }
+
+    uv_meter_app_free(app);
+    return 0;
+}

+ 30 - 0
uv_meter_as7331/uv_meter_app.hpp

@@ -0,0 +1,30 @@
+/**
+ * @file uv_meter_app.hpp
+ * @brief UV Meter Application for AS7331 UV Spectral Sensor
+ *
+ * This application interfaces with the AS7331 UV spectral sensor using I2C communication
+ * to measure UV-A, UV-B, and UV-C irradiance. The measurements are displayed on the Flipper Zero's screen.
+ *
+ * Hardware Connections:
+ * - SCL: C0 [pin 16]
+ * - SDA: C1 [pin 15]
+ * - 3V3: 3V3 [pin 9]
+ * - GND: GND [pin 11 or 18]
+ */
+#pragma once
+
+typedef struct UVMeterApp UVMeterApp;
+
+typedef enum {
+    UVMeterI2CAddressAuto,
+    UVMeterI2CAddress74,
+    UVMeterI2CAddress75,
+    UVMeterI2CAddress76,
+    UVMeterI2CAddress77,
+} UVMeterI2CAddress;
+
+typedef enum {
+    UVMeterUnituW_cm_2,
+    UVMeterUnitW_m_2,
+    UVMeterUnitmW_m_2,
+} UVMeterUnit;

+ 56 - 0
uv_meter_as7331/uv_meter_app_i.hpp

@@ -0,0 +1,56 @@
+#pragma once
+
+#include "uv_meter_app.hpp"
+
+#include <gui/gui.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/widget.h>
+#include <gui/modules/variable_item_list.h>
+
+#include <furi.h>
+#include <furi_hal.h>
+
+#include <furi_hal_gpio.h>
+#include <furi_hal_resources.h>
+
+#include "uv_meter_as7331_icons.h"
+#include "scenes/uv_meter_scene.hpp"
+#include "views/uv_meter_wiring.hpp"
+#include "views/uv_meter_data.hpp"
+#include "AS7331.hpp"
+
+// Prevent compiler optimization for debugging (remove in production).
+// #pragma GCC optimize("O0")
+
+typedef struct {
+    AS7331::Results results; /**< Processed measurement results */
+    AS7331::RawResults raw_results; /**< Raw measurement results */
+    AS7331 as7331; /**< AS7331 sensor object */
+    bool as7331_initialized; /**< Flag indicating if sensor is initialized */
+    FuriMutex* as7331_mutex; /**< Mutex for thread-safe data access */
+    uint32_t last_sensor_check_timestamp; /**< Last time sensor availability was checked */
+    // Settings
+    UVMeterI2CAddress i2c_address;
+    UVMeterUnit unit;
+} UVMeterAppState;
+
+struct UVMeterApp {
+    Gui* gui;
+    SceneManager* scene_manager;
+    ViewDispatcher* view_dispatcher;
+    // Views
+    UVMeterWiring* uv_meter_wiring_view;
+    VariableItemList* variable_item_list;
+    UVMeterData* uv_meter_data_view;
+    Widget* widget;
+
+    UVMeterAppState* app_state; /**< Shared app_state */
+};
+
+typedef enum {
+    UVMeterViewWiring,
+    UVMeterViewVariableItemList,
+    UVMeterViewData,
+    UVMeterViewWidget,
+} UVMeterView;

+ 7 - 0
uv_meter_as7331/uv_meter_event.hpp

@@ -0,0 +1,7 @@
+#pragma once
+
+typedef enum {
+    UVMeterCustomEventSceneEnterHelp,
+    UVMeterCustomEventSceneEnterAbout,
+    UVMeterCustomEventSceneEnterSettings,
+} UVMeterCustomEvent;

+ 693 - 0
uv_meter_as7331/views/uv_meter_data.cpp

@@ -0,0 +1,693 @@
+#include "uv_meter_data.hpp"
+
+#include <gui/elements.h>
+#include "uv_meter_as7331_icons.h"
+
+#include <locale/locale.h>
+#include <math.h>
+
+#define UV_METER_MAX_RAW_VALUE 65535.0
+
+struct UVMeterData {
+    View* view;
+    AS7331* sensor;
+    FuriMutex* sensor_mutex;
+    UVMeterDataEnterSettingsCallback callback;
+    void* context;
+};
+
+// Configuration mode states
+typedef enum {
+    UVMeterConfigModeNone, // No config selected
+    UVMeterConfigModeGain, // Configure gain
+    UVMeterConfigModeExposureTime, // Configure exposure time
+    UVMeterConfigModeEyesProtection, // Configure eyes protection mode
+} UVMeterConfigMode;
+
+typedef struct {
+    FuriString* buffer;
+    UVMeterConfigMode current_config_mode;
+    AS7331::Results results;
+    AS7331::RawResults raw_results;
+    UVMeterEffectiveResults effective_results;
+    int16_t gain_value;
+    double conversion_time;
+    bool eyes_protected;
+    UVMeterUnit unit;
+} UVMeterDataModel;
+
+static void uv_meter_data_draw_raw_meter(
+    Canvas* canvas,
+    int x,
+    int y,
+    uint16_t raw_value,
+    double max_meter_value) {
+    int meter_value = (int)lround((double)raw_value / max_meter_value * (double)8.0);
+
+    // Draw the meter frame
+    canvas_draw_frame(canvas, x, y, 3, 10);
+
+    // Draw the meter level
+    canvas_draw_line(canvas, x + 1, y + 9, x + 1, y + 9 - meter_value);
+
+    // Show alert if value is too low or at max
+    if(raw_value < 5 || raw_value >= max_meter_value) {
+        canvas_draw_icon(canvas, x + 5, y + 1, &I_Alert_9x8);
+    }
+}
+
+static void uv_meter_data_draw_uv_measurements(
+    Canvas* canvas,
+    const AS7331::Results* results,
+    const AS7331::RawResults* raw_results,
+    UVMeterUnit unit,
+    FuriString* buffer) {
+    canvas_set_font(canvas, FontSecondary);
+    int x_1_align = 0;
+    int y_uva_bottom = 9;
+    int y_uvb_bottom = 23;
+    int y_uvc_bottom = 37;
+
+    // Draw labels
+    canvas_draw_str_aligned(canvas, x_1_align, y_uva_bottom, AlignLeft, AlignBottom, "UVA:");
+    canvas_draw_str_aligned(canvas, x_1_align, y_uvb_bottom, AlignLeft, AlignBottom, "UVB:");
+    canvas_draw_str_aligned(canvas, x_1_align, y_uvc_bottom, AlignLeft, AlignBottom, "UVC:");
+
+    // Display UV measurements
+    canvas_set_font(canvas, FontPrimary);
+    int x_2_align = 51;
+
+    double multiplier = 1.0;
+    switch(unit) {
+    case UVMeterUnituW_cm_2:
+        multiplier = 1.0;
+        break;
+    case UVMeterUnitW_m_2:
+        multiplier = 0.01;
+        break;
+    case UVMeterUnitmW_m_2:
+        multiplier = 10;
+        break;
+    }
+
+    // Display UVA value
+    double uv_a = results->uv_a * multiplier;
+    furi_string_printf(buffer, "%.*f", (uv_a >= 1000 ? 0 : (uv_a >= 100 ? 1 : 2)), uv_a);
+    canvas_draw_str_aligned(
+        canvas, x_2_align, y_uva_bottom, AlignRight, AlignBottom, furi_string_get_cstr(buffer));
+
+    // Display UVB value
+    double uv_b = results->uv_b * multiplier;
+    furi_string_printf(buffer, "%.*f", (uv_b >= 1000 ? 0 : (uv_b >= 100 ? 1 : 2)), uv_b);
+    canvas_draw_str_aligned(
+        canvas, x_2_align, y_uvb_bottom, AlignRight, AlignBottom, furi_string_get_cstr(buffer));
+
+    // Display UVC value
+    double uv_c = results->uv_c * multiplier;
+    furi_string_printf(buffer, "%.*f", (uv_c >= 1000 ? 0 : (uv_c >= 100 ? 1 : 2)), uv_c);
+    canvas_draw_str_aligned(
+        canvas, x_2_align, y_uvc_bottom, AlignRight, AlignBottom, furi_string_get_cstr(buffer));
+
+    // Draw raw meters with alerts
+    int raw_meter_x = x_2_align + 3;
+
+    // UVA raw meter
+    uv_meter_data_draw_raw_meter(
+        canvas, raw_meter_x, y_uva_bottom - 9, raw_results->uv_a, UV_METER_MAX_RAW_VALUE);
+
+    // UVB raw meter
+    uv_meter_data_draw_raw_meter(
+        canvas, raw_meter_x, y_uvb_bottom - 9, raw_results->uv_b, UV_METER_MAX_RAW_VALUE);
+
+    // UVC raw meter
+    uv_meter_data_draw_raw_meter(
+        canvas, raw_meter_x, y_uvc_bottom - 9, raw_results->uv_c, UV_METER_MAX_RAW_VALUE);
+}
+
+static void uv_meter_data_draw_uv_effectiveness(
+    Canvas* canvas,
+    const UVMeterEffectiveResults* effective_results,
+    FuriString* buffer) {
+    canvas_set_font(canvas, FontSecondary);
+    int x_3_align = 94;
+    int y_uva_bottom = 9;
+    int y_uvb_bottom = 23;
+    int y_uvc_bottom = 37;
+
+    // Skip if total is zero to avoid division by zero
+    if(effective_results->uv_total_eff <= 0) {
+        return;
+    }
+
+    // UVA percentage of Maximum Daily Exposure Time
+    furi_string_printf(
+        buffer,
+        "%d%%",
+        (int)lround(effective_results->uv_a_eff / effective_results->uv_total_eff * 100));
+    canvas_draw_str_aligned(
+        canvas, x_3_align, y_uva_bottom, AlignRight, AlignBottom, furi_string_get_cstr(buffer));
+
+    // UVB percentage of Maximum Daily Exposure Time
+    furi_string_printf(
+        buffer,
+        "%d%%",
+        (int)lround(effective_results->uv_b_eff / effective_results->uv_total_eff * 100));
+    canvas_draw_str_aligned(
+        canvas, x_3_align, y_uvb_bottom, AlignRight, AlignBottom, furi_string_get_cstr(buffer));
+
+    // UVC percentage of Maximum Daily Exposure Time
+    furi_string_printf(
+        buffer,
+        "%d%%",
+        (int)lround(effective_results->uv_c_eff / effective_results->uv_total_eff * 100));
+    canvas_draw_str_aligned(
+        canvas, x_3_align, y_uvc_bottom, AlignRight, AlignBottom, furi_string_get_cstr(buffer));
+
+    // Draw separator line and arrow
+    int x_3_4 = 96;
+    canvas_draw_line(canvas, x_3_4, y_uva_bottom - 9, x_3_4, y_uvc_bottom);
+    canvas_draw_icon(canvas, x_3_4 + 1, y_uvb_bottom - 6, &I_ButtonRightSmall_3x5);
+}
+
+static void uv_meter_data_draw_maximum_daily_exposure_time(
+    Canvas* canvas,
+    double t_max,
+    FuriString* buffer) {
+    int x_center_4_4 = 112;
+    int y_uvb_bottom = 23;
+
+    // Draw sun icon
+    canvas_draw_icon(canvas, x_center_4_4 - 7, -7, &I_Sun_15x16);
+
+    // Draw "min" label
+    canvas_set_font(canvas, FontSecondary);
+    canvas_draw_str_aligned(canvas, x_center_4_4, y_uvb_bottom + 2, AlignCenter, AlignTop, "min");
+
+    // Draw max exposure time in minutes
+    canvas_set_font(canvas, FontPrimary);
+    double t_max_minutes = t_max / 60;
+    furi_string_printf(
+        buffer, "%.*f", (t_max_minutes >= 100 ? 0 : (t_max_minutes >= 10 ? 1 : 2)), t_max_minutes);
+    canvas_draw_str_aligned(
+        canvas, x_center_4_4, y_uvb_bottom, AlignCenter, AlignBottom, furi_string_get_cstr(buffer));
+}
+
+static void uv_meter_data_draw_config_section(
+    Canvas* canvas,
+    int16_t gain_value,
+    double conversion_time,
+    bool eyes_protected,
+    UVMeterUnit unit,
+    UVMeterConfigMode current_config_mode,
+    FuriString* buffer) {
+    // Draw unit
+    const Icon* icon = NULL;
+    switch(unit) {
+    case UVMeterUnituW_cm_2:
+        icon = &I_Unit_uW_cm2_34x11;
+        break;
+    case UVMeterUnitW_m_2:
+        icon = &I_Unit_W_m2_22x11;
+        break;
+    case UVMeterUnitmW_m_2:
+        icon = &I_Unit_mW_m2_28x11;
+        break;
+    }
+    int x_1_align = 0;
+    int y_conf = 52;
+    canvas_draw_icon(canvas, x_1_align, y_conf - 11, icon);
+
+    // Draw text explaining selected setting
+    canvas_set_font(canvas, FontSecondary);
+    int x_setting_right = 123;
+
+    const char* setting_string;
+    switch(current_config_mode) {
+    case UVMeterConfigModeGain:
+        setting_string = "Gain";
+        break;
+    case UVMeterConfigModeExposureTime:
+        setting_string = "Exposure Time (s)";
+        break;
+    case UVMeterConfigModeEyesProtection:
+        setting_string = "Eyes Protected";
+        break;
+    default:
+        setting_string = "";
+        break;
+    }
+
+    uint16_t text_width = canvas_string_width(canvas, setting_string);
+    canvas_draw_str_aligned(
+        canvas, x_setting_right, y_conf - 2, AlignRight, AlignBottom, setting_string);
+
+    // Navigation arrows
+    canvas_draw_icon(canvas, x_setting_right + 2, y_conf - 8, &I_ButtonRightSmall_3x5);
+    canvas_draw_icon(canvas, x_setting_right - text_width - 5, y_conf - 8, &I_ButtonLeftSmall_3x5);
+
+    // Frames/Boxes for settings
+    int setting_x_size = 33;
+    int setting_y_size = 14;
+
+    // Config button box
+    canvas_draw_rframe(canvas, 0, y_conf, setting_x_size, setting_y_size, 3);
+
+    // Gain box
+    if(current_config_mode == UVMeterConfigModeGain) {
+        canvas_draw_rbox(canvas, setting_x_size - 1, y_conf, setting_x_size, setting_y_size, 3);
+    } else {
+        canvas_draw_rframe(canvas, setting_x_size - 1, y_conf, setting_x_size, setting_y_size, 3);
+    }
+
+    // Exposure Time box
+    if(current_config_mode == UVMeterConfigModeExposureTime) {
+        canvas_draw_rbox(
+            canvas, setting_x_size * 2 - 2, y_conf, setting_x_size, setting_y_size, 3);
+    } else {
+        canvas_draw_rframe(
+            canvas, setting_x_size * 2 - 2, y_conf, setting_x_size, setting_y_size, 3);
+    }
+
+    // Eyes Protection box
+    if(current_config_mode == UVMeterConfigModeEyesProtection) {
+        canvas_draw_rbox(
+            canvas, setting_x_size * 3 - 3, y_conf, setting_x_size - 1, setting_y_size, 3);
+    } else {
+        canvas_draw_rframe(
+            canvas, setting_x_size * 3 - 3, y_conf, setting_x_size - 1, setting_y_size, 3);
+    }
+
+    // Config button
+    canvas_draw_icon(canvas, 2, y_conf + 3, &I_ButtonCenter_7x7);
+    canvas_draw_str_aligned(canvas, 11, y_conf + 3, AlignLeft, AlignTop, "Conf");
+
+    // Gain value
+    if(current_config_mode == UVMeterConfigModeGain) {
+        canvas_set_color(canvas, ColorWhite);
+    }
+    furi_string_printf(buffer, "%d", gain_value);
+    canvas_draw_str_aligned(
+        canvas,
+        setting_x_size - 1 + (setting_x_size / 2),
+        y_conf + 3,
+        AlignCenter,
+        AlignTop,
+        furi_string_get_cstr(buffer));
+    canvas_set_color(canvas, ColorBlack);
+
+    // Exposure Time value
+    if(current_config_mode == UVMeterConfigModeExposureTime) {
+        canvas_set_color(canvas, ColorWhite);
+    }
+    furi_string_printf(
+        buffer,
+        "%.*f",
+        (conversion_time >= 100 ? 1 : (conversion_time >= 10 ? 2 : 3)),
+        conversion_time);
+    canvas_draw_str_aligned(
+        canvas,
+        setting_x_size * 2 - 2 + (setting_x_size / 2),
+        y_conf + 3,
+        AlignCenter,
+        AlignTop,
+        furi_string_get_cstr(buffer));
+    canvas_set_color(canvas, ColorBlack);
+
+    // Eyes Protection
+    if(current_config_mode == UVMeterConfigModeEyesProtection) {
+        canvas_set_color(canvas, ColorWhite);
+    }
+    canvas_draw_icon(
+        canvas,
+        setting_x_size * 3 - 3 + 4,
+        y_conf + 2,
+        (eyes_protected) ? &I_Sunglasses_24x8 : &I_Glasses_24x8);
+    canvas_set_color(canvas, ColorBlack);
+}
+
+static void uv_meter_data_draw_callback(Canvas* canvas, void* model) {
+    auto* m = static_cast<UVMeterDataModel*>(model);
+    FURI_LOG_D("UV_Meter Data", "Redrawing");
+
+    // Draw UV measurements section
+    uv_meter_data_draw_uv_measurements(canvas, &m->results, &m->raw_results, m->unit, m->buffer);
+
+    // Draw UV effectiveness percentages
+    uv_meter_data_draw_uv_effectiveness(canvas, &m->effective_results, m->buffer);
+
+    // Draw maximum daily exposure time
+    uv_meter_data_draw_maximum_daily_exposure_time(canvas, m->effective_results.t_max, m->buffer);
+
+    // Draw configuration section
+    uv_meter_data_draw_config_section(
+        canvas,
+        m->gain_value,
+        m->conversion_time,
+        m->eyes_protected,
+        m->unit,
+        m->current_config_mode,
+        m->buffer);
+}
+
+static bool uv_meter_data_input_callback(InputEvent* event, void* context) {
+    auto* instance = static_cast<UVMeterData*>(context);
+
+    bool consumed = false;
+    bool setting_changed = false;
+
+    if(event->type != InputTypeShort) {
+        return false;
+    }
+
+    if(event->key == InputKeyOk) {
+        if(instance->callback) {
+            instance->callback(instance->context);
+            return true;
+        }
+        return false;
+    }
+    FURI_LOG_D("UV_Meter Data", "Update Input");
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        {
+            // Handle left/right to select config
+            if(event->key == InputKeyLeft || event->key == InputKeyRight) {
+                if(event->key == InputKeyLeft) {
+                    // Move to previous config mode
+                    switch(model->current_config_mode) {
+                    case UVMeterConfigModeNone:
+                    case UVMeterConfigModeGain:
+                        model->current_config_mode = UVMeterConfigModeEyesProtection;
+                        break;
+                    case UVMeterConfigModeExposureTime:
+                        model->current_config_mode = UVMeterConfigModeGain;
+                        break;
+                    case UVMeterConfigModeEyesProtection:
+                        model->current_config_mode = UVMeterConfigModeExposureTime;
+                        break;
+                    }
+                } else { // InputKeyRight
+                    // Move to next config mode
+                    switch(model->current_config_mode) {
+                    case UVMeterConfigModeNone:
+                    case UVMeterConfigModeGain:
+                        model->current_config_mode = UVMeterConfigModeExposureTime;
+                        break;
+                    case UVMeterConfigModeExposureTime:
+                        model->current_config_mode = UVMeterConfigModeEyesProtection;
+                        break;
+                    case UVMeterConfigModeEyesProtection:
+                        model->current_config_mode = UVMeterConfigModeGain;
+                        break;
+                    }
+                }
+                consumed = true;
+                setting_changed = true;
+            }
+
+            // Handle up/down to change selected config mode
+            else if(
+                instance->sensor && model->current_config_mode != UVMeterConfigModeNone &&
+                (event->key == InputKeyUp || event->key == InputKeyDown)) {
+                furi_mutex_acquire(instance->sensor_mutex, FuriWaitForever);
+
+                switch(model->current_config_mode) {
+                case UVMeterConfigModeGain: {
+                    // Adjust gain
+                    int current_gain = static_cast<int>(instance->sensor->getGain());
+                    int new_gain = (event->key == InputKeyUp) ? current_gain - 1 :
+                                                                current_gain + 1;
+
+                    if(new_gain >= static_cast<int>(GAIN_2048) &&
+                       new_gain <= static_cast<int>(GAIN_1)) {
+                        instance->sensor->setGain(static_cast<as7331_gain_t>(new_gain));
+                        model->gain_value = instance->sensor->getGainValue();
+                        setting_changed = true;
+                    }
+                    break;
+                }
+
+                case UVMeterConfigModeExposureTime: {
+                    // Adjust integration time
+                    int current_time = static_cast<int>(instance->sensor->getIntegrationTime());
+                    int new_time = (event->key == InputKeyUp) ? current_time + 1 :
+                                                                current_time - 1;
+
+                    if(new_time >= static_cast<int>(TIME_1MS) &&
+                       new_time <= static_cast<int>(TIME_16384MS)) {
+                        instance->sensor->setIntegrationTime(
+                            static_cast<as7331_integration_time_t>(new_time));
+                        model->conversion_time = instance->sensor->getConversionTime();
+                        setting_changed = true;
+                    }
+                    break;
+                }
+
+                case UVMeterConfigModeEyesProtection:
+                    // Toggle eyes protected
+                    model->eyes_protected = !model->eyes_protected;
+                    model->effective_results = uv_meter_data_calculate_effective_results(
+                        &model->results, model->eyes_protected);
+                    setting_changed = true;
+                    break;
+
+                default:
+                    break;
+                }
+                furi_mutex_release(instance->sensor_mutex);
+                consumed = true;
+            }
+        },
+        setting_changed);
+
+    return consumed;
+}
+
+UVMeterData* uv_meter_data_alloc(void) {
+    UVMeterData* instance = new UVMeterData();
+    instance->view = view_alloc();
+    view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(UVMeterDataModel));
+    view_set_draw_callback(instance->view, uv_meter_data_draw_callback);
+    view_set_input_callback(instance->view, uv_meter_data_input_callback);
+    view_set_context(instance->view, instance);
+
+    FURI_LOG_D("UV_Meter Data", "Update Alloc");
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        {
+            model->buffer = furi_string_alloc();
+            model->current_config_mode = UVMeterConfigModeGain;
+            model->results.uv_a = 0;
+            model->results.uv_b = 0;
+            model->results.uv_c = 0;
+            model->raw_results.uv_a = 0;
+            model->raw_results.uv_b = 0;
+            model->raw_results.uv_c = 0;
+            model->effective_results.uv_a_eff = 0;
+            model->effective_results.uv_b_eff = 0;
+            model->effective_results.uv_c_eff = 0;
+            model->effective_results.uv_total_eff = 0;
+            model->effective_results.t_max = 0;
+            model->gain_value = 1;
+            model->conversion_time = 1.0;
+            model->eyes_protected = true;
+            model->unit = UVMeterUnituW_cm_2;
+        },
+        true);
+
+    return instance;
+}
+
+void uv_meter_data_free(UVMeterData* instance) {
+    furi_assert(instance);
+
+    with_view_model_cpp(
+        instance->view, UVMeterDataModel*, model, { furi_string_free(model->buffer); }, false);
+
+    view_free(instance->view);
+    delete instance;
+    // Data View is not responsible for `sensor` and `sensor_mutex`
+}
+
+void uv_meter_data_reset(UVMeterData* instance, bool update) {
+    furi_assert(instance);
+    FURI_LOG_D("UV_Meter Data", "Update Reset");
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        {
+            model->current_config_mode = UVMeterConfigModeGain;
+            model->results.uv_a = 0;
+            model->results.uv_b = 0;
+            model->results.uv_c = 0;
+            model->raw_results.uv_a = 0;
+            model->raw_results.uv_b = 0;
+            model->raw_results.uv_c = 0;
+            model->effective_results.uv_a_eff = 0;
+            model->effective_results.uv_b_eff = 0;
+            model->effective_results.uv_c_eff = 0;
+            model->effective_results.uv_total_eff = 0;
+            model->effective_results.t_max = 0;
+            model->gain_value = 1;
+            model->conversion_time = 1.0;
+            model->eyes_protected = true;
+            model->unit = UVMeterUnituW_cm_2;
+        },
+        update);
+}
+
+View* uv_meter_data_get_view(UVMeterData* instance) {
+    furi_assert(instance);
+    return instance->view;
+}
+
+void uv_meter_data_set_enter_settings_callback(
+    UVMeterData* instance,
+    UVMeterDataEnterSettingsCallback callback,
+    void* context) {
+    furi_assert(instance);
+    furi_assert(callback);
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        {
+            UNUSED(model);
+            instance->callback = callback;
+            instance->context = context;
+        },
+        false);
+}
+
+void uv_meter_data_set_sensor(UVMeterData* instance, AS7331* sensor, FuriMutex* sensor_mutex) {
+    furi_assert(instance);
+    furi_assert(sensor);
+    furi_assert(sensor_mutex);
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        {
+            UNUSED(model);
+            instance->sensor = sensor;
+            instance->sensor_mutex = sensor_mutex;
+        },
+        false);
+}
+
+void uv_meter_update_from_sensor(UVMeterData* instance) {
+    furi_assert(instance);
+    if(instance->sensor) {
+        furi_mutex_acquire(instance->sensor_mutex, FuriWaitForever);
+        FURI_LOG_D("UV_Meter Data", "Update From Sensor");
+        with_view_model_cpp(
+            instance->view,
+            UVMeterDataModel*,
+            model,
+            {
+                model->gain_value = instance->sensor->getGainValue();
+                model->conversion_time = instance->sensor->getConversionTime();
+            },
+            true);
+        furi_mutex_release(instance->sensor_mutex);
+    }
+}
+
+void uv_meter_data_set_results(
+    UVMeterData* instance,
+    const AS7331::Results* results,
+    const AS7331::RawResults* raw_results) {
+    furi_assert(instance);
+    furi_assert(results);
+    furi_assert(raw_results);
+
+    FURI_LOG_D("UV_Meter Data", "Update Set Results");
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        {
+            model->results = *results;
+            model->raw_results = *raw_results;
+            model->effective_results =
+                uv_meter_data_calculate_effective_results(&model->results, model->eyes_protected);
+        },
+        true);
+}
+
+UVMeterEffectiveResults uv_meter_data_get_effective_results(UVMeterData* instance) {
+    furi_assert(instance);
+    UVMeterEffectiveResults effective_results;
+
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        { effective_results = model->effective_results; },
+        false);
+
+    return effective_results;
+}
+
+void uv_meter_data_set_eyes_protected(UVMeterData* instance, bool eyes_protected) {
+    furi_assert(instance);
+    FURI_LOG_D("UV_Meter Data", "Update Set Eyes Protected");
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        { model->eyes_protected = eyes_protected; },
+        true);
+}
+
+bool uv_meter_data_get_eyes_protected(UVMeterData* instance) {
+    furi_assert(instance);
+    bool eyes_protected = false;
+
+    with_view_model_cpp(
+        instance->view,
+        UVMeterDataModel*,
+        model,
+        { eyes_protected = model->eyes_protected; },
+        false);
+
+    return eyes_protected;
+}
+
+void uv_meter_data_set_unit(UVMeterData* instance, UVMeterUnit unit) {
+    furi_assert(instance);
+    FURI_LOG_D("UV_Meter Data", "Update Set Unit");
+    with_view_model_cpp(instance->view, UVMeterDataModel*, model, { model->unit = unit; }, true);
+}
+
+UVMeterEffectiveResults
+    uv_meter_data_calculate_effective_results(const AS7331::Results* results, bool eyes_protected) {
+    // Weighted Spectral Effectiveness
+    double w_spectral_eff_uv_a = 0.0002824;
+    double w_spectral_eff_uv_b = 0.3814;
+    double w_spectral_eff_uv_c = 0.6047;
+
+    if(eyes_protected) { // 😎
+        // w_spectral_eff_uv_a is the same
+        w_spectral_eff_uv_b = 0.2009;
+        w_spectral_eff_uv_c = 0.2547;
+    }
+    UVMeterEffectiveResults effective_results;
+    // Effective Irradiance
+    effective_results.uv_a_eff = results->uv_a * w_spectral_eff_uv_a;
+    effective_results.uv_b_eff = results->uv_b * w_spectral_eff_uv_b;
+    effective_results.uv_c_eff = results->uv_c * w_spectral_eff_uv_c;
+    effective_results.uv_total_eff =
+        effective_results.uv_a_eff + effective_results.uv_b_eff + effective_results.uv_c_eff;
+
+    // Daily dose (seconds) based on the total effective irradiance
+    double daily_dose = 0.003; // J/cm^2
+    double uW_to_W = 1e-6;
+    effective_results.t_max = daily_dose / (effective_results.uv_total_eff * uW_to_W);
+    return effective_results;
+}

+ 46 - 0
uv_meter_as7331/views/uv_meter_data.hpp

@@ -0,0 +1,46 @@
+#pragma once
+
+#include <gui/view.h>
+#include "AS7331.hpp"
+#include "uv_meter_app.hpp"
+
+typedef struct UVMeterData UVMeterData;
+typedef void (*UVMeterDataEnterSettingsCallback)(void* context);
+
+/** @brief Struct to hold effective irradiance and daily exposure time */
+typedef struct {
+    double uv_a_eff; /**< Effective UV-A Irradiance in µW/cm² */
+    double uv_b_eff; /**< Effective UV-B Irradiance in µW/cm² */
+    double uv_c_eff; /**< Effective UV-C Irradiance in µW/cm² */
+    double uv_total_eff; /**< Effective total UV Irradiance in µW/cm² */
+    double t_max; /**< Maximum Daily Exposure Time in seconds*/
+} UVMeterEffectiveResults;
+
+UVMeterData* uv_meter_data_alloc(void);
+void uv_meter_data_free(UVMeterData* instance);
+void uv_meter_data_reset(UVMeterData* instance, bool update = false);
+
+View* uv_meter_data_get_view(UVMeterData* instance);
+
+void uv_meter_data_set_enter_settings_callback(
+    UVMeterData* instance,
+    UVMeterDataEnterSettingsCallback callback,
+    void* context);
+
+// AS7331 Sensor
+void uv_meter_data_set_sensor(UVMeterData* instance, AS7331* sensor, FuriMutex* sensor_mutex);
+void uv_meter_update_from_sensor(UVMeterData* instance);
+
+// General getter and setter
+void uv_meter_data_set_results(
+    UVMeterData* instance,
+    const AS7331::Results* results,
+    const AS7331::RawResults* raw_results);
+UVMeterEffectiveResults uv_meter_data_get_effective_results(UVMeterData* instance);
+void uv_meter_data_set_eyes_protected(UVMeterData* instance, bool eyes_protected);
+bool uv_meter_data_get_eyes_protected(UVMeterData* instance);
+void uv_meter_data_set_unit(UVMeterData* instance, UVMeterUnit unit);
+
+// Helper
+UVMeterEffectiveResults
+    uv_meter_data_calculate_effective_results(const AS7331::Results* results, bool eyes_protected);

+ 78 - 0
uv_meter_as7331/views/uv_meter_wiring.cpp

@@ -0,0 +1,78 @@
+#include "uv_meter_wiring.hpp"
+
+#include <gui/elements.h>
+#include "uv_meter_as7331_icons.h"
+
+#include <locale/locale.h>
+#include <math.h>
+
+#define UV_METER_MAX_RAW_VALUE 65535.0
+
+struct UVMeterWiring {
+    View* view;
+    UVMeterWiringEnterSettingsCallback callback;
+    void* context;
+    //IconAnimation* icon;
+};
+
+typedef struct {
+    IconAnimation* icon;
+} UVMeterWiringModel;
+
+static void uv_meter_wiring_draw_callback(Canvas* canvas, void* model) {
+    UNUSED(model);
+    //auto* m = static_cast<UVMeterWiringModel*>(model);
+    FURI_LOG_D("UV_Meter Wiring", "Redrawing");
+
+    canvas_draw_icon(canvas, 0, 0, &I_Wiring_128x64);
+}
+
+static bool uv_meter_wiring_input_callback(InputEvent* event, void* context) {
+    auto* instance = static_cast<UVMeterWiring*>(context);
+    bool consumed = false;
+
+    if(event->key == InputKeyOk && event->type == InputTypeShort && instance->callback) {
+        instance->callback(instance->context);
+        consumed = true;
+    }
+    return consumed;
+}
+
+UVMeterWiring* uv_meter_wiring_alloc(void) {
+    UVMeterWiring* instance = new UVMeterWiring();
+    instance->view = view_alloc();
+    view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(UVMeterWiringModel));
+    view_set_draw_callback(instance->view, uv_meter_wiring_draw_callback);
+    view_set_input_callback(instance->view, uv_meter_wiring_input_callback);
+    view_set_context(instance->view, instance);
+    return instance;
+}
+
+void uv_meter_wiring_free(UVMeterWiring* instance) {
+    furi_assert(instance);
+    view_free(instance->view);
+    delete instance;
+}
+
+View* uv_meter_wiring_get_view(UVMeterWiring* instance) {
+    furi_assert(instance);
+    return instance->view;
+}
+
+void uv_meter_wiring_set_enter_settings_callback(
+    UVMeterWiring* instance,
+    UVMeterWiringEnterSettingsCallback callback,
+    void* context) {
+    furi_assert(instance);
+    furi_assert(callback);
+    with_view_model_cpp(
+        instance->view,
+        UVMeterWiringModel*,
+        model,
+        {
+            UNUSED(model);
+            instance->callback = callback;
+            instance->context = context;
+        },
+        false);
+}

+ 15 - 0
uv_meter_as7331/views/uv_meter_wiring.hpp

@@ -0,0 +1,15 @@
+#pragma once
+
+#include <gui/view.h>
+
+typedef struct UVMeterWiring UVMeterWiring;
+typedef void (*UVMeterWiringEnterSettingsCallback)(void* context);
+
+UVMeterWiring* uv_meter_wiring_alloc(void);
+void uv_meter_wiring_free(UVMeterWiring* instance);
+View* uv_meter_wiring_get_view(UVMeterWiring* instance);
+
+void uv_meter_wiring_set_enter_settings_callback(
+    UVMeterWiring* instance,
+    UVMeterWiringEnterSettingsCallback callback,
+    void* context);