FireflyApi hardware
3.3 硬件接口
-
使能看门狗
函数:public boolean watchDogEnable(boolean enable)描述:打开/关闭看门狗参数:enable为true启用,为false关闭返回:为true设置成功,为false设置失败备注:打开看门狗后,每隔30s需要喂狗一次,负责看门狗会关闭范例:boolean success = mFireflyApi.watchDogEnable(true); -
看门狗喂狗
函数:public boolean watchDogFeed()描述:喂狗一次返回:为true喂狗成功范例:boolean success = mFireflyApi.watchDogFeed(); -
麦克风切换(3128板型不支持)
函数:public boolean switchMic(int mic_type)描述:麦克风切换到板载/耳机参数:mic_type TYPE_DEFAULT_MIC 板载micTYPE_HEADSET_MIC 耳机mic返回:为true切换成功范例:boolean success = mFireflyApi.switchMic(FireflyApi.TYPE_DEFAULT_MIC); -
gpio控制
函数:public boolean gpioCtrl(int gpio, String direction, int value)描述:控制gpio参数:gpiodirection in, out, high, low high/lowvalue 1/0返回:为true设置成功范例:boolean success = mFireflyApi.gpioCtrl(263,"out",1);//GPIO8_A7的gpio节点为263 -
gpio读值
函数:public int gpioRead(int gpio)描述:读取gpio的值参数:gpio返回:读取失败时返回-1范例:int gpioValue = mFireflyApi.gpioRead(263);//GPIO8_A7的gpio节点为263 -
检查gpio口是否被系统占用
函数:public boolean isGpioOccupied(int gpio)描述:检查gpio口是否被系统占用参数:gpio返回:为true被占用范例:boolean occupied = mFireflyApi.isGpioOccupied(263);//GPIO8_A7的gpio节点为263 -
解析gpio的节点值
函数:public int gpioParse(String gpioStr)描述:解析gpio的节点值,例GPIO8_A7转换为节点263参数:gpioStr返回:解析失败返回-1范例:int gpioValue= mFireflyApi.gpioParse("GPIO8_A7");//GPIO8_A7的gpio节点为263 -
设置USB电源,选择控制OTG或USB接口
函数:public boolean setUsbPower(int type, boolean connect )描述:设置USB电源,选择控制OTG或USB接口参数:type TYPE_USBHOST //控制USB口TYPE_OTG //控制OTG口connect返回:获取失败返回-1范例:mFireflyApi.setUsbPower("TYPE_USBHOST",ture);//连接USB HOSTmFireflyApi.setUsbPower("TYPE_USBHOST",false);//断开USB HOSTmFireflyApi.setUsbPower("TYPE_OTG",ture);//连接OTGmFireflyApi.setUsbPower("TYPE_OTG",false);//断开OTG注意: 由于硬件设计不同,3128板型机器OTG接口连接主机时无法断电。
-
串口使用
- 导入头文件
import com.firefly.api.serialport.SerialPort;import com.firefly.api.serialport.SerialPort.Callback;import com.firefly.api.serialport.SerialPortFinder;
- 根据路径和波特率打开串口,并设置回调函数
private boolean openSerialPort(String path,int baudrate){try {SerialPort mSerialPort = new SerialPort(new File(path), baudrate, 0);mSerialPort.setCallback(new Callback() {@Overridepublic void onDataReceived(byte[] buffer, int size) {// TODO Auto-generated method stubString result = new String(buffer, 0, size);Log.d(TAG, "onDataReceived:"+result);}});} catch (SecurityException e) {// TODO Auto-generated catch blocke.printStackTrace();Log.d(TAG, "open serialport("+path +") error:"+e.toString());return false;} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();Log.d(TAG, "open serialport("+path +") error:"+e.toString());return false;}return true;}
- 向串口发送字符串
mSerialPort.sendMsg("112233445566");
- 关闭串口
mSerialPort.closeSerialPort();