This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspi UPS Hat in Android
#11
As per post #1
Current driver now reads the values over i2c and is picked up in the kernel. Just need to convert the bit swapped hex value to dec, convert to mA and mV and it should be fully working. Post has been updated with up to date github repo with source and instructions.
Reply
#12
Ok, driver is up to date and is functioning as far as I can tell. Update on Github link in first post.
The values are being fed into /sys/class/power_supply as they are meant to.

There appears to be something that is setting the battery monitoring so that BatteryMonitor.cpp is supplying fake battery details (100%, and temp at 42.4C) which overrides the battery driver. I've cut the makefile and kconfig down so know that none of the others conflict.

Might have to have a poke about in BatteryMonitor.cpp and see if its doing something silly (like not recursing down to the next folder under class to get the battery)
Reply
#13
Hi lostangel556,
today I had time to look into this. Last days worked hard and I was somehow powerless.
I took the fake battery driver from odroid C2 and compiled into the tinker kernel and it seems to work. I changed the capacity to 80 and the temp to 23°, renamed it to tinker-battery and got this with dmesg:
Code:
healthd: battery l=80 v=0 t=23.0 h=2 st=2 chg=a 1970-01-01 00:00:18.877475800 UTC
And also the gauge in the status bar shows 80% now.
I eliminated all other drivers in power, except these:
   
Here is the link to the odroid code: https://github.com/hardkernel/linux/blob...-battery.c
Maybe you can take parts this code for your driver to make it work.
The sysfs now filled with this nodes:

Code:
shell@rk3288:/ $ ls /sys/class/power_supply/battery/                          
capacity
device
health
power
present
status
subsystem
technology
temp
type
uevent
voltage_now
shell@rk3288:/ $ cat /sys/class/power_supply/battery/capacity                  
80
shell@rk3288:/ $ cat /sys/class/power_supply/battery/temp                      
230
Reply
#14
Thanks Lobo. I understand with work, the run up to xmas is crazy.

I've put together the updated code on my github site (post #1) and it does actually work. I've got it reporting the levels back to the right places etc 

Code:
~/Android$ adb shell ls /sys/class/power_supply/battery/
capacity
charge_type
cycle_count
device
health
online
power
present
scope
status
subsystem
type
uevent
voltage_now

Code:
~/Android$ adb shell cat /sys/class/power_supply/battery/uevent
POWER_SUPPLY_NAME=battery
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_VOLTAGE_NOW=4179
POWER_SUPPLY_CYCLE_COUNT=Li-poly
POWER_SUPPLY_HEALTH=Good
POWER_SUPPLY_CAPACITY=89
POWER_SUPPLY_TYPE=1
POWER_SUPPLY_CHARGE_TYPE=Fast
POWER_SUPPLY_ONLINE=4
POWER_SUPPLY_SCOPE=Battery

Oddly though, its reading the battery level perfectly fine and the driver i've "made" has the same items as the odroid one, if not more involved because of the i2c component (which funnily wasnt too difficult to implement once i read through the i2c.h), but it still doesnt report mine into the batterymonitor on the status bar. :S Ill figure it out eventually. If all else fails ill use Tasker to read the file and run a shutdown script once it gets to a set amount and is discharging.
Reply
#15
(12-24-2017, 12:42 AM)lostangel556 Wrote: Thanks Lobo. I understand with work, the run up to xmas is crazy.

I've put together the updated code on my github site (post #1) and it does actually work. I've got it reporting the levels back to the right places etc 

Code:
~/Android$ adb shell ls /sys/class/power_supply/battery/
capacity
charge_type
cycle_count
device
health
online
power
present
scope
status
subsystem
type
uevent
voltage_now

Code:
~/Android$ adb shell cat /sys/class/power_supply/battery/uevent
POWER_SUPPLY_NAME=battery
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_VOLTAGE_NOW=4179
POWER_SUPPLY_CYCLE_COUNT=Li-poly
POWER_SUPPLY_HEALTH=Good
POWER_SUPPLY_CAPACITY=89
POWER_SUPPLY_TYPE=1
POWER_SUPPLY_CHARGE_TYPE=Fast
POWER_SUPPLY_ONLINE=4
POWER_SUPPLY_SCOPE=Battery

Oddly though, its reading the battery level perfectly fine and the driver i've "made" has the same items as the odroid one, if not more involved because of the i2c component (which funnily wasnt too difficult to implement once i read through the i2c.h), but it still doesnt report mine into the batterymonitor on the status bar. :S Ill figure it out eventually. If all else fails ill use Tasker to read the file and run a shutdown script once it gets to a set amount and is discharging.
Nevermind, Issue with the odroid driver was differences in the power_supply.h header.
Corrected the header and will use this as a template to get the i2c part working.
Reply
#16
Updated Driver is on the github page Big Grin
and it now reads the battery percentage and voltage into the OS, so that it can shutdown automatically when battery low.

Copied the Odroid layout and then modified it with the parts of the i2c driver to get it to read the values.
I've seen that there is a full MAX17048 driver out on GoogleSource hub, which gives a lot more functionality. Might have a look in future but for now this works and does what i need it to.

A few words to those that want to use this battery pack to power their Tinker though.
1. Once the tinker shuts down, it will need to cut the power in order to turn off again, so dont put it somewhere where you cant reach the power button on the Hat(im going to implement a timer delay relay circuit running off the 3.3v pin to act as a switch for the 5v in order to work mine).
2. This battery pack isnt able to supply enough power to the GPIO pins to run the Tinker and much else, I would recommend that you Dual power the tinker and the Hat so that you have the power you need plus some redundancy (aka Dual Usb Micro splitter cable)
Reply
#17
Fine that you got it.
I plan to add a small attiny chip to my self baked ups with same i2c registers, so maybe I can use your driver. But don't know, when I will start this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)