mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 12:35:33 -04:00
universal7885: fm-hidl: Move to libfileio and libcachedclass
This commit is contained in:
parent
3e5e571267
commit
0c4beb3f8c
3 changed files with 23 additions and 16 deletions
|
|
@ -11,6 +11,7 @@ cc_binary {
|
||||||
"libhidlbase",
|
"libhidlbase",
|
||||||
"libutils",
|
"libutils",
|
||||||
"liblog",
|
"liblog",
|
||||||
|
"libfileio",
|
||||||
"vendor.eureka.hardware.fmradio@1.0",
|
"vendor.eureka.hardware.fmradio@1.0",
|
||||||
"vendor.eureka.hardware.fmradio@1.1",
|
"vendor.eureka.hardware.fmradio@1.1",
|
||||||
"vendor.eureka.hardware.fmradio@1.2",
|
"vendor.eureka.hardware.fmradio@1.2",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
template <class C> static inline C *cachedClass(C *cached) {
|
||||||
|
if (cached != nullptr) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
cached = new C();
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define USE_CACHED(cache) ({ return cachedClass((cache)); })
|
||||||
|
|
@ -19,29 +19,31 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <FileIO.h>
|
||||||
|
#include "CachedClass.h"
|
||||||
|
|
||||||
static int mChannelSpacing = 3;
|
static int mChannelSpacing = 3;
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::fmradio::V1_2 {
|
namespace vendor::eureka::hardware::fmradio::V1_2 {
|
||||||
|
|
||||||
|
static FMRadio *kCached = nullptr;
|
||||||
|
|
||||||
|
constexpr const char* FM_FREQ_CTL = "/sys/devices/virtual/s610_radio/s610_radio/radio_freq_ctrl";
|
||||||
|
constexpr const char* FM_FREQ_SEEK = "/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek";
|
||||||
|
|
||||||
Return<void> FMRadio::setManualFreq(float freq) {
|
Return<void> FMRadio::setManualFreq(float freq) {
|
||||||
std::ofstream file;
|
FileIO::writeline(FM_FREQ_CTL, freq * 1000);
|
||||||
file.open("/sys/devices/virtual/s610_radio/s610_radio/radio_freq_ctrl");
|
|
||||||
file << freq * 1000;
|
|
||||||
file.close();
|
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> FMRadio::adjustFreqByStep(fmradio::V1_0::Direction dir) {
|
Return<void> FMRadio::adjustFreqByStep(fmradio::V1_0::Direction dir) {
|
||||||
std::ofstream file;
|
|
||||||
std::string value = "";
|
std::string value = "";
|
||||||
if (dir == V1_0::Direction::UP) {
|
if (dir == V1_0::Direction::UP) {
|
||||||
value = "1 " + std::to_string(mChannelSpacing * 10);
|
value = "1 " + std::to_string(mChannelSpacing * 10);
|
||||||
} else if (dir == V1_0::Direction::DOWN) {
|
} else if (dir == V1_0::Direction::DOWN) {
|
||||||
value = "0 " + std::to_string(mChannelSpacing * 10);
|
value = "0 " + std::to_string(mChannelSpacing * 10);
|
||||||
}
|
}
|
||||||
file.open("/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek");
|
FileIO::writeline(FM_FREQ_SEEK, value);
|
||||||
file << value;
|
|
||||||
file.close();
|
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
Return<V1_1::Status> FMRadio::isAvailable() {
|
Return<V1_1::Status> FMRadio::isAvailable() {
|
||||||
|
|
@ -53,16 +55,11 @@ Return<V1_1::Status> FMRadio::isAvailable() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Return<void> FMRadio::setChannelSpacing(V1_2::Space space) {
|
Return<void> FMRadio::setChannelSpacing(V1_2::Space space) {
|
||||||
mChannelSpacing = (int)space;
|
mChannelSpacing = static_cast<int>(space);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
Return<int32_t> FMRadio::getFreqFromSysfs() {
|
Return<int32_t> FMRadio::getFreqFromSysfs() {
|
||||||
std::ifstream file;
|
return FileIO::readline(FM_FREQ_CTL);
|
||||||
std::string value;
|
|
||||||
file.open("/sys/devices/virtual/s610_radio/s610_radio/radio_freq_ctrl");
|
|
||||||
std::getline(file, value);
|
|
||||||
file.close();
|
|
||||||
return std::stoi(value);
|
|
||||||
}
|
}
|
||||||
Return<V1_2::Space> FMRadio::getChannelSpacing() {
|
Return<V1_2::Space> FMRadio::getChannelSpacing() {
|
||||||
switch (mChannelSpacing) {
|
switch (mChannelSpacing) {
|
||||||
|
|
@ -80,5 +77,5 @@ Return<V1_2::Space> FMRadio::getChannelSpacing() {
|
||||||
return V1_2::Space::CHANNEL_SPACING_30HZ;
|
return V1_2::Space::CHANNEL_SPACING_30HZ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IFMRadio *FMRadio::getInstance(void) { return new FMRadio(); }
|
IFMRadio *FMRadio::getInstance(void) { USE_CACHED(kCached); }
|
||||||
} // namespace vendor::eureka::hardware::fmradio::V1_2
|
} // namespace vendor::eureka::hardware::fmradio::V1_2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue