首页 > 解决方案 > 从 Beaglebone 发送 IR NEC 信号

问题描述

我的部分项目需要我发送一个 IR 信号来改变遥控 RGB 泛光灯的颜色。首先,我使用 Arduino 解码从遥控器发送的信号。然后我开始编写一个内核模块来发送这个信号。由于我在 Beaglebone Black 中使用的是 Linux 内核的 buildroot 版本,因此我无法使用许多库。我将这些值存储在两个数组中:

int RED[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1};
int BLUE[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1};

这包含地址、反向地址、命令和反向命令。然后我将像这样运行 IR 信号:

void preamble(void){
        gpio_set_value(IR_LED, HIGH);
        mdelay(9);
        gpio_set_value(IR_LED, LOW);
        udelay(1000);
        udelay(1000);
        udelay(1000);
        udelay(1000);
        udelay(500);

}

void color_changer(int color){
    int *color_command;
    int bitl;
    int i;
    switch(color){
    case 1:
    color_command = RED;
    break;
    case 2:
    color_command = BLUE;
    break;
}
    preamble();
    for(i = 0; i< sizeof(color_command); i++){
        bitl = color_command[i];
        if (bitl == 1){
            gpio_set_value(IR_LED, HIGH);
            ndelay(562500);
            gpio_set_value(IR_LED, LOW);
            ndelay(1687500);
            
        }
        else if(bitl == 0){
            gpio_set_value(IR_LED, HIGH);
            ndelay(562500);
            gpio_set_value(IR_LED, LOW);
            ndelay(562500);
        }

    }
    gpio_set_value(IR_LED, HIGH);
    ndelay(562500);
    gpio_set_value(IR_LED, LOW);
}

但是,泛光灯不会改变颜色,我的 Arduino 也不会检测到任何信号。我试过的接线是:GPIO 67 -> 330Ohm Resistor -> IR LED -> Ground

以及此处描述的内容(我相应地更改了代码以考虑低电平有效设置)。我的代码有什么问题还是我错过了其他东西?

标签: c++cembedded-linuxkernel-modulebeagleboneblack

解决方案


推荐阅读