Skip to content

Commit

Permalink
fix_temp
Browse files Browse the repository at this point in the history
  • Loading branch information
lich4 committed Apr 28, 2024
1 parent 11fb59b commit f05129d
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 99 deletions.
30 changes: 26 additions & 4 deletions ChargeLimiter/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,19 @@ static void onBatteryEventEnd() {
}
}

static float getTempAsC(NSString* key) {
NSNumber* temp_mode = getlocalKV(@"temp_mode");
NSNumber* temp = getlocalKV(key);
float temp_c = temp.intValue / 100.0;
if (temp_mode.intValue == 0) { // °C
return temp_c;
} else if (temp_mode.intValue == 1) { // °F
float temp_f = (temp_c - 32) / 1.8;
return temp_f;
}
return 0;
}

static void onBatteryEvent(io_service_t serv) {
@autoreleasepool {
NSDictionary* old_bat_info = bat_info;
Expand All @@ -459,14 +472,14 @@ static void onBatteryEvent(io_service_t serv) {
NSNumber* charge_below = getlocalKV(@"charge_below");
NSNumber* charge_above = getlocalKV(@"charge_above");
NSNumber* enable_temp = getlocalKV(@"enable_temp");
NSNumber* charge_temp_above = getlocalKV(@"charge_temp_above");
NSNumber* charge_temp_below = getlocalKV(@"charge_temp_below");
NSNumber* capacity = bat_info[@"CurrentCapacity"];
NSNumber* is_charging = bat_info[@"IsCharging"];
NSNumber* is_inflow_enabled = bat_info[@"ExternalConnected"];
BOOL is_adaptor_connected = isAdaptorConnect(bat_info);
NSNumber* adv_disable_inflow = getlocalKV(@"adv_disable_inflow");
NSNumber* temperature_ = bat_info[@"Temperature"];
float charge_temp_above = getTempAsC(@"charge_temp_above");
float charge_temp_below = getTempAsC(@"charge_temp_below");
float temperature = temperature_.intValue / 100.0;
// 优先级: 电量极低 > 停充(电量>温度) > 充电(电量>温度) > 插电
do {
Expand All @@ -493,7 +506,7 @@ static void onBatteryEvent(io_service_t serv) {
}
break;
}
if (enable_temp.boolValue && temperature >= charge_temp_above.intValue) { // 停充-温度高,优先级=3
if (enable_temp.boolValue && temperature >= charge_temp_above) { // 停充-温度高,优先级=3
if (is_charging.boolValue) {
NSFileLog(@"stop charging for high temperature");
setBatteryStatus(NO);
Expand Down Expand Up @@ -523,7 +536,7 @@ static void onBatteryEvent(io_service_t serv) {
break;
}
if ([mode isEqualToString:@"charge_on_plug"]) {
if (enable_temp.boolValue && temperature <= charge_temp_below.intValue) { // 充电-温度低,优先级=5
if (enable_temp.boolValue && temperature <= charge_temp_below) { // 充电-温度低,优先级=5
if (is_adaptor_connected) {
if (adv_disable_inflow.boolValue && !is_inflow_enabled.boolValue) {
NSFileLog(@"enable inflow for low temperature");
Expand Down Expand Up @@ -579,6 +592,7 @@ static void initConf(BOOL reset) {
@"charge_below": @20,
@"charge_above": @80,
@"enable_temp": @NO,
@"temp_mode": @0,
@"charge_temp_above": @35,
@"charge_temp_below": @10,
@"acc_charge": @NO,
Expand Down Expand Up @@ -715,6 +729,14 @@ static void showFloatwnd(BOOL flag) {
});
} else if ([key isEqualToString:@"adv_def_thermal_mode"]) {
setThermalSimulationMode(val);
} else if ([key isEqualToString:@"temp_mode"]) {
NSLog(@"%@ aa1", log_prefix);
NSArray* vals = nsreq[@"vals"];
if (vals != nil && vals.count >= 2) {
NSLog(@"%@ aa1 %@ %@", log_prefix, vals[0], vals[1]);
setlocalKV(@"charge_temp_below", vals[0]);
setlocalKV(@"charge_temp_above", vals[1]);
}
}
return @{
@"status": @0,
Expand Down
12 changes: 7 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CL支持第三方电池吗?
为什么手机用一会不充电了?(小白经常遇到的问题)
* CL并非傻瓜式工具,如果开启了温控请根据实际情况调整温度上下限,否则到达上限会停止充电,下限又无法达到自然无法充电.
* CL的设计思路就是减少充电次数,因此不会连着usb就充电,充电/停充都有触发条件,请仔细查看本页说明.
* 电池由于老化严重健康度低,刚启动系统时可以使用CL,一段时间后CL再也无法控制充电/停充.此种情况无法使用CL.

CL可以不依赖越狱或巨魔类工具吗?
* CL需要用到私有API所以无法上架.
Expand All @@ -50,9 +51,10 @@ CL可以不依赖越狱或巨魔类工具吗?
## 测试电池兼容性

&emsp;&emsp;在使用CL前需要测试电池兼容性,如果不支持请放弃使用
* 1.测试电池是否支持停充.关闭CL全局开关,在“正在充电”按钮开启的状态下,手动关闭之,若120秒内按钮有反应则电池支持停充,但如果停充后有较大持续电池电流(>=5mA)则无法支持停充(有些电池返回电池电流值有误,此时以实际电量变化为准).
* 1.测试电池是否支持停充.关闭CL全局开关,关闭"高级"中所有选项,在“正在充电”按钮开启的状态下,手动关闭之,若120秒内按钮有反应则电池支持停充,但如果停充后有较大持续电池电流(>=5mA)则无法支持停充(有些电池返回电池电流值有误,此时以实际电量变化为准).
* 2.测试电池是否支持智能停充.开启"高级-智能停充",其余同1.
* 3,测试电池是否支持禁流.关闭CL全局开关,在“电源已连接”按钮开启的状态下,手动关闭之,若120秒内按钮有反应则电池支持禁流,但如果禁流后有较大持续电流(>=5mA)则无法支持禁流(有些电池返回电池电流值有误,此时以实际电量变化为准).
* 3.测试电池是否支持禁流.关闭CL全局开关,在“电源已连接”按钮开启的状态下,手动关闭之,若120秒内按钮有反应则电池支持禁流,但如果禁流后有较大持续电流(>=5mA)则无法支持禁流(有些电池返回电池电流值有误,此时以实际电量变化为准).
* 有的电池因为老化而健康度过低,会出现刚重启系统时可以使用上述方式停充但过一段时间就再也无法停充,这种电池也无法被CL所兼容.
* 若电池既不支持停充也不支持禁流则永远不被CL支持.
* 如果使用CL过程中,健康度以不正常的方式下降,请自行调整高级菜单中的选项或卸载CL.

Expand Down Expand Up @@ -323,6 +325,7 @@ Will the battery health percentage increase after using CL for a period of time?
Why does my iPhone won't charge any more after using for a while(Most questions from freshman)?
* CL is not a fully-automatic tool, please set the threshhold carefully according to the actual temperature if temperature control is enabled, or CL will surely stop charging and won't re-charge any more.
* CL is designed to minimize the charging count, so it won't start charging or recover charging for connecting to a power source in "Plug and charge" mode, but will start charging for re-connecting to a power source.
* There are a few cases of battery with low health cause this problem. In this case, CL can contorl charge/discharge normally after a system reboot, but will fail to control after tens of minutes. CL is unavailable for this kind of battery.

Is it possible to install CL without Jailbreak or TrollStore(-like) environment?
* Private api is used in CL, so it is impossible to be published to Appstore.
Expand All @@ -335,12 +338,11 @@ How to cool down the battery in summer?

## Compatibility

关闭全局开关

Please test battery compatibility before using CL, stop and uninstall CL if unsupported
* 1.Check compatibility of ChargeInhibit. Disable CL by toggling the "Enable" button first, then disable charging by toggling the "Charging" button, any change within 120 seconds means ChargeInhibit is supported, unless the InstantAmperage keep above 5mA after being disabled.(InstantAmperage may be invalid for a few kinds of batteries, in this case take a look at capacity increasement)
* 1.Check compatibility of ChargeInhibit. Disable CL by toggling the "Enable" button first, and disable all options in "Advanced", then disable charging by toggling the "Charging" button, any change within 120 seconds means ChargeInhibit is supported, unless the InstantAmperage keep above 5mA after being disabled.(InstantAmperage may be invalid for a few kinds of batteries, in this case take a look at capacity increasement)
* 2.Check compatibility of PredictiveChargingInhibit. Enable it from "Advanced-Predictive charging inhibit", then follow steps in '1'.
* 3.Check compatibility of DisableInflow. Disable CL by toggling the "Enable" button first, then disable inflow by toggling the "External connected" button when it is enabled, any change within 120 seconds means DisableInflow is supported, unless the InstantAmperage keep above 5mA after being disabled.(InstantAmperage may be invalid for a few kinds of batteries, in this case take a look at capacity increasement)
* There are a few cases of battery with low health prevent CL from working well. In this case, CL can contorl charge/discharge normally after a system reboot, but will fail to control after tens of minutes. CL is unavailable for this kind of battery.
* The battery will never be supported by CL if neither ChargeInhibit nor DisableInflow is supported.
* If the health of battery keep dropping abnormally while using CL, please adjust the configuration in Advanced menu, or just uninstall CL.

Expand Down
29 changes: 16 additions & 13 deletions www/float.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
margin-bottom: 0;
}

.tip-line {
height: 12px;
.el-row, i, span {
top: -5px;
height: 12px !important;
}

.thermometer {
Expand Down Expand Up @@ -75,12 +76,14 @@
font-size: 12px;
}

.spinner {
.ban {
font-size: 12;
margin-top: 5px;
margin-left: 10px;
}

#app {
padding-left: 10px;
padding-left: 5px;
background-color:white;
border-radius: 15px;
opacity: 0.5;
Expand All @@ -89,14 +92,14 @@
</head>
<body>
<div id="app" @click="invset_enable">
<div id="main_page" v-if="daemon_alive">
<template v-if="bat_info">
<el-row class="tip-line">
<div id="main_page">
<div v-if="daemon_alive&&bat_info">
<el-row>
<i class="fa fa-toggle-on icon toggle-on" v-if="enable"></i>
<i class="fa fa-toggle-off icon toggle-off" v-else></i>
<span class="text">{{"CL v"+ver}}</span>
</el-row>
<el-row class="tip-line">
<el-row>
<i class="fa fa-battery-0 icon battery" v-if="bat_info.CurrentCapacity<5"></i>
<i class="fa fa-battery-1 icon battery" v-else-if="bat_info.CurrentCapacity<35"></i>
<i class="fa fa-battery-2 icon battery" v-else-if="bat_info.CurrentCapacity<65"></i>
Expand All @@ -106,18 +109,18 @@
<span class="text">{{bat_info.CurrentCapacity+'%'}}</span>
<i class="fa fa-plug icon plug" v-if="bat_info.ExternalConnected"></i>
</el-row>
<el-row class="tip-line">
<el-row>
<i class="fa fa-thermometer-0 icon thermometer" v-if="bat_info.Temperature<1000"></i>
<i class="fa fa-thermometer-1 icon thermometer" v-else-if="bat_info.Temperature<2000"></i>
<i class="fa fa-thermometer-2 icon thermometer" v-else-if="bat_info.Temperature<3500"></i>
<i class="fa fa-thermometer-3 icon thermometer" v-else-if="bat_info.Temperature<4500"></i>
<i class="fa fa-thermometer-4 icon thermometer" v-else></i>
<span class="text">{{get_temp_desc()}}</span>
</el-row>
</template>
</div>
<div v-else>
<i class="fa fa-spinner fa-pulse fa-3x spinner"></i>
</div>
<div v-else>
<i class="fa fa-ban fa-2x ban"></i>
</div>
</div>
</div>
</body>
Expand Down
6 changes: 4 additions & 2 deletions www/help_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Will the battery health percentage increase after using CL for a period of time?
Why does my iPhone won't charge any more after using for a while(Most questions from freshman)?
* CL is not a fully-automatic tool, please set the threshhold carefully according to the actual temperature if temperature control is enabled, or CL will surely stop charging and won't re-charge any more.
* CL is designed to minimize the charging count, so it won't start charging or recover charging for connecting to a power source in "Plug and charge" mode, but will start charging for re-connecting to a power source.
* There are a few cases of battery with low health cause this problem. In this case, CL can contorl charge/discharge normally after a system reboot, but will fail to control after tens of minutes. CL is unavailable for this kind of battery.

Is it possible to install CL without Jailbreak or TrollStore(-like) environment?
* Private api is used in CL, so it is impossible to be published to Appstore.
Expand All @@ -43,9 +44,10 @@ How to cool down the battery in summer?
## Compatibility

Please test battery compatibility before using CL, stop and uninstall CL if unsupported
* 1.Check compatibility of ChargeInhibit. Disable CL by toggling the "Enable" button first, then disable charging by toggling the "Charging" button, any change within 120 seconds means ChargeInhibit is supported, unless the InstantAmperage keep above 5mA after being disabled.(InstantAmperage may be invalid for a few kinds of batteries, in this case take a look at capacity increasement)
* 1.Check compatibility of ChargeInhibit. Disable CL by toggling the "Enable" button first, and disable all options in "Advanced", then disable charging by toggling the "Charging" button, any change within 120 seconds means ChargeInhibit is supported, unless the InstantAmperage keep above 5mA after being disabled.(InstantAmperage may be invalid for a few kinds of batteries, in this case take a look at capacity increasement)
* 2.Check compatibility of PredictiveChargingInhibit. Enable it from "Advanced-Predictive charging inhibit", then follow steps in '1'.
* 3.Check compatibility of DisableInflow. Disable CL by toggling the "Enable" button first, then disable inflow by toggling the "External connected" button when it is enabled, any change within 120 seconds means DisableInflow is supported, unless the InstantAmperage keep above 5mA after being disabled.(InstantAmperage may be invalid for a few kinds of batteries, in this case take a look at capacity increasement)
* There are a few cases of battery with low health prevent CL from working well. In this case, CL can contorl charge/discharge normally after a system reboot, but will fail to control after tens of minutes. CL is unavailable for this kind of battery.
* The battery will never be supported by CL if neither ChargeInhibit nor DisableInflow is supported.
* If the health of battery keep dropping abnormally while using CL, please adjust the configuration in Advanced menu, or just uninstall CL.

Expand Down Expand Up @@ -204,7 +206,7 @@ curl http://localhost:1230 -d '{"api":"get_conf","key":"enable"}' -H "content-ty

|request |type |description |
|------------|-----------|--------------------------------|
|api |string |get_bat_info |
|api |string |get_bat_info |
|response | | |
|status |integer |0:成功 |
|data | |数据 |
Expand Down
6 changes: 4 additions & 2 deletions www/help_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CL支持第三方电池吗?
为什么手机用一会不充电了?(小白经常遇到的问题)
* CL并非傻瓜式工具,如果开启了温控请根据实际情况调整温度上下限,否则到达上限会停止充电,下限又无法达到自然无法充电.
* CL的设计思路就是减少充电次数,因此不会连着usb就充电,充电/停充都有触发条件,请仔细查看本页说明.
* 电池由于老化严重健康度低,刚启动系统时可以使用CL,一段时间后CL再也无法控制充电/停充.此种情况无法使用CL.

CL可以不依赖越狱或巨魔类工具吗?
* CL需要用到私有API所以无法上架.
Expand All @@ -40,9 +41,10 @@ CL可以不依赖越狱或巨魔类工具吗?
## 测试电池兼容性

&emsp;&emsp;在使用CL前需要测试电池兼容性,如果不支持请放弃使用
* 1.测试电池是否支持停充.关闭CL全局开关,在“正在充电”按钮开启的状态下,手动关闭之,若120秒内按钮有反应则电池支持停充,但如果停充后有较大持续电池电流(>=5mA)则无法支持停充(有些电池返回电池电流值有误,此时以实际电量变化为准).
* 1.测试电池是否支持停充.关闭CL全局开关,关闭"高级"中所有选项,在“正在充电”按钮开启的状态下,手动关闭之,若120秒内按钮有反应则电池支持停充,但如果停充后有较大持续电池电流(>=5mA)则无法支持停充(有些电池返回电池电流值有误,此时以实际电量变化为准).
* 2.测试电池是否支持智能停充.开启"高级-智能停充",其余同1.
* 3.测试电池是否支持禁流.关闭CL全局开关,在“电源已连接”按钮开启的状态下,手动关闭之,若120秒内按钮有反应则电池支持禁流,但如果禁流后有较大持续电流(>=5mA)则无法支持禁流(有些电池返回电池电流值有误,此时以实际电量变化为准).
* 有的电池因为老化而健康度过低,会出现刚重启系统时可以使用上述方式停充但过一段时间就再也无法停充,这种电池也无法被CL所兼容.
* 若电池既不支持停充也不支持禁流则永远不被CL支持.
* 如果使用CL过程中,健康度以不正常的方式下降,请自行调整高级菜单中的选项或卸载CL.

Expand Down Expand Up @@ -207,7 +209,7 @@ curl http://localhost:1230 -d '{"api":"get_conf","key":"enable"}' -H "content-ty

|请求 |类型 |描述 |
|------------|-----------|--------------------------------|
|api |字符串 |get_bat_info |
|api |字符串 |get_bat_info |
|响应 | | |
|status |整型 |0:成功 |
|data | |数据 |
Expand Down

0 comments on commit f05129d

Please sign in to comment.