| 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 <fcntl.h> | ||
| 16 | #include <unistd.h> | ||
| 17 | |||
| 18 | #include "../common.h" | ||
| 19 | |||
| 20 | #include "TmpFileGPIO.h" | ||
| 21 | |||
| 22 | 50429 | TmpFilePinCapabilities::TmpFilePinCapabilities(const std::string& n, uint32_t kg) : | |
| 23 | 50429 | PinCapabilitiesFluent(n, kg) { | |
| 24 |
1/2✓ Branch 0 taken 50429 times.
✗ Branch 1 not taken.
|
50429 | filename = "/tmp/GPIO-"; |
| 25 |
1/2✓ Branch 0 taken 50429 times.
✗ Branch 1 not taken.
|
50429 | filename += n; |
| 26 | 50429 | } | |
| 27 | |||
| 28 | 538 | int TmpFilePinCapabilities::configPin(const std::string& mode, | |
| 29 | bool directionOut, | ||
| 30 | const std::string& desc) const { | ||
| 31 | 538 | unlink(filename.c_str()); | |
| 32 | 538 | return 0; | |
| 33 | } | ||
| 34 | |||
| 35 | 728 | bool TmpFilePinCapabilities::getValue() const { | |
| 36 | 728 | return FileExists(filename); | |
| 37 | } | ||
| 38 | 1190 | void TmpFilePinCapabilities::setValue(bool i) const { | |
| 39 |
2/2✓ Branch 0 taken 484 times.
✓ Branch 1 taken 706 times.
|
1190 | if (i) |
| 40 | 484 | Touch(filename); | |
| 41 | else | ||
| 42 | 706 | unlink(filename.c_str()); | |
| 43 | 1190 | } | |
| 44 | |||
| 45 | class NullTmpFilePinCapabilities : public TmpFilePinCapabilities { | ||
| 46 | public: | ||
| 47 | 3289 | NullTmpFilePinCapabilities() : | |
| 48 |
2/4✓ Branch 0 taken 3289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3289 times.
✗ Branch 3 not taken.
|
9867 | TmpFilePinCapabilities("-none-", 0) {} |
| 49 | 345 | virtual const PinCapabilities* ptr() const override { return nullptr; } | |
| 50 | }; | ||
| 51 | static NullTmpFilePinCapabilities NULL_TMPFILE_INSTANCE; | ||
| 52 | |||
| 53 | static std::vector<TmpFilePinCapabilities> TMPFILE_PINS; | ||
| 54 | |||
| 55 | 2357 | void TmpFilePinProvider::Init() { | |
| 56 |
2/2✓ Branch 0 taken 47140 times.
✓ Branch 1 taken 2357 times.
|
49497 | for (int x = 1; x <= 20; x++) { |
| 57 |
1/2✓ Branch 0 taken 47140 times.
✗ Branch 1 not taken.
|
47140 | std::string p = "TF-" + std::to_string(x); |
| 58 |
2/4✓ Branch 0 taken 47140 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47140 times.
✗ Branch 3 not taken.
|
47140 | TMPFILE_PINS.push_back(TmpFilePinCapabilities(p, x)); |
| 59 | 47140 | } | |
| 60 | 2357 | } | |
| 61 | 2372 | std::vector<std::string> TmpFilePinProvider::getPinNames() { | |
| 62 | 2372 | std::vector<std::string> ret; | |
| 63 |
2/2✓ Branch 0 taken 47440 times.
✓ Branch 1 taken 2372 times.
|
49812 | for (auto& a : TMPFILE_PINS) { |
| 64 |
1/2✓ Branch 0 taken 47440 times.
✗ Branch 1 not taken.
|
47440 | ret.push_back(a.name); |
| 65 | } | ||
| 66 | 2372 | return ret; | |
| 67 | ✗ | } | |
| 68 | 1173 | const PinCapabilities& TmpFilePinProvider::getPinByName(const std::string& name) { | |
| 69 |
2/2✓ Branch 0 taken 10877 times.
✓ Branch 1 taken 270 times.
|
11147 | for (auto& a : TMPFILE_PINS) { |
| 70 |
2/2✓ Branch 0 taken 903 times.
✓ Branch 1 taken 9974 times.
|
10877 | if (a.name == name) { |
| 71 | 903 | return a; | |
| 72 | } | ||
| 73 | } | ||
| 74 | 270 | return NULL_TMPFILE_INSTANCE; | |
| 75 | } | ||
| 76 | 7 | const PinCapabilities& TmpFilePinProvider::getPinByGPIO(int chip, int gpio) { | |
| 77 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 7 times.
|
147 | for (auto& a : TMPFILE_PINS) { |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
|
140 | if (a.gpio == gpio) { |
| 79 | ✗ | return a; | |
| 80 | } | ||
| 81 | } | ||
| 82 | 7 | return NULL_TMPFILE_INSTANCE; | |
| 83 | } | ||
| 84 | 69 | const PinCapabilities& TmpFilePinProvider::getPinByUART(const std::string& n) { | |
| 85 | 69 | return NULL_TMPFILE_INSTANCE; | |
| 86 | } | ||
| 87 |