| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include "MultiSensorSource.h" | ||
| 18 | |||
| 19 | 1 | MultiSensorSource::MultiSensorSource(Json::Value& config) : | |
| 20 | 1 | SensorSource(config) { | |
| 21 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | for (int x = 0; x < config["sources"].size(); x++) { |
| 22 |
3/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1 | std::string sourcename = config["sources"][x]["source"].asString(); |
| 23 | ✗ | uint32_t chan = config["sources"][x]["channels"].asInt(); | |
| 24 | ✗ | SensorSource* src = Sensors::INSTANCE.getSensorSource(sourcename); | |
| 25 | ✗ | if (src) { | |
| 26 | ✗ | sources.push_back(src); | |
| 27 | ✗ | channels.push_back(chan); | |
| 28 | } | ||
| 29 | ✗ | } | |
| 30 | 3 | } | |
| 31 | ✗ | MultiSensorSource::~MultiSensorSource() { | |
| 32 | ✗ | } | |
| 33 | |||
| 34 | ✗ | void MultiSensorSource::Init(std::map<int, std::function<bool(int)>>& callbacks) { | |
| 35 | ✗ | std::map<int, std::function<bool(int)>> cb; | |
| 36 | ✗ | for (auto& a : sources) { | |
| 37 | ✗ | if (a) { | |
| 38 | ✗ | a->Init(cb); | |
| 39 | } | ||
| 40 | } | ||
| 41 | ✗ | } | |
| 42 | |||
| 43 | ✗ | void MultiSensorSource::lockToGroup(int i) { | |
| 44 | ✗ | for (auto& a : sources) { | |
| 45 | ✗ | if (a) { | |
| 46 | ✗ | a->lockToGroup(i); | |
| 47 | } | ||
| 48 | } | ||
| 49 | ✗ | } | |
| 50 | |||
| 51 | ✗ | void MultiSensorSource::update(bool forceInstant) { | |
| 52 | ✗ | for (auto& a : sources) { | |
| 53 | ✗ | if (a) { | |
| 54 | ✗ | a->update(forceInstant); | |
| 55 | } | ||
| 56 | } | ||
| 57 | ✗ | } | |
| 58 | ✗ | void MultiSensorSource::enable(int id) { | |
| 59 | ✗ | if (id < 0) { | |
| 60 | ✗ | return; | |
| 61 | } | ||
| 62 | ✗ | for (int x = 0; x < sources.size(); x++) { | |
| 63 | ✗ | if (id < channels[x]) { | |
| 64 | ✗ | sources[x]->enable(id); | |
| 65 | ✗ | return; | |
| 66 | } | ||
| 67 | ✗ | id -= channels[x]; | |
| 68 | } | ||
| 69 | } | ||
| 70 | ✗ | int32_t MultiSensorSource::getValue(int id) { | |
| 71 | ✗ | if (id < 0) { | |
| 72 | ✗ | return 0; | |
| 73 | } | ||
| 74 | ✗ | for (int x = 0; x < sources.size(); x++) { | |
| 75 | ✗ | if (id < channels[x]) { | |
| 76 | ✗ | return sources[x]->getValue(id); | |
| 77 | } | ||
| 78 | ✗ | id -= channels[x]; | |
| 79 | } | ||
| 80 | ✗ | return 0; | |
| 81 | } | ||
| 82 |