搜索

451

主题

663

帖子

5245

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5245
QQ
发表于 2022-1-20 13:48:53 1502 浏览 1 回复

SC60 SDM450 Android9.0 HP5806驱动

需求:
      实现在SC60 Android9.0的平台上,驱动HP5806,是现在APP端获取到温度和气压高度值!

解决方案:
     JNI部分代码如下(hp5806_driver.tar.gz  为在Android9.0下的驱动移植包;):
  1. typedef struct
  2. {
  3.     int16_t        C0;
  4.     int16_t        C1;
  5.     int32_t        C00;
  6.     int32_t        C10;
  7.     int16_t        C01;
  8.     int16_t        C11;
  9.     int16_t        C20;
  10.     int16_t        C21;
  11.     int16_t        C30;
  12.     uint32_t tmp_osr_scale_coeff;
  13.     uint32_t prs_osr_scale_coeff;
  14. }hp5806_calib_data;

  15. typedef struct{
  16.     uint8_t  pressure[3];
  17.     uint8_t  temperature[3];
  18.     hp5806_calib_data calib_coeffs;
  19. }hp5806_report_s;

  20. static int hp5806_fd = -1;

  21. #define KT        524288
  22. #define KP        253952
  23. void hp5806_convert(hp5806_report_s * rp,float * pressure,float *temp)
  24. {
  25.     long         press_raw;
  26.     long         temp_raw;

  27.     long int temputer_valu = 0;
  28.     long int pressure_valu = 0;

  29.     long    Traw;
  30.     long    Praw;
  31.     double  Traw_sc;
  32.     double  Praw_sc;

  33.     double         temp_scaled;
  34.     float         temp_final;
  35.     double         press_scaled;
  36.     float         press_final;

  37.     LOGE("pressure[0]=0x%x,pressure[1]=0x%x,pressure[2]=0x%x,temperature[0]=0x%x,temperature[1]=0x%x,temperature[2]=0x%x\r\n",rp->pressure[0],rp->pressure[1],rp->pressure[2],rp->temperature[0],rp->temperature[1],rp->temperature[2]);
  38.     LOGE("calib.C0 =%d,C1 =%d,C00 =%d,C10 =%d,C01 =%d,C11 =%d,C20 =%d,C21 =%d,C30 =%d\r\n",rp->calib_coeffs.C0,rp->calib_coeffs.C1,rp->calib_coeffs.C00,rp->calib_coeffs.C10,rp->calib_coeffs.C01,rp->calib_coeffs.C11,rp->calib_coeffs.C20,rp->calib_coeffs.C21,rp->calib_coeffs.C30);

  39.     press_raw = (rp->pressure[2]) + (rp->pressure[1]<<8) + (rp->pressure[0] <<16);
  40.     temp_raw  = (rp->temperature[2]) + (rp->temperature[1]<<8) + (rp->temperature[0] <<16);

  41.     LOGE("press_raw %ld temp_raw %ld\r\n",press_raw,temp_raw);
  42.     if(press_raw>8388607)
  43.     {
  44.         press_raw=press_raw-16777216;
  45.     }

  46.     Traw_sc=(double)temp_raw/KT;
  47.     Praw_sc=(double)press_raw/KP;

  48.     LOGE("Praw_sc %lf Traw_sc %lf\r\n",Praw_sc,Traw_sc);

  49.     temp_final=(float)rp->calib_coeffs.C0*0.5f + (float)rp->calib_coeffs.C1*Traw_sc;
  50.     LOGE("temp_final %f\r\n",temp_final);


  51.     press_final=rp->calib_coeffs.C00 + Praw_sc *(rp->calib_coeffs.C10 + Praw_sc *(rp->calib_coeffs.C20+ Praw_sc *rp->calib_coeffs.C30)) + Traw_sc*rp->calib_coeffs.C01 + Traw_sc *Praw_sc *(rp->calib_coeffs.C11+Praw_sc *rp->calib_coeffs.C21);
  52.     LOGE("press_final %f\r\n",press_final);

  53.     temputer_valu = (long int)(temp_final*1000);
  54.     pressure_valu = (long int)(press_final*1000);
  55.     LOGE("temputer_valu %ld pressure_valu %ld \r\n",temputer_valu,pressure_valu);
  56. }




  57. bool hp5806_open()
  58. {
  59.     hp5806_fd = open("/dev/HP5806", O_RDONLY);
  60.     usleep(10000);
  61.     if(hp5806_fd < 0){
  62.         LOGE("Can not open dev %s!\n", "/dev/hp5806");
  63.         return false;
  64.     }
  65.     LOGE("open dev %s! success!\n", "/dev/hp5806");
  66.     return true;
  67. }

  68. bool hp5806_close()
  69. {
  70.     int ret = 0;
  71.     ret = close(hp5806_fd);

  72.     return ret;
  73. }

  74. long nmh21_get_temp(void)
  75. {
  76.     int ret;
  77.     long    temputer_valu = 0,temp_raw;
  78.     double  Traw_sc;
  79.     float         temp_final;

  80.     hp5806_report_s report_hp5806;

  81.     hp5806_open();
  82.     ret = read(hp5806_fd,&report_hp5806,sizeof(report_hp5806));
  83.     if(ret < 0)
  84.         LOGE("read hp5806_fd fail!\n");
  85.     else{
  86.          //LOGE("report_hp5806.pressure 0x%x 0x%x 0x%x!\n",report_hp5806.pressure[0],report_hp5806.pressure[1],report_hp5806.pressure[2]);
  87.          LOGE("report_hp5806.temperature 0x%x 0x%x 0x%x!\n",report_hp5806.temperature[0],report_hp5806.temperature[1],report_hp5806.temperature[2]);

  88.         temp_raw  = (report_hp5806.temperature[2]) + (report_hp5806.temperature[1]<<8) + (report_hp5806.temperature[0] <<16);
  89.         if(temp_raw>8388607)
  90.         {
  91.             temp_raw=temp_raw-16777216;
  92.         }
  93.         Traw_sc=(double)temp_raw/KT;

  94.         temp_final=(float)report_hp5806.calib_coeffs.C0*0.5f + report_hp5806.calib_coeffs.C1*Traw_sc;

  95.         temputer_valu = (long)(temp_final * 1000);

  96.         LOGE("temp_raw=%ld , Traw_sc=%lf, temp_final=%f temputer_valu=%ld\r\n",temp_raw,Traw_sc,temp_final,temputer_valu);
  97.     }

  98.     hp5806_close();

  99.     return temputer_valu;

  100. }

  101. long nmh21_get_pressure(void)
  102. {
  103.     int ret;
  104.     long    pressure_valu = 0,press_raw,temp_raw;
  105.     double  Praw_sc,Traw_sc;
  106.     float        press_final;

  107.     hp5806_report_s report_hp5806;

  108.     hp5806_open();
  109.     ret = read(hp5806_fd,&report_hp5806,sizeof(report_hp5806));
  110.     if(ret < 0)
  111.         LOGE("read hp5806_fd fail!\n");
  112.     else{
  113.         press_raw = (report_hp5806.pressure[2]) + (report_hp5806.pressure[1]<<8) + (report_hp5806.pressure[0] <<16);
  114.         LOGE("report_hp5806.pressure 0x%x 0x%x 0x%x!\n",report_hp5806.pressure[0],report_hp5806.pressure[1],report_hp5806.pressure[2]);

  115.         temp_raw  = (report_hp5806.temperature[2]) + (report_hp5806.temperature[1]<<8) + (report_hp5806.temperature[0] <<16);
  116.         LOGE("report_hp5806.temperature 0x%x 0x%x 0x%x!\n",report_hp5806.temperature[0],report_hp5806.temperature[1],report_hp5806.temperature[2]);

  117.         if(temp_raw>8388607)
  118.         {
  119.             temp_raw=temp_raw-16777216;
  120.         }
  121.         Traw_sc=(double)temp_raw/KT;

  122.         if(press_raw>8388607)
  123.         {
  124.             press_raw=press_raw-16777216;
  125.         }
  126.         Praw_sc=(double)press_raw/KP;

  127.         press_final=report_hp5806.calib_coeffs.C00 + Praw_sc *(report_hp5806.calib_coeffs.C10 + Praw_sc *(report_hp5806.calib_coeffs.C20+ Praw_sc *report_hp5806.calib_coeffs.C30)) + Traw_sc*report_hp5806.calib_coeffs.C01 + Traw_sc *Praw_sc *(report_hp5806.calib_coeffs.C11+Praw_sc *report_hp5806.calib_coeffs.C21);

  128.         pressure_valu = (long)(press_final * 1000);

  129.         LOGE("temp_raw=%ld , Traw_sc=%lf, press_final=%f pressure_valu=%ld\r\n",temp_raw,Traw_sc,press_final,pressure_valu);
  130.     }

  131.     hp5806_close();

  132.     return pressure_valu;


  133. }
  134. float hp5806_altitude_convert(float Press, float Ref_P)
  135. {
  136.     return 44330 * (1 - powf(((float)Press / (float)Ref_P),(1/5.255)));
  137. }
复制代码










本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
手机微信同号:13682654092
回复

使用道具 举报

451

主题

663

帖子

5245

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5245
QQ
 楼主| 发表于 2022-1-20 14:13:17
HP206P demo和规格书

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
手机微信同号:13682654092
回复

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


登录或注册
快速回复 返回顶部 返回列表