Alios Things 空调红外解码和发射

解码主要涉及2个功能,下划线是irda.c添加的部分:

static void fill_pwm_data(void)

{

    int i;

    if (pwm_div == 0) {

        KIDS_A10_PRT("pwm_div is zero!\n");

        return;

    }

    char pwmdataSettmp[128];

    char pwmdataSet[256];

    for (i = 0; i < feature_found; ++i) {

        pwm_data[i] = feature_code[i] / pwm_div;

        if (feature_code[i] % pwm_div > pwm_div / 2) {

            ++pwm_data[i];

        }

        sprintf(pwmdataSettmp,"%d",pwm_data[i]);

        strcat(pwmdataSet,pwmdataSettmp);

        strcat(pwmdataSet,",");

    }

    printf("pwm_data:%s\r\n",pwmdataSet);

    sprintf(pwmdataSettmp,"%d",pwm_div);

    strcat(pwmdataSet,pwmdataSettmp);

    strcat(pwmdataSet,",");

    printf("pwm_div:%d\r\n",pwm_div);

    sprintf(pwmdataSettmp,"%d",rcv_count-1);

    strcat(pwmdataSet,pwmdataSettmp);

    printf("rcv_count:%d\r\n",rcv_count-1);

}

static int irda_fill_send_buffer(void)

{

    int ret = 0;

    int i;

    uint32_t total_period = 0;

    uint32_t alloc_bytes = 0;

    uint32_t pwm_index = 0;

    

    char rcvdataSettmps[4];

    char rcvdataSettmpe[4];

    char rcvdataSets[512];

    char rcvdataSete[256];

    for (i = lead_data_hit; i < rcv_count; ++i) {

        total_period += pwm_data[rcv_data[i].pwm_data_s];

        total_period += pwm_data[rcv_data[i].pwm_data_e];

 

        printf("{%lu,%lu,%lu,%lu},\r\n",0,0,rcv_data[i].pwm_data_s,rcv_data[i].pwm_data_e);

 

        sprintf(rcvdataSettmps,"%d",rcv_data[i].pwm_data_s);

        strcat(rcvdataSets,rcvdataSettmps);

        strcat(rcvdataSets,",");

 

        sprintf(rcvdataSettmpe,"%d",rcv_data[i].pwm_data_e);

        strcat(rcvdataSete,rcvdataSettmpe);

        if(i<rcv_count-1){strcat(rcvdataSete,",");}

    }

    printf("rcv_data complete!\r\n");   

    printf("pwm_data_s:%s\r\n",rcvdataSets);

    printf("pwm_data_e:%s\r\n",rcvdataSete);

    strcat(rcvdataSets,rcvdataSete);

 

    pwm_send_max = total_period;

    alloc_bytes = total_period / 8;

    alloc_bytes += (total_period % 8 == 0 ? 0 : 1);

    

    pwm_send_buffer = (uint8_t *)aos_malloc(alloc_bytes);

    if (pwm_send_buffer == NULL) {

        KIDS_A10_PRT("aos_malloc return NULL.\n");

        return -1;

    }

    memset(pwm_send_buffer, 0, alloc_bytes);

    

    for (i = lead_data_hit; i < rcv_count; ++i) {

        fill_once(pwm_index, pwm_data[rcv_data[i].pwm_data_s]);

        pwm_index += pwm_data[rcv_data[i].pwm_data_s];

        pwm_index += pwm_data[rcv_data[i].pwm_data_e];

    }

    

    return 0;

}

 

新增自定义发射部分:

int pre_irda_send_code(IR_sig_data rcvdata[],uint32_t pwmdata[],uint32_t pwmdiv,uint32_t rcvcount)

{

    lead_data_hit=0;

    pwm_div=pwmdiv;

    rcv_count=rcvcount;

    for(int i=0;i<rcv_count;i++)

    {

        rcv_data[i]=rcvdata[i];

    }   

    

    for(int i=0;i<6;i++)

    {

        pwm_data[i]=pwmdata[i];

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值