|
| 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