Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb committed Dec 23, 2024
1 parent dff25cf commit 8e8c2f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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-????????????"]
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/BL0942/shelly_pm_bl0942.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

}
}
}
Expand Down

0 comments on commit 8e8c2f8

Please sign in to comment.