IOT台灯软件设计
<p style="text-align: center;"><strong>IOT 台灯设计</strong></p><p><strong>1、作品简介</strong></p>
<p> 随着IOT的兴起,越来越多的家庭设备通过网关或者路由接入云端,用户可以远在千里之外控制监控家里的设备,灯具天然具有IOT基因的,使用频率高,7X24供电,不需要单独在铺设网线或电线,只要有路由或者网关就可以很方便接入云,实现远程控制。因为具有了IOT功能,可以赋予台灯更多的新的功能,台灯不再只是照明设备还是一个可以随心把玩的家庭伴侣,通过APP可以实现各种炫酷的灯效和功能,定时开关机、全家外出旅游的时候模拟家庭灯光情况,不法分子通过灯光以为家庭有人而怯步。炫酷灯效和模拟自然界的太阳阳光节律。所有这些功能可以通过手机APP和rs10的BLE连接实现控制和和功能转换。</p>
<p> </p>
<p class="imagemiddle" style="text-align: center;"></p>
<p> </p>
<p><strong>2、系统框图</strong></p>
<p><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"> RSL10 QFN EVB作为IOT灯具的主控,</span></span></span></span>因为RSL10的GPIO 有限,数据协议采用单线归零码的通讯方式,系统只需要一个<span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体">GPIO1 作为LED RGBW的驱动GPIO用来驱动WS2812 ,</span></span></span></span>WS2812是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。,另外一个ADC口用来采集灯具的温度,在温度超过限定标准的情况下自动降低灯具的发光效率避免温度过高烧坏LED。 </p>
<p class="imagemiddle" style="text-align: center;"></p>
<p><strong>3、软件架构</strong></p>
<p> IOT台灯基础架构</p>
<p> 要实现IOT功能、因为蓝牙不能直接连上物联网,必须通过网关进行连接进行转换,IOT蓝牙台灯架构如下:</p>
<p>a、蓝牙和网关通讯功能,所有控制命令和设备参数通过BLE和发送给网关网关再把IOT台灯的参数上报云端服务器、通过手机APP把数据通过网关转换后发给IOT台灯执行、还有就是没有网络的时候在家APP直接通过BLE和IOT台灯进行通讯实现台灯功能。</p>
<p>b、RS10demo程序已经有freertos,为了方便调试和模块化编程,采用了FREERTOS<br />
c、因为网关通讯协议涉及公司机密本次大赛不把协议内容进行具体阐述,只进行APP和BLE直接通讯进行控制、和台灯功能实现。</p>
<p> </p>
<p><strong>4、部分功能实现</strong></p>
<p>WS1258驱动</p>
<p>#define WS1258_GPIO 0<br />
#define WS2812_EN_GPIO 1<br />
#define _nop_() __NOP()<br />
#define PERCENT 1<br />
#define T0H (350+150/PERCENT) //0.35us<br />
#define T0L (800+150/PERCENT) //0.8us<br />
#define T1H (700+150/PERCENT) //0.7us<br />
#define T1L (600+150/PERCENT) //0.6us<br />
#define RESTIME 2400<br />
void delay_us(uint32_t ns)<br />
{<br />
uint32_t i =0;<br />
while(ns){<br />
ns--;<br />
for(i=100;i>1;i--){<br />
_nop_();<br />
}<br />
}</p>
<p>}<br />
void ledGpioInit(void)<br />
{</p>
<p> Sys_DIO_Config(WS1258_GPIO, DIO_MODE_GPIO_OUT_0);<br />
Sys_DIO_Config(WS2812_EN_GPIO, DIO_MODE_GPIO_OUT_0);</p>
<p><br />
}<br />
void ledGpio(gpio_status_e on)<br />
{<br />
if (GPIO_HIGH==on){<br />
Sys_GPIO_Set_High(WS1258_GPIO);<br />
}else{<br />
Sys_GPIO_Set_Low(WS1258_GPIO);<br />
}</p>
<p><br />
}</p>
<p>void onsemLedEnable(xt_ledenable_e enable)<br />
{<br />
if (enable==LEDENABLE){<br />
Sys_GPIO_Set_High(WS2812_EN_GPIO);<br />
}else{<br />
Sys_GPIO_Set_Low(WS2812_EN_GPIO);<br />
}<br />
}<br />
//-------------------------------------------------------------------------------<br />
//-------------------------------------------------------------------------------<br />
//子程序名称:ResetDateFlow(void)<br />
//功能:复位,为下一次发送做准备,<br />
//说明:将DI置位为0后,延时约65us<br />
//-------------------------------------------------------------------------------<br />
//-------------------------------------------------------------------------------<br />
void ResetDataFlow(void)<br />
{<br />
unsigned char i,j;<br />
ledGpio(GPIO_LOW);//DI=0; <br />
delay_us(RESTIME);<br />
}</p>
<p>//发送3BYTE的数据给LED 控制RGB<br />
static void WS2811_SendByte(uint32_t dat)//<br />
{<br />
uint8_t i = 0;<br />
uint32_t temp =dat;<br />
for(i=0;i<24;i++)<br />
{<br />
if(temp&0x800000) //<br />
{<br />
//LINEZERO_GPIO_Port->BSRR = (uint32_t)LINEZERO_Pin;<br />
ledGpio(GPIO_HIGH); <br />
_nop_(); <br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
//delay_us(T1H);<br />
//LINEZERO_GPIO_Port->BRR = (uint32_t)LINEZERO_Pin;<br />
ledGpio(GPIO_LOW); //DI=0;<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
//delay_us(T1L);<br />
}<br />
else <br />
{<br />
//LINEZERO_GPIO_Port->BSRR = (uint32_t)LINEZERO_Pin;<br />
ledGpio(GPIO_HIGH);<br />
//delay_us(T0H);<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
//LINEZERO_GPIO_Port->BRR = (uint32_t)LINEZERO_Pin;<br />
ledGpio(GPIO_LOW); //DI=0;<br />
//delay_us(T0L);<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
_nop_();<br />
}<br />
temp=(temp<<1); <br />
}</p>
<p><br />
}</p>
<p><br />
//把RGB打包发送</p>
<p>void send_data(uint8_t r,uint8_t g,uint8_t b)<br />
{<br />
uint8_t i;<br />
uint32_t para =0;<br />
para= (r<<16|g<<8|b);<br />
WS2811_SendByte(para);</p>
<p> //ResetDataFlow(); <br />
}</p>
<p>//应用直接调用函数</p>
<p>void ledDriver(RGB_T rgb[],uint8_t lens )<br />
{ <br />
uint8_t i=0;<br />
if (rgb==NULL||lens<1){<br />
return;<br />
}<br />
<br />
ResetDataFlow(); //发送帧复位信号<br />
for (i=0;i<lens;i++){//sizeof(rgb)/sizeof(rgb)<br />
send_data(rgb<i>.r,rgb<i>.g ,rgb<i>.b);<br />
}<br />
ResetDataFlow(); //发送帧复位信号<br />
}</i></i></i></p>
<p>APP 和RS10 通过BLE通讯接收数据</p>
<p>uint8_t CUSTOMSS_RXLongCharCallback(uint8_t conidx, uint16_t attidx, uint16_t handle,<br />
uint8_t *to, const uint8_t *from, uint16_t length,<br />
uint16_t operation)<br />
{<br />
memcpy(to, from, length);<br />
#if RSL10_DEBUG<br />
PRINTF("\n\rRXLongCharCallback (%d): ", conidx, length);<br />
for (int i = 0; i < length; i++)<br />
{<br />
PRINTF("%02x ", app_env_cs.from_air_buffer_long<i>);<br />
}<br />
#endif /* if RSL10_DEBUG */<br />
PRINTF("\r\n");</i></p>
<p><i> /* Update TX long characteristic with the inverted version of<br />
* RX long characteristic just received */<br />
if(operation == GATTC_WRITE_REQ_IND)<br />
{<br />
for (uint8_t i = 0; i < CS_LONG_VALUE_MAX_LENGTH; i++)<br />
{<br />
//app_env_cs.to_air_buffer_long<i> = 0xFF ^ app_env_cs.from_air_buffer_long<i>;<br />
}<br />
<span style="color:#2ecc71;"><strong> smartLightProtocolDataInsert((void *)app_env_cs.from_air_buffer_long, length); //接收数据放入缓冲区</strong></span><br />
}<br />
return ATT_ERR_NO_ERROR;<br />
}</i></i></i></p>
<p><i><i><i> </i></i></i></p>
<p><i><i><i>协议解析和灯效功能实现</i></i></i></p>
<p><i><i><i>__NO_RETURN void ledDriverThread(void *argument)<br />
{<br />
EFFECT_MODE effectMode = EFFECT_MAX;</i></i></i></p>
<p><i><i><i> uint8_t state=0;<br />
uint64_t pass_time =0;<br />
LIGHT_ATTR light_attr;</i></i></i></p>
<p><i><i><i> xt_protocol_data_t *ble_protocol_data=& sg_ble_protocol_data;<br />
/* creation of rgbQueue */<br />
rgbQueueHandle = osMessageQueueNew (1, sizeof(LIGHT_ATTR), &rgbQueue_attributes);<br />
memset(&gradint_timer,0,sizeof(gradint_timer));<br />
memset(&light_attr,0,sizeof(light_attr));<br />
gradint_timer.expired_ms=500;<br />
//gradint_timer.status=1;<br />
//XtimerStart(&gradint_timer);<br />
for(;;)<br />
{<br />
osDelay(10);<br />
if(1==onsemi_fifo_HaveData(&fifo_dev)){<br />
smartLightProtocolDataRead();<br />
PRINTF("%s header=%x\r\n",__func__,ble_protocol_data->header);<br />
if (HEADER_0==ble_protocol_data->header&&HEADER_1==ble_protocol_data->header){<br />
effectMode = ble_protocol_data->cmd;<br />
if (effectMode<EFFECT_MAX){<br />
PRINTF("%s\r\n",effectmode);<br />
}<br />
gradint_timer.expired_ms=1000;<br />
XtimerStart(&gradint_timer);<br />
sg_ble_to_air_data.header=0x7F;<br />
sg_ble_to_air_data.header=0x80;<br />
sg_ble_to_air_data.lenght=3;<br />
sg_ble_to_air_data.cmd=ble_protocol_data->cmd;<br />
sg_ble_to_air_data.buf=0x0d;<br />
sg_ble_to_air_data.buf=0x0a;<br />
airProtocolDataInsert(&sg_ble_to_air_data, sg_ble_to_air_data.lenght+4);<br />
}<br />
}<br />
switch(effectMode)<br />
{<br />
case PARTY:<br />
//ke_msg_send_basic(APP_LIGHT_ACTION, TASK_APP, TASK_APP);<br />
<br />
pass_time =XtimerPassMs(&gradint_timer);<br />
if(XOK==timeExpire(&gradint_timer)){<br />
gradint_timer.expired_ms=1000;<br />
XtimerStart(&gradint_timer);<br />
PRINTF("gradint_timer restart\r\n");<br />
}<br />
//PRINTF("gradint_timer.oldtick=%d gradint_timer.status=:%d pass_time:%d\r\n",gradint_timer.oldtick,gradint_timer.status,(xt_u32)pass_time);<br />
PRINTF("%s pass_time:%d\r\n",__func__,(xt_u32)pass_time);</i></i></i></p>
<p><i><i><i> switch(state){<br />
case 0:<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
//gradient_time++;<br />
if (timeExpire(&gradint_timer)==XOK){<br />
currgb =1;<br />
currgb =1;<br />
currgb =1;<br />
currgb =1;<br />
resetCurRgb();<br />
//XtimerStop(&gled_timer);<br />
gradint_timer.expired_ms=PARTY_TIME;<br />
XtimerStart(&gradint_timer);<br />
state = 1;<br />
}<br />
break;<br />
case 1:<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
if (timeExpire(&gradint_timer)==XOK){<br />
currgb =5;<br />
currgb =10;<br />
currgb =3;<br />
currgb =5;<br />
resetCurRgb();<br />
gradint_timer.expired_ms=PARTY_TIME;<br />
XtimerStart(&gradint_timer);<br />
state = 2;<br />
}<br />
break;<br />
case 2:<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
if (timeExpire(&gradint_timer)==1){<br />
currgb =3;<br />
currgb =2;<br />
currgb =5;<br />
currgb =2;<br />
resetCurRgb();<br />
gradint_timer.expired_ms=PARTY_TIME;<br />
XtimerStart(&gradint_timer);<br />
state = 3;<br />
}<br />
break;<br />
case 3:<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
if (timeExpire(&gradint_timer)==1){<br />
currgb =2;<br />
currgb =3;<br />
currgb =4;<br />
currgb =2;<br />
resetCurRgb();<br />
gradint_timer.expired_ms=PARTY_TIME;<br />
XtimerStart(&gradint_timer);<br />
state = 4;<br />
}<br />
break;<br />
case 4:<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)0;<br />
memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
if (timeExpire(&gradint_timer)==XOK){<br />
currgb =4;<br />
currgb =3;<br />
currgb =6;<br />
currgb =0;<br />
resetCurRgb();<br />
gradint_timer.expired_ms=PARTY_TIME;<br />
XtimerStart(&gradint_timer);<br />
state = 5;<br />
}<br />
break;<br />
case 5:<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.r=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)0;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
if (timeExpire(&gradint_timer)==1){<br />
currgb =10;<br />
currgb =10;<br />
currgb =10;<br />
currgb =10;<br />
resetCurRgb();<br />
gradint_timer.expired_ms=PARTY_TIME;<br />
XtimerStart(&gradint_timer);<br />
state = 0;<br />
}<br />
break;<br />
default:<br />
;<br />
}<br />
//log_debug(logger,"%d state:%d currgb:%f %f %f\r\n",__LINE__,state ,currgb,currgb,currgb);<br />
osDelay(100);<br />
//light_attr.mode = PARTY;<br />
//LightEffectProcess(light_attr);<br />
break;<br />
break;<br />
case NIGHT:<br />
<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
if (timeExpire(&gradint_timer)==XOK){<br />
XtimerStop(&gradint_timer);<br />
}</i></i></i></p>
<p><i><i><i> break;<br />
case SUNSET:<br />
#if 1<br />
if(0==light_attr.startFlag){ <br />
//log_debug(logger,"%d SUNSET currgb:%f %f %f\r\n",__LINE__,currgb,currgb,currgb);<br />
pass_time = XtimerPassMs(&gradint_timer);<br />
gain= pass_time*1.0/gradint_timer.expired_ms;<br />
gain = gain>1?1:gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
currgb =currgb + (targetrgb-currgb)*gain;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.r=(uint8_t)0;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.b=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
cur_rgb.g=(uint8_t)currgb;<br />
//memcpy(&light_attr.rgb,&cur_rgb,sizeof(light_attr.rgb));<br />
if (timeExpire(&gradint_timer)==XOK){<br />
gradint_timer.expired_ms=SUNSET_TIME;<br />
XtimerStop(&gradint_timer);<br />
light_attr.startFlag =1;<br />
}<br />
}<br />
#endif<br />
light_attr.mode =SUNSET;<br />
//memcpy(light_attr.rgb,cur_rgb,sizeof(cur_rgb));<br />
//LightEffectProcess(light_attr);<br />
break; <br />
case VOICE_CONTROL:</i></i></i></p>
<p><i><i><i> break;<br />
case FLASH_MODE:<br />
#if 1<br />
switch(state){<br />
case 0:<br />
cur_rgb.r=0xff;<br />
cur_rgb.r=0xff;<br />
cur_rgb.r=0xff;<br />
cur_rgb.r=0xff;<br />
cur_rgb.b=0;<br />
cur_rgb.b=0;<br />
cur_rgb.b=0;<br />
cur_rgb.b=0;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
if (XOK==timeExpire(&gradint_timer)){<br />
XtimerStart(&gradint_timer);<br />
gradint_timer.expired_ms=FLASH_MODE_TIME;<br />
//light_attr_para->processFlag=1;<br />
state =1;<br />
}<br />
break;<br />
case 1:<br />
cur_rgb.r=0;<br />
cur_rgb.r=0;<br />
cur_rgb.r=0;<br />
cur_rgb.r=0;<br />
cur_rgb.b=0xff;<br />
cur_rgb.b=0xff;<br />
cur_rgb.b=0xff;<br />
cur_rgb.b=0xff;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
cur_rgb.g=0;//(uint32_t)input&0xFF;<br />
if (XOK==timeExpire(&gradint_timer)){<br />
gradint_timer.expired_ms=FLASH_MODE_TIME;<br />
XtimerStart(&gradint_timer);<br />
//light_attr_para->processFlag=1;<br />
state =0;<br />
}<br />
break;<br />
}<br />
//ledDriver(cur_rgb,4 );<br />
#endif<br />
break;<br />
default:<br />
pass_time = XtimerPassMs(&gradint_timer); <br />
}<br />
ledDriver(cur_rgb,4 );<br />
}<br />
}</i></i></i></p>
<p><i><i><i>注册灯效事件</i></i></i></p>
<p><i><i><i> </i></i></i></p>
<p><i><i><i>void APP_LIGHT_Action_Handler(ke_msg_id_t const msg_id,<br />
void const *param,<br />
ke_task_id_t const dest_id,<br />
ke_task_id_t const src_id)<br />
{<br />
<br />
uint8_t conidx = KE_IDX_GET(src_id);<br />
PRINTF("%s msg_id:%d\r\n",__func__,msg_id);<br />
switch(msg_id)<br />
{<br />
case GAPM_CMP_EVT:<br />
{<br />
PRINTF("%s GAPM_CMP_EVT msg_id:%d\r\n",__func__,msg_id);<br />
//onsemLedEnable(LEDDISABLE);</i></i></i></p>
<p><i><i><i> }<br />
break;<br />
<br />
case GAPM_PROFILE_ADDED_IND:<br />
{<br />
onsemLedEnable(LEDENABLE);<br />
PRINTF("%s GAPM_CMP_EVT msg_id:%d\r\n",__func__,msg_id);</i></i></i></p>
<p><i><i><i> }<br />
break;<br />
<br />
case GAPC_CONNECTION_REQ_IND:<br />
{<br />
PRINTF("%s GAPM_PROFILE_ADDED_IND msg_id:%d\r\n",__func__,msg_id);<br />
}<br />
break;<br />
<br />
case GAPC_DISCONNECT_IND:<br />
{<br />
PRINTF("%s GAPC_DISCONNECT_IND msg_id:%d\r\n",__func__,msg_id);<br />
onsemLedEnable(LEDDISABLE);</i></i></i></p>
<p><i><i><i> }<br />
break;<br />
case APP_LIGHT_ACTION:<br />
{<br />
PRINTF("APP_LIGHT_ACTION\r\n");<br />
}<br />
break;<br />
default:<br />
;<br />
</i></i></i></p>
<p><i><i><i> </i></i></i></p>
<p><i><i><i> </i></i></i></p>
<p><i><i><i> }</i></i></i></p>
<p><br />
<i><i><i>}</i></i></i></p>
<p><i><i><i> </i></i></i></p>
<p><i><i><i> </i></i></i><br />
<strong>4 、竞赛源码</strong></p>
<p> <a href="https://download.eeworld.com.cn/detail/skyworth74/620208">https://download.eeworld.com.cn/detail/skyworth74/620208</a></p>
<p> </p>
<p><strong>5、作品视频演示</strong></p>
<p><iframe allowfullscreen="true" frameborder="0" height="510" src="https://training.eeworld.com.cn/shareOpenCourseAPI?isauto=true&lessonid=30614" style="background:#eee;margin-bottom:10px;" width="750"></iframe></p>
<p><iframe allowfullscreen="true" frameborder="0" height="510" src="https://training.eeworld.com.cn/shareOpenCourseAPI?isauto=true&lessonid=30806" style="background:#eee;margin-bottom:10px;" width="750"></iframe><br />
</p>
<p> </p>
<p></p>
<p><strong>6、总结</strong></p>
<p> IOT(物联网)是最近几年非常火爆的一个新趋势、未来随着5G的普及 IOT更是会深入到社会的各个方面,灯具是很好的物联网载体,有家的地方就有灯,用户体验到IOT的好处以后会更容易接受其它智能产品、比如智能窗帘、智能晾衣架,RS10是一款优秀的SOC芯片,拥有超低功耗提供了大量的实用例程,嵌入式工程师很容易就上手开发自己想要的产品,唯一的做IOT的缺点就是必须配套网关进行转换才能接入互联网,否则只能进行短距离控制。</p>
<p> </p>
<p><strong>7、其他</strong></p>
<p>分享帖:</p>
<ul>
<li><a href="https://bbs.eeworld.com.cn/thread-1170337-1-1.html">大赛分享,小白开箱</a></li>
<li><a href="https://bbs.eeworld.com.cn/thread-1171178-1-1.html">IOT台灯软件设计</a></li>
</ul>
<p></p>
<p>不错不错!这个想法挺好!</p>
w494143467 发表于 2021-7-18 15:23
不错不错!这个想法挺好!
<p>谢谢</p>
页:
[1]