From 8e8c2f8fc69859f9f51a0b0f5aa1a13252254664 Mon Sep 17 00:00:00 2001 From: Markus Kirberg Date: Mon, 23 Dec 2024 10:48:47 +0100 Subject: [PATCH] wip --- mos.yml | 16 ++++++++++++++++ src/BL0942/shelly_pm_bl0942.cpp | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mos.yml b/mos.yml index 2bdcc8ef..ef650d24 100644 --- a/mos.yml +++ b/mos.yml @@ -135,6 +135,12 @@ config_schema: - ["gains.bwgain", "f", 4194304, {title: ""}] - ["gains.phcalb", "f", 0, {title: ""}] + - ["scales", "o", {title: "", abstract: true}] + - ["scales.voltage_scale", "f", 1, {title: ""}] #default register values are 0x40000 + - ["scales.current_scale", "f", 1, {title: ""}] + - ["scales.aenergy_scale", "f", 1, {title: ""}] + - ["scales.apower_scale", "f", 1, {title: ""}] + build_vars: # BLE disabled for most models. MGOS_HAP_BLE: 0 @@ -766,6 +772,8 @@ conds: PRODUCT_HW_REV: "0.1.0" STOCK_FW_MODEL: Mini1PMG3 MAX_NUM_HAP_SESSIONS: 16 + MGOS_CONFIG_DEV_6: "shelly" + MGOS_CONFIG_DEV_7: "shelly,4096" config_schema: - ["device.id", "Shelly1PMMiniG3-????????????"] - ["shelly.name", "Shelly1PMMiniG3-????????????"] @@ -779,6 +787,14 @@ conds: - ["gdo1.name", "Garage Door"] - ["gdo1.open_sensor_mode", 2] + - ["factory", "o", {title: ""}] + - ["factory.batch", "s", "", {title: ""}] + - ["factory.model", "s", "", {title: ""}] + - ["factory.version", "i", 0, {title: ""}] + - ["factory.calib", "o", {title: "Factory calib settings"}] + - ["factory.calib.done", "b", false, {title: ""}] + - ["factory.calib.scales0", "scales", {title: ""}] + - when: build_vars.MODEL == "ShellyMini1Gen3" apply: name: Mini1G3 diff --git a/src/BL0942/shelly_pm_bl0942.cpp b/src/BL0942/shelly_pm_bl0942.cpp index 09080780..4d3529f6 100644 --- a/src/BL0942/shelly_pm_bl0942.cpp +++ b/src/BL0942/shelly_pm_bl0942.cpp @@ -125,7 +125,7 @@ bool BL0942PowerMeter::WriteReg(uint8_t reg, uint32_t val) { bool BL0942PowerMeter::ReadReg(uint8_t reg, uint8_t *rx_buf, size_t len) { uint8_t tx_buf[2] = {BL_READ | BL_ADDR, reg}; - size_t j = mgos_uart_write(uart_no_, tx_buf, 2); + mgos_uart_write(uart_no_, tx_buf, 2); mgos_uart_flush(uart_no_); // Delay to allow data to be available @@ -147,11 +147,17 @@ bool BL0942PowerMeter::ReadReg(uint8_t reg, uint8_t *rx_buf, size_t len) { return true; } +uint32_t convert_le24(uint8_t v[3]){ + return ((uint32_t)v[2] << 16) | (uint32_t)(v[1] << 8) | v[0]; +} + void BL0942PowerMeter::MeasureTimerCB() { packet rx_buf; if (this->ReadReg(0xAA, (uint8_t *) rx_buf, sizeof(rx_buf))) { if (rx_buf.frame_header == 0x55) { - // TODO preocess + // TODO preocess readings: + uint32_t cf = convert_le24(rx_buf.cf_count); + } } }