Skip to content

Commit

Permalink
1PM support
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 17, 2024
1 parent f3129b3 commit 65d13bd
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ ShellyMini1Gen3: PLATFORM=esp32c3
ShellyMini1Gen3: build-ShellyMini1Gen3
@true

ShellyMini1PMGen3: PLATFORM=esp32c3
ShellyMini1PMGen3: build-ShellyMini1PMGen3
@true

ShellyRGBW2: build-ShellyRGBW2
@true

Expand Down
45 changes: 43 additions & 2 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,48 @@ conds:
- ["bl0937.power_coeff", "f", 0, {title: "BL0937 counts -> watts conversion coefficient"}]
- ["bl0937.power_coeff", 1.64358469] # (16 + 1010 + 1935) / (9.55 + 617 + 1175)

- when: build_vars.MODEL == "ShellyMini1PMGen3"
apply:
name: Mini1PMG3
libs:
- location: https://github.com/mongoose-os-libs/mongoose
build_vars:
OTA_DATA_ADDR: 0x10000
OTA_DATA_SIZE: 0x4000
NVS_ADDR: 0x14000
NVS_SIZE: 0xC000
APP_OFFSET: 0x20000
APP_SLOT_SIZE: 0x280000
MGOS_ROOT_FS_TYPE: LFS
MGOS_ROOT_FS_SIZE: 1048576
ESP_IDF_EXTRA_PARTITION: "scratch,data,0x80,0x720000,0x80000,encrypted"
ESP_IDF_EXTRA_PARTITION_2: "shelly,data,0x88,0x7F0000,64K,encrypted"
ESP_IDF_SDKCONFIG_OPTS: >
${build_vars.ESP_IDF_SDKCONFIG_OPTS}
CONFIG_FREERTOS_UNICORE=y
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
cdefs:
LED_GPIO: 0
LED_ON: 0
BTN_GPIO: 1
BTN_DOWN: 0
PRODUCT_HW_REV: "0.1.0"
STOCK_FW_MODEL: Mini1PMG3
MAX_NUM_HAP_SESSIONS: 16
config_schema:
- ["device.id", "ShellyMini1G3-??????"]
- ["shelly.name", "ShellyMini1G3-??????"]
- ["wifi.ap.ssid", "ShellyMini1G3-??????"]
- ["sw1", "sw", {title: "SW1 settings"}]
- ["sw1.name", "Shelly SW"]
- ["in1", "in", {title: "Input 1 settings"}]
- ["in1.ssw.name", "Shelly SSW1"]
- ["in1.sensor.name", "Shelly S1"]
- ["gdo1", "gdo", {title: "GDO1 settings"}]
- ["gdo1.name", "Garage Door"]
- ["gdo1.open_sensor_mode", 2]

- when: build_vars.MODEL == "ShellyMini1Gen3"
apply:
name: Mini1G3
Expand All @@ -642,7 +684,6 @@ conds:
APP_OFFSET: 0x20000
APP_SLOT_SIZE: 0x280000
MGOS_ROOT_FS_TYPE: LFS
#MGOS_ROOT_FS_SIZE: 10485762
MGOS_ROOT_FS_SIZE: 1048576
ESP_IDF_EXTRA_PARTITION: "scratch,data,0x80,0x720000,0x80000,encrypted"
ESP_IDF_EXTRA_PARTITION_2: "shelly,data,0x88,0x7F0000,64K,encrypted"
Expand All @@ -656,7 +697,7 @@ conds:
LED_ON: 0
BTN_GPIO: 1
BTN_DOWN: 0
PRODUCT_HW_REV: "0.1.6"
PRODUCT_HW_REV: "0.1.0"
STOCK_FW_MODEL: Mini1G3
MAX_NUM_HAP_SESSIONS: 16
config_schema:
Expand Down
70 changes: 70 additions & 0 deletions src/ShellyMini1PMGen3/shelly_init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) Shelly-HomeKit Contributors
* All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "shelly_hap_garage_door_opener.hpp"
#include "shelly_hap_input.hpp"
#include "shelly_input_pin.hpp"
#include "shelly_main.hpp"
#include "shelly_sys_led_btn.hpp"
#include "shelly_temp_sensor_ntc.hpp"

namespace shelly {

void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
std::vector<std::unique_ptr<Output>> *outputs,
std::vector<std::unique_ptr<PowerMeter>> *pms UNUSED_ARG,
std::unique_ptr<TempSensor> *sys_temp) {
outputs->emplace_back(new OutputPin(1, 5, 1));
auto *in = new InputPin(1, 10, 1, MGOS_GPIO_PULL_NONE, true);
in->AddHandler(std::bind(&HandleInputResetSequence, in, LED_GPIO, _1, _2));
in->Init();
inputs->emplace_back(in);

// not yet compatible
#ifdef MGOS_HAVE_ADC
sys_temp->reset(new TempSensorSDNT1608X103F3950(3, 3.3f, 10000.0f));
#endif

//std::unique_ptr<PowerMeter> pm()
//BL0942 GPIO6 TX GPIO7 RX
//const Status &st = pm->Init();
//if (st.ok()) {
// pms->emplace_back(std::move(pm));
//} else {
// const std::string &s = st.ToString();
// LOG(LL_ERROR, ("PM init failed: %s", s.c_str()));
//}

InitSysLED(LED_GPIO, LED_ON);
InitSysBtn(BTN_GPIO, BTN_DOWN);
}

void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
HAPAccessoryServerRef *svr) {
bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor;
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
svr, true);
} else {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, true);
}
}

} // namespace shelly

0 comments on commit 65d13bd

Please sign in to comment.