九鼎创展论坛

标题: x6818_ADC测试说明 [打印本页]

作者: hhy    时间: 2016-9-13 16:18
标题: x6818_ADC测试说明
一.布局
1.     背景颜色为橘黄色,最上面显示的是一个TextView文本框,背景为黑色覆盖掉了橘黄色。
2.     下面四个ADC显示栏是一个线性布局,线性布局里面垂直放置四个TextView文本框用于显示ADC。
二.实现方法
   通过调用DeviceIO类里面的read方法读取相应的装置文件得到的字符串就是ADC的数值,然后将读取获得的数值显示在相应的TextView的文本框里。

  1. private void updateStatus()
  2.     {
  3.         String adc0 = DeviceIO.read("/sys/bus/platform/drivers/nxp-adc/nxp-adc/iio:device0/in_voltage0_raw").replaceAll("\r|\n", "");
  4.         mTextViewAdc0.setText("ADC0 : " + adc0);
  5.         String adc1 = DeviceIO.read("/sys/bus/platform/drivers/nxp-adc/nxp-adc/iio:device0/in_voltage1_raw").replaceAll("\r|\n", "");
  6.         mTextViewAdc1.setText("ADC1 : " + adc1);
  7.         String adc2 = DeviceIO.read("/sys/bus/platform/drivers/nxp-adc/nxp-adc/iio:device0/in_voltage2_raw").replaceAll("\r|\n", "");
  8.         mTextViewAdc2.setText("ADC2 : " + adc2);
  9.         String adc3 = DeviceIO.read("/sys/bus/platform/drivers/nxp-adc/nxp-adc/iio:device0/in_voltage3_raw").replaceAll("\r|\n", "");
  10.         mTextViewAdc3.setText("ADC3 : " + adc3);
  11.     }
复制代码
  1. public static String read(String fileName) {
  2.                 String res = "";
  3.                 try {
  4.                         FileInputStream fin = new FileInputStream(fileName);
  5.                         int length = fin.available();
  6.                         byte[] buffer = new byte[length];
  7.                         length = fin.read(buffer);
  8.                         res = new String(buffer);
  9.                         res = String.copyValueOf(res.toCharArray(), 0, length);
  10.                         fin.close();
  11.                 } catch (Exception e) {
  12.                         e.printStackTrace();
  13.                 }
  14.                 return res;
  15.         }
复制代码
通过开启一个线程让读取和显示的操作每两秒进行一次,就可以检测ADC的变化。

  1.                 handler = new Handler();
  2.                 runnable = new Runnable() {
  3.                         @Override
  4.                         public void run() {
  5.                                 handler.postDelayed(this, 2000);
  6.                                 updateStatus();
  7.                         }
  8.                 };
  9.                 handler.postDelayed(runnable, 2000);
  10.         }
复制代码

ADC的数值大小范围为0 ~ 2^12,0 ~ 4095;对应的电压为0 ~ 1.8V;



ADC测试.png (24.07 KB, 下载次数: 199)

ADC测试

ADC测试





欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/) Powered by Discuz! X3.2