我正在编写 android 应用程序,但无法发送 IR 密钥。这是我的 code.I 不知道什么是 wrong.I 使用 android 9
I am writing android application and i can't send IR key. Here is my code.I don't know what is wrong.I use android 9
当执行我的应用程序并按下必须发送 IR key.After 的按钮时,IR 只是闪烁而 IR 键未传输(我使用 arduino 进行检查)。可能我的 [=26= 频率错误](Redmi Note 5) 可能存在另一个频率公式。
这是我的代码
我要传输的密钥:
irData.put(R.id.buttonOn, hex2dec("0000 006d 0022 0003 00a9 00a8 0015 003f 0015 003f 0015 " +
"003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015" +
" 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015" +
" 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f" +
" 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702 00a9 00a8 0015 0015 0015 0e6e"));'
函数return红外数据
protected String hex2dec(String irData) {
List<String> list = new ArrayList<String>(Arrays.asList(irData
.split(" ")));
list.remove(0); // dummy
int frequency = Integer.parseInt(list.remove(0), 16); // frequency
list.remove(0); // seq1
list.remove(0); // seq2
for (int i = 0; i < list.size(); i++) {
list.set(i, Integer.toString(Integer.parseInt(list.get(i), 16)));
}
frequency = (int) (1000000 / (frequency * 0.241246));
list.add(0, Integer.toString(frequency));
irData = "";
for (String s : list) {
irData += s + ",";
}
return irData;
}
及传输方式
public void transmitting(int frequency, int[] pattern) {
ConsumerIrManager cIr = (ConsumerIrManager) getApplicationContext().getSystemService(Context.CONSUMER_IR_SERVICE);
cIr.transmit(frequency, pattern);
}
我有一个示例代码。你能试试吗?
private IRCommand hex2ir(final String irData) {
List<String> list = new ArrayList<>(Arrays.asList(irData.split(" ")));
list.remove(0); // dummy
int frequency = Integer.parseInt(list.remove(0), 16); // frequency
list.remove(0); // seq1
list.remove(0); // seq2
frequency = (int) (1000000 / (frequency * 0.241246));
int pulses = 1000000 / frequency;
int count;
int[] pattern = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
count = Integer.parseInt(list.get(i), 16);
pattern[i] = count * pulses;
}
return new IRCommand(frequency, pattern);
}
private class IRCommand {
private final int freq;
private final int[] pattern;
private IRCommand(int freq, int[] pattern) {
this.freq = freq;
this.pattern = pattern;
}
}
当执行我的应用程序并按下必须发送 IR key.After 的按钮时,IR 只是闪烁而 IR 键未传输(我使用 arduino 进行检查)。可能我的 [=26= 频率错误](Redmi Note 5) 可能存在另一个频率公式。
这是我的代码
我要传输的密钥:
irData.put(R.id.buttonOn, hex2dec("0000 006d 0022 0003 00a9 00a8 0015 003f 0015 003f 0015 " +
"003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015" +
" 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015" +
" 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f" +
" 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702 00a9 00a8 0015 0015 0015 0e6e"));'
函数return红外数据
protected String hex2dec(String irData) {
List<String> list = new ArrayList<String>(Arrays.asList(irData
.split(" ")));
list.remove(0); // dummy
int frequency = Integer.parseInt(list.remove(0), 16); // frequency
list.remove(0); // seq1
list.remove(0); // seq2
for (int i = 0; i < list.size(); i++) {
list.set(i, Integer.toString(Integer.parseInt(list.get(i), 16)));
}
frequency = (int) (1000000 / (frequency * 0.241246));
list.add(0, Integer.toString(frequency));
irData = "";
for (String s : list) {
irData += s + ",";
}
return irData;
}
及传输方式
public void transmitting(int frequency, int[] pattern) {
ConsumerIrManager cIr = (ConsumerIrManager) getApplicationContext().getSystemService(Context.CONSUMER_IR_SERVICE);
cIr.transmit(frequency, pattern);
}
我有一个示例代码。你能试试吗?
private IRCommand hex2ir(final String irData) {
List<String> list = new ArrayList<>(Arrays.asList(irData.split(" ")));
list.remove(0); // dummy
int frequency = Integer.parseInt(list.remove(0), 16); // frequency
list.remove(0); // seq1
list.remove(0); // seq2
frequency = (int) (1000000 / (frequency * 0.241246));
int pulses = 1000000 / frequency;
int count;
int[] pattern = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
count = Integer.parseInt(list.get(i), 16);
pattern[i] = count * pulses;
}
return new IRCommand(frequency, pattern);
}
private class IRCommand {
private final int freq;
private final int[] pattern;
private IRCommand(int freq, int[] pattern) {
this.freq = freq;
this.pattern = pattern;
}
}