Skip to content

Commit 266969e

Browse files
committed
WIP Shelly Plug US support
Stock calls it "us1", implying there may be 2 at som point, so we call it ShellyPlugUS1 as well. #749
1 parent 6108151 commit 266969e

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MAKEFLAGS += --warn-undefined-variables
22

3-
.PHONY: build check-format format release upload Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyI3 ShellyPlug ShellyPlugS ShellyRGBW2
3+
.PHONY: build check-format format release upload \
4+
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyI3 ShellyPlug ShellyPlugS ShellyPlugUS1 ShellyRGBW2
45

56
MOS ?= mos
67
# Build locally by default if Docker is available.
@@ -56,6 +57,9 @@ ShellyPlug: build-ShellyPlug
5657
ShellyPlugS: build-ShellyPlugS
5758
@true
5859

60+
ShellyPlugUS1: build-ShellyPlugUS1
61+
@true
62+
5963
ShellyRGBW2: build-ShellyRGBW2
6064
@true
6165

mos.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,37 @@ conds:
438438
- ["sw1.state_led_en", 1]
439439
- ["bl0937.power_coeff", 1.64358469] # (16 + 1010 + 1935) / (9.55 + 617 + 1175)
440440

441+
- when: build_vars.MODEL == "ShellyPlugUS1"
442+
apply:
443+
name: shelly-plug-us1
444+
libs:
445+
- location: https://github.com/mongoose-os-libs/mongoose
446+
variant: esp8266-nossl
447+
build_vars:
448+
FLASH_SIZE: 2097152
449+
FS_SIZE: 262144
450+
BOOT_CONFIG_ADDR: 0x7000
451+
MGOS_ROOT_FS_TYPE: SPIFFS
452+
cdefs:
453+
LED_GPIO: 2 # Blue, 0 red.
454+
LED_ON: 0
455+
BTN_GPIO: 13
456+
BTN_DOWN: 0
457+
PRODUCT_HW_REV: '"1.0"'
458+
STOCK_FW_MODEL: '"SHPLG-U1"'
459+
MG_ENABLE_SSL: 0
460+
config_schema:
461+
- ["device.id", "shellyplugu1-??????"]
462+
- ["shelly.name", "shellyplugu1-??????"]
463+
- ["wifi.ap.ssid", "shellyplugu1-??????"]
464+
- ["sw1", "sw", {title: "Plug settings"}]
465+
- ["sw1.name", "Shelly Plug US"]
466+
- ["sw1.in_mode", -1]
467+
- ["sw1.svc_type", 1] # Outlet
468+
- ["sw1.initial_state", 2]
469+
- ["sw1.state_led_en", 1]
470+
- ["bl0937.power_coeff", 1.64358469] # Same as ShellyPlugS
471+
441472
- when: build_vars.MODEL == "ShellyRGBW2"
442473
apply:
443474
name: rgbw2-color # To allow OTA from stock fw.

src/ShellyPlugUS1/shelly_init.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Shelly-HomeKit Contributors
3+
* All rights reserved
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "shelly_main.hpp"
19+
#include "shelly_output.hpp"
20+
#include "shelly_pm_bl0937.hpp"
21+
#include "shelly_temp_sensor_ntc.hpp"
22+
23+
namespace shelly {
24+
25+
static OutputPin *s_led_out = nullptr;
26+
27+
void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
28+
std::vector<std::unique_ptr<Output>> *outputs,
29+
std::vector<std::unique_ptr<PowerMeter>> *pms,
30+
std::unique_ptr<TempSensor> *sys_temp) {
31+
outputs->emplace_back(new OutputPin(1, 15, 1));
32+
s_led_out = new OutputPin(99, 0, 0); // Red LED.
33+
std::unique_ptr<PowerMeter> pm(
34+
new BL0937PowerMeter(1, 5 /* CF */, 14 /* CF1 */, 12 /* SEL */, 2));
35+
const Status &st = pm->Init();
36+
if (st.ok()) {
37+
pms->emplace_back(std::move(pm));
38+
} else {
39+
const std::string &s = st.ToString();
40+
LOG(LL_ERROR, ("PM init failed: %s", s.c_str()));
41+
}
42+
sys_temp->reset(new TempSensorSDNT1608X103F3950(0, 3.3f, 33000.0f));
43+
}
44+
45+
void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
46+
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
47+
HAPAccessoryServerRef *svr) {
48+
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), nullptr, comps, accs, svr,
49+
true /* to_pri_acc */, s_led_out);
50+
}
51+
52+
} // namespace shelly

0 commit comments

Comments
 (0)