import the quick script I wrote to support the chip on the One Mix Yoga
This commit is contained in:
parent
c1c7d066b1
commit
42d0870904
|
@ -0,0 +1,63 @@
|
|||
#!/usr/local/bin/perl
|
||||
|
||||
#
|
||||
# 0 contains this data as well... not exactly certain what the difference is
|
||||
#
|
||||
open( my $fh, '/usr/sbin/i2c -f /dev/iic6 -a 34 -d r -o 0 -c 1 -b|') || die "can't fork: $!";
|
||||
read( $fh, my $charge_raw, 1);
|
||||
close $fh;
|
||||
my (undef, undef, $vbus, $vbus_valid, undef, $charge_direction_bin)=split(//, unpack(B8, $charge_raw));
|
||||
|
||||
my $power="";
|
||||
if ( $vbus ){
|
||||
$power='P';
|
||||
}
|
||||
my $charge_direction='D';
|
||||
if ( $charge_direction_bin ){
|
||||
$charge_direction='C';
|
||||
}
|
||||
|
||||
#
|
||||
# 0 contains this data as well... not exactly certain what the difference is
|
||||
#
|
||||
open( my $fh, '/usr/sbin/i2c -f /dev/iic6 -a 34 -d r -o 1 -c 1 -b|') || die "can't fork: $!";
|
||||
read( $fh, my $charge_raw, 1);
|
||||
close $fh;
|
||||
my (undef, $charge_status)=split(//, unpack(B8, $charge_raw));
|
||||
|
||||
|
||||
|
||||
#default to discharging
|
||||
my $status='D';
|
||||
if ( $charge_status ){
|
||||
#if this bit is set to one AKA true it means it is charging
|
||||
$status='C';
|
||||
}
|
||||
|
||||
open( $fh, '/usr/sbin/i2c -f /dev/iic6 -a 34 -d r -o B9 -c 1 -b|') || die "can't fork: $!";
|
||||
read( $fh, my $data, 1);
|
||||
close $fh;
|
||||
my ($valid, @chargeA)=split(//,unpack( B8, $data ));
|
||||
my $charge_percent=oct('0b0'.join('', @chargeA));
|
||||
|
||||
open( $fh, '/usr/sbin/i2c -f /dev/iic6 -a 34 -d r -o E4 -c 1 -b|') || die "can't fork: $!";
|
||||
read( $fh, $data, 1);
|
||||
close $fh;
|
||||
my ($valid_ocv, @chargeA_ocv)=split(//,unpack( B8, $data ));
|
||||
my $charge_percent_ocv=oct('0b0'.join('', @chargeA_ocv));
|
||||
|
||||
open( $fh, '/usr/sbin/i2c -f /dev/iic6 -a 34 -d r -o E5 -c 1 -b|') || die "can't fork: $!";
|
||||
read( $fh, $data, 1);
|
||||
close $fh;
|
||||
my ($valid_c, @chargeA_c)=split(//,unpack( B8, $data ));
|
||||
my $charge_percent_c=oct('0b0'.join('', @chargeA_c));
|
||||
|
||||
# This should never happen.
|
||||
if ( ! $valid ){
|
||||
warn('The charge value is being reported as not valid');
|
||||
exit 1;
|
||||
}
|
||||
|
||||
#print 'Status: '.$status."\n".'Percent: '.$charge_percent."\n";
|
||||
print $power.$charge_direction.$status.$charge_percent.','.$charge_percent_ocv.','.$charge_percent_c;
|
||||
|
Loading…
Reference in New Issue