| 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 <string.h> | ||
| 18 | #include <string> | ||
| 19 | |||
| 20 | #include "ChannelOutput.h" | ||
| 21 | #include "../commands/Commands.h" | ||
| 22 | #include "../log.h" | ||
| 23 | #include "../util/GPIOUtils.h" | ||
| 24 | |||
| 25 | 1276 | ChannelOutput::ChannelOutput(unsigned int startChannel, | |
| 26 | 1276 | unsigned int channelCount) : | |
| 27 |
1/2✓ Branch 0 taken 1276 times.
✗ Branch 1 not taken.
|
1276 | m_outputType(""), |
| 28 | 1276 | m_startChannel(startChannel), | |
| 29 | 2552 | m_channelCount(channelCount) { | |
| 30 | 1276 | } | |
| 31 | |||
| 32 | 2552 | ChannelOutput::~ChannelOutput() { | |
| 33 | 2552 | LogDebug(VB_CHANNELOUT, "ChannelOutput::~ChannelOutput()\n"); | |
| 34 | 2552 | } | |
| 35 | |||
| 36 | 1210 | int ChannelOutput::Init(Json::Value config) { | |
| 37 | 1210 | LogDebug(VB_CHANNELOUT, "ChannelOutput::Init(JSON)\n"); | |
| 38 |
2/4✓ Branch 0 taken 1210 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1210 times.
✗ Branch 3 not taken.
|
1210 | m_outputType = config["type"].asString(); |
| 39 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1209 times.
|
1210 | if (m_channelCount == -1) |
| 40 | 1 | m_channelCount = 0; | |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1170 times.
|
1210 | if (config.isMember("base")) { |
| 43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (config["base"].isMember("gpios")) { |
| 44 | ✗ | Json::Value gpios = config["base"]["gpios"]; | |
| 45 | ✗ | std::string pinName; | |
| 46 | ✗ | for (int i = 0; i < gpios.size(); i++) { | |
| 47 | ✗ | pinName = gpios[i]["pin"].asString(); | |
| 48 | |||
| 49 | ✗ | if (gpios[i].isMember("mode")) { | |
| 50 | ✗ | m_usedGPIOS.push_back(pinName); | |
| 51 | ✗ | const PinCapabilities& pin = PinCapabilities::getPinByName(pinName); | |
| 52 | |||
| 53 | ✗ | std::string pinMode = gpios[i]["mode"].asString(); | |
| 54 | |||
| 55 | ✗ | if ((pinMode == "gpio") || (pinMode == "gpio_pu") || (pinMode == "gpio_pd")) { | |
| 56 | ✗ | std::string pinDirection = gpios[i]["direction"].asString(); | |
| 57 | ✗ | if (pinDirection == "out") { | |
| 58 | ✗ | pin.configPin(pinMode, true, GetOutputType()); | |
| 59 | ✗ | } else if (pinDirection == "in") { | |
| 60 | ✗ | pin.configPin(pinMode, false, GetOutputType()); | |
| 61 | } else { | ||
| 62 | ✗ | LogErr(VB_CHANNELOUT, "Invalid pin direction of '%s' on GPIO pin %s\n", pinDirection.c_str(), pinName.c_str()); | |
| 63 | ✗ | continue; | |
| 64 | } | ||
| 65 | |||
| 66 | ✗ | if (gpios[i].isMember("value")) { | |
| 67 | ✗ | int value = gpios[i]["value"].asInt(); | |
| 68 | |||
| 69 | ✗ | if (value == 0) { | |
| 70 | ✗ | pin.setValue(false); | |
| 71 | ✗ | } else if (value == 1) { | |
| 72 | ✗ | pin.setValue(true); | |
| 73 | } else { | ||
| 74 | ✗ | LogErr(VB_CHANNELOUT, "Invalid pin value of '%d' on GPIO pin %s\n", value, pinName.c_str()); | |
| 75 | ✗ | continue; | |
| 76 | } | ||
| 77 | } | ||
| 78 | ✗ | } else { | |
| 79 | ✗ | pin.configPin(pinMode, true, GetOutputType()); | |
| 80 | } | ||
| 81 | ✗ | } | |
| 82 | } | ||
| 83 | ✗ | } | |
| 84 | } | ||
| 85 | |||
| 86 | 1210 | DumpConfig(); | |
| 87 | 1210 | return 1; | |
| 88 | } | ||
| 89 | |||
| 90 | 1231 | int ChannelOutput::Close(void) { | |
| 91 | 1231 | LogDebug(VB_CHANNELOUT, "ChannelOutput::Close()\n"); | |
| 92 |
2/2✓ Branch 0 taken 278 times.
✓ Branch 1 taken 1231 times.
|
1509 | for (auto& gpio : m_usedGPIOS) { |
| 93 |
1/2✓ Branch 0 taken 278 times.
✗ Branch 1 not taken.
|
278 | const PinCapabilities& pin = PinCapabilities::getPinByName(gpio); |
| 94 |
1/2✓ Branch 0 taken 278 times.
✗ Branch 1 not taken.
|
278 | pin.releasePin(); |
| 95 | } | ||
| 96 | 1231 | m_usedGPIOS.clear(); | |
| 97 | 1231 | return 1; | |
| 98 | } | ||
| 99 | |||
| 100 | 1255 | void ChannelOutput::DumpConfig(void) { | |
| 101 | 1255 | LogDebug(VB_CHANNELOUT, "ChannelOutput::DumpConfig()\n"); | |
| 102 | |||
| 103 | 1255 | LogDebug(VB_CHANNELOUT, " Output Type : %s\n", m_outputType.c_str()); | |
| 104 | 1255 | LogDebug(VB_CHANNELOUT, " Start Channel : %u\n", m_startChannel + 1); | |
| 105 | 1255 | LogDebug(VB_CHANNELOUT, " Channel Count : %u\n", m_channelCount); | |
| 106 | 1255 | } | |
| 107 |