由于扫瞄头功耗太大(60mA工作电流),考虑使用特殊的电源管理
1. 串口连接 - 直接给扫瞄头发命令休眠唤醒
系统启动时让扫瞄头休眠,打开程序时再唤醒,关闭程序时再休眠。
/* system/vold/main.cpp */
char c0[] = {0x16,'M',0x0D, 'T','R','G','L','P','T','1','.'}; char c1[] = {0x16,'M',0x0D, 'T','R','G','M','O','D','2','.'}; int fd = open("/dev/s3c2410_serial2", O_RDWR); write(fd, c0, sizeof(c0)); write(fd, c1, sizeof(c0));
2. USB OTG连接
系统启动/USB热插拔插上时让扫瞄头休眠,打开程序时再唤醒,关闭程序时再休眠。
/* system/vold/NetlinkHandler.cpp */
void NetlinkHandler::onEvent(NetlinkEvent *evt) { VolumeManager *vm = VolumeManager::Instance(); const char *subsys = evt->getSubsystem(); else if (!strcmp(subsys, "tty")) { usleep(2000000); chmod("/dev/ttyACM0", 0777); char c = 0xFF; int fd = open("/dev/ttyACM0", O_RDWR); write(fd, &c, sizeof(c)); close(fd); }
static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct acm *acm = tty->driver_data; struct usb_device *usb_dev = interface_to_usbdev(acm->control); if (*buf == 0xFF) { usb_port_suspend(usb_dev, PMSG_AUTO_SUSPEND); } if (*buf == 0xFE) { usb_port_resume(usb_dev, PMSG_ON); }