void mylog( char*name, float data)``````static void rec_sensor_entry(void *param) { struct recvdata *equipment; char str[80]; equipment=(struct recvdata *)malloc(sizeof(struct recvdata)); while(1) { if( temp_switch != 0) if(rt_mb_recv(&mb_temp,(rt_ubase_t *)&equipment,RT_WAITING_FOREVER == RT_EOK)) { sprintf(str, "[%s]data is: %d",equipment->name,(int)equipment->data); rt_kprintf(str); equipment = RT_NULL; rt_thread_mdelay(1000); } } }```通过这两个函数就可以实现数据通过邮件的收发了。下面看一下按键部分的代码:``` void key_pin_0(void * args) { rt_thread_mdelay(20); k0_vol++; if(k0_vol%2 == 1) { temp_switch = 1; humi_switch = 0; } else { temp_switch = 0; humi_switch = 0; } } void key_pin_1(void * args) { k1_vol++; if(k1_vol%2 == 1) { temp_switch = 0; humi_switch = 1; } else { temp_switch = 0; humi_switch = 0; } } void key_pin_2(void * args) { k2_vol++; if(k2_vol%2 == 1) { pm25_switch = 1; } else { pm25_switch = 0; } } void key_init(void) { rt_pin_mode(key_0, PIN_MODE_INPUT_PULLUP); rt_pin_attach_irq(key_0, PIN_IRQ_MODE_FALLING, key_pin_0, RT_NULL); rt_pin_irq_enable(key_0, PIN_IRQ_ENABLE); rt_pin_mode(key_1, PIN_MODE_INPUT_PULLUP); rt_pin_attach_irq(key_1, PIN_IRQ_MODE_FALLING , key_pin_1, RT_NULL); rt_pin_irq_enable(key_1, PIN_IRQ_ENABLE); rt_pin_mode(key_2, PIN_MODE_INPUT_PULLUP); rt_pin_attach_irq(key_2, PIN_IRQ_MODE_FALLING , key_pin_2, RT_NULL); rt_pin_irq_enable(key_2, PIN_IRQ_ENABLE); }```按键部分比较简单,这里不再讲解,然后就是利用事件或者信号量等实现系统跑起来,具体使用哪个不做要求。![FastAdmin](https://oss-club.rt-thread.org/uploads/201910/28/211742idjevso5owgsjgdw.png)
查看更多
回到 顶部
发布 问题
分享 好友
手机 浏览
投诉 建议
回到 底部