Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

04 Leds control #34

Open
wants to merge 5 commits into
base: Oksana.Shevchenko
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions hikey960/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### Led Control Application
Led Control application is placed by the path: ```vendor\gl\hikey960\packages\apps\LedControlApplication```
### Led Control Service
Led Control service is placed by the path: ```vendor\gl\hikey960\packages\services\LedService```
### Led Control HAL
Led Control HAL is placed by the path: ```vendor\gl\hikey960\hardware\interfaces\leds```

### Dependencies:

Android manifest: ```https://github.com/Oksana-Shevchenko/android_manifest```

Hikey Linaro Device: ```https://github.com/Oksana-Shevchenko/hikey-linaro-device```

Hikey Linaro Kernel: ```https://github.com/Oksana-Shevchenko/hikey-linaro-kernel```

Hikey Linaro Poprietary: ```https://github.com/Oksana-Shevchenko/hikey-linaro-proprietary/tree/hikey960-android-p```

Led control HAL, Service, Application: ```https://github.com/Oksana-Shevchenko/gl-android-training-2020/tree/04-LedHal```

### How to build:

1. cd ~/hikey960
2. sync repo in project folder
3. . ./build/envsetup.sh
4. lunch hikey960-userdebug
5. make -j4
6. adb reboot bootloader
7. cd device/linaro/hikey/installer/hikey960
8. ./flash-all.sh
13 changes: 13 additions & 0 deletions hikey960/device-vendor.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PRODUCT_PACKAGES += \
[email protected] \
LedService \
LedControlApplication

DEVICE_MANIFEST_FILE += \
vendor/gl/hikey960/hardware/interfaces/manifest.xml \

DEVICE_MATRIX += \
vendor/gl/hikey960/hardware/interfaces/compatibility_matrix.xml

BOARD_SEPOLICY_DIRS += \
vendor/gl/hikey960/sepolicy
4 changes: 4 additions & 0 deletions hikey960/hardware/interfaces/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hidl_package_root {
name: "vendor.gl.hikey960.hardware",
path: "vendor/gl/hikey960/hardware/interfaces"
}
10 changes: 10 additions & 0 deletions hikey960/hardware/interfaces/compatibility_matrix.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<compatibility-matrix version="1.0" type="device">
<hal format="hidl" optional="false">
<name>vendor.gl.hikey960.hardware.leds</name>
<version>1.0</version>
<interface>
<name>ILedControl</name>
<instance>default</instance>
</interface>
</hal>
</compatibility-matrix>
12 changes: 12 additions & 0 deletions hikey960/hardware/interfaces/leds/1.0/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
hidl_interface {
name: "[email protected]",
root: "vendor.gl.hikey960.hardware",
srcs: [
"ILedControl.hal",
],
interfaces: [
"[email protected]",
],
gen_java:true,
gen_java_constants: true,
}
30 changes: 30 additions & 0 deletions hikey960/hardware/interfaces/leds/1.0/ILedControl.hal
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

package [email protected];

/**
* ILedControl is an interface that can manage leds
*/
interface ILedControl {
/**
* Set custom led settings, triggers to none state, brightnesses to 0
*/
setCustomLedSettings();
/**
* Update led state
*
* @return result true if successful, false otherwise.
*/
updateState(string ledType, bool turnOn) generates (bool result);

/**
* Get led state
*
* @return state true if led is ON, false otherwise.
*/
getLedState(string ledType) generates (bool state);
/**
* Set default led settings: triggers for user leds = heartbeat, trigger for bt = hci0rx, trigger for wifi = phy0tx, brightnesses = 0
*/
setDefaultLedSettings();
};

17 changes: 17 additions & 0 deletions hikey960/hardware/interfaces/leds/1.0/default/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cc_binary {
name: "[email protected]",
init_rc: ["[email protected]"],
relative_install_path: "hw",
vendor: true,
srcs: [
"Leds.cpp",
"service.cpp",
],
shared_libs: [
"libhidlbase",
"libhidltransport",
"libutils",
"liblog",
"[email protected]",
],
}
224 changes: 224 additions & 0 deletions hikey960/hardware/interfaces/leds/1.0/default/Leds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#define LOG_TAG "[email protected]::Leds"

#include <log/log.h>
#include "Leds.h"
#include <iostream>
#include <fstream>
#include <string>


namespace vendor {
namespace gl {
namespace hikey960 {
namespace hardware {
namespace leds {
namespace V1_0 {
namespace implementation {

Leds::Leds() {
ALOGI("Leds::Leds()");
}

Leds::~Leds() {
ALOGI("Leds::~Leds()");
}

Return<void> Leds::setCustomLedSettings() {
ALOGI("Leds::setCustomLedSettings");

saveInitSate();

writeToFile(LEDS_PATH + USR_LED1_FOLDER + TRIGGER_FILE_NAME, NONE_TRIGGER_VALUE);
writeToFile(LEDS_PATH + USR_LED2_FOLDER + TRIGGER_FILE_NAME, NONE_TRIGGER_VALUE);
writeToFile(LEDS_PATH + USR_LED3_FOLDER + TRIGGER_FILE_NAME, NONE_TRIGGER_VALUE);
writeToFile(LEDS_PATH + USR_LED4_FOLDER + TRIGGER_FILE_NAME, NONE_TRIGGER_VALUE);
writeToFile(LEDS_PATH + BT_FOLDER + TRIGGER_FILE_NAME, NONE_TRIGGER_VALUE);
writeToFile(LEDS_PATH + WIFI_FOLDER + TRIGGER_FILE_NAME, NONE_TRIGGER_VALUE);

writeToFile(LEDS_PATH + USR_LED1_FOLDER + BRIGHTNESS_FILE_NAME, LED_TURN_OFF_VALUE);
writeToFile(LEDS_PATH + USR_LED2_FOLDER + BRIGHTNESS_FILE_NAME, LED_TURN_OFF_VALUE);
writeToFile(LEDS_PATH + USR_LED3_FOLDER + BRIGHTNESS_FILE_NAME, LED_TURN_OFF_VALUE);
writeToFile(LEDS_PATH + USR_LED4_FOLDER + BRIGHTNESS_FILE_NAME, LED_TURN_OFF_VALUE);
writeToFile(LEDS_PATH + BT_FOLDER + BRIGHTNESS_FILE_NAME, LED_TURN_OFF_VALUE);
writeToFile(LEDS_PATH + WIFI_FOLDER + BRIGHTNESS_FILE_NAME, LED_TURN_OFF_VALUE);

ALOGI("Leds::setCustomLedSettings. Check that init values are written.");


std::string usrLed1TriggerInitValueTmp = readFromFile(LEDS_PATH + USR_LED1_FOLDER + TRIGGER_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Trigger value from usrLed1 file= %s", usrLed1TriggerInitValue.c_str(), usrLed1TriggerInitValueTmp.c_str());
std::string usrLed2TriggerInitValueTmp = readFromFile(LEDS_PATH + USR_LED2_FOLDER + TRIGGER_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Trigger value from usrLed2 file= %s", usrLed2TriggerInitValue.c_str(), usrLed2TriggerInitValueTmp.c_str());
std::string usrLed3TriggerInitValueTmp = readFromFile(LEDS_PATH + USR_LED3_FOLDER + TRIGGER_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Trigger value from usrLed3 file= %s", usrLed3TriggerInitValue.c_str(), usrLed3TriggerInitValueTmp.c_str());
std::string usrLed4TriggerInitValueTmp = readFromFile(LEDS_PATH + USR_LED4_FOLDER + TRIGGER_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Trigger value from usrLed4 file= %s", usrLed4TriggerInitValue.c_str(), usrLed4TriggerInitValueTmp.c_str());
std::string btLedTriggerInitValueTmp = readFromFile(LEDS_PATH + BT_FOLDER + TRIGGER_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Trigger value from btLed file= %s", btLedTriggerInitValue.c_str(), btLedTriggerInitValueTmp.c_str());
std::string wifiLedTriggerInitValueTmp = readFromFile(LEDS_PATH + WIFI_FOLDER + TRIGGER_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Trigger value from wifiLed file= %s", wifiLedTriggerInitValue.c_str(), wifiLedTriggerInitValueTmp.c_str());

std::string usrLed1BrightnessInitValueTmp = readFromFile(LEDS_PATH + USR_LED1_FOLDER + BRIGHTNESS_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Brightness value from usrLed1 file= %s", usrLed1BrightnessInitValue.c_str(), usrLed1BrightnessInitValueTmp.c_str());
std::string usrLed2BrightnessInitValueTmp = readFromFile(LEDS_PATH + USR_LED2_FOLDER + BRIGHTNESS_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Brightness value from usrLed2 file= %s", usrLed2BrightnessInitValue.c_str(), usrLed2BrightnessInitValueTmp.c_str());
std::string usrLed3BrightnessInitValueTmp = readFromFile(LEDS_PATH + USR_LED3_FOLDER + BRIGHTNESS_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Brightness value from usrLed3 file= %s", usrLed3BrightnessInitValue.c_str(), usrLed3BrightnessInitValueTmp.c_str());
std::string usrLed4BrightnessInitValueTmp = readFromFile(LEDS_PATH + USR_LED4_FOLDER + BRIGHTNESS_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Brightness value from usrLed4 file= %s", usrLed4BrightnessInitValue.c_str(), usrLed4BrightnessInitValueTmp.c_str());
std::string btLedBrightnessInitValueTmp = readFromFile(LEDS_PATH + BT_FOLDER + BRIGHTNESS_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Brightness value from btLed file= %s", btLedBrightnessInitValue.c_str(), btLedBrightnessInitValueTmp.c_str());
std::string wifiLedBrightnessInitValueTmp = readFromFile(LEDS_PATH + WIFI_FOLDER + BRIGHTNESS_FILE_NAME);
ALOGI("Leds::setCustomLedSettings. Value from variable= %s. Brightness value from wifiLed file= %s", wifiLedBrightnessInitValue.c_str(), wifiLedBrightnessInitValueTmp.c_str());

return Void();
}

Return<bool> Leds::updateState(const hidl_string& ledType, bool turnOn) {
std::string ledTypeValue = ledType;
std::string brightnessValue;
std::string ledFolder;

ALOGI("Leds::updateState(%s, %d)", ledTypeValue.c_str(), turnOn);


if (turnOn) {
brightnessValue = LED_TURN_ON_VALUE;
} else {
brightnessValue = LED_TURN_OFF_VALUE;
}

ledFolder = defineLedFolder(ledTypeValue);

if (!ledFolder.empty()) {
writeToFile(LEDS_PATH + ledFolder + BRIGHTNESS_FILE_NAME, brightnessValue);
return true;
} else {
ALOGI("Unable to define led folder");
return false;
}

return false;
}

Return<bool> Leds::getLedState(const hidl_string& ledType) {
std::string ledTypeValue = ledType;
std::string brightnessValue;
std::string ledFolder;

ALOGI("Leds::getLedState(%s)", ledTypeValue.c_str());

ledFolder = defineLedFolder(ledTypeValue);
if (!ledFolder.empty()) {
brightnessValue = readFromFile(LEDS_PATH + ledFolder + BRIGHTNESS_FILE_NAME);
ALOGI("Brightness value = %s for ledType = %s", brightnessValue.c_str(), ledTypeValue.c_str());
if (brightnessValue == LED_TURN_ON_VALUE) {
return true;
} else {
return false;
}

} else {
ALOGI("Unable to define led folder");
return false;
}
}

Return<void> Leds::setDefaultLedSettings() {
ALOGI("Leds::setDefaultLedSettings");

writeToFile(LEDS_PATH + USR_LED1_FOLDER + TRIGGER_FILE_NAME, usrLed1TriggerInitValue);
writeToFile(LEDS_PATH + USR_LED2_FOLDER + TRIGGER_FILE_NAME, usrLed2TriggerInitValue);
writeToFile(LEDS_PATH + USR_LED3_FOLDER + TRIGGER_FILE_NAME, usrLed3TriggerInitValue);
writeToFile(LEDS_PATH + USR_LED4_FOLDER + TRIGGER_FILE_NAME, usrLed4TriggerInitValue);
writeToFile(LEDS_PATH + BT_FOLDER + TRIGGER_FILE_NAME, btLedTriggerInitValue);
writeToFile(LEDS_PATH + WIFI_FOLDER + TRIGGER_FILE_NAME, wifiLedTriggerInitValue);

writeToFile(LEDS_PATH + USR_LED1_FOLDER + BRIGHTNESS_FILE_NAME, usrLed1BrightnessInitValue);
writeToFile(LEDS_PATH + USR_LED2_FOLDER + BRIGHTNESS_FILE_NAME, usrLed2BrightnessInitValue);
writeToFile(LEDS_PATH + USR_LED3_FOLDER + BRIGHTNESS_FILE_NAME, usrLed3BrightnessInitValue);
writeToFile(LEDS_PATH + USR_LED4_FOLDER + BRIGHTNESS_FILE_NAME, usrLed4BrightnessInitValue);
writeToFile(LEDS_PATH + BT_FOLDER + BRIGHTNESS_FILE_NAME, btLedBrightnessInitValue);
writeToFile(LEDS_PATH + WIFI_FOLDER + BRIGHTNESS_FILE_NAME, wifiLedBrightnessInitValue);

return Void();
}

Return<void> Leds::saveInitSate() {
ALOGI("Leds::saveInitSate");

usrLed1TriggerInitValue = readFromFile(LEDS_PATH + USR_LED1_FOLDER + TRIGGER_FILE_NAME);
usrLed2TriggerInitValue = readFromFile(LEDS_PATH + USR_LED2_FOLDER + TRIGGER_FILE_NAME);
usrLed3TriggerInitValue = readFromFile(LEDS_PATH + USR_LED3_FOLDER + TRIGGER_FILE_NAME);
usrLed4TriggerInitValue = readFromFile(LEDS_PATH + USR_LED4_FOLDER + TRIGGER_FILE_NAME);
btLedTriggerInitValue = readFromFile(LEDS_PATH + BT_FOLDER + TRIGGER_FILE_NAME);
wifiLedTriggerInitValue = readFromFile(LEDS_PATH + WIFI_FOLDER + TRIGGER_FILE_NAME);

usrLed1BrightnessInitValue = readFromFile(LEDS_PATH + USR_LED1_FOLDER + BRIGHTNESS_FILE_NAME);
usrLed2BrightnessInitValue = readFromFile(LEDS_PATH + USR_LED2_FOLDER + BRIGHTNESS_FILE_NAME);
usrLed3BrightnessInitValue = readFromFile(LEDS_PATH + USR_LED3_FOLDER + BRIGHTNESS_FILE_NAME);
usrLed4BrightnessInitValue = readFromFile(LEDS_PATH + USR_LED4_FOLDER + BRIGHTNESS_FILE_NAME);
btLedBrightnessInitValue = readFromFile(LEDS_PATH + BT_FOLDER + BRIGHTNESS_FILE_NAME);
wifiLedBrightnessInitValue = readFromFile(LEDS_PATH + WIFI_FOLDER + BRIGHTNESS_FILE_NAME);

return Void();
}

Return<std::string> Leds::defineLedFolder(std::string ledType) {
std::string ledFolder;

if (ledType == USR_LED1_FOLDER) {
ledFolder = USR_LED1_FOLDER;
} else if (ledType == USR_LED2_FOLDER) {
ledFolder = USR_LED2_FOLDER;
} else if (ledType == USR_LED3_FOLDER) {
ledFolder = USR_LED3_FOLDER;
} else if (ledType == USR_LED4_FOLDER) {
ledFolder = USR_LED4_FOLDER;
} else if (ledType == BT_FOLDER) {
ledFolder = BT_FOLDER;
} else if (ledType == WIFI_FOLDER) {
ledFolder = WIFI_FOLDER;
}

return ledFolder;
}

Return<void> Leds::writeToFile(std::string fileName, std::string value) {
ALOGI("Leds::writeToFile(%s, %s)", fileName.c_str(), value.c_str());

std::fstream fs;
fs.open(fileName, std::fstream::out);
if (!fs.is_open()) {
ALOGI("Unable to open file (%s)", fileName.c_str());
} else {
fs << value;
fs.close();
}
return Void();
}

Return<std::string> Leds::readFromFile(std::string fileName) {
ALOGI("Leds::readFromFile (%s)", fileName.c_str());

std::string line;

std::ifstream file (fileName);
if (file.is_open()) {
std::getline(file, line);
ALOGI("Read from file=%s, value=%s ", fileName.c_str(), line.c_str());
file.close();
} else {
ALOGI("Unable to open file (%s)", fileName.c_str());
}

return line;
}

} // namespace implementation
} // namespace V1_0
} // namespace leds
} // namespace hardware
} // namespace hikey960
} // namespace gl
} // namespace vendor
Loading