Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e85f02dd authored by xNUTx's avatar xNUTx Committed by Ethan Yonker
Browse files

Support reading since_epoch and secondary brightness files

TWFunc::Fixup_Time_On_Boot: Will now try to read
/sys/class/rtc/rtc0/since_epoch to correct time, if that fails
it will try to use the ats files to correct time.

TWFunc::Set_Brightness: One single function to set brightness
from both the automated functions and the gui actions. It is
able to set a second brightness path if present, it will set
them both the same value. Many Sony devices have 2 brightness
files in the sysfs that must be set to properly set the
brightness.

Change-Id: I7ca582109085dfbcb46b8de73ad031e4b7903fca
parent cd56f8cb
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -261,6 +261,9 @@ endif
ifneq ($(TW_BRIGHTNESS_PATH),)
	LOCAL_CFLAGS += -DTW_BRIGHTNESS_PATH=$(TW_BRIGHTNESS_PATH)
endif
ifneq ($(TW_SECONDARY_BRIGHTNESS_PATH),)
	LOCAL_CFLAGS += -DTW_SECONDARY_BRIGHTNESS_PATH=$(TW_SECONDARY_BRIGHTNESS_PATH)
endif
ifneq ($(TW_MAX_BRIGHTNESS),)
	LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=$(TW_MAX_BRIGHTNESS)
endif
+14 −6
Original line number Diff line number Diff line
@@ -976,8 +976,17 @@ void DataManager::SetDefaultValues()
		mConstValues.insert(make_pair("tw_brightness_max", maxVal.str()));
		mValues.insert(make_pair("tw_brightness", make_pair(maxVal.str(), 1)));
		mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1)));
#ifdef TW_SECONDARY_BRIGHTNESS_PATH
		string secondfindbright = EXPAND(TW_SECONDARY_BRIGHTNESS_PATH);
		if (secondfindbright != "" && TWFunc::Path_Exists(secondfindbright)) {
			LOGINFO("Will use a second brightness file at '%s'\n", secondfindbright.c_str());
			mConstValues.insert(make_pair("tw_secondary_brightness_file", secondfindbright));
		} else {
			LOGINFO("Specified secondary brightness file '%s' not found.\n", secondfindbright.c_str());
		}
#endif
		string max_bright = maxVal.str();
		TWFunc::write_file(findbright, max_bright);
		TWFunc::Set_Brightness(max_bright);
	}
#endif
	mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1)));
@@ -1139,12 +1148,11 @@ void DataManager::ReadSettingsFile(void)
#endif // ifdef TW_OEM_BUILD
	PartitionManager.Mount_All_Storage();
	update_tz_environment_variables();

	string brightness_path = GetStrValue("tw_brightness_file");
	if (!brightness_path.empty() && brightness_path != "/nobrightness" && TWFunc::Path_Exists(brightness_path)) {
		string brightness_value = GetStrValue("tw_brightness");
		TWFunc::write_file(brightness_path, brightness_value);
#ifdef TW_MAX_BRIGHTNESS
	if (GetStrValue("tw_brightness_path") != "/nobrightness") {
		TWFunc::Set_Brightness(GetStrValue("tw_brightness"));
	}
#endif
}

string DataManager::GetCurrentStoragePath(void)
+5 −0
Original line number Diff line number Diff line
@@ -824,6 +824,11 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
		return 0;
	}

	if (function == "setbrightness")
	{
		return TWFunc::Set_Brightness(arg);
	}

	if (isThreaded)
	{
		if (function == "fileexists")
+11 −29
Original line number Diff line number Diff line
@@ -97,11 +97,11 @@ int blanktimer::setClockTimer(void) {
		if (sleepTimer > 2 && diff.tv_sec > (sleepTimer - 2) && conblank == 0) {
			orig_brightness = getBrightness();
			setConBlank(1);
			setBrightness(5);
			TWFunc::Set_Brightness("5");
		}
		if (sleepTimer && diff.tv_sec > sleepTimer && conblank < 2) {
			setConBlank(2);
			setBrightness(0);
			TWFunc::Set_Brightness("0");
			screenoff = true;
			TWFunc::check_and_run_script("/sbin/postscreenblank.sh", "blank");
			PageManager::ChangeOverlay("lock");
@@ -115,39 +115,20 @@ int blanktimer::setClockTimer(void) {
	return -1; //shouldn't get here
}

int blanktimer::getBrightness(void) {
	string results;
string blanktimer::getBrightness(void) {
	string result;
	string brightness_path;
	DataManager::GetValue("tw_brightness_file", brightness_path);
	if ((TWFunc::read_file(brightness_path, results)) != 0)
		return -1;
	int result = atoi(results.c_str());
	if (result == 0) {
		int tw_brightness;
		DataManager::GetValue("tw_brightness", tw_brightness);
		if (tw_brightness) {
			result = tw_brightness;
		} else {
			result = 255;
		}
	if (brightness_path == "/nobrightness")
		return brightness_path;
	DataManager::GetValue("tw_brightness", result);
	if (result == "") {
		result = "255";
	}
	return result;

}

int blanktimer::setBrightness(int brightness) {
	string brightness_path;
	string bstring;
	char buff[100];
	DataManager::GetValue("tw_brightness_file", brightness_path);
	sprintf(buff, "%d", brightness);
	bstring = buff;
	if ((TWFunc::write_file(brightness_path, bstring)) != 0)
		return -1;
	gui_forceRender();
	return 0;
}

void blanktimer::resetTimerAndUnblank(void) {
	setTimer();
	switch (conblank) {
@@ -165,7 +146,8 @@ void blanktimer::resetTimerAndUnblank(void) {
			screenoff = false;
			// No break here, we want to keep going
		case 1:
			setBrightness(orig_brightness);
			if (orig_brightness != "/nobrightness")
				TWFunc::Set_Brightness(orig_brightness);
			setConBlank(0);
			break;
	}
+2 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ private:
	void setConBlank(int blank);
	void setTimer(void);
	timespec getTimer(void);
	int getBrightness(void);
	string getBrightness(void);
	int setBrightness(int brightness);
	int setBlankTimer(void);
	int setClockTimer(void);
@@ -51,7 +51,7 @@ private:
	int conblank;
	timespec btimer;
	unsigned long long sleepTimer;
	int orig_brightness;
	string orig_brightness;
	bool screenoff;
};

Loading