From e3249bea61db68a3d7f577aab0ec9acca0b0b974 Mon Sep 17 00:00:00 2001 From: zeeexsixare <32753720+zeeexsixare@users.noreply.github.com> Date: Mon, 15 Oct 2018 00:13:19 -0400 Subject: [PATCH] Implement csouers 67-70% charging to preserve batt --- selfdrive/thermald.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index 7f39d310d7afd6..9f31a50a60367c 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -195,6 +195,16 @@ def thermald_thread(): msg.thermal.freeSpace = avail with open("/sys/class/power_supply/battery/capacity") as f: msg.thermal.batteryPercent = int(f.read()) + + #begining of limit charging. read the charging enabled flag in to charging_enabled + with open("/sys/class/power_supply/battery/charging_enabled") as f: + charging_enabled = int(f.read()) + if msg.thermal.batteryPercent > 70 and charging_enabled: + os.system("echo 0 > /sys/class/power_supply/battery/charging_enabled") + elif msg.thermal.batteryPercent < 67 and not charging_enabled: + os.system("echo 1 > /sys/class/power_supply/battery/charging_enabled") + #end limit charging + with open("/sys/class/power_supply/battery/status") as f: msg.thermal.batteryStatus = f.read().strip() with open("/sys/class/power_supply/battery/current_now") as f: @@ -262,7 +272,7 @@ def thermald_thread(): should_start = should_start and msg.thermal.freeSpace > 0.02 # require usb power in passive mode - should_start = should_start and (not passive or msg.thermal.usbOnline) + #should_start = should_start and (not passive or msg.thermal.usbOnline) # confirm we have completed training and aren't uninstalling should_start = should_start and accepted_terms and (passive or completed_training) and (not do_uninstall)