diff --git a/Makefile b/Makefile index 66b960d4..a65123b7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ MAKEFLAGS += --warn-undefined-variables -.PHONY: build check-format format release upload Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyI3 ShellyPlug ShellyPlugS ShellyRGBW2 +.PHONY: build check-format format release upload \ + Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyI3 ShellyPlug ShellyPlugS ShellyPlugUS1 ShellyRGBW2 MOS ?= mos # Build locally by default if Docker is available. @@ -56,6 +57,9 @@ ShellyPlug: build-ShellyPlug ShellyPlugS: build-ShellyPlugS @true +ShellyPlugUS1: build-ShellyPlugUS1 + @true + ShellyRGBW2: build-ShellyRGBW2 @true diff --git a/mos.yml b/mos.yml index c66d0885..0acfc6f2 100644 --- a/mos.yml +++ b/mos.yml @@ -438,6 +438,37 @@ conds: - ["sw1.state_led_en", 1] - ["bl0937.power_coeff", 1.64358469] # (16 + 1010 + 1935) / (9.55 + 617 + 1175) + - when: build_vars.MODEL == "ShellyPlugUS1" + apply: + name: shelly-plug-us1 + libs: + - location: https://github.com/mongoose-os-libs/mongoose + variant: esp8266-nossl + build_vars: + FLASH_SIZE: 2097152 + FS_SIZE: 262144 + BOOT_CONFIG_ADDR: 0x7000 + MGOS_ROOT_FS_TYPE: SPIFFS + cdefs: + LED_GPIO: 2 # Blue, 0 red. + LED_ON: 0 + BTN_GPIO: 13 + BTN_DOWN: 0 + PRODUCT_HW_REV: '"1.0"' + STOCK_FW_MODEL: '"SHPLG-U1"' + MG_ENABLE_SSL: 0 + config_schema: + - ["device.id", "shellyplugu1-??????"] + - ["shelly.name", "shellyplugu1-??????"] + - ["wifi.ap.ssid", "shellyplugu1-??????"] + - ["sw1", "sw", {title: "Plug settings"}] + - ["sw1.name", "Shelly Plug S"] + - ["sw1.in_mode", -1] + - ["sw1.svc_type", 1] # Outlet + - ["sw1.initial_state", 2] + - ["sw1.state_led_en", 1] + - ["bl0937.power_coeff", 1.64358469] # Same as ShellyPlugS + - when: build_vars.MODEL == "ShellyRGBW2" apply: name: rgbw2-color # To allow OTA from stock fw. diff --git a/src/ShellyPlugUS1/shelly_init.cpp b/src/ShellyPlugUS1/shelly_init.cpp new file mode 100644 index 00000000..4d98c813 --- /dev/null +++ b/src/ShellyPlugUS1/shelly_init.cpp @@ -0,0 +1,52 @@ +/* + * 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_main.hpp" +#include "shelly_output.hpp" +#include "shelly_pm_bl0937.hpp" +#include "shelly_temp_sensor_ntc.hpp" + +namespace shelly { + +static OutputPin *s_led_out = nullptr; + +void CreatePeripherals(std::vector> *inputs, + std::vector> *outputs, + std::vector> *pms, + std::unique_ptr *sys_temp) { + outputs->emplace_back(new OutputPin(1, 15, 1)); + s_led_out = new OutputPin(99, 0, 0); // Red LED. + std::unique_ptr pm( + new BL0937PowerMeter(1, 5 /* CF */, 14 /* CF1 */, 12 /* SEL */, 2)); + 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())); + } + sys_temp->reset(new TempSensorSDNT1608X103F3950(0, 3.3f, 33000.0f)); +} + +void CreateComponents(std::vector> *comps, + std::vector> *accs, + HAPAccessoryServerRef *svr) { + CreateHAPSwitch(1, mgos_sys_config_get_sw1(), nullptr, comps, accs, svr, + true /* to_pri_acc */, s_led_out); +} + +} // namespace shelly