Steward
分享是一種喜悅、更是一種幸福
掌機 - Miyoo Mini - C/C++ - Read Battery
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <time.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/stat.h> int main ( int argc, char **argv) { int fd = -1; uint32_t v[2] = {0}; fd = open ( "/dev/sar" , O_RDWR ); printf ( "fd %d\n" , fd); ioctl (fd, 0x6100, 0); ioctl (fd, 0x6101, v); close (fd); printf ( "bat %d, %d\n" , v[0], v[1]); return 0; } |