huangcm
2025-04-09 02d4ce54b909bd733f12e9f3fa4c1b03cf2d6f45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package jp.co.toshiba.newtion.cir;
 
import java.io.IOException;
 
import jp.co.ntt.east.hardware.IrRemoteController;
import jp.co.ntt.east.hardware.IrRemoteController.Data;
import android.util.Log;
 
public class RemoteControl {
   private static final String TAG = "NewtonTest";
 
   private static final int SEND_TIMEOUT = 1;
 
   private static final int CARRIER_HIGH_TIME = 130;
 
   private static final int CARRIER_LOW_TIME = 130;
 
   private static final int PULSE_0_HIGH_TIME = 560;
 
   private static final int PULSE_0_LOW_TIME = 560;
 
   private static final int PULSE_1_HIGH_TIME = 1690;
 
   private static final int PULSE_1_LOW_TIME = 560;
 
   private static final int START_HIGH_TIME = 9000;
 
   private static final int START_LOW_TIME = 4500;
 
   private static final int STOP_HIGH_TIME = 560;
 
   private static final int REPEAT_HIGH_TIME = 9000;
 
   private static final int REPEAT_LOW_TIME = 2250;
 
   private static final int DURATION_TIME = 1080;
 
   private static final int REPEAT_COUNT = 1;
 
   private static final byte CUSTOM_CODE = (byte) 0x40;
 
   public static final byte COMMAND_POWER = (byte) 0x12;
 
   public static final byte COMMAND_CHANNEL_BASE = (byte) 0x01;
 
   public static final byte COMMAND_CHANNEL_UP = (byte) 0x1b;
 
   public static final byte COMMAND_CHANNEL_DOWN = (byte) 0x1f;
 
   public static final byte COMMAND_VOLUME_UP = (byte) 0x1a;
 
   public static final byte COMMAND_VOLUME_DOWN = (byte) 0x1e;
 
   public static final byte COMMAND_MUTE = (byte) 0x10;
 
   public static final byte COMMAND_INPUT_SWITCH = (byte) 0x0f;
 
   public static final int CHANNEL_MIN = 1;
 
   public static final int CHANNEL_MAX = 12;
 
   public static boolean sendCommand(byte command) {
       boolean returnValue = false;
       byte sendData[] = new byte[4];
 
       sendData[0] = (byte) (CUSTOM_CODE);
       sendData[1] = (byte) (~CUSTOM_CODE);
 
       sendData[2] = (byte) command;
       sendData[3] = (byte) (~command);
 
       IrRemoteController.Data irData1 = new IrRemoteController.Data();
       irData1.setCarrier(CARRIER_HIGH_TIME, CARRIER_LOW_TIME);
       irData1.setPulse(IrRemoteController.Data.HIGH_LOW, PULSE_0_HIGH_TIME,
               PULSE_0_LOW_TIME, IrRemoteController.Data.HIGH_LOW,
               PULSE_1_HIGH_TIME, PULSE_1_LOW_TIME);
       irData1.setParameter(START_HIGH_TIME, START_LOW_TIME, STOP_HIGH_TIME);
       irData1.setData(sendData, sendData.length * 8);
       irData1.setDuration(DURATION_TIME);
       irData1.setRepeatCount(REPEAT_COUNT);
 
       IrRemoteController irController = IrRemoteController.getInstance();
       IrRemoteController.Data irDatas[] = { irData1 };
 
       returnValue = true;
       try {
           irController.send(irDatas, SEND_TIMEOUT);
       } catch (IllegalStateException e) {
       }
 
       catch (IOException ex) {
           returnValue = false;
           Log.e(TAG, ex.getMessage());
       }
 
       return returnValue;
   }
 
   public static boolean sendChannelCommand(int channel) {
       boolean returnValue = false;
 
       if (CHANNEL_MIN <= channel && channel <= CHANNEL_MAX) {
           byte commandValue = (byte) (channel - CHANNEL_MIN + COMMAND_CHANNEL_BASE);
           boolean bResult = sendCommand(commandValue);
           if (bResult) {
               returnValue = true;
           }
       }
 
       return returnValue;
   }
}