掌機 - Miyoo Mini - C/C++ - Read Battery



main.c

#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;
}