123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991 |
- #include "u_app_handler.h"
- #include "u_main.h"
- #include "u_time.h"
- #include "u_ble.h"
- #include "u_light_ctrl.h"
- #include "u_effect_normal.h"
- #include "u_effect_color.h"
- #include "u_effect_rhythm.h"
- #include "user_driver.h"
- #include "LH_TaskManager.h"
- uint32_t m_clr_play_buff[APP_MODE_CLR_MAX_NUM] = {0x00};
- AppModeInfo_t m_app_mode_info[APP_MODE_SCENE_MAX_NUM] = {0x00};
- void app_mode_info_init(void)
- {
-
- //晚安
- m_app_mode_info[0].bright = 5;
- m_app_mode_info[0].speed = 1;
- m_app_mode_info[0].effect = 0xc0;
- // m_app_mode_info[0].last_effect = 1;
- m_app_mode_info[0].clr_num = 1;
-
- m_app_mode_info[0].clr_data[0] = 0xff;
- m_app_mode_info[0].clr_data[1] = 0x75;
- m_app_mode_info[0].clr_data[2] = 0x00;
-
- //阅读
- m_app_mode_info[1].bright = 100;
- m_app_mode_info[1].speed = 1;
- m_app_mode_info[1].effect = 0xc0;
- // m_app_mode_info[1].last_effect = 1;
- m_app_mode_info[1].clr_num = 1;
-
- m_app_mode_info[1].clr_data[0] = 0xff;
- m_app_mode_info[1].clr_data[1] = 0xc4;
- m_app_mode_info[1].clr_data[2] = 0x37;
- //自定义
- m_app_mode_info[2].bright = 50;
- m_app_mode_info[2].speed = 5;
- m_app_mode_info[2].effect = 0xc1;
- // m_app_mode_info[2].last_effect = 1;
- m_app_mode_info[2].clr_num = 3;
-
- m_app_mode_info[2].clr_data[0] = 0xff;
- m_app_mode_info[2].clr_data[1] = 0x00;
- m_app_mode_info[2].clr_data[2] = 0x00;
- m_app_mode_info[2].clr_data[3] = 0x2b;
- m_app_mode_info[2].clr_data[4] = 0xfc;
- m_app_mode_info[2].clr_data[5] = 0x0a;
-
- m_app_mode_info[2].clr_data[6] = 0x02;
- m_app_mode_info[2].clr_data[7] = 0x28;
- m_app_mode_info[2].clr_data[8] = 0xfe;
- //缤纷
- m_app_mode_info[3].bright = 100;
- m_app_mode_info[3].speed = 7;
- m_app_mode_info[3].effect = 0xc1;
- // m_app_mode_info[3].last_effect = 1;
- m_app_mode_info[3].clr_num = 7;
- m_app_mode_info[3].clr_data[0] = 0xff;
- m_app_mode_info[3].clr_data[1] = 0x00;
- m_app_mode_info[3].clr_data[2] = 0x00;
- m_app_mode_info[3].clr_data[3] = 0xfd;
- m_app_mode_info[3].clr_data[4] = 0xfd;
- m_app_mode_info[3].clr_data[5] = 0x00;
-
- m_app_mode_info[3].clr_data[6] = 0x2b;
- m_app_mode_info[3].clr_data[7] = 0xfc;
- m_app_mode_info[3].clr_data[8] = 0x0a;
-
- m_app_mode_info[3].clr_data[9] = 0x02;
- m_app_mode_info[3].clr_data[10] = 0xf9;
- m_app_mode_info[3].clr_data[11] = 0xfe;
-
- m_app_mode_info[3].clr_data[12] = 0x02;
- m_app_mode_info[3].clr_data[13] = 0x28;
- m_app_mode_info[3].clr_data[14] = 0xfe;
- m_app_mode_info[3].clr_data[15] = 0x93;
- m_app_mode_info[3].clr_data[16] = 0x0a;
- m_app_mode_info[3].clr_data[17] = 0xfc;
- m_app_mode_info[3].clr_data[18] = 0xff;
- m_app_mode_info[3].clr_data[19] = 0xff;
- m_app_mode_info[3].clr_data[20] = 0xff;
- // //炫彩
- m_app_mode_info[4].bright = 100;
- m_app_mode_info[4].speed = 7;
- m_app_mode_info[4].effect = 0xc1;
- // m_app_mode_info[4].last_effect = 1;
- m_app_mode_info[4].clr_num = 3;
-
- m_app_mode_info[4].clr_data[0] = 0xff;
- m_app_mode_info[4].clr_data[1] = 0x00;
- m_app_mode_info[4].clr_data[2] = 0x00;
- m_app_mode_info[4].clr_data[3] = 0x2b;
- m_app_mode_info[4].clr_data[4] = 0xfc;
- m_app_mode_info[4].clr_data[5] = 0x0a;
-
- m_app_mode_info[4].clr_data[6] = 0x02;
- m_app_mode_info[4].clr_data[7] = 0x28;
- m_app_mode_info[4].clr_data[8] = 0xfe;
- //斑斓
- m_app_mode_info[5].bright = 100;
- m_app_mode_info[5].speed = 5;
- m_app_mode_info[5].effect = 0xc2;
- // m_app_mode_info[5].last_effect = 2;
- m_app_mode_info[5].clr_num = 7;
-
- m_app_mode_info[5].clr_data[0] = 0xff;
- m_app_mode_info[5].clr_data[1] = 0x00;
- m_app_mode_info[5].clr_data[2] = 0x00;
- m_app_mode_info[5].clr_data[3] = 0xfd;
- m_app_mode_info[5].clr_data[4] = 0xfd;
- m_app_mode_info[5].clr_data[5] = 0x00;
-
- m_app_mode_info[5].clr_data[6] = 0x2b;
- m_app_mode_info[5].clr_data[7] = 0xfc;
- m_app_mode_info[5].clr_data[8] = 0x0a;
-
- m_app_mode_info[5].clr_data[9] = 0x02;
- m_app_mode_info[5].clr_data[10] = 0xf9;
- m_app_mode_info[5].clr_data[11] = 0xfe;
-
- m_app_mode_info[5].clr_data[12] = 0x02;
- m_app_mode_info[5].clr_data[13] = 0x28;
- m_app_mode_info[5].clr_data[14] = 0xfe;
- m_app_mode_info[5].clr_data[15] = 0x93;
- m_app_mode_info[5].clr_data[16] = 0x0a;
- m_app_mode_info[5].clr_data[17] = 0xfc;
- m_app_mode_info[5].clr_data[18] = 0xff;
- m_app_mode_info[5].clr_data[19] = 0xff;
- m_app_mode_info[5].clr_data[20] = 0xff;
-
- //火焰
- m_app_mode_info[6].bright = 100;
- m_app_mode_info[6].speed = 2;
- m_app_mode_info[6].effect = 0xc2;
- // m_app_mode_info[6].last_effect = 1;
- m_app_mode_info[6].clr_num = 1;
-
- m_app_mode_info[6].clr_data[0] = 0xff;
- m_app_mode_info[6].clr_data[1] = 0x00;
- m_app_mode_info[6].clr_data[2] = 0x00;
- //闪动
- m_app_mode_info[7].bright = 100;
- m_app_mode_info[7].speed = 2;
- m_app_mode_info[7].effect = 0xc1;
- // m_app_mode_info[7].last_effect = 1;
- m_app_mode_info[7].clr_num = 3;
-
- m_app_mode_info[7].clr_data[0] = 0xff;
- m_app_mode_info[7].clr_data[1] = 0x00;
- m_app_mode_info[7].clr_data[2] = 0x00;
- m_app_mode_info[7].clr_data[3] = 0x2b;
- m_app_mode_info[7].clr_data[4] = 0xfc;
- m_app_mode_info[7].clr_data[5] = 0x0a;
-
- m_app_mode_info[7].clr_data[6] = 0x02;
- m_app_mode_info[7].clr_data[7] = 0x28;
- m_app_mode_info[7].clr_data[8] = 0xfe;
-
- //灯光秀
- m_app_mode_info[8].bright = 100;
- m_app_mode_info[8].speed = 2;
- m_app_mode_info[8].effect = 0xc1;
- // m_app_mode_info[8].last_effect = 1;
- m_app_mode_info[8].clr_num = 7;
-
- m_app_mode_info[8].clr_data[0] = 0xff;
- m_app_mode_info[8].clr_data[1] = 0x00;
- m_app_mode_info[8].clr_data[2] = 0x00;
- m_app_mode_info[8].clr_data[3] = 0xfd;
- m_app_mode_info[8].clr_data[4] = 0xfd;
- m_app_mode_info[8].clr_data[5] = 0x00;
-
- m_app_mode_info[8].clr_data[6] = 0x2b;
- m_app_mode_info[8].clr_data[7] = 0xfc;
- m_app_mode_info[8].clr_data[8] = 0x0a;
- m_app_mode_info[8].clr_data[9] = 0x02;
- m_app_mode_info[8].clr_data[10] = 0xf9;
- m_app_mode_info[8].clr_data[11] = 0xfe;
-
- m_app_mode_info[8].clr_data[12] = 0x02;
- m_app_mode_info[8].clr_data[13] = 0x28;
- m_app_mode_info[8].clr_data[14] = 0xfe;
- m_app_mode_info[8].clr_data[15] = 0x93;
- m_app_mode_info[8].clr_data[16] = 0x0a;
- m_app_mode_info[8].clr_data[17] = 0xfc;
- m_app_mode_info[8].clr_data[18] = 0xff;
- m_app_mode_info[8].clr_data[19] = 0xff;
- m_app_mode_info[8].clr_data[20] = 0xff;
- }
- void light_state_upload(void) //回发灯的状态给app
- {
- uint8_t upload_buff[14] = {0};
-
- if(g_light_para.power_st == GLO_EN) //灯当前是否开关
- {
- upload_buff[0] = 1;
- }
- else
- {
- upload_buff[0] = 0;
- }
-
- if (g_light_para.app_mode[0] >= LIGHT_APP_MODE_RC_MIN)
- {
- upload_buff[1] = LIGHT_APP_MODE_COLORUR;
- }
- else
- {
- upload_buff[1] = g_light_para.app_mode[0]; //灯当前的模式
- upload_buff[2] = g_light_para.app_mode[1];
- }
-
- upload_buff[3] = g_light_para.bright; //灯当前的亮度
- upload_buff[4] = g_light_para.app_speed;
- upload_buff[5] = 100 - g_light_para.rhythm_sensit * APP_SENSIT_K;
- upload_buff[6] = g_light_para.clr_temp[0];
- upload_buff[7] = g_light_para.clr_temp[1];
- upload_buff[8] = g_light_para.clr_temp[2];
- upload_buff[9] = g_light_para.clr_temp[3];
- upload_buff[10] = g_light_para.rgb_order[0];
- upload_buff[11] = g_light_para.rgb_order[1];
- upload_buff[12] = g_light_para.rgb_order[2];
- if( g_light_para.mic==0)
- {
- upload_buff[13] = 0x00; //区分带麦
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("no mic");
- U_UART_PRINTF("\r\n");
- #endif
- }else
- {
- upload_buff[13] = 0x01; //区分带麦
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("have mic");
- U_UART_PRINTF("\r\n");
- #endif
- }
- //UART_PRINTF("user_send_light_state %d %d %d\r\n",Rgb_Para.color_arr[10],Rgb_Para.color_arr[11],Rgb_Para.color_arr[12]);
- reply_app_encode(0x10, upload_buff, 14);
- }
- static void app_light_colour_enter(const uint32_t *static_clr, uint8_t static_bright)
- {
- u_rhythm_timer_ctrl(GLO_DIS);
- light_mode_static_cfg(&g_light_info, static_clr, static_bright);
- }
- static void app_rhythm_enter(uint8_t *app_mode)
- {
- if (app_mode[0] == APP_RHYTHM_MODE_MUSIC)
- {
- g_light_para.mic_AppOrDriver=0;
- light_rhythm_enter(RHYTHM_MODE_GRADUAL_7);
- }
- else
- {
- switch (app_mode[1])
- {
- case APP_RHYTHM_MODE_FADE3:
- {
- light_rhythm_enter(RHYTHM_MODE_FADE_3);
- }
- break;
- case APP_RHYTHM_MODE_FADE7:
- {
- light_rhythm_enter(RHYTHM_MODE_FADE_7);
- }
- break;
- case APP_RHYTHM_MODE_JUMP3:
- {
- light_rhythm_enter(RHYTHM_MODE_JUMP_3);
- }
- break;
- case APP_RHYTHM_MODE_JUMP7:
- {
- light_rhythm_enter(RHYTHM_MODE_JUMP_7);
- }
- break;
- }
- }
- }
- void light_mode_set(uint8_t *app_mode)
- {
- uint8_t app_mode_info_ind = 0;
- memcpy(g_light_para.app_mode, app_mode, 2);
-
- switch (g_light_para.app_mode[0])
- {
- case LIGHT_APP_MODE_WHITE_LIGHT:
- case LIGHT_APP_MODE_COLORUR:
- {
- clr_format_transition(CLR_TS_TYPE_8_32, 1, g_light_para.clr_temp, m_clr_play_buff);
- app_light_colour_enter(m_clr_play_buff, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_S_RED:
- case LIGHT_APP_MODE_S_BLUE:
- case LIGHT_APP_MODE_S_GREEN:
- case LIGHT_APP_MODE_S_CYAN:
- case LIGHT_APP_MODE_S_YELLOW:
- case LIGHT_APP_MODE_S_PURPLE:
- case LIGHT_APP_MODE_S_WHITE:
- {
- uint8_t clr_ind = g_light_para.app_mode[0] - LIGHT_APP_MODE_S_RED;
- light_mode_static_cfg(&g_light_info, &app_static_clr[clr_ind], g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_JUMP_3:
- {
- light_mode_jump_cfg(&g_light_info, base_clr, 3, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_JUMP_7:
- {
- light_mode_jump_cfg(&g_light_info, base_clr, 7, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_FADE_3:
- {
- light_mode_gradual_cfg(&g_light_info, base_clr, 3, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_FADE_7:
- {
- light_mode_gradual_cfg(&g_light_info, base_clr, 7, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_BREATH_RED:
- case LIGHT_APP_MODE_BREATH_BLUE:
- case LIGHT_APP_MODE_BREATH_GREEN:
- case LIGHT_APP_MODE_BREATH_YELLOW:
- case LIGHT_APP_MODE_BREATH_CYAN:
- case LIGHT_APP_MODE_BREATH_PURPLE:
- case LIGHT_APP_MODE_BREATH_WHITE:
- {
- uint8_t clr_ind = g_light_para.app_mode[0] - LIGHT_APP_MODE_BREATH_RED;
- light_mode_breath_cfg(&g_light_info, &base_clr[clr_ind], 1, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_FADE_RG:
- {
- light_mode_gradual_cfg(&g_light_info, base_clr, 2, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_FADE_RB:
- {
- light_mode_gradual_cfg(&g_light_info, app_static_clr, 2, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_FADE_GB:
- {
- light_mode_gradual_cfg(&g_light_info, &base_clr[1], 2, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_BLINK_7:
- {
- light_mode_blink_cfg(&g_light_info, base_clr, 7, 5, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_BLINK_RED:
- case LIGHT_APP_MODE_BLINK_GREEN:
- case LIGHT_APP_MODE_BLINK_BLUE:
- case LIGHT_APP_MODE_BLINK_YELLOW:
- case LIGHT_APP_MODE_BLINK_CYAN:
- case LIGHT_APP_MODE_BLINK_PURPLE:
- case LIGHT_APP_MODE_BLINK_WHITE:
- {
- uint8_t clr_ind = g_light_para.app_mode[0] - LIGHT_APP_MODE_BLINK_RED;
- light_mode_blink_cfg(&g_light_info, &base_clr[clr_ind], 1, 5, g_light_para.speed, g_light_para.bright);
- }
- break;
- case LIGHT_APP_MODE_RHYTHM_APP: //手机麦
- {
- if(g_light_para.mic == 1)
- {
- g_light_para.mic_AppOrDriver = 0;
- }else if(g_light_para.mic == 0)
- {
- g_light_para.mic_AppOrDriver = 0;
- }
- app_rhythm_enter(app_mode);
- }
- break;
- case LIGHT_APP_MODE_RHYTHM_DRIVER: //外部麦
- {
- if(g_light_para.mic == 1)
- {
- g_light_para.mic_AppOrDriver = 1;
- app_rhythm_enter(app_mode);
- if(g_light_para.rhythm_mode!=RHYTHM_MODE_STOP)//增加对律动保存功能支持 2021/10/12 liuhao
- {
- u_rhythm_timer_ctrl(GLO_EN);
- }
- }else if(g_light_para.mic == 0)
- {
- g_light_para.mic_AppOrDriver=0;
- }
- //app_rhythm_enter(app_mode);
- }
- break;
- case LIGHT_APP_MODE_RHYTHM_MUSIC: //律动
- {
- g_light_para.mic_AppOrDriver = 0;
- app_rhythm_enter(app_mode);
- }
- break;
- case LIGHT_APP_MODE_GOODNIGHT :
- case LIGHT_APP_MODE_READ :
- case LIGHT_APP_MODE_WORD :
- case LIGHT_APP_MODE_COLORFUL :
- case LIGHT_APP_MODE_DAZZLING :
- case LIGHT_APP_MODE_MULT :
- case LIGHT_APP_MODE_FLAME :
- case LIGHT_APP_MODE_BLINK :
- case LIGHT_APP_MODE_SHOW :
- {
- app_mode_info_ind = g_light_para.app_mode[0] - LIGHT_APP_MODE_SCENE_MIN;
- // if(app_mode[1] == 0xFF)
- // {
- // g_light_para.app_mode[1] = m_app_mode_info[app_mode_info_ind].effect;
- // U_UART_PRINTF("app_mode[1]=%x \r\n",g_light_para.app_mode[1]);
- // }else
- // {
- // m_app_mode_info[app_mode_info_ind].effect = g_light_para.app_mode[1];
- // }
- if(g_light_para.app_mode[0] == 0xC2)
- {
- if(app_mode[1] == 0xFF)
- {
- // g_light_para.app_mode[1] = m_app_mode_info[app_mode_info_ind].effect;
- // U_UART_PRINTF("app_mode[1]=%x \r\n",g_light_para.app_mode[1]);
- }else
- {
- m_app_mode_info[app_mode_info_ind].effect = g_light_para.app_mode[1];
- }
- m_app_mode_info[app_mode_info_ind].speed = g_light_para.speed;
- m_app_mode_info[app_mode_info_ind].bright = g_light_para.bright;
-
- }
- g_light_para.app_mode[1] = m_app_mode_info[app_mode_info_ind].effect;
- clr_format_transition(CLR_TS_TYPE_8_32, m_app_mode_info[app_mode_info_ind].clr_num, m_app_mode_info[app_mode_info_ind].clr_data, m_clr_play_buff);
- app_light_normal_effect_enter(m_app_mode_info[app_mode_info_ind].effect, m_clr_play_buff, m_app_mode_info[app_mode_info_ind].clr_num, m_app_mode_info[app_mode_info_ind].speed, m_app_mode_info[app_mode_info_ind].bright);
- // app_light_normal_effect_enter(g_light_para.app_mode[1], m_clr_play_buff, m_app_mode_info[app_mode_info_ind].clr_num, g_light_para.speed,g_light_para.bright);
- if(app_mode[1] == 0xFF)
- {
- light_state_upload();
- }
- }
- break;
- }
- }
- void app_light_normal_effect_enter(uint8_t app_effect, uint32_t *clr_buff, uint8_t clr_num, uint8_t speed, uint8_t bright)
- {
-
- switch(app_effect) //灯的效果
- {
-
- case LIGHT_APP_EFFECT_STATIC: //静态模式
- {
- light_mode_static_cfg(&g_light_info, clr_buff, bright);
- }
- break;
- case LIGHT_APP_EFFECT_JUMP:
- {
- light_mode_jump_cfg(&g_light_info, clr_buff, clr_num, speed, bright);
- }
- break;
- case LIGHT_APP_EFFECT_GRADUAL:
- {
- light_mode_gradual_cfg(&g_light_info, clr_buff, clr_num, speed, bright);
- }
- break;
- }
- }
- void app_read_mode_clr(uint8_t mode,uint8_t *reply_buff, uint8_t *len)
- {
- uint32_t i = 0;
- reply_buff[0] = mode;//g_light_para.app_mode[1];
- if (mode >= LIGHT_APP_MODE_SCENE_MIN && mode <= LIGHT_APP_MODE_SCENE_MAX)
- {
- uint8_t app_mode_info_ind = mode - LIGHT_APP_MODE_SCENE_MIN;
- if (m_app_mode_info[app_mode_info_ind].clr_num > APP_MODE_CLR_MAX_NUM)
- {
- m_app_mode_info[app_mode_info_ind].clr_num = APP_MODE_CLR_MAX_NUM;
- }
-
- for(i = 0; i < m_app_mode_info[app_mode_info_ind].clr_num; i++)
- {
- reply_buff[i*4+1] = m_app_mode_info[app_mode_info_ind].clr_data[i*3+0];
- reply_buff[i*4+2] = m_app_mode_info[app_mode_info_ind].clr_data[i*3+1];
- reply_buff[i*4+3] = m_app_mode_info[app_mode_info_ind].clr_data[i*3+2];
- reply_buff[i*4+4] = 0x65;
- // U_UART_PRINTF("i: %d, %d,%d,%d \r\n", i, m_app_mode_info[app_mode_info_ind].clr_data[i*3+0],m_app_mode_info[app_mode_info_ind].clr_data[i*3+1],m_app_mode_info[app_mode_info_ind].clr_data[i*3+2]);
- }
- *len = m_app_mode_info[app_mode_info_ind].clr_num * 4 + 1;
- // U_UART_PRINTF("app_mode_info_ind: %d\r\n", app_mode_info_ind);
- }
- else
- {
- *len = 1;
- }
- }
- void app_set_mode_clr(uint8_t *data, uint8_t len)
- {
- uint8_t j= 0, k = 0;
- uint8_t app_mode_info_ind = data[0] - LIGHT_APP_MODE_SCENE_MIN;
- uint32_t i = 0;
-
- len = (len - 4) / 4; //有效组数
- // if(len>=APP_MODE_CLR_MAX_NUM)
- // {
- // len=APP_MODE_CLR_MAX_NUM;
- // }
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("len: %d\r\n", len);
- #endif
- m_app_mode_info[app_mode_info_ind].clr_num = 0;
-
- for(i = 0; i <= len; i++)
- {
- m_app_mode_info[app_mode_info_ind].clr_data[k] = data[j + 1];
- m_app_mode_info[app_mode_info_ind].clr_data[k + 1] = data[j + 2];
- m_app_mode_info[app_mode_info_ind].clr_data[k + 2] = data[j + 3];
- // U_UART_PRINTF("[%d]: %d, [%d]:%d, [%d]:%d",k,m_app_mode_info[app_mode_info_ind].clr_data[k] ,k+1,m_app_mode_info[app_mode_info_ind].clr_data[k+1],k+2,m_app_mode_info[app_mode_info_ind].clr_data[k+2]);
- // U_UART_PRINTF(" CC: %d, %d,%d,%d,%d\r\n", m_app_mode_info[app_mode_info_ind].clr_num, data[j+1],data[j+2],data[j+3],data[j+4]);
- m_app_mode_info[app_mode_info_ind].clr_num++;
- j += 4;
- k += 3;
- }
- clr_format_transition(CLR_TS_TYPE_8_32, m_app_mode_info[app_mode_info_ind].clr_num, m_app_mode_info[app_mode_info_ind].clr_data, m_clr_play_buff);
- app_light_normal_effect_enter(m_app_mode_info[app_mode_info_ind].effect, m_clr_play_buff, m_app_mode_info[app_mode_info_ind].clr_num, g_light_para.speed, g_light_para.bright);
- // U_UART_PRINTF("app_mode_info_ind: %d\r\n", app_mode_info_ind);
- }
- static void app_mode_enter(uint8_t *app_mode)
- {
- light_mode_set(app_mode);
- }
- void reply_app_encode(uint8_t cmd, uint8_t *data, uint8_t len) //回发app解码数据
- {
- static uint8_t send[64]={0};
- uint8_t i=0;
- uint16_t crc=0;
- send[0] = 0xA1;
- send[1] = cmd;
- send[2] = len + 3;
- for(i = 0; i<len; i++)
- {
- send[3+i] = data[i];
- }
- crc = crc_16(send, len +3);
- send[3+len] = crc & 0xff;
- send[4+len] = crc >> 8;
- //UART_PRINTF("crc: %x\r\n", crc);
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("tx:");
- for(i = 0; i < len + 5; i++)
- {
- U_UART_PRINTF("%02X ", send[i]);
- }
- U_UART_PRINTF("\r\n");
- #endif
- u_ble_data_send(send, len + 5);
- }
- //app下发数据的处理函数
- void decode_app_cmd(uint8_t cmd, uint8_t *data, uint8_t len)
- {
- static uint8_t xx = 0, yy = 0;
- uint8_t reply_state;
- #if 0
- //UART_PRINTF("app cmd: 0x%x, %d\r\n", cmd, len);
- UART_PRINTF("app cmd: %02x, %02x %02x\r\n",data[0],data[1],data[2]);
- #endif
- switch(cmd)
- {
- case 0x00: //握手指令
- {
- if(memcmp(&data[0], "CCHIP", 5) == 0)
- {
- uint8_t str[7] = "CCHIP";
- xx = HW_Get_Native_Clk_Avoid_Race() % 8;
- yy = HW_Get_Native_Clk_Avoid_Race() /100 % 8;
- str[5] = xx;
- str[6] = yy;
- reply_app_encode(0x00, str, 7);
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("check device1: %02x,%02x\r\n", xx, yy);
- #endif
- }
- }
- break;
- case 0x01: //握手指令
- {
- if(memcmp(&data[0], "CCHIP", 5) == 0)
- {
- uint8_t send[6] = "CCHIP";
- //U_UART_PRINTF("check device2: %02x,%02x, %02x,%02x\r\n", (xx^36),data[5],(yy^63+13)&0xff,data[6]);
- if((((xx^36) &0xff) == data[5]) && (((yy^63+13) &0xff) == data[6]))
- {
- send[5] = 0x00;
- reply_app_encode(0x01, send, 6);
- //user_connect();
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("check ok\r\n");
- #endif
- }
- else
- {
- send[5] = 0x01;
- reply_app_encode(0x01, send, 6);
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("check error\r\n");
- #endif
- }
- }
- }
- break;
- case 0x10: //读取灯属性的指令
- {
- light_state_upload();
- }
- break;
- case 0x11: //设置灯开关的指令
- {
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("light_power_st = %d\n", data[0]);
- #endif
- light_power_set(data[0]);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x12: //设置灯模式
- {
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("\r\n app_mode = %X, app_effect = %X\r\n",data[0], data[1]);
- #endif
- app_mode_enter(data);
- light_power_set(g_light_para.power_st);
- }
- break;
- case 0x13: //设置灯亮度
- {
- //data[0] bright
- light_bright_ctrl(data[0]);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x15: //设置灯颜色
- {
- memcpy(g_light_para.clr_temp, &data[0], 4);
- reply_state = 0x01;
- reply_app_encode(cmd, &reply_state, 1);
-
- clr_format_transition(CLR_TS_TYPE_8_32, 1, g_light_para.clr_temp, m_clr_play_buff);
- app_light_colour_enter(m_clr_play_buff, g_light_para.bright);
- g_light_para.app_mode[0] = LIGHT_APP_MODE_COLORUR;
- light_power_set(g_light_para.power_st);
- }
- break;
- case 0x16: //设置灯速度
- {
- //data[0] speed
- light_speed_ctrl(data[0]);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x17: //设置律动灵敏度
- {
- rhythm_sensit_ctrl(NULL, data[0]);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x18: //设置RGB线序
- {
- memcpy(g_light_para.rgb_order, data, 3);
- rgb_line_order_check();
- light_power_set(g_light_para.power_st);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x19: //设置白光
- {
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x1A: //设置律动 颜色&亮度
- {
-
- }
- break;
- case 0x20: //白光颜色&色温
- {
- memcpy(g_light_para.clr_temp, data, 4);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- clr_format_transition(CLR_TS_TYPE_8_32, 1, g_light_para.clr_temp, m_clr_play_buff);
- app_light_colour_enter(m_clr_play_buff, g_light_para.bright);
- g_light_para.app_mode[0] = LIGHT_APP_MODE_COLORUR;
- }
- break;
- case 0x21: //律动开始&暂停
- {
- u_rhythm_timer_ctrl(data[0]);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x28: //读取设置
- {
- uint8_t reply_buff[2] = {0x00};
-
- reply_buff[0] = g_light_para.app_seting >> 4;
- reply_buff[1] = g_light_para.app_seting & 0x0F;
- reply_app_encode(cmd, reply_buff, 2);
- }
- break;
- case 0x29: //设置连接状态
- {
- g_light_para.app_seting = (data[0] << 4) | (g_light_para.app_seting & 0x0F);
- reply_state = 0x01;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x2A: //设置断开状态
- {
- g_light_para.app_seting = (g_light_para.app_seting & 0xF0) | (data[0] & 0x0F);
- reply_state = 0x01;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x31: //同步当前的时间
- {
- time_app_driver_sync(data);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x34: //闹钟的设置
- {
- time_alarm_set(data);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0x35: //读取闹钟的状态
- {
- uint8_t reply_len = 0, alarm_st[24] = {0x00};
- time_alarm_state_query(alarm_st, &reply_len);
- reply_app_encode(cmd, alarm_st, reply_len);
- }
- break;
- case 0x51: //律动值
- {
- app_rhythm_val_up(data[0]);
- reply_state = 1;
- reply_app_encode(cmd, &reply_state, 1);
- }
- // case 0x52: // 上报律动开始/停止
- // {
- //
- //
- // reply_state = 1;
- // reply_app_encode(cmd, &reply_state, 1);
- // }
- break;
- case 0x41: //读取版本号
- {
- uint8_t temp[] = "1.1.1";
- reply_app_encode(0x41, temp, sizeof(temp) - 1);
- }
- break;
- case 0xA1: //设置某模式颜色
- {
- uint8_t bao_len = data[1] - 1 ,temp_len = 0,i;
- static uint8_t mode_set_buff[5] = {0x00};
- static uint8_t mode_clr_set_buff[40] = {0x00};
- static uint8_t clr_buff_len = 0;
-
- if(data[2]==0) //第一包数据
- {
- mode_set_buff[0] = data[3];
- mode_set_buff[1] = g_light_para.app_mode[1];
- mode_clr_set_buff[0] = data[3];
- clr_buff_len = len - 4 - 3;
- memcpy(&mode_clr_set_buff[1], &data[4], clr_buff_len);
- if( bao_len == data[2])
- {
- light_mode_set(mode_set_buff);
- app_set_mode_clr(mode_clr_set_buff, clr_buff_len );
- }
- }else if(data[2] == 1)
- {
- temp_len = len - 3 -3;
- clr_buff_len = clr_buff_len + temp_len;
- memcpy(&mode_clr_set_buff[12], &data[3], temp_len);
- if( bao_len == data[2] )
- {
- light_mode_set(mode_set_buff);
- app_set_mode_clr(mode_clr_set_buff, clr_buff_len);
- }
- }else if(data[2] == 2)
- {
- temp_len = len - 3 - 3;
- clr_buff_len = clr_buff_len+temp_len;
- memcpy(&mode_clr_set_buff[24], &data[3], temp_len);
- if( bao_len == data[2] )
- {
- light_mode_set(mode_set_buff);
- app_set_mode_clr(mode_clr_set_buff, clr_buff_len);
- }
- }
- reply_state = 0x01;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0xA3: //设置群组 模式-灯效-亮度-速度-色值
- {
- uint8_t i=0;
- uint8_t bao_len = data[1] - 1 , temp_len = 0;
- static uint8_t mode_set_buff[5] = {0x00};
- static uint8_t mode_clr_set_buff[40] = {0x00};
- static uint8_t bao_bright = 0,bao_speed = 0,clr_buff_len = 0;
-
- if(data[2]== 0 ) //第一包数据
- {
- mode_set_buff[0] = data[3];
- mode_set_buff[1] = data[4];
-
- mode_clr_set_buff[0] = data[3];
- bao_bright = data[5];
- bao_speed = data[6];
- clr_buff_len = len - 7 -3;
- memcpy(&mode_clr_set_buff[1], &data[7], clr_buff_len);
- if( bao_len==data[2])
- {
- light_bright_ctrl(bao_bright);
- light_speed_ctrl(bao_speed);
- light_mode_set(mode_set_buff);
- app_set_mode_clr(mode_clr_set_buff, clr_buff_len);
- }
- }else if(data[2] == 1 )
- {
- temp_len = len - 3 -3;
- clr_buff_len = clr_buff_len + temp_len;
- memcpy(&mode_clr_set_buff[9], &data[3], temp_len);
- if( bao_len == data[2] )
- {
- light_bright_ctrl(bao_bright);
- light_speed_ctrl(bao_speed);
- light_mode_set(mode_set_buff);
- app_set_mode_clr(mode_clr_set_buff, clr_buff_len);
- }
- }else if(data[2] == 2 )
- {
- temp_len = len - 3 -3;
- clr_buff_len = clr_buff_len + temp_len ;
- memcpy(&mode_clr_set_buff[21], &data[3], temp_len);
- if( bao_len == data[2] )
- {
- light_bright_ctrl(bao_bright);
- light_speed_ctrl(bao_speed);
- light_mode_set(mode_set_buff);
- app_set_mode_clr(mode_clr_set_buff, clr_buff_len);
- }
- }
- reply_state = 0x01;
- reply_app_encode(cmd, &reply_state, 1);
- }
- break;
- case 0xA2: //读取某模式颜色
- {
- uint8_t FrameReq = 0;
- uint8_t bao_set_len = 0; //包数量
- uint8_t reply_len = 0; //总长度
- uint8_t reply_buff[APP_MODE_CLR_MAX_NUM * 4] = {0x00};
- uint8_t set_buff[45] = {0x00};
-
- app_read_mode_clr(data[1],reply_buff, &reply_len);
- FrameReq = data[0];
- bao_set_len = reply_len / 12 ;
- if( bao_set_len == 0 )
- {
- set_buff[0] = FrameReq;
- set_buff[1] = 1;
- set_buff[2] = 0;
- memcpy(&set_buff[3],&reply_buff[0],reply_len);
- reply_app_encode(cmd, &set_buff[0], reply_len+3);
-
- } else if ( bao_set_len == 1 )
- {
- set_buff[0] = FrameReq;
- set_buff[1] = 2;
- set_buff[2] = 0;
- memcpy(&set_buff[3],&reply_buff[0],12);
- reply_app_encode(cmd, &set_buff[0], 15);
-
- reply_len = reply_len - 12;
- set_buff[15]=FrameReq;
- set_buff[16]=2;
- set_buff[17]=1;
- memcpy(&set_buff[18],&reply_buff[12],reply_len);
- reply_app_encode(cmd, &set_buff[15], reply_len+3);
- }else if ( bao_set_len == 2 )
- {
- set_buff[0] = FrameReq;
- set_buff[1] = 3;
- set_buff[2] = 0;
- memcpy(&set_buff[3],&reply_buff[0],12);
- reply_app_encode(cmd, &set_buff[0], 0x0f);
-
- set_buff[15]=FrameReq;
- set_buff[16]=3;
- set_buff[17]=1;
- memcpy(&set_buff[18],&reply_buff[12],12);
- reply_app_encode(cmd, &set_buff[15], 0x0f);
-
- reply_len = reply_len - 24;
- set_buff[30]=FrameReq;
- set_buff[31]=3;
- set_buff[32]=2;
- memcpy(&set_buff[33],&reply_buff[24],reply_len);
- reply_app_encode(cmd, &set_buff[30], reply_len+3);
- }
- //reply_app_encode(cmd, reply_buff, reply_len);
- }
- break;
-
- case 0xF1:
- {
- uint32_t sys_time=sys_time_handle.get_run_ticks(); //获取运行时间
- uint8_t sys_temp[4] = {0};
- memcpy(sys_temp,&sys_time,4);
- reply_app_encode(0xF1, sys_temp, 4);
- }
- break;
-
- case 0xF2:
- {
- reply_app_encode(0xF2, (uint8_t*)firmware_version, sizeof(firmware_version) - 1);
- }
- break;
- }
- light_info_save_set();
- }
|