今天我們把CDC serial driver 中的 setParameters 修改如下:
@Override
public void setParameters(int baudRate, int dataBits, int stopBits, int parity) throws IOException {
byte stopBitsByte;
switch (stopBits) {
case STOPBITS_1: stopBitsByte = 0; break;
case STOPBITS_1_5: stopBitsByte = 1; break;
case STOPBITS_2: stopBitsByte = 2; break;
default: throw new IllegalArgumentException("Bad value for stopBits: " + stopBits);
}
byte parityBitesByte;
switch (parity) {
case PARITY_NONE: parityBitesByte = 0; break;
case PARITY_ODD: parityBitesByte = 1; break;
case PARITY_EVEN: parityBitesByte = 2; break;
case PARITY_MARK: parityBitesByte = 3; break;
case PARITY_SPACE: parityBitesByte = 4; break;
default: throw new IllegalArgumentException("Bad value for parity: " + parity);
}
// byte[] baudRate = le32_to_cpu( baudRate );
// little endian binary (32bit) formate
byte[] msg = {
(byte) ( baudRate & 0xff),
(byte) ((baudRate >> 8 ) & 0xff),
(byte) ((baudRate >> 16) & 0xff),
(byte) ((baudRate >> 24) & 0xff),
stopBitsByte,
parityBitesByte,
(byte) dataBits};
/* Fix Arduino Frimata protocol connect , need setDTR msg before set parameters control msgs.
對應昨天看到的 acm_set_control(acm, acm->ctrlout = newctrl); 這行指令
ref :
http://lxr.free-electrons.com/ident?i=acm_tty_set_termios
http://lxr.free-electrons.com/source/drivers/usb/class/cdc-acm.c#L989
*/
setDTR(true);
sendAcmControlMessage(SET_LINE_CODING, 0, msg);
}
重新打包封裝 APP 後,push 到 zenfone 6 上面測試....
燈!燈!燈! 可以收到由 arduino 送出來的資料了,有圖為證:
Android Serial Driver 專案放在這邊: https://github.com/jyyan/usb-serial-for-android
我們明天見 :P