After several consecutive days of preparation, the Android mobile phone code has finally been completed. At present, the remote control of the infrared remote control electrical equipment in my dormitory, home, and control room has been completed, in addition, I remotely controlled my D7000 camera, and it was finished.
The code is classified into two types:
Various TV, camera, and other remote control codes are the simplest. You only need to copy the key code and directly convert it into a mobile phone launch code. (In this encoding mode, a single key only emits a single message)
The most difficult part is the air-conditioning code, because the air-conditioning code is to transmit all the control information for a single key, such as increasing the temperature for a certain time, and to transmit all the information such as the control mode, temperature, air volume, and so on together, there is also a verification code. After a long experiment, if the device that imitates the remote control (such as the universal remote control) code is to save the various combinations separately, it will be very long and troublesome, however, the first method is easy to implement. The second method is difficult to find the rule, and it is troublesome to convert the code into a combination in the program and then an android launch code.
After exploring the Gree Remote Control Coding rules as follows (the previous information was collected online and summarized here ):
** File Format: Switch name/button location/icon name/command code: gree air conditioner YB0FB ** 0 1 2 3 mode 4 Open 5 wind 6 sleep 7 temperature 8 10 strong dry light ++/24, 65, 22/38000, 358,179/100/0/00/00/0101/0000/0000/0/0/0/0/0000/1010/010 /, 24,795/0000/0000/1000/0100/0000/0000/0000/+ ** name/location/icon/location/initial value/change + +/air conditioner switch/20/power/4/2 +/Mode /21/mode/3/5/p1/auto/coldm/dryingm/windm/warmm ++/air volume/22/velocity/5/4/t2/wind0/wind1/wind2/wind3 ++ /temperature +/23/up/7/14/t1/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30 + +/temperature-/28/down/7/14/t1 /16/17/18/19/20/21/22/23/24/25/26/27/28/29/30 + +/light/25/light/11/2/p3/nu/lightm ++/sleep/26/sleep /6/2/p4/nu/sleepm the above is the Gree air-conditioner encoding scheme
The following code is directly encoded: TV switch/0/power/38000,358,179, 21, 21, values, 21, 21, 21, 38000,361,176, 22 mute/6/mute/, 21, 21, 21, 21, 21, 22, 22, 22, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 20,, 22, 22, 22, 21 display mode/5/screen/38000,359,178, 21, 25, 18, 21, 21, 21, 21, 25, 18, 21, 21, 25, 18, 21, 22, 21, 25, 18, 21, 21, 21, 21, 21, 25 signal sources/1/Second/38000,362,175, 24, 20, 21, 22, 21, 24, 20, 21, 22, 21, 24, 64, 22, 21, 24, 20, 21, 21, 22, 21, 24, 20, 21, 22, 21, 24, 64, 22, 21, 24, 64, 21, 24, 20, 21, 21, 24, 20, 67, 24, 20, 21, 67, hour, hour, 24, 20, hour, hour, 21
The following is the source code of the android language: users who do not like programming do not need to read it: (if you are interested, contact me. There is a QQ number on the picture)
Package com. example. sumxingir; import java. io. fileInputStream; import java. util. arrayList; import java. util. hashMap; import java. util. map; import org. apache. http. util. encodingUtils; import android. app. activity; import android. content. intent; import android. content. res. resources; import android. graphics. color; import android. OS. bundle; import android. OS. environment; import android. view. layoutInflater; import Droid. view. view; import android. view. viewGroup; import android. widget. adapterView; import android. widget. arrayAdapter; import android. widget. gridView; import android. widget. imageView; import android. widget. relativeLayout; import android. widget. textView; public class room extends Activity {String Temp; String [] STR = new String [2]; String [] rv = new String [2]; private MyAdapter adapter = null; private ArrayList <M Ap <String, Object> array; GridView layout; String [] Kt = new String [20]; // Kt1 overall code int Ktonof = 0; // Kt1 switch; string [] base = new String [] {"", "", ""}; // 0 Level Width 1 Level Width; High Level Width; int check = 0; string [] Ktmode = new String [10]; // air conditioning mode String [] Ktwendu = new String [30]; // temperature variation String [] Ktwind = new String [10]; // wind variation String [] Ktp3 = new String [] {"", "", "", ""}; // other keys of the air conditioner String [] Ktp4 = new String [] {"," ", ""}; // Air Conditioner Other keys String [] Ktt2 = new String [] {"", ""}; // other keys of the air conditioner int Count; string [] name = new String [40]; int [] image = new int [40]; String [] code = new String [40]; string [] mode = new String [5]; // android. view. viewGroup. layoutParams lp; // declares the control parameter acquisition object LayoutParams lp; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. room); GridView layout = (GridView) findViewById (R. id. gridview); RelativeLayout view = (RelativeLayout) findViewById (R. id. view); android. view. viewGroup. layoutParams lp; // declare the control parameter to obtain the object LayoutParams lp; lp = view. getLayoutParams (); // 2. Obtain control parameters: lp = Control id. getLayoutParams (); lp. height = 0; view. setLayoutParams (lp); // setContentView (layout); Intent intent = getIntent (); Temp = intent. getStringExtra ("strcode"); setTitle (Temp); setTitleCo Lor (Color. GREEN); Temp = readFileSdcard (Temp. trim (); STR = Temp. split ("\ r \ n"); // =============== File Processing Count = 0; for (int I = 0; I <STR. length; I ++) {if (STR [I]. trim (). length () <10) {continue;} if (STR [I]. substring (0, 2 ). equals ("**") {continue;} if (STR [I]. substring (0, 2 ). equals ("++") {if (STR [I]. substring (0, 4 ). equals ("+++") {Kt = STR [I]. trim (). split ("/"); lp. height = 150; view. setLayoutParams (lp); base = Kt [1]. tr Im (). split (","); // if (Kt [Kt. length-1]. trim (). equals ("++") {Kt [Kt. length-1] = "1111"; check = 1 ;}} // =========== else for air conditioning processing {// ++/air conditioning switch/20/power/251/+ 1 rv = STR [I]. split ("/"); int s = (Integer. parseInt (rv [2]); // key position number name [s] = (rv [1]). trim (); code [s] = (rv [4] + "," + rv [5]); // point to the code bit // int k = Integer. parseInt (rv [4]); if (rv [1]. equals ("Mode") {for (int j = 4; j <rv. length; j ++) {Ktmode [j-4] = rv [j]. trim () ;}} else if (rv [1]. equals ("Temperature +") {for (int j = 4; j <rv. length; j ++) {Ktwendu [j-4] = rv [j]. trim () ;}} else if (rv [1]. equals ("air volume") {for (int j = 4; j <rv. length; j ++) {Ktwind [j-4] = rv [j]. trim () ;}} else if (rv [1]. equals ("Air Conditioning switch") {Ktonof = Integer. parseInt (rv [4]. trim ();} else if (rv [6]. equals ("p3") {for (int j = 4; j <rv. length; j ++) {Ktp3 [j-4] = rv [j]. trim () ;}} else if (rv [6]. equals ("p4") {for (int j = 4; j <rv. length; j ++) {Ktp4 [j-4] = rv [j]. trim () ;}} else If (rv [6]. equals ("t2") {for (int j = 4; j <rv. length; j ++) {Ktt2 [j-4] = rv [j]. trim () ;}} String m = rv [3]; if (s> Count) {Count = s;} Resources res = getResources (); image [s] = res. getIdentifier (m, "drawable", getPackageName ());}} else {// =============================== general key handling rv = STR [I]. split ("/"); int s = (Integer. parseInt (rv [1]); name [s] = (rv [0]); code [s] = (rv [3]); string m = rv [2]; if (s> Count) {Count = s;} Resources res = getResource S (); image [s] = res. getIdentifier (m, "drawable", getPackageName () ;}} array = getData (); adapter = new MyAdapter (); layout. setAdapter (adapter); layout. setOnItemClickListener (new ItemClickEvent (); if (Ktonof! = 0) {show () ;}// display the air conditioner status} public String readFileSdcard (String fileName) {// read the txt file // Temp = Environment. getExternalStorageDirectory () + "/SUMIR/code.txt"; String res = ""; try {FileInputStream fin = new FileInputStream (Environment. getExternalStorageDirectory () + "/SUMIR/" + fileName + ". txt "); int length = fin. available (); byte [] buffer = new byte [length]; fin. read (buffer); res = EncodingUtils. getString (B Uffer, "UNICODE"); fin. close ();} catch (Exception e) {e. printStackTrace ();} return res;} class MyAdapter extends ArrayAdapter <Map <String, Object> {MyAdapter () {super (room. this, R. layout. mygrid, array);} public ArrayList <Map <String, Object> getList () {return array;} public View getView (int position, View convertView, ViewGroup parent) {View row = convertView; // String [] name1 = new String [Coun T + 1]; name1 = name; if (row = null) {LayoutInflater inflater = getLayoutInflater (); row = inflater. inflate (R. layout. mygrid, parent, false);} ImageView imageView = (ImageView) row. findViewById (R. id. img); imageView. setScaleType (ImageView. scaleType. FIT_CENTER); imageView. setImageResource (Integer. valueOf (array. get (position ). get ("img "). toString (); TextView tv1 = (TextView) row.findViewById(R.id.txt); tv1.s EtText (name [position]); return (row) ;}} private ArrayList <Map <String, Object> getData () {ArrayList <Map <String, object> list = new ArrayList <Map <String, Object> (); for (int I = 0; I <Count + 1; I ++) {Map <String, object> map = new HashMap <String, Object> (); map. put ("img", image [I]); list. add (map);} return list ;} // click to process ================================================= ====================================== class ItemClickEven T implements AdapterView. OnItemClickListener {String ircode; RelativeLayout view = (RelativeLayout) findViewById (R. id. view); @ Overridepublic void onItemClick (AdapterView <?> Arg0, View arg1, int arg2, long arg3) {// Toast. makeText (room. this, name [arg2], Toast. LENGTH_SHORT ). show (); arg1.setPressed (false); arg1.setSelected (false); if (code [arg2]! = Null) {if (code [arg2]. length ()> 20) {ircode = code [arg2];} else {rv = code [arg2]. split (","); int k1 = Integer. parseInt (rv [0]); int LimUP = Integer. parseInt (rv [1]); if (name [arg2]. substring (name [arg2]. length ()-1 ). equals ("-") {opj (k1, 0, LimUP);} else {opj (k1, 1, LimUP);} // Kt position, ±, upper Limit ircode = readcode (); if (Kt [Kt. length-1]. trim (). equals ("++") {ircode + = check (ircode) ;}show () ;}try {Object localObject = getSystemSe Rvice ("irda"); localObject. getClass (); localObject. getClass (). getMethod ("write_irsend", new Class [] {String. class }). invoke (localObject, new Object [] {ircode}); return;} catch (Exception localException) {localException. printStackTrace () ;}}} private void opj (int ktsit, int bb, int Lm) {// ================+-operation code Kt [ktsit] = Kt [ktsit]. trim (); int L = Kt [ktsit]. length (); int m = readKt (ktsit); if (bb = 0) {m --;} Else {m ++;} if (m >=lm) {if (Lm> 10) {m = Lm ;} else {m = 0 ;}} if (m <0) {m = 0;} Temp = "0000000000" + Integer. toBinaryString (m); Temp = Temp. substring (Temp. length ()-L); Kt [ktsit] = ""; for (int I = 0; I <L; I ++) {Kt [ktsit] + = Temp. substring (L-i-1, L-I);} private String check (String SS) {// ================================== check the verification code String T1 = ""; int lim = Integer. parseInt (base [0])/2 + Integer. parseInt (base [1])/2; int sum = 0; int x = 0; in T Y = 0; rv = SS. split (","); for (int I = 4; I <rv. length; I + = 2) {if (x = 8) {x = 0; sum + = Y; Y = 0;} if (Integer. parseInt (rv [I])> lim) {Y + = 1 <x ;}x ++;} sum = sum % 16; // T1 = String. valueOf (sum); T1 = "," + base [2] + "," + base [sum % 2] + "," + base [2] + ", "+ base [(sum % 4)/2] +", "+ base [2] +", "+ base [(sum % 8)/4] + ", "+ base [2] +", "+ base [sum % 16/8] +", "+ base [2]; return T1;} private void show () {// ================================================ set show ImageView Pv1 = (ImageView) findViewById (R. id. p1); ImageView Pv2 = (ImageView) findViewById (R. id. p2); ImageView Pv3 = (ImageView) findViewById (R. id. p3); ImageView Pv4 = (ImageView) findViewById (R. id. p4); TextView Tv1 = (TextView) findViewById (R. id. t1); TextView Tv2 = (TextView) findViewById (R. id. t2); Resources res = getResources (); if (Kt [Ktonof]. trim (). equals ("0") {Pv1.setVisibility (View. INVISIBLE); Pv2.setVisibility (View. INVISIBLE ); Pv3.setVisibility (View. INVISIBLE); Pv4.setVisibility (View. INVISIBLE); Tv1.setVisibility (View. INVISIBLE); Tv2.setVisibility (View. invisibility);} else {Pv1.setVisibility (View. VISIBLE); Pv2.setVisibility (View. VISIBLE); Pv3.setVisibility (View. VISIBLE); Pv4.setVisibility (View. VISIBLE); Tv1.setVisibility (View. VISIBLE); Tv2.setVisibility (View. VISIBLE); int m = readKt (Integer. parseInt (Ktmode [0]); // display int Pv = res. g EtIdentifier (Ktmode [m + 3], "drawable", getPackageName (); Pv1.setImageResource (Pv); m = readKt (Integer. parseInt (Ktwendu [0]); // Temperature Display Tv1.setText (Ktwendu [m + 3]); if (Ktt2 [0]! = "") {M = readKt (Integer. parseInt (Ktt2 [0]); // Temperature Display Tv2.setText (Ktwendu [m + 3]);} if (Ktwind [0]! = "") {M = readKt (Integer. parseInt (Ktwind [0]); // Pv = res. getIdentifier (Ktwind [m + 3], "drawable", getPackageName (); Pv2.setImageResource (Pv);} if (Ktp3 [0]! = "") {M = readKt (Integer. parseInt (Ktp3 [0]); // p3 displays Pv = res. getIdentifier (Ktp3 [m + 3], "drawable", getPackageName (); Pv3.setImageResource (Pv);} if (Ktp4 [0]! = "") {M = readKt (Integer. parseInt (Ktp4 [0]); // p4 displays Pv = res. getIdentifier (Ktp4 [m + 3], "drawable", getPackageName (); Pv4.setImageResource (Pv) ;}} private int readKt (int ktsit) {// ============== read the value of the specified position byte [] B = (KT [ktsit]. trim ()). getBytes (); int sum = 0; for (int I = 0; I <B. length; I ++) {sum = sum + (B [I]-48) <I);} return sum;} private String readcode () {// ================================ convert to the transmit code String T1 = Kt [2]. trim (); for (int I = 3; I <Kt. length; I ++) {Kt [I] = Kt [I]. trim (); if (Kt [I]. substring (0, 1 ). equals (",") {T1 = T1 + Kt [I];} // code else if (Kt [I] directly. substring (0, 1 ). equals ("-") {// execute the reverse code rv = Kt [I]. split ("-"); Temp = ""; for (int j = 1; j <rv. length; j ++) {Temp + = Kt [Integer. parseInt (rv [j])];} Temp = Temp. replace ("", ""); for (int j = 0; j <Temp. length (); j ++) {T1 + = "," + base [2] + "," + base [(Integer. parseInt (Temp. substring (j, j + 1) + 1) % 2] ;}} else if (Kt [I]. substring (0, 1 ). equals ("+") {continue;} else {byte [] B = (Kt [I]). getBytes (); for (int j = 0; j <B. length; j ++) {T1 + = "," + base [2] + "," + base [B [j]-48] ;}} return T1 ;}}