当前位置: 首页 > news >正文

国际知名设计公司收入嘉兴优化网站公司哪家好

国际知名设计公司收入,嘉兴优化网站公司哪家好,文案写作网站,备案后怎么建设网站前言 本章结合之前的hx711驱动#xff0c;实现读取质量#xff0c;记录时间及剩余质量并存入csv文件#xff0c;计算质量差并总计。 代码 luckfox-pico\project\app\test_app\hx711\hx711_app_addtime.c #include stdio.h #include stdlib.h #include 实现读取质量记录时间及剩余质量并存入csv文件计算质量差并总计。 代码 luckfox-pico\project\app\test_app\hx711\hx711_app_addtime.c #include stdio.h #include stdlib.h #include fcntl.h #include unistd.h // #include linux/delay.h #include sys/time.h #include string.h #include time.h#define IIO_DEVICE /sys/bus/iio/devices/iio:device0 #define SENSOR_CALI_PATH_OFFSET /root/hx711_cal_offset #define SENSOR_CALI_PATH_SCALE /root/hx711_cal_scalestatic int cal_offset 8500000; // save raw value without test itemsstatic int cal_scale 475; // when set phone, 1g is 475 static int cal_weight 187; // the weight of phone// static float weight 0; static int weight 0;//--------------- hx711 value process --------------- #define LIST_NUM_MAX 64 #define CSV_PATH /root/hx711.csvint v1,v2; int flag_change;struct weight_data{int weight;time_t time; };struct weight_data list[LIST_NUM_MAX]; int current_list_num0;int drink_water0;//--------------- hx711 value process ---------------// float convert_to_weight(int sensor_data) { int convert_to_weight(int sensor_data) {int weight;// weight (float)(sensor_data - cal_offset) / cal_scale;// printf(\nsensor_raw%d,cal_offset%d,cal_scale%d\n,sensor_data,cal_offset,cal_scale);if(cal_scale ! 0)weight (sensor_data - cal_offset) / cal_scale;elseweight 0;// printf(Sensor data: %.1f\n, weight);// printf(Sensor data: %d\n, weight);return weight; }int get_hx711_raw(){int fd;char buf[64];ssize_t num_read;fd open(IIO_DEVICE /in_voltage0_raw, O_RDONLY);if (fd 0) {perror(Failed to open iio device);return 1;}num_read read(fd, buf, sizeof(buf) - 1);if (num_read 0) {perror(Failed to read sensor data);close(fd);return 1;}close(fd);buf[num_read] \0;int sensor_data atoi(buf);// printf( raw sensor_data%d\n,sensor_data);return sensor_data; }// float get_hx711_value(){ int get_hx711_value(){int sensor_data get_hx711_raw();weight convert_to_weight(sensor_data);return weight; }// save scaleoffset to file void set_cal_value(){int fd;char tmp_char[64];fd open(SENSOR_CALI_PATH_OFFSET, O_CREAT|O_RDWR ,0777);if (fd 0) {perror(Failed to open cal offset.);return;}// printf(-------\ncal_offset%d\n,cal_offset);memset(tmp_char,0,sizeof(tmp_char));sprintf(tmp_char,%d\0,cal_offset);// printf(xxx tmp_char[%s]\n,tmp_char);write(fd, tmp_char, sizeof(tmp_char));close(fd);fd open(SENSOR_CALI_PATH_SCALE, O_CREAT|O_RDWR ,0777);if (fd 0) {perror(Failed to open cal offset.);return;}// printf(cal_scale%d\n,cal_scale);memset(tmp_char,0,sizeof(tmp_char));sprintf(tmp_char,%d\0,cal_scale) ;// printf(xxx tmp_char[%s]\n-------\n,tmp_char);write(fd, tmp_char, sizeof(tmp_char)-1);close(fd); }void print_cal_value_and_raw(int sensor_raw_tmp){printf(calraw:\n);printf( cal_offset%d sensor_raw%d\n, cal_offset, sensor_raw_tmp);printf( test_offset\t%d\n cal_weight\t%d\n cal_scale\t%d\n,sensor_raw_tmp - cal_offset, cal_weight, cal_scale);printf(\n); }void print_cal_value(){printf(hx711 calibration value\n);printf( cal_offset\t%d\n cal_weight\t%d\n cal_scale\t%d\n,cal_offset, cal_weight, cal_scale);printf(\n); }void sns_calibration(){int cal_test_num 10;int cal_average 0;int cal_test_tmp 0;int cal_scale_raw 0;// test 10 times to get offset averagefor(int i0; ical_test_num; i){cal_test_tmp get_hx711_raw();usleep(10);cal_average (cal_average * i cal_test_tmp)/(i1);}cal_offsetcal_average;usleep(20);printf(!!! Please put test items on the board whose weight same with cmd3\nWaiting input char to continue ...\n);getchar();cal_test_tmp get_hx711_raw();cal_scale_raw cal_test_tmp - cal_offset;cal_scale (cal_scale_raw)/cal_weight;print_cal_value_and_raw(cal_test_tmp);set_cal_value(); }void get_cal_value(){int tmp_offset;int tmp_scale;char tmp_file_value[64];int fd;// printf(get_cal_value\n);fd open(SENSOR_CALI_PATH_OFFSET, O_RDWR,0777);if (fd 0) {perror(Failed to open cal offset.);return;}read(fd, tmp_file_value, sizeof(tmp_file_value) - 1);// printf(tmp_file_value%s\n,tmp_file_value);tmp_offset atoi(tmp_file_value);// printf(tmp_offset%d\n,tmp_offset);close(fd);fd open(SENSOR_CALI_PATH_SCALE, O_RDWR,0777);if (fd 0) {perror(Failed to open cal offset.);return;}memset(tmp_file_value,0,sizeof(tmp_file_value));read(fd, tmp_file_value, sizeof(tmp_file_value) - 1);tmp_scale atoi(tmp_file_value);// printf(tmp_offset%d\n,tmp_scale);close(fd);cal_offset tmp_offset;cal_scale tmp_scale; }#define LEN_MAX 30void save_to_csv(struct weight_data value) {char tmp_c[LEN_MAX];char * tmp;FILE *fp fopen(CSV_PATH, a);if (fp NULL) {fprintf(stderr, fopen() failed.\n);exit(EXIT_FAILURE);}struct tm *tm_t;tm_t localtime(value.time);strftime(tmp_c,LEN_MAX,%F %T,tm_t);printf(time%s\t,tmp_c);fprintf(fp, tmp_c);fprintf(fp, | );memset(tmp_c,0,LEN_MAX);sprintf(tmp_c, %d, value.weight);printf(weight%s\n,tmp_c);fprintf(fp, tmp_c);fprintf(fp, \n);fclose(fp); }int value_changed(int value1, int value2) {if(value1 ! value2){flag_change 1;// printf(change value v1%d v2%d\n,value1,value2);}else{if(flag_change 1 value1 ! 0){// save value// printf(change value %d\n,value1);list[current_list_num].weight value1;// printf(change value %d\n,list[current_list_num].weight);// save timetime_t tnow time(0);// printf(当前时间为%ld\r\n,tnow);list[current_list_num].time tnow;if(list[current_list_num].weight list[current_list_num-1].weight){drink_water drink_water list[current_list_num-1].weight - list[current_list_num].weight;printf( drink %dmL\n,drink_water);}// save value to filesave_to_csv(list[current_list_num]);current_list_num;flag_change 0;}}return flag_change; }int get_value() {int value 0;// get valuevalue get_hx711_value();// save value to v1v2v1 v2;v2 value;// judgevalue_changed(v1,v2);return value; }int main(int argc, char *argv[]) {char cmd1[16];char cmd2[16];char cmd3[16];int ret;int val_tmp0;// calibration: put the items whose weight is known. weight sends to cmd3// ./hx771_app -c 187if(argc 3){strcpy(cmd2,argv[1]);strcpy(cmd3,argv[2]);printf(cmd2%s cmd3%s\n,cmd2,cmd3);if(strcmp(cmd2, -c) 0){printf(get cal cal_weight %s\n,cmd3);cal_weightatoi(cmd3); // save the weight of cal items} else {printf(hx711 no cal_weight\n);return 0;}sns_calibration();sleep(1);// test the calibration resultval_tmp get_hx711_value();printf(sensor value: %d\n, val_tmp);return 0;}printf(-------------test-------------\n);get_cal_value();print_cal_value();int sensor_data;while(1){// val_tmp get_hx711_value();val_tmp get_value();// if(val_tmp ! 0)// printf(%02d: %d\n,50 - test_num,val_tmp);sleep(1);}printf(--------------------------\n);return 0; }编译 luckfox-pico\project\app\test_app\hx711\build.sh export PATH/home/youkai/0_pro/luckfox/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin:$PATH source ~/.bashrc cd ~/0_pro/luckfox/luckfox-pico/project/app/test_app/hx711 arm-rockchip830-linux-uclibcgnueabihf-gcc hx711_app_addtime.c -o hx711_app_addtime运行 运行bat可以进行快速测试放在windows本地 time_get_hx711.bat scp youkai192.168.206.130:/home/youkai/0_pro/luckfox/luckfox-pico/project/app/test_app/hx711/hx711_app_addtime .adb push hx711_app_addtime /root/ adb shell chmod 777 /root/hx711_app_addtime adb shell ./root/hx711_app_addtime结果 代码实现了测试重量并计算出喝水的毫升数。 读取保存的时间和重量。 # cat hx711.csv 2023-11-15 19:42:55 | 68 2023-11-15 19:43:07 | 194 2023-11-15 19:43:14 | 3 2023-11-15 19:43:27 | 68 2023-11-15 19:43:38 | 10
http://wiki.neutronadmin.com/news/5210/

相关文章:

  • php做简单网站教程视频教程wordpress 重定向函数
  • 网站建设的报告用ps做网站得多大像素
  • 明港网站建设公司架子鼓谱那个网站做的好
  • 石家庄做网站排名公司哪家好成立个人工作室需要什么条件
  • 有哪些网站做自建房设计ui是什么设计
  • 西安哪家做网站公司好网站从建设到上线流程
  • 做外贸业务去哪些网站全网最低价业务网站
  • 苏州住房城乡建设部网站网站开发表格整体页面居中
  • 多语种网站建设方案wordpress 锚点 插件
  • 怎么添加网站程序新浪sae 安装wordpress
  • 做网站合成APP个人网站模板制作教程
  • 太原市建设工程招投标信息网站石家庄在哪个省
  • 网站建设总结经验高德开放平台
  • 外贸网站 测速建站教程下载
  • 松原手机网站开发公司网页链接
  • ei网站怎么兼做平舆网站建设
  • html5 手机网站 模版查看WordPress网站插件
  • 沈阳快速建站模板电子商务网站建设教学
  • 如何制作一网站个人如何注册网址
  • 全运会网站建设方案wordpress安装nextapp
  • 定制化网站开发公司鞍山58同城最新招聘信息
  • Wix做的网站在国内打不开项目建设网站大全
  • 昆明做网站的个人google adwords
  • 帝国网站调用图片集西安互联网网站搭建公司排名
  • 公司网站怎么设计《网站开发与应用》大作业要求
  • 封面型网页网站有哪些内容苏州写信小程序开发公司
  • 昌邑网站建设公司企业网站关键字优化
  • 郑州高端网站建设公司营销型网站建设企业
  • c网站开发案例详解公司宣传一般建的是网页还是网站
  • 商业网站设计欣赏企业资质证书查询官方网站