查看: 950|回复: 3

[原创] 米尔电子HMI试用报告#8——设计展示之后的补充说明

[复制链接]

该用户从未签到

发表于 2019-5-8 09:27:42 | 显示全部楼层 |阅读模式
分享到:
1. 上一帖虽然基本完成了设计界面展示的任务,但是作为一个开发平台来说,这个工作是不完整的。因为只有底层的开发才是设计最终需要的内容,HMI简化的是界面开发,底层开发还是要靠大家。

2. 在myir提供的代码中,也包含了对于硬件GPIO,I2C,SPI等的访问,可以直接使用。原来从核心板上的资料上,有ADC的2路,希望能直接采样电压电流信号,不过在开发板上只引出了GPIO接口,需要自己定制其他的开发工作。这里简单说明一下范例代码的分析。

如下是GPIO_LED的代码,
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <linux/input.h>
  4. #include <stdlib.h>
  5. #include <fcntl.h>
  6. #include <string.h>

  7. //#define DEBUG        1
  8. #define ARRAY_SIZE(x)        (sizeof(x)/sizeof(x[0]))

  9. #define LED_DELAY_US        (1000*1000) /* 200 ms */

  10. #ifdef DEBUG
  11. #define dbg_info(fmt, args...)                printf(fmt, #args)
  12. #else
  13. #define dbg_info(fmt, args...)
  14. #endif

  15. #define dbg_err(fmt, args...)                printf(fmt, #args)

  16. typedef struct gpio_s {
  17.         int gpio;
  18.         char value_path[64];
  19.         char dir_path[64];
  20.         int value;
  21. }gpio_t;
  22. void leds_ctrl(const char **leds, int count, unsigned int status)
  23. {
  24.         int i = 0;
  25.         char cmd[128] = {0};
  26.         static unsigned int pre_status = 0;/* It was on by default */
  27. for (i = 0; i < count; i++, leds++) {
  28.                 if ((pre_status ^ status) & (1 << i)) {
  29.                         sprintf(cmd, "echo %d > %s", !!(status&(1 << i)), *leds);
  30.                         if (system(cmd)) {
  31.                                 dbg_info("run cmd [%s] failed!\n", cmd);
  32.                         }
  33.                 }
  34.         }
  35.         pre_status = status;
  36. }

  37. int main (int argc, char *argv[])
  38. {
  39.         int keys_fd;
  40.         char ret[2];
  41.         struct input_event t[2];
  42.         fd_set fds;
  43.         struct timeval tv;
  44.         const char* leds[]={argv[1]};
  45.         keys_fd = open (argv[1], O_RDONLY);
  46.         if (keys_fd <= 0) {
  47.                 dbg_err ("open %s device error!\n", argv[1]);
  48.                 return 0;
  49.         }

  50.     /* Set all LEDs to ON to info user for key pressing */
  51.     while(1){
  52.             leds_ctrl(leds, ARRAY_SIZE(leds), 0xF);
  53.             usleep(LED_DELAY_US);
  54.         leds_ctrl(leds, ARRAY_SIZE(leds), 0);
  55.             usleep(LED_DELAY_US);
  56.     }

  57.         return 0;
  58. }

复制代码
这里面,调用了linux的input库函数,对于led控制就实现了下面的主要语句,
leds_ctrl(leds, ARRAY_SIZE(leds), 0xF);
3. 这个代码编译后可以直接在开发板上执行。在QT开发环境中,如果控制实现GPIO的功能,需要把这样的程序作为一个函数库程序,导入,就可以一起编译执行了。




回复

使用道具 举报

  • TA的每日心情
    擦汗
    昨天 10:32
  • 签到天数: 41 天

    连续签到: 1 天

    [LV.5]常住居民I

    发表于 2019-5-15 09:43:57 | 显示全部楼层
    完结撒花,辛苦了

    点评

    谢谢。  发表于 2019-5-16 09:07
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-3-29 18:02 , Processed in 0.142000 second(s), 23 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.