made progress on remote implementation

This commit is contained in:
strawmanbobi
2026-01-17 20:38:30 +08:00
parent 2bcd983909
commit 58baedfebd
5 changed files with 34 additions and 7 deletions

View File

@@ -81,7 +81,7 @@ public class ArduinoSocket {
callback.onResponse(response);
}
}
if (callback != null) {
callback.onDisconnected();
}
@@ -93,7 +93,7 @@ public class ArduinoSocket {
if (callback != null) {
callback.onDisconnected();
}
connectionStatus = EMITTER_DISCONNECTED;
}
}).start();

View File

@@ -1,25 +1,38 @@
package net.irext.ircontrol.controller;
import android.content.Context;
import android.util.Log;
import net.irext.decode.sdk.IRDecode;
import net.irext.decode.sdk.bean.ACStatus;
import net.irext.ircontrol.controller.implementable.IRemote;
public class PhoneRemote implements IRemote {
private static final String TAG = PhoneRemote.class.getSimpleName();
IRDecode mIRDecode;
Context mContext;
public PhoneRemote(Context context) {
mContext = context;
mIRDecode = new IRDecode();
}
@Override
public int irControl(int category, int subCategory, int keyCode) {
int []decoded;
StringBuilder debugStr = new StringBuilder();
ACStatus acStatus = new ACStatus();
int inputKeyCode = ControlUtils.translateKeyCode(category, keyCode, acStatus);
decoded = mIRDecode.decodeBinary(inputKeyCode, acStatus);
for (int i = 0; i < decoded.length; i++) {
debugStr.append(decoded[i]);
if (i != decoded.length - 1) {
debugStr.append(",");
}
}
Log.d(TAG, "IR control decoded: " + debugStr);
ControlUtils.transmitIr(mContext, decoded);
return 0;
}

View File

@@ -197,7 +197,12 @@ public class ControlFragment extends Fragment implements View.OnClickListener {
String binFileName = FileUtils.binDir + FileUtils.FILE_NAME_PREFIX +
mCurrentRemoteControl.getRemoteMap() + FileUtils.FILE_NAME_EXT;
byte []binContent = FileUtils.getByteArrayFromFile(binFileName);
mArduinoSocket.sendBinToEmitter(binContent, mCurrentRemoteControl.getCategoryId(), mCurrentRemoteControl.getSubCategory());
if (null != binContent) {
mArduinoSocket.sendBinToEmitter(binContent, mCurrentRemoteControl.getCategoryId(), mCurrentRemoteControl.getSubCategory());
} else {
Log.e(TAG, "emitter sender could not open the binary file");
ToastUtils.showToast(mParent, mParent.getString(R.string.file_could_not_open), Toast.LENGTH_SHORT);
}
}
private void processECtrl(String response) {
@@ -248,7 +253,7 @@ public class ControlFragment extends Fragment implements View.OnClickListener {
keyCode = IRemote.KEY_MENU;
}
if (mArduinoSocket.isConnected()) {
if (mArduinoSocket.isConnected() && mArduinoSocket.getConnectionStatus() == ArduinoSocket.EMITTER_BIN_RECEIVED) {
remote = new ArduinoRemote(mParent, mArduinoSocket);
} else {
remote = new PhoneRemote(mParent);

View File

@@ -30,15 +30,20 @@
<string name="button_ok">确定</string>
<string name="button_plus">+</string>
<string name="button_minus">-</string>
<string name="ir_not_supported">该设备不支持红外发射, 请连接外部模块进行发射</string>
<!-- Emitter panel -->
<string name="emitter_ip">发射端 IP</string>
<string name="default_ip">192.168.1.40</string>
<string name="connect">连接</string>
<string name="decode_on_board">在单片机上解码</string>
<!-- Error messages -->
<string name="ir_not_supported">该设备不支持红外发射, 请连接外部模块进行发射</string>
<string name="input_emitter_ip_address">请输入接收器的 IP 地址</string>
<string name="connect_failed">连接失败</string>
<string name="connect_disconnected">连接已断开</string>
<string name="status_not_connected">未连接</string>
<string name="status_connected">已连接</string>
<string name="file_could_not_open">编码文件无法打开</string>
</resources>

View File

@@ -30,16 +30,20 @@
<string name="button_ok">OK</string>
<string name="button_plus">+</string>
<string name="button_minus">-</string>
<string name="ir_not_supported">IR emitter is not supported in this device, please try with external emitters</string>
<!-- Emitter panel -->
<string name="emitter_ip">Emitter IP</string>
<string name="default_ip">192.168.1.40</string>
<string name="connect">connect</string>
<string name="connect">Connect</string>
<string name="decode_on_board">Decode On Board</string>
<!-- Error messages -->
<string name="ir_not_supported">IR emitter is not supported in this device, please try with external emitters</string>
<string name="input_emitter_ip_address">Please input IP address of emitter</string>
<string name="connect_failed">Connect failed</string>
<string name="connect_disconnected">The connection has lost</string>
<string name="status_not_connected">Disconnected</string>
<string name="status_connected">Connected</string>
<string name="file_could_not_open">The IR binary file could not be opened</string>
</resources>