Skip to content

Commit

Permalink
Advanced charge control interface: simplifying a bit
Browse files Browse the repository at this point in the history
Signed-off-by: sunilpaulmathew <sunil.kde@gmail.com>
  • Loading branch information
sunilpaulmathew committed Mar 21, 2018
1 parent 1cc3adc commit fd486e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,12 @@ protected void init() {
protected void addItems(List<RecyclerViewItem> items) {
levelInit(items);
voltageInit(items);
fastChargeControlInit(items);
chargeRateInit(items);
if (mBattery.hasBlx()) {
blxInit(items);
}
if (mBattery.hasForceFastCharge()) {
ForceFastChargeInit(items);
}
if (mBattery.hasFastChargeControlAC()) {
FastChargeControlACinit(items);
}
if (mBattery.hasFastChargeControlUSB()) {
FastChargeControlUSBinit(items);
}
if (mBattery.hasFastChargeControlWIRELESS()) {
FastChargeControlWirelessinit(items);
}
if (mBattery.hasMtpForceFastCharge()) {
MtpFastChargeInit(items);
}
if (mBattery.hasScreenCurrentLimit()) {
ScreenCurrentLimitInit(items);
}
if (mBattery.hasChargeCustomAC()) {
WarningChargingInit(items);
fastChargeInit(items);
}
}

Expand Down Expand Up @@ -118,14 +99,11 @@ private void voltageInit(List<RecyclerViewItem> items) {
items.add(mVoltage);
}

private void fastChargeControlInit(List<RecyclerViewItem> items) {
CardView FastChargeCard = new CardView(getActivity());
FastChargeCard.setTitle(getString(R.string.charge_levels));

items.add(FastChargeCard);
}
private void fastChargeInit(List<RecyclerViewItem> items) {
CardView fastChargeCard = new CardView(getActivity());
fastChargeCard.setTitle(getString(R.string.acci));

private void ForceFastChargeInit(List<RecyclerViewItem> items) {
if (mBattery.hasForceFastCharge()) {
SelectView forceFastCharge = new SelectView();
forceFastCharge.setTitle(getString(R.string.fast_charge));
forceFastCharge.setSummary(getString(R.string.fast_charge_summary));
Expand All @@ -138,10 +116,11 @@ public void onItemSelected(SelectView selectView, int position, String item) {
}
});

items.add(forceFastCharge);
fastChargeCard.addItem(forceFastCharge);

}

private void FastChargeControlACinit(List<RecyclerViewItem> items) {
if (mBattery.hasFastChargeControlAC()) {
SelectView ACLevelCard = new SelectView();
ACLevelCard.setTitle(getString(R.string.charge_level_ac));
ACLevelCard.setSummary(getString(R.string.charge_level_ac_summary));
Expand All @@ -153,10 +132,11 @@ public void onItemSelected(SelectView selectView, int position, String item) {
mBattery.setFastChargeControlAC(item, getActivity());
}
});
items.add(ACLevelCard);
fastChargeCard.addItem(ACLevelCard);

}

private void FastChargeControlUSBinit(List<RecyclerViewItem> items) {
if (mBattery.hasFastChargeControlUSB()) {
SelectView USBLevelCard = new SelectView();
USBLevelCard.setTitle(getString(R.string.charge_level_usb));
USBLevelCard.setSummary(getString(R.string.charge_level_usb_summary));
Expand All @@ -168,10 +148,10 @@ public void onItemSelected(SelectView selectView, int position, String item) {
mBattery.setFastChargeControlUSB(item, getActivity());
}
});
items.add(USBLevelCard);
fastChargeCard.addItem(USBLevelCard);
}

private void FastChargeControlWirelessinit(List<RecyclerViewItem> items) {
if (mBattery.hasFastChargeControlWIRELESS()) {
SelectView WirelessLevelCard = new SelectView();
WirelessLevelCard.setTitle(getString(R.string.charge_level_wireless));
WirelessLevelCard.setSummary(getString(R.string.charge_level_wireless_summary));
Expand All @@ -183,10 +163,10 @@ public void onItemSelected(SelectView selectView, int position, String item) {
mBattery.setFastChargeControlWIRELESS(item, getActivity());
}
});
items.add(WirelessLevelCard);
fastChargeCard.addItem(WirelessLevelCard);
}

private void MtpFastChargeInit(List<RecyclerViewItem> items) {
if (mBattery.hasMtpForceFastCharge()) {
SwitchView MtpFastCharge = new SwitchView();
MtpFastCharge.setTitle(getString(R.string.mtp_fast_charge));
MtpFastCharge.setSummary(getString(R.string.mtp_fast_charge_summary));
Expand All @@ -198,10 +178,10 @@ public void onChanged(SwitchView switchView, boolean isChecked) {
}
});

items.add(MtpFastCharge);
fastChargeCard.addItem(MtpFastCharge);
}

private void ScreenCurrentLimitInit(List<RecyclerViewItem> items) {
if (mBattery.hasScreenCurrentLimit()) {
SwitchView ScreenLimit = new SwitchView();
ScreenLimit.setTitle(getString(R.string.screen_limit));
ScreenLimit.setSummary(getString(R.string.screen_limit_summary));
Expand All @@ -213,99 +193,11 @@ public void onChanged(SwitchView switchView, boolean isChecked) {
}
});

items.add(ScreenLimit);
}

private void WarningChargingInit(List<RecyclerViewItem> items) {
CardView WarningChargeCard = new CardView(getActivity());
WarningChargeCard.setTitle(getString(R.string.warning_charge));

if (mBattery.hasFailsafe()) {
SwitchView Failsafe = new SwitchView();
Failsafe.setTitle(getString(R.string.failsafe));
Failsafe.setSummary(getString(R.string.failsafe_summary));
Failsafe.setChecked(mBattery.isFailsafe());
Failsafe.addOnSwitchListener(new SwitchView.OnSwitchListener() {
@Override
public void onChanged(SwitchView switchView, boolean isChecked) {
mBattery.enableFailsafe(isChecked, getActivity());
}
});

WarningChargeCard.addItem(Failsafe);
}

if (mBattery.hasFastChargeCustomAC()) {
SeekBarView chargingCustomAC = new SeekBarView();
chargingCustomAC.setTitle(getString(R.string.charging_custom_ac));
chargingCustomAC.setSummary(getString(R.string.charging_current_ac_summary));
chargingCustomAC.setUnit(getString(R.string.ma));
chargingCustomAC.setMax(2200);
chargingCustomAC.setMin(100);
chargingCustomAC.setOffset(10);
chargingCustomAC.setProgress(mBattery.getChargeCustomAC() / 10 - 10 );
chargingCustomAC.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {
@Override
public void onMove(SeekBarView seekBarView, int position, String value) {
}

@Override
public void onStop(SeekBarView seekBarView, int position, String value) {
mBattery.setChargeControlAC((position + 10) * 10, getActivity());
}
});

WarningChargeCard.addItem(chargingCustomAC);
}

if (mBattery.hasFastChargeCustomUSB()) {
SeekBarView chargingCustomUSB = new SeekBarView();
chargingCustomUSB.setTitle(getString(R.string.charging_custom_usb));
chargingCustomUSB.setSummary(getString(R.string.charging_current_usb_summary));
chargingCustomUSB.setUnit(getString(R.string.ma));
chargingCustomUSB.setMax(1200);
chargingCustomUSB.setMin(100);
chargingCustomUSB.setOffset(10);
chargingCustomUSB.setProgress(mBattery.getChargeCustomUSB() / 10 - 10);
chargingCustomUSB.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {
@Override
public void onStop(SeekBarView seekBarView, int position, String value) {
mBattery.setChargeControlUSB((position + 10) * 10, getActivity());
}

@Override
public void onMove(SeekBarView seekBarView, int position, String value) {
}
});

WarningChargeCard.addItem(chargingCustomUSB);
}

if (mBattery.hasFastChargeCustomWireless()) {
SeekBarView chargingCustomWireless = new SeekBarView();
chargingCustomWireless.setTitle(getString(R.string.charging_custom_wireless));
chargingCustomWireless.setSummary(getString(R.string.charging_current_wireless_summary));
chargingCustomWireless.setUnit(getString(R.string.ma));
chargingCustomWireless.setMax(1400);
chargingCustomWireless.setMin(100);
chargingCustomWireless.setOffset(10);
chargingCustomWireless.setProgress(mBattery.getChargeCustomWireless() / 10 - 10 );
chargingCustomWireless.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {
@Override
public void onMove(SeekBarView seekBarView, int position, String value) {
}

@Override
public void onStop(SeekBarView seekBarView, int position, String value) {
mBattery.setChargeControlWireless((position + 10) * 10, getActivity());
}
});

WarningChargeCard.addItem(chargingCustomWireless);
fastChargeCard.addItem(ScreenLimit);
}

if (WarningChargeCard.size() > 0) {
items.add(WarningChargeCard);
if (fastChargeCard.size() > 0) {
items.add(fastChargeCard);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,22 @@ public static Battery getInstance(@NonNull Context context) {
return sInstance;
}

private static final String FORCE_FAST_CHARGE = "/sys/kernel/fast_charge/force_fast_charge";
private static final String MTP_FORCE_FAST_CHARGE = "/sys/kernel/fast_charge/use_mtp_during_fast_charge";
private static final String SCREEN_ON_CURRENT_LIMT = "/sys/kernel/fast_charge/screen_on_current_limit";
private static final String BLX = "/sys/devices/virtual/misc/batterylifeextender/charging_limit";
private static final String AC_CHARGE_LEVEL = "/sys/kernel/fast_charge/ac_levels";
private static final String USB_CHARGE_LEVEL = "/sys/kernel/fast_charge/usb_levels";
private static final String WIRELESS_CHARGE_LEVEL = "/sys/kernel/fast_charge/wireless_levels";
private static final String FAILSAFE_CONTROL = "/sys/kernel/fast_charge/failsafe";
private static final String FAST_CHARGE = "/sys/kernel/fast_charge";
private static final String FORCE_FAST_CHARGE = FAST_CHARGE + "/force_fast_charge";
private static final String CUSTOM_AC_CHARGE_LEVEL = FAST_CHARGE + "/ac_charge_level";
private static final String CUSTOM_USB_CHARGE_LEVEL = FAST_CHARGE + "/usb_charge_level";
private static final String CUSTOM_WIRELESS_CHARGE_LEVEL = FAST_CHARGE + "/wireless_charge_level";

private static final String MTP_FORCE_FAST_CHARGE = FAST_CHARGE + "/use_mtp_during_fast_charge";
private static final String SCREEN_ON_CURRENT_LIMT = FAST_CHARGE + "/screen_on_current_limit";

private static final String AC_CHARGE_LEVEL = FAST_CHARGE + "/ac_levels";
private static final String USB_CHARGE_LEVEL = FAST_CHARGE + "/usb_levels";
private static final String WIRELESS_CHARGE_LEVEL = FAST_CHARGE + "/wireless_levels";
private static final String FAILSAFE_CONTROL = FAST_CHARGE + "/failsafe";

private static final String BLX = "/sys/devices/virtual/misc/batterylifeextender/charging_limit";

private static final String CHARGE_RATE = "/sys/kernel/thundercharge_control";
private static final String CHARGE_RATE_ENABLE = CHARGE_RATE + "/enabled";
private static final String CUSTOM_CURRENT = CHARGE_RATE + "/custom_current";
Expand Down Expand Up @@ -145,32 +148,16 @@ public void setForceFastCharge(int value, Context context) {

public static boolean hasFastChargeControlAC() {
return Utils.existFile(AC_CHARGE_LEVEL);
}

public static boolean hasFastChargeCustomAC() {
return Utils.existFile(CUSTOM_AC_CHARGE_LEVEL);
}

public static boolean hasChargeCustomAC() {
return Utils.existFile(CUSTOM_AC_CHARGE_LEVEL);
}

}

public static String getFastChargeCustomAC() {
return Utils.readFile(CUSTOM_AC_CHARGE_LEVEL);
}

public static int getChargeCustomAC() {
return Utils.strToInt(Utils.readFile(CUSTOM_AC_CHARGE_LEVEL));
}

public void setFastChargeControlAC (String value, Context context) {
run(Control.write(String.valueOf(value), CUSTOM_AC_CHARGE_LEVEL), CUSTOM_AC_CHARGE_LEVEL, context);
}

public void setChargeControlAC(int value, Context context) {
run(Control.write(String.valueOf(value), CUSTOM_AC_CHARGE_LEVEL), CUSTOM_AC_CHARGE_LEVEL, context);
}

public static List<String> getFastChargeControlAC() {
if (sBatteryAvailable == null) {
sBatteryAvailable = Utils.readFile(AC_CHARGE_LEVEL).split(" ");
Expand All @@ -181,19 +168,11 @@ public static List<String> getFastChargeControlAC() {
public static boolean hasFastChargeControlUSB() {
return Utils.existFile(USB_CHARGE_LEVEL);
}

public static boolean hasFastChargeCustomUSB() {
return Utils.existFile(CUSTOM_USB_CHARGE_LEVEL);
}

public static String getFastChargeCustomUSB() {
return Utils.readFile(CUSTOM_USB_CHARGE_LEVEL);
}

public static int getChargeCustomUSB() {
return Utils.strToInt(Utils.readFile(CUSTOM_USB_CHARGE_LEVEL));
}

public static List<String> getFastChargeControlUSB() {
if (sBatteryUSBAvailable == null) {
sBatteryUSBAvailable = Utils.readFile(USB_CHARGE_LEVEL).split(" ");
Expand All @@ -205,10 +184,6 @@ public void setFastChargeControlUSB (String value, Context context) {
run(Control.write(String.valueOf(value), CUSTOM_USB_CHARGE_LEVEL), CUSTOM_USB_CHARGE_LEVEL, context);
}

public void setChargeControlUSB(int value, Context context) {
run(Control.write(String.valueOf(value), CUSTOM_USB_CHARGE_LEVEL), CUSTOM_USB_CHARGE_LEVEL, context);
}

public boolean hasFastChargeControlWIRELESS() {
return Utils.existFile(WIRELESS_CHARGE_LEVEL);
}
Expand All @@ -228,18 +203,6 @@ public void setFastChargeControlWIRELESS (String value, Context context) {
run(Control.write(String.valueOf(value), CUSTOM_WIRELESS_CHARGE_LEVEL), CUSTOM_WIRELESS_CHARGE_LEVEL, context);
}

public static boolean hasFastChargeCustomWireless() {
return Utils.existFile(CUSTOM_WIRELESS_CHARGE_LEVEL);
}

public int getChargeCustomWireless() {
return Utils.strToInt(Utils.readFile(CUSTOM_WIRELESS_CHARGE_LEVEL));
}

public void setChargeControlWireless(int value, Context context) {
run(Control.write(String.valueOf(value), CUSTOM_WIRELESS_CHARGE_LEVEL), CUSTOM_WIRELESS_CHARGE_LEVEL, context);
}

public void enableMtpForceFastCharge(boolean enable, Context context) {
run(Control.write(enable ? "1" : "0", MTP_FORCE_FAST_CHARGE), MTP_FORCE_FAST_CHARGE, context);
}
Expand All @@ -263,18 +226,6 @@ public boolean isScreenCurrentLimit() {
public boolean hasScreenCurrentLimit() {
return Utils.existFile(SCREEN_ON_CURRENT_LIMT);
}

public void enableFailsafe(boolean enable, Context context) {
run(Control.write(enable ? "1" : "0", FAILSAFE_CONTROL), FAILSAFE_CONTROL, context);
}

public boolean isFailsafe() {
return Utils.readFile(FAILSAFE_CONTROL).equals("1");
}

public boolean hasFailsafe() {
return Utils.existFile(FAILSAFE_CONTROL);
}

public int getCapacity() {
return mCapacity;
Expand Down
25 changes: 9 additions & 16 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -567,29 +567,22 @@
<string name="charge_rate">Charge Rate</string>
<string name="charging_current">Charging Current</string>
<string name="charging_current_summary">Set charging current. Caution: Exceeding 1250mA may damage your charging driver.</string>
<string name="charge_levels">Fast Charge Advanced Control Interface</string>

<!-- Advanced Charge Control Interface -->
<string name="acci">Advanced Charge Control Interface</string>
<string name="fast_charge">Fast Charge</string>
<string name="fast_charge_summary">In Custom Mode, the device will charge as per the selected level. Replug your charger when changing this option.</string>
<string name="custom_charge">Custom Mode</string>
<string name="charge_level_ac">AC Charge mA</string>
<string name="charge_level_ac">AC Charge Level (mA)</string>
<string name="charge_level_ac_summary">Choose your Level</string>
<string name="charge_level_usb">USB Charge mA</string>
<string name="charge_level_usb">USB Charge Level (mA)</string>
<string name="charge_level_usb_summary">Choose your Level</string>
<string name="charge_level_wireless">WIRELESS Charge mA</string>
<string name="charge_level_wireless">WIRELESS Charge Level (mA)</string>
<string name="charge_level_wireless_summary">Choose your Level</string>
<string name="mtp_fast_charge">MTP During Fast Charge</string>
<string name="mtp_fast_charge_summary">You can choose if you want MTP during fast charge or not.</string>
<string name="mtp_fast_charge">MTP while Fast Charge</string>
<string name="mtp_fast_charge_summary">Enable MTP while fast charge</string>
<string name="screen_limit">Screen On Current Limit</string>
<string name="screen_limit_summary">Our device majorly reduces the amount of power it draws from the power supply when the screen is on. This happens with and without fast charging capable adapters.</string>
<string name="warning_charge">WARNING CHARGE AREA</string>
<string name="charging_custom_ac">Charging Current AC</string>
<string name="charging_current_ac_summary">Set charging current. Caution: Exceeding 2100mA may damage your equipment.</string>
<string name="charging_custom_usb">Charging Current USB</string>
<string name="charging_current_usb_summary">Set charging current. Caution: Exceeding 1000mA may damage your USB driver.</string>
<string name="charging_custom_wireless">Charging Current WIRELESS</string>
<string name="charging_current_wireless_summary">Set charging current. Caution: Exceeding 1200mA may damage your equipment.</string>
<string name="failsafe">Failsafe</string>
<string name="failsafe_summary">If disabled, you can choose your charging current that is not supported by your equipment (i have limited for secure...)</string>
<string name="screen_limit_summary">Enable Screen On Current Limit</string>

<!-- LED -->
<string name="fade">Fade</string>
Expand Down

0 comments on commit fd486e2

Please sign in to comment.