package com.example.administrator.wingcool_gt9_apk;

import android.Manifest;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 */

public class Config extends AppCompatActivity
        //implements OpenDevicesReceiver.OpenDevicesListener, View.OnClickListener , ViewPager.OnPageChangeListener, AdapterView.OnItemSelectedListener{
        implements OpenDevicesReceiver.OpenDevicesListener, View.OnClickListener , ViewPager.OnPageChangeListener{
    private static final int CONNECTED_SUCCESS = 0;
    private static final int RECEIVER_MESSAGE_SUCCESS = 1;
    private static final int SEND_MESSAGE_SUCCESS = 2;
    private static final int DEBUG_MESSAGE_SUCCESS = 3;
    private static final int DEBUG_MESSAGE_ERROR = 4;

    private static final String USB_ACTION = "com.host2device";
    private static final String ACTION_USB_PERMISSION = "com.host2device.USB_PERMISSION";
    private ExecutorService mThreadPool;
    private UsbManager mUsbManager;
    private OpenDevicesReceiver cfgOpenDevicesReceiver;
    private UsbDeviceConnection mUsbDeviceConnection;

    private UsbEndpoint mUsbEndpointOut;
    private UsbEndpoint mUsbEndpointIn;
    private int iProductId;
    private byte byProductType = 0;
    private static final byte GT9 = 0x01;
    private static final byte GT7 = 0x02;
    private Button mReadCfg;
    private Button mSendCfg;
    private byte[] mBytes = new byte[2048];
    private byte[] mSendData = new byte[2048];
    private String[] mConfigShow = new String[2048];

    private Context mAlertContext;

    String value;

    private boolean isNeedFindDevice  = true;

    private int bottonMode = 0;

    private UsbInterface mUsbInterface;
    private StringBuffer mStringBuffer = new StringBuffer();
    private Context mContext;

    private Button btnLocalFileButton;  //本地文件按钮
    private Button btnUDiskFileButton;  //U盘文件按钮
    private TextView edit_search;
    private EditText edit_text;

    private EditText editname;
    //private EditText editdetail;
    private Button btnsave;
    private Context mSaveCfgContext;

    private TextView mShow;
    private EditText edtConfigDataShow;
    private TextView tvVenderID;

    //View Sample 定义
    private CheckBox cbAllDrivingEn,cbDualFreq;
    private EditText edtFreqAFactor,edtFreqBFactor;
    private EditText edtPannelBitFreq,edtDuration;  //2 bytes
    private EditText edtFreqA,edtFreqB;
    private EditText edtDumpShift;
    private EditText edtSubFrameDrvNum;
    private Spinner spinDrvOutputR,spinDACGain;
    private Spinner spinPGAC,spinPGAR,spinRxVcmi,spinPGAGain;
    private Spinner spinBoostTime,spinVoltage,spinAlterCount;
    private CheckBox cbExtoscen;
    //private boolean PGAGainSelected = false;  //判断是否为刚进去时触发onItemSelected的标志
    private TextWatcher twBitFreq,twDuration,twFreqAFactor,twFreqBFactor,twFreqA,twFreqB;

    //View Module Switch 定义
    private CheckBox cbX2Y,cbSito;
    private Spinner spinStretchRank,spinInterrupt;
    private CheckBox cbMonitorConsistencyConflictEn,cbFirstFilterDis;
    private CheckBox cbDiffDivideBy2or4,cbWaterSpeedLimitEn;
    private CheckBox cbShapeEn,cbWaterProofDis;
    private CheckBox cbLcdPlusMinusEn,cbESDEn;
    private CheckBox cbX2X,cbY2Y;
    private CheckBox cbINTWakeup;

    //View Normal Setting 定义
    private EditText edtConfigVersion,edtTouchNumber;
    private EditText edtShakeCnt;
    private EditText edtFirstFilter,edtNormalFilter;
    private EditText edtNoiseReduction;
    private EditText edtScreenTouchLv,edtScreenLeaveLv;
    private EditText edtLowPowerControl;
    private Spinner spinRefreshRate;
    private EditText edtXThreshold,edtYThreshold;
    private EditText edtSpaceUpDown,edtSpaceLeftRight;
    private EditText edtStretchR0,edtStretchR1,edtStretchR2,edtStretchRM;
    private EditText edtMiniFilter;
    private EditText edtChargingLevelUp;
    private EditText edtLcdPlusMinusValue,edtConThreshold;
    private EditText edtShapeRestrain,edtShapeContrl;
    private EditText edtWaterFrameTime,edtWaterUpdateTime;
    private EditText edtSlideInEdgeConfig,edtSlideOutEdgeConfig;
    private EditText edtCombineDis,edtSplitSet;
    private EditText edtSitoDiffRefLevel;

    //View Channel Setting 定义
    private EditText edtXOutputMax,edtYOutputMax;
    private EditText edtDrvGroupAnumber,edtDrvGroupBnumber;
    private EditText edtSenGroupANumber,edtSenGroupBNumber;
    private EditText edtSensorCH0,edtSensorCH1,edtSensorCH2,edtSensorCH3,edtSensorCH4,edtSensorCH5,edtSensorCH6,edtSensorCH7,edtSensorCH8,edtSensorCH9;
    private EditText edtSensorCH10,edtSensorCH11,edtSensorCH12,edtSensorCH13,edtSensorCH14,edtSensorCH15,edtSensorCH16,edtSensorCH17,edtSensorCH18,edtSensorCH19;
    private EditText edtSensorCH20,edtSensorCH21,edtSensorCH22,edtSensorCH23,edtSensorCH24,edtSensorCH25,edtSensorCH26,edtSensorCH27,edtSensorCH28,edtSensorCH29;
    private EditText edtSensorStart,edtSensorEnd;
    private Button btnSensorRev,btnAllSensorChannels;
    private EditText edtDriverCH0,edtDriverCH1,edtDriverCH2,edtDriverCH3,edtDriverCH4,edtDriverCH5,edtDriverCH6,edtDriverCH7,edtDriverCH8,edtDriverCH9;
    private EditText edtDriverCH10,edtDriverCH11,edtDriverCH12,edtDriverCH13,edtDriverCH14,edtDriverCH15,edtDriverCH16,edtDriverCH17,edtDriverCH18,edtDriverCH19;
    private EditText edtDriverCH20,edtDriverCH21,edtDriverCH22,edtDriverCH23,edtDriverCH24,edtDriverCH25,edtDriverCH26,edtDriverCH27,edtDriverCH28,edtDriverCH29;
    private EditText edtDriverCH30,edtDriverCH31,edtDriverCH32,edtDriverCH33,edtDriverCH34,edtDriverCH35,edtDriverCH36,edtDriverCH37,edtDriverCH38,edtDriverCH39;
    private EditText edtDriverCH40,edtDriverCH41;
    private EditText edtDriverStart,edtDriverEnd;
    private Button btnDriverRev,btnAllDriverChannels;
    private byte bSensorNumber,bDriverNumber;

    //View Pen Setting 定义
    private CheckBox cbPenEn,cbOnlyFingerEn;
    private EditText edtPenLowSize,edtPenHighSize;
    private EditText edtRectsumPLowL,edtRectsumPHighL;
    private EditText edtRectsumFLowL;
    private EditText edtPRectMaxDiffLimit,edtPRectAreaLimit;
    private EditText edtFLeavelevel,edtPTouchHighlevel;
    private Spinner spinFingerRestrainPen;

    //View Plam Restrain 定义
    private CheckBox cbAllPlamRestrain;
    private EditText edtLargeTouch;
    private EditText edtExpanNumOutX,edtExpanNumOutY;
    private EditText edtExpanNumInX,edtExpanNumInY;
    private EditText edtSingleRectTopSignNum,edtAllRectTopSignSum;
    private CheckBox cbWaterLargeRestrainEn;

    //View Key Setting 定义
    private CheckBox cbTouchKey;
    private EditText edtKeyArea;
    private EditText edtKey1,edtKey2,edtKey3,edtKey4;
    private EditText edtKeyTouchLevel,edtKeyLeaveLevel;
    private EditText edtKeySens1and2,edtKeySens3and4;
    private EditText edtKeyRestrain,edtKeyRestrainTime;

    //View Hopping Setting 定义
    private CheckBox cbHoppingEn;
    private CheckBox cbRangeExt;
    private EditText edtFreqStart,edtFreqEnd;
    private EditText edtDetectStayTimes,edtDetectConfirmTimes;
    private CheckBox cbDisForceRef,cbDelayHopping;
    private EditText edtFastHopLimit,edtHopThreshold,edtNoiseMinTh,edtSensorGroup;
    private EditText edtSeg1Normalize,edtSeg1Factor;
    private EditText edtMainClockAjdust;
    private EditText edtSeg2Normalize,edtSeg2Factor;
    private EditText edtSeg3Normalize,edtSeg3Factor;
    private EditText edtSeg4Normalize,edtSeg4Factor;
    private EditText edtSeg5Normalize,edtSeg5Factor;
    private EditText edtSeg6Normalize;
    private EditText edtHopFreqAddr;
    private EditText edtHopDetectTimes;

    //View Cfg Ram 定义
    private EditText mCfg8047,mCfg8048,mCfg8049,mCfg804A,mCfg804B,mCfg804C,mCfg804D,mCfg804E,mCfg804F;

    private EditText mCfg8050,mCfg8051,mCfg8052,mCfg8053,mCfg8054,mCfg8055,mCfg8056,mCfg8057;
    private EditText mCfg8058,mCfg8059,mCfg805A,mCfg805B,mCfg805C,mCfg805D,mCfg805E,mCfg805F;

    private EditText mCfg8060,mCfg8061,mCfg8062,mCfg8063,mCfg8064,mCfg8065,mCfg8066,mCfg8067;
    private EditText mCfg8068,mCfg8069,mCfg806A,mCfg806B,mCfg806C,mCfg806D,mCfg806E,mCfg806F;

    private EditText mCfg8070,mCfg8071,mCfg8072,mCfg8073,mCfg8074,mCfg8075,mCfg8076,mCfg8077;
    private EditText mCfg8078,mCfg8079,mCfg807A,mCfg807B,mCfg807C,mCfg807D,mCfg807E,mCfg807F;

    private EditText mCfg8080,mCfg8081,mCfg8082,mCfg8083,mCfg8084,mCfg8085,mCfg8086,mCfg8087;
    private EditText mCfg8088,mCfg8089,mCfg808A,mCfg808B,mCfg808C,mCfg808D,mCfg808E,mCfg808F;

    private EditText mCfg8090,mCfg8091,mCfg8092,mCfg8093,mCfg8094,mCfg8095,mCfg8096,mCfg8097;
    private EditText mCfg8098,mCfg8099,mCfg809A,mCfg809B,mCfg809C,mCfg809D,mCfg809E,mCfg809F;

    private EditText mCfg80A0,mCfg80A1,mCfg80A2,mCfg80A3,mCfg80A4,mCfg80A5,mCfg80A6,mCfg80A7;
    private EditText mCfg80A8,mCfg80A9,mCfg80AA,mCfg80AB,mCfg80AC,mCfg80AD,mCfg80AE,mCfg80AF;

    private EditText mCfg80B0,mCfg80B1,mCfg80B2,mCfg80B3,mCfg80B4,mCfg80B5,mCfg80B6,mCfg80B7;
    private EditText mCfg80B8,mCfg80B9,mCfg80BA,mCfg80BB,mCfg80BC,mCfg80BD,mCfg80BE,mCfg80BF;

    private EditText mCfg80C0,mCfg80C1,mCfg80C2,mCfg80C3,mCfg80C4,mCfg80C5,mCfg80C6,mCfg80C7;
    private EditText mCfg80C8,mCfg80C9,mCfg80CA,mCfg80CB,mCfg80CC,mCfg80CD,mCfg80CE,mCfg80CF;

    private EditText mCfg80D0,mCfg80D1,mCfg80D2,mCfg80D3,mCfg80D4,mCfg80D5,mCfg80D6,mCfg80D7;
    private EditText mCfg80D8,mCfg80D9,mCfg80DA,mCfg80DB,mCfg80DC,mCfg80DD,mCfg80DE,mCfg80DF;

    private EditText mCfg80E0,mCfg80E1,mCfg80E2,mCfg80E3,mCfg80E4,mCfg80E5,mCfg80E6,mCfg80E7;
    private EditText mCfg80E8,mCfg80E9,mCfg80EA,mCfg80EB,mCfg80EC,mCfg80ED,mCfg80EE,mCfg80EF;

    private EditText mCfg80F0,mCfg80F1,mCfg80F2,mCfg80F3,mCfg80F4,mCfg80F5,mCfg80F6,mCfg80F7;
    private EditText mCfg80F8,mCfg80F9,mCfg80FA,mCfg80FB,mCfg80FC,mCfg80FD,mCfg80FE,mCfg80FF;

    private EditText mCfg8100,mCfg8101,mCfg8102,mCfg8103,mCfg8104,mCfg8105,mCfg8106,mCfg8107;
    private EditText mCfg8108,mCfg8109,mCfg810A,mCfg810B,mCfg810C,mCfg810D,mCfg810E,mCfg810F;

    private EditText mCfg8110,mCfg8111,mCfg8112,mCfg8113,mCfg8114,mCfg8115,mCfg8116,mCfg8117;
    private EditText mCfg8118,mCfg8119,mCfg811A,mCfg811B,mCfg811C,mCfg811D,mCfg811E,mCfg811F;

    private EditText mCfg8120,mCfg8121,mCfg8122,mCfg8123,mCfg8124,mCfg8125,mCfg8126,mCfg8127;
    private EditText mCfg8128,mCfg8129,mCfg812A,mCfg812B,mCfg812C,mCfg812D,mCfg812E,mCfg812F;

    private EditText mCfg8130,mCfg8131,mCfg8132,mCfg8133,mCfg8134,mCfg8135,mCfg8136,mCfg8137;
    private EditText mCfg8138,mCfg8139,mCfg813A,mCfg813B,mCfg813C,mCfg813D,mCfg813E,mCfg813F;

    private EditText mCfg8140,mCfg8141,mCfg8142,mCfg8143,mCfg8144,mCfg8145,mCfg8146,mCfg8147;
    private EditText mCfg8148,mCfg8149,mCfg814A,mCfg814B,mCfg814C,mCfg814D,mCfg814E,mCfg814F;

    private EditText mCfg8150,mCfg8151,mCfg8152,mCfg8153,mCfg8154,mCfg8155,mCfg8156,mCfg8157;
    private EditText mCfg8158,mCfg8159,mCfg815A,mCfg815B,mCfg815C,mCfg815D,mCfg815E,mCfg815F;

    private EditText mCfg8160,mCfg8161,mCfg8162,mCfg8163,mCfg8164,mCfg8165,mCfg8166,mCfg8167;
    private EditText mCfg8168,mCfg8169,mCfg816A,mCfg816B,mCfg816C,mCfg816D,mCfg816E,mCfg816F;

    private EditText mCfg8170,mCfg8171,mCfg8172,mCfg8173,mCfg8174,mCfg8175,mCfg8176,mCfg8177;
    private EditText mCfg8178,mCfg8179,mCfg817A,mCfg817B,mCfg817C,mCfg817D,mCfg817E,mCfg817F;

    private EditText mCfg8180,mCfg8181,mCfg8182,mCfg8183,mCfg8184,mCfg8185,mCfg8186,mCfg8187;
    private EditText mCfg8188,mCfg8189,mCfg818A,mCfg818B,mCfg818C,mCfg818D,mCfg818E,mCfg818F;

    private EditText mCfg8190,mCfg8191,mCfg8192,mCfg8193,mCfg8194,mCfg8195,mCfg8196,mCfg8197;
    private EditText mCfg8198,mCfg8199,mCfg819A,mCfg819B,mCfg819C,mCfg819D,mCfg819E,mCfg819F;

    private EditText mCfg81A0,mCfg81A1,mCfg81A2,mCfg81A3,mCfg81A4,mCfg81A5,mCfg81A6,mCfg81A7;
    private EditText mCfg81A8,mCfg81A9,mCfg81AA,mCfg81AB,mCfg81AC,mCfg81AD,mCfg81AE,mCfg81AF;

    private EditText mCfg81B0,mCfg81B1,mCfg81B2,mCfg81B3,mCfg81B4,mCfg81B5,mCfg81B6,mCfg81B7;
    private EditText mCfg81B8,mCfg81B9,mCfg81BA,mCfg81BB,mCfg81BC,mCfg81BD,mCfg81BE,mCfg81BF;

    private EditText mCfg81C0,mCfg81C1,mCfg81C2,mCfg81C3,mCfg81C4,mCfg81C5,mCfg81C6,mCfg81C7;
    private EditText mCfg81C8,mCfg81C9,mCfg81CA,mCfg81CB,mCfg81CC,mCfg81CD,mCfg81CE,mCfg81CF;

    private EditText mCfg81D0,mCfg81D1,mCfg81D2,mCfg81D3,mCfg81D4,mCfg81D5,mCfg81D6,mCfg81D7;
    private EditText mCfg81D8,mCfg81D9,mCfg81DA,mCfg81DB,mCfg81DC,mCfg81DD,mCfg81DE,mCfg81DF;

    private EditText mCfg81E0,mCfg81E1,mCfg81E2,mCfg81E3,mCfg81E4,mCfg81E5,mCfg81E6,mCfg81E7;
    private EditText mCfg81E8,mCfg81E9,mCfg81EA,mCfg81EB,mCfg81EC,mCfg81ED,mCfg81EE,mCfg81EF;

    private EditText mCfg81F0,mCfg81F1,mCfg81F2,mCfg81F3,mCfg81F4,mCfg81F5,mCfg81F6,mCfg81F7;
    private EditText mCfg81F8,mCfg81F9,mCfg81FA,mCfg81FB,mCfg81FC,mCfg81FD,mCfg81FE,mCfg81FF;

    private EditText mCfg8200,mCfg8201,mCfg8202,mCfg8203,mCfg8204,mCfg8205,mCfg8206,mCfg8207;
    private EditText mCfg8208,mCfg8209,mCfg820A,mCfg820B;

    //private ViewPager vpagerCfg;
    private ImageView img_cursor;
    private TextView tvSample;
    private TextView tvModuleSwitch;
    private TextView tvNormalSetting;
    private TextView tvChannelSetting;
    private TextView tvPenSetting;
    private TextView tvPlamRestrain;
    private TextView tvKeySetting;
    private TextView tvHoppingSetting;
    private TextView tvCfgRam;

    private ArrayList<View> listViews;
    View viewsample;
    View viewmoduleswitch;
    View viewnormalsetting;
    View viewchannelsetting;
    View viewpensetting;
    View viewplamrestrain;
    View viewkeysetting;
    View viewhoppingsetting;
    View viewcfgram;
    private int offset = 0;//移动条图片的偏移量
    private int currIndex = 0;//当前页面的编号
    private int bmpWidth;// 移动条图片的长度
    private int one = 0; //移动条滑动一页的距离
    private int two = 0; //滑动条移动两页的距离
    private int three = 0; //滑动条移动三页的距离
    private int four = 0; //滑动条移动四页的距离
    private int five = 0; //滑动条移动五页的距离
    private int six = 0; //滑动条移动六页的距离
    private int seven = 0; //滑动条移动七页的距离
    private int eight = 0; //滑动条移动八页的距离
    private int nine = 0; //滑动条移动九页的距离
    private int iChooseVPager = 0; //当前停在哪个vpager

    private byte mSendGetGt9ConfigData[]={
            0x03,0x00,0x0f,(byte)0x80,0x47,0x00,0x3f,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    };

    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            StringBuilder stringBuilder = new StringBuilder("");
            StringBuffer resultSb = new StringBuffer();
            // for (int i = 1; i < mBytes.length; i++) {
            int checksum = 0 ;
            switch (msg.what) {
                case CONNECTED_SUCCESS://车机和手机连接成功
                    //mError.setText("");
                    mReadCfg.setEnabled(true);
                    mSendCfg.setEnabled(true);
                    break;

                case RECEIVER_MESSAGE_SUCCESS://成功接受到数据
                    //mSendCfg.setEnabled(true);
                    //String hv = null;

                    for (int i = 0; i < 189; i++) {

                        if (i == 0 || i == 64 || i == 128)
                        {
                            continue;
                        }
                        int v = mBytes[i] & 0xFF;
                        checksum =checksum+ v;
                        String hv = Integer.toHexString(v);
                        stringBuilder.append(hv);
                        stringBuilder.append(",");
                    }
                     if(checksum % 256 == 0)  //校验和正确
                     {
                         mShow.setText("Cfg Checksum is correct!");
                     }
                     else {
                         mShow.setText("Cfg Checksum is error!");
                     }

                    //String d_value =Arrays.toString(mBytes);
                    //String d_value =Arrays.hv.toString();
                    //mMessage.setText( stringBuilder.toString() );//输出显示
                    //edit_search.setText(uri.getPath().toString());
                    // mLog.setText(mStringBuffer.toString());
                    break;

                case SEND_MESSAGE_SUCCESS://成功发送数据
                    //mMessage.setText("");
                    break;

                case DEBUG_MESSAGE_SUCCESS://成功发送数据
                    //StringBuilder stringBuilder = new StringBuilder("");
                   // StringBuffer resultSb = new StringBuffer();

                    checksum = 0 ;
                    for (int i = 0; i < 216; i++) {

                        int v = mSendData[i] & 0xFF;
                        checksum =checksum+ v;
                        //byte v = mSendData[i];
                        String hv = Integer.toHexString(v);
                        //String hv = Byte.toString(v);
                        stringBuilder.append(hv);
                        stringBuilder.append(",");
                    }
                    //mShow.setText(stringBuilder.toString());
                    //mShow.setText(value);
                    break;
                case DEBUG_MESSAGE_ERROR://成功发送数据
                    //mShow.setText("ERROR");
                    //mError.setText("ERROR");
                    break;

            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
        mAlertContext = Config.this;
        ConstantsActivity.activityList.add(this);
        //switchLanguage(ConstantsActivity.langae);
        init();
    }

    //核心设置的代码
    protected void switchLanguage(String language) {
        Resources resources = getResources();
        Configuration config = resources.getConfiguration();
        DisplayMetrics dm = resources.getDisplayMetrics();
        switch (language) {
            case "zh":
                config.locale = Locale.CHINESE;
                resources.updateConfiguration(config, dm);
                break;
            case "en":
                config.locale = Locale.ENGLISH;
                resources.updateConfiguration(config, dm);
                break;
            default:
                config.locale = Locale.US;
                resources.updateConfiguration(config, dm);
                break;
        }
    }

    private void init() {
        initView();
        initViewPager();
        initSampleSpin();
        initModuleSwitchSpin();
        initNormalSettingSpin();
        initChannelSettingSpin();
        initPenSettingSpin();
        initPlamRestrainSpin();
        initKeySettingSpin();
        initHoppingSettingSpin();
        initCfgShow();
        initListener();
        initData();
        openDevices();
    }

    private void initView() {
        mReadCfg = (Button) findViewById(R.id.readcfg);
        mSendCfg = (Button) findViewById(R.id.sendcfg);
        mShow = (TextView) findViewById(R.id.show);
        edtConfigDataShow = (EditText) findViewById(R.id.configdata);

        edit_search = (TextView) findViewById(R.id.editsearch);
        edit_text = (EditText) findViewById(R.id.editsearch);

        //选择本地文件
        btnLocalFileButton = (Button) findViewById(R.id.localfile);
        btnLocalFileButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //ActivityCompat.requestPermissions(  Config.this, new String[]{android
                //        .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("*/*");//设置类型，我这里是任意类型，任意后缀的可以这样写。
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                startActivityForResult(intent, 2);
            }
        });

        //选择U盘文件
        btnUDiskFileButton = (Button) findViewById(R.id.udiskfile);
        btnUDiskFileButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //ActivityCompat.requestPermissions(  Config.this, new String[]{android
                //        .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("*/*");//设置类型，我这里是任意类型，任意后缀的可以这样写。
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                startActivityForResult(intent, 1);
            }
        });

        //editdetail = (EditText) findViewById(R.id.message);
        editname = (EditText) findViewById(R.id.editname);
        btnsave = (Button) findViewById(R.id.savecfg);
        //btnread = (Button) findViewById(R.id.btnread);
        tvVenderID = (TextView) findViewById(R.id.venderid);

        btnsave.setOnClickListener(this);

        mSaveCfgContext = getApplicationContext();

    }

    private void initViewPager() {
        //vpagerCfg = (ViewPager) findViewById(R.id.vpagercfg);

        tvSample = (TextView) findViewById(R.id.tvsample);
        tvModuleSwitch = (TextView) findViewById(R.id.tvmoduleswitch);
        tvNormalSetting = (TextView) findViewById(R.id.tvnormal);
        tvChannelSetting = (TextView) findViewById(R.id.tvchannel);
        tvPenSetting = (TextView) findViewById(R.id.tvpen);
        tvPlamRestrain = (TextView) findViewById(R.id.tvplamrestrain);
        tvKeySetting = (TextView) findViewById(R.id.tvkey);
        tvHoppingSetting = (TextView) findViewById(R.id.tvhopping);
        tvCfgRam = (TextView) findViewById(R.id.tvcfgram);

        img_cursor = (ImageView) findViewById(R.id.img_cursor);

        //下划线动画的相关设置：
        bmpWidth = BitmapFactory.decodeResource(getResources(), R.mipmap.line).getWidth();// 获取图片宽度
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenW = dm.widthPixels;// 获取分辨率宽度
        //offset = (screenW / 3 - bmpWidth) / 2;// 计算偏移量
        offset = (screenW / 9 - bmpWidth) / 2;// 计算偏移量
        Matrix matrix = new Matrix();
        matrix.postTranslate(offset, 0);
        img_cursor.setImageMatrix(matrix);// 设置动画初始位置
        //移动的距离
        one = offset * 2 + bmpWidth;// 移动一页的偏移量,比如1->2,或者2->3
        two = one * 2;// 移动两页的偏移量,比如1直接跳3
        three = one * 3;// 移动两页的偏移量,比如1直接跳3
        four = one * 4;// 移动两页的偏移量,比如1直接跳3
        five = one * 5;// 移动两页的偏移量,比如1直接跳3
        six = one * 6;// 移动两页的偏移量,比如1直接跳3
        seven = one * 7;// 移动两页的偏移量,比如1直接跳3
        eight = one * 8;// 移动两页的偏移量,比如1直接跳3
        nine = one * 9;// 移动两页的偏移量,比如1直接跳3

        //往ViewPager填充View，同时设置点击事件与页面切换事件
        listViews = new ArrayList<View>();

        //LayoutInflater mInflater = getLayoutInflater();
        viewsample = View.inflate(this,R.layout.view_sample, null);
        viewmoduleswitch = View.inflate(this,R.layout.view_module_switch, null);
        viewnormalsetting = View.inflate(this,R.layout.view_normal_setting, null);
        viewchannelsetting = View.inflate(this,R.layout.view_channel_setting, null);
        viewpensetting = View.inflate(this,R.layout.view_pen_setting, null);
        viewplamrestrain = View.inflate(this,R.layout.view_plam_restrain, null);
        viewkeysetting = View.inflate(this,R.layout.view_key_setting, null);
        viewhoppingsetting = View.inflate(this,R.layout.view_hopping_setting, null);
        viewcfgram = View.inflate(this,R.layout.view_cfg_ram, null);

        //listViews.add(mInflater.inflate(R.layout.view_one, null, false));
        //listViews.add(mInflater.inflate(R.layout.view_two, null, false));
        //listViews.add(mInflater.inflate(R.layout.view_three, null, false));

        listViews.add(viewsample);
        listViews.add(viewmoduleswitch);
        listViews.add(viewnormalsetting);
        listViews.add(viewchannelsetting);
        listViews.add(viewpensetting);
        listViews.add(viewplamrestrain);
        listViews.add(viewkeysetting);
        listViews.add(viewhoppingsetting);
        listViews.add(viewcfgram);
        //vpagerCfg.setAdapter(new MyPagerAdapter(listViews));
        //vpagerCfg.setCurrentItem(0);          //设置ViewPager当前页，从0开始算

        tvSample.setOnClickListener(this);
        tvModuleSwitch.setOnClickListener(this);
        tvNormalSetting.setOnClickListener(this);
        tvChannelSetting.setOnClickListener(this);
        tvPenSetting.setOnClickListener(this);
        tvPlamRestrain.setOnClickListener(this);
        tvKeySetting.setOnClickListener(this);
        tvHoppingSetting.setOnClickListener(this);
        tvCfgRam.setOnClickListener(this);

        //vpagerCfg.addOnPageChangeListener(this);
    }

    //===============================各view中的元素初始化开始===============================================//
    private void initSampleSpin() {
        cbAllDrivingEn = viewsample.findViewById(R.id.alldrivingen);
        cbDualFreq = viewsample.findViewById(R.id.dualfreq);
        edtFreqAFactor = viewsample.findViewById(R.id.freqafactor);
        edtFreqBFactor = viewsample.findViewById(R.id.freqbfactor);
        edtPannelBitFreq = viewsample.findViewById(R.id.bitfreq);
        edtDuration = viewsample.findViewById(R.id.duration);
        edtFreqA = viewsample.findViewById(R.id.freqa);
        edtFreqB = viewsample.findViewById(R.id.freqb);
        twBitFreq = new TextWatcher(){
            int ibitfreq = 0;
            float fduration = 0;
            float ffactortemp;
            int ifactortemp;
            int ifreq;

            @Override
            public void onTextChanged(CharSequence s, int start, int before,int count) {
                edtDuration.removeTextChangedListener(twDuration);
                try {
                    ibitfreq = Integer.parseInt(s.toString(),10);
                } catch (Exception ex) {
                    ibitfreq = 1;
                }
                fduration = (float) (1000000.0 / ibitfreq);
                CharSequence csduration = Float.toString(fduration);
                //删除.后面超过两位的数字
                if (csduration.toString().contains(".")) {
                    if (csduration.length() - 1 - csduration.toString().indexOf(".") > 2) {
                        csduration = csduration.toString().subSequence(0,
                                csduration.toString().indexOf(".") + 3);
                        edtDuration.setText(csduration);
                        //edtDuration.setSelection(csduration.length());
                    }
                }

                //如果.在起始位置,则起始位置自动补0
                if (csduration.toString().trim().substring(0).equals(".")) {
                    csduration = "0" + csduration;
                    edtDuration.setText(csduration);
                    //edtDuration.setSelection(2);
                }

                //如果起始位置为0并且第二位跟的不是".",则无法后续输入
                if (csduration.toString().startsWith("0")
                        && csduration.toString().trim().length() > 1) {
                    if (!csduration.toString().substring(1, 2).equals(".")) {
                        edtDuration.setText(csduration.subSequence(0, 1));
                        //edtDuration.setSelection(1);
                        return;
                    }
                }

                edtDuration.setText(csduration.toString());
                ffactortemp = (float)(ibitfreq / 57.2205);
                ifactortemp = (int)ffactortemp;
                ffactortemp = (float) (ifactortemp * 57.2205);
                ibitfreq = (int)ffactortemp;
                ifreq = Integer.parseInt(edtFreqAFactor.getText().toString(),10) * ibitfreq;
                edtFreqA.setText(Integer.toString(ifreq));
                ifreq = Integer.parseInt(edtFreqBFactor.getText().toString(),10) * ibitfreq;
                edtFreqB.setText(Integer.toString(ifreq));

                edtPannelBitFreq.setSelection(s.length());
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                edtDuration.addTextChangedListener(twDuration);
            }
        };

        twDuration = new TextWatcher(){
            int ibitfreq = 0;
            float fduration = 0;
            float ffactortemp;
            int ifactortemp;
            int ifreq;

            @Override
            public void onTextChanged(CharSequence s, int start, int before,int count) {
                if (bottonMode == 0) {
                    edtPannelBitFreq.removeTextChangedListener(twBitFreq);
                    try {
                        //删除.后面超过两位的数字
                        if (s.toString().contains(".")) {
                            if (s.length() - 1 - s.toString().indexOf(".") > 2) {
                                s = s.toString().subSequence(0, s.toString().indexOf(".") + 3);
                                edtDuration.setText(s);
                                edtDuration.setSelection(s.length());
                            }
                        }

                        //如果.在起始位置,则起始位置自动补0
                        if (s.toString().trim().substring(0).equals(".")) {
                            s = "0" + s;
                            edtDuration.setText(s);
                            edtDuration.setSelection(2);
                        }

                        //如果起始位置为0并且第二位跟的不是".",则无法后续输入
                        if (s.toString().startsWith("0")
                                && s.toString().trim().length() > 1) {
                            if (!s.toString().substring(1, 2).equals(".")) {
                                edtDuration.setText(s.subSequence(0, 1));
                                edtDuration.setSelection(1);
                                return;
                            }
                        }

                        fduration = Float.parseFloat(s.toString());
                    } catch (Exception ex) {
                        fduration = 1;
                    }
                    ibitfreq = (int) (1000000 / fduration);
                    edtPannelBitFreq.setText(Integer.toString(ibitfreq));
                    ffactortemp = (float) (ibitfreq / 57.2205);
                    ifactortemp = (int) ffactortemp;
                    ffactortemp = (float) (ifactortemp * 57.2205);
                    ibitfreq = (int) ffactortemp;
                    ifreq = Integer.parseInt(edtFreqAFactor.getText().toString(), 10) * ibitfreq;
                    edtFreqA.setText(Integer.toString(ifreq));
                    ifreq = Integer.parseInt(edtFreqBFactor.getText().toString(), 10) * ibitfreq;
                    edtFreqB.setText(Integer.toString(ifreq));
                }
                bottonMode = 0;
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                /*
                String temp = s.toString();
                //int posDot = temp.indexOf(".");
                if (temp.indexOf(".") > 0){//(posDot > 0){
                    int posDot = s.length() - 1 - temp.indexOf(".");
                    if (posDot > 2){
                        s.delete(temp.indexOf(".") + 3, temp.length());
                        edtDuration.setText(s.toString());
                        edtDuration.setSelection(s.length());
                    }
                }
                */
                edtPannelBitFreq.addTextChangedListener(twBitFreq);
            }
        };

        edtPannelBitFreq.addTextChangedListener(twBitFreq);
        edtDuration.addTextChangedListener(twDuration);

        twFreqAFactor = new TextWatcher(){
            int ibitfreq = 0;
            float ffactortemp;
            int ifactortemp;
            int ifreq;

            @Override
            public void onTextChanged(CharSequence s, int start, int before,int count) {
                //edtFreqA.removeTextChangedListener(twFreqA);
                try {
                    ifactortemp = Integer.parseInt(s.toString(),10);
                } catch (Exception ex) {
                    ifactortemp = 0;
                }
                ibitfreq = Integer.parseInt(edtPannelBitFreq.getText().toString(),10);
                ffactortemp = (float)(ibitfreq / 57.2205);
                ifactortemp = (int)ffactortemp;
                ffactortemp = (float) (ifactortemp * 57.2205);
                ibitfreq = (int)ffactortemp;
                ifreq = ifactortemp * ibitfreq;
                edtFreqA.setText(Integer.toString(ifreq));
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //edtFreqA.addTextChangedListener(twFreqA);
            }
        };
        /*
        twFreqA = new TextWatcher(){
            int ibitfreq = 0;
            float fduration = 0;
            float ffactortemp;
            int ifactortemp;
            int ifreq;

            @Override
            public void onTextChanged(CharSequence s, int start, int before,int count) {
                edtFreqAFactor.removeTextChangedListener(twFreqAFactor);
                try {
                    ifreq = Integer.parseInt(s.toString());
                } catch (Exception ex) {
                    ifreq = 0;
                }
                ibitfreq = Integer.parseInt(edtPannelBitFreq.getText().toString());
                ffactortemp = (float)(ibitfreq / 57.2205);
                ifactortemp = (int)ffactortemp;
                ffactortemp = (float) (ifactortemp * 57.2205);
                ibitfreq = (int)ffactortemp;
                if (ibitfreq == 0){
                    ibitfreq = 1;
                }
                edtFreqAFactor.setText(Integer.toString(ifreq / ibitfreq));
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                edtFreqAFactor.addTextChangedListener(twFreqAFactor);
            }
        };
        */
        edtFreqAFactor.addTextChangedListener(twFreqAFactor);
        //edtFreqA.addTextChangedListener(twFreqA);

        twFreqBFactor = new TextWatcher(){
            int ibitfreq = 0;
            float ffactortemp;
            int ifactortemp;
            int ifreq;

            @Override
            public void onTextChanged(CharSequence s, int start, int before,int count) {
                //edtFreqB.removeTextChangedListener(twFreqB);
                try {
                    ifactortemp = Integer.parseInt(s.toString(),10);
                } catch (Exception ex) {
                    ifactortemp = 0;
                }
                ibitfreq = Integer.parseInt(edtPannelBitFreq.getText().toString(),10);
                ffactortemp = (float)(ibitfreq / 57.2205);
                ifactortemp = (int)ffactortemp;
                ffactortemp = (float) (ifactortemp * 57.2205);
                ibitfreq = (int)ffactortemp;
                ifreq = ifactortemp * ibitfreq;
                edtFreqB.setText(Integer.toString(ifreq));
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //edtFreqB.addTextChangedListener(twFreqB);
            }
        };
        /*
        twFreqB = new TextWatcher(){
            int ibitfreq = 0;
            float ffactortemp;
            int ifactortemp;
            int ifreq;

            @Override
            public void onTextChanged(CharSequence s, int start, int before,int count) {
                edtFreqBFactor.removeTextChangedListener(twFreqBFactor);
                try {
                    ifreq = Integer.parseInt(s.toString());
                } catch (Exception ex) {
                    ifreq = 0;
                }
                ibitfreq = Integer.parseInt(edtPannelBitFreq.getText().toString());
                ffactortemp = (float)(ibitfreq / 57.2205);
                ifactortemp = (int)ffactortemp;
                ffactortemp = (float) (ifactortemp * 57.2205);
                ibitfreq = (int)ffactortemp;
                if (ibitfreq == 0){
                    ibitfreq = 1;
                }
                edtFreqBFactor.setText(Integer.toString(ifreq / ibitfreq));
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                edtFreqBFactor.addTextChangedListener(twFreqBFactor);
            }
        };
        */
        edtFreqBFactor.addTextChangedListener(twFreqBFactor);
        //edtFreqB.addTextChangedListener(twFreqB);

        edtDumpShift = viewsample.findViewById(R.id.dumpshift);
        edtSubFrameDrvNum = viewsample.findViewById(R.id.subframedrvnum);
        spinDrvOutputR = viewsample.findViewById(R.id.drvoutputr);
        spinDACGain = viewsample.findViewById(R.id.dacgain);
        spinPGAC = viewsample.findViewById(R.id.pgac);
        spinPGAR = viewsample.findViewById(R.id.pgar);
        spinRxVcmi = viewsample.findViewById(R.id.rxvcmi);
        spinPGAGain = viewsample.findViewById(R.id.pgagainspin);
        //spinPGAGain.setOnItemSelectedListener(this);
        spinBoostTime = viewsample.findViewById(R.id.boosttime);
        spinVoltage = viewsample.findViewById(R.id.voltage);
        spinAlterCount = viewsample.findViewById(R.id.altercount);
        cbExtoscen = viewsample.findViewById(R.id.extoscen);
    }

    private void initModuleSwitchSpin() {
        cbX2Y = viewmoduleswitch.findViewById(R.id.x2y);
        cbSito = viewmoduleswitch.findViewById(R.id.sito);
        spinStretchRank = viewmoduleswitch.findViewById(R.id.stretchrank);
        spinInterrupt = viewmoduleswitch.findViewById(R.id.interrupt);
        cbMonitorConsistencyConflictEn = viewmoduleswitch.findViewById(R.id.mccen);
        cbFirstFilterDis = viewmoduleswitch.findViewById(R.id.firstfilterdis);
        cbDiffDivideBy2or4 = viewmoduleswitch.findViewById(R.id.diffdivideby2or4);
        cbWaterSpeedLimitEn = viewmoduleswitch.findViewById(R.id.waterspeedlimiten);
        cbShapeEn = viewmoduleswitch.findViewById(R.id.shapeen);
        cbWaterProofDis = viewmoduleswitch.findViewById(R.id.waterproofdis);
        cbLcdPlusMinusEn = viewmoduleswitch.findViewById(R.id.lcdplusminusen);
        cbESDEn = viewmoduleswitch.findViewById(R.id.esden);
        cbX2X = viewmoduleswitch.findViewById(R.id.x2x);
        cbY2Y = viewmoduleswitch.findViewById(R.id.y2y);
        cbINTWakeup = viewmoduleswitch.findViewById(R.id.intwakeup);
    }

    private void initNormalSettingSpin(){
        edtConfigVersion = viewnormalsetting.findViewById(R.id.configversion);
        edtTouchNumber = viewnormalsetting.findViewById(R.id.touchnumber);
        edtShakeCnt = viewnormalsetting.findViewById(R.id.shakecnt);
        edtFirstFilter = viewnormalsetting.findViewById(R.id.firstfilter);
        edtNormalFilter = viewnormalsetting.findViewById(R.id.normalfilter);
        edtNoiseReduction = viewnormalsetting.findViewById(R.id.noisereduction);
        edtScreenTouchLv = viewnormalsetting.findViewById(R.id.touchlevel);
        edtScreenLeaveLv = viewnormalsetting.findViewById(R.id.leavelevel);
        edtLowPowerControl = viewnormalsetting.findViewById(R.id.lowpowercontrol);
        spinRefreshRate = viewnormalsetting.findViewById(R.id.refreshrate);
        edtXThreshold = viewnormalsetting.findViewById(R.id.xthreshold);
        edtYThreshold = viewnormalsetting.findViewById(R.id.ythreshold);
        edtSpaceUpDown = viewnormalsetting.findViewById(R.id.spaceupdown);
        edtSpaceLeftRight = viewnormalsetting.findViewById(R.id.spaceleftright);
        edtStretchR0 = viewnormalsetting.findViewById(R.id.stretchr0);
        edtStretchR1 = viewnormalsetting.findViewById(R.id.stretchr1);
        edtStretchR2 = viewnormalsetting.findViewById(R.id.stretchr2);
        edtStretchRM = viewnormalsetting.findViewById(R.id.stretchrm);
        edtMiniFilter = viewnormalsetting.findViewById(R.id.minifilter);
        edtChargingLevelUp = viewnormalsetting.findViewById(R.id.charginglevelup);
        edtLcdPlusMinusValue = viewnormalsetting.findViewById(R.id.lcdplusminusvalue);
        edtConThreshold = viewnormalsetting.findViewById(R.id.conthreshold);
        edtShapeRestrain = viewnormalsetting.findViewById(R.id.shaperestrain);
        edtShapeContrl = viewnormalsetting.findViewById(R.id.shapecontrl);
        edtWaterFrameTime = viewnormalsetting.findViewById(R.id.waterframetime);
        edtWaterUpdateTime = viewnormalsetting.findViewById(R.id.waterupdatetime);
        edtSlideInEdgeConfig = viewnormalsetting.findViewById(R.id.slideinedgeconfig);
        edtSlideOutEdgeConfig = viewnormalsetting.findViewById(R.id.slideoutedgeconfig);
        edtCombineDis = viewnormalsetting.findViewById(R.id.combinedis);
        edtSplitSet = viewnormalsetting.findViewById(R.id.splitset);
        edtSitoDiffRefLevel = viewnormalsetting.findViewById(R.id.sitodiffreflevel);
    }

    private void initChannelSettingSpin(){
        edtXOutputMax = viewchannelsetting.findViewById(R.id.xoutputmax);
        edtYOutputMax = viewchannelsetting.findViewById(R.id.youtputmax);
        edtDrvGroupAnumber = viewchannelsetting.findViewById(R.id.drvgroupanum);
        edtDrvGroupBnumber = viewchannelsetting.findViewById(R.id.drvgroupbnum);
        edtSenGroupANumber = viewchannelsetting.findViewById(R.id.sengroupanum);
        edtSenGroupBNumber = viewchannelsetting.findViewById(R.id.sengroupbnum);
        edtSensorCH0 = viewchannelsetting.findViewById(R.id.sensorch0);
        edtSensorCH1 = viewchannelsetting.findViewById(R.id.sensorch1);
        edtSensorCH2 = viewchannelsetting.findViewById(R.id.sensorch2);
        edtSensorCH3 = viewchannelsetting.findViewById(R.id.sensorch3);
        edtSensorCH4 = viewchannelsetting.findViewById(R.id.sensorch4);
        edtSensorCH5 = viewchannelsetting.findViewById(R.id.sensorch5);
        edtSensorCH6 = viewchannelsetting.findViewById(R.id.sensorch6);
        edtSensorCH7 = viewchannelsetting.findViewById(R.id.sensorch7);
        edtSensorCH8 = viewchannelsetting.findViewById(R.id.sensorch8);
        edtSensorCH9 = viewchannelsetting.findViewById(R.id.sensorch9);
        edtSensorCH10 = viewchannelsetting.findViewById(R.id.sensorch10);
        edtSensorCH11 = viewchannelsetting.findViewById(R.id.sensorch11);
        edtSensorCH12 = viewchannelsetting.findViewById(R.id.sensorch12);
        edtSensorCH13 = viewchannelsetting.findViewById(R.id.sensorch13);
        edtSensorCH14 = viewchannelsetting.findViewById(R.id.sensorch14);
        edtSensorCH15 = viewchannelsetting.findViewById(R.id.sensorch15);
        edtSensorCH16 = viewchannelsetting.findViewById(R.id.sensorch16);
        edtSensorCH17 = viewchannelsetting.findViewById(R.id.sensorch17);
        edtSensorCH18 = viewchannelsetting.findViewById(R.id.sensorch18);
        edtSensorCH19 = viewchannelsetting.findViewById(R.id.sensorch19);
        edtSensorCH20 = viewchannelsetting.findViewById(R.id.sensorch20);
        edtSensorCH21 = viewchannelsetting.findViewById(R.id.sensorch21);
        edtSensorCH22 = viewchannelsetting.findViewById(R.id.sensorch22);
        edtSensorCH23 = viewchannelsetting.findViewById(R.id.sensorch23);
        edtSensorCH24 = viewchannelsetting.findViewById(R.id.sensorch24);
        edtSensorCH25 = viewchannelsetting.findViewById(R.id.sensorch25);
        edtSensorCH26 = viewchannelsetting.findViewById(R.id.sensorch26);
        edtSensorCH27 = viewchannelsetting.findViewById(R.id.sensorch27);
        edtSensorCH28 = viewchannelsetting.findViewById(R.id.sensorch28);
        edtSensorCH29 = viewchannelsetting.findViewById(R.id.sensorch29);
        edtSensorStart = viewchannelsetting.findViewById(R.id.sensorstart);
        edtSensorEnd = viewchannelsetting.findViewById(R.id.sensorend);
        btnSensorRev = viewchannelsetting.findViewById(R.id.btnsensorrev);
        btnSensorRev.setOnClickListener(this);
        btnAllSensorChannels = viewchannelsetting.findViewById(R.id.allsensorchannels);
        btnAllSensorChannels.setOnClickListener(this);

        edtDriverCH0 = viewchannelsetting.findViewById(R.id.driverch0);
        edtDriverCH1 = viewchannelsetting.findViewById(R.id.driverch1);
        edtDriverCH2 = viewchannelsetting.findViewById(R.id.driverch2);
        edtDriverCH3 = viewchannelsetting.findViewById(R.id.driverch3);
        edtDriverCH4 = viewchannelsetting.findViewById(R.id.driverch4);
        edtDriverCH5 = viewchannelsetting.findViewById(R.id.driverch5);
        edtDriverCH6 = viewchannelsetting.findViewById(R.id.driverch6);
        edtDriverCH7 = viewchannelsetting.findViewById(R.id.driverch7);
        edtDriverCH8 = viewchannelsetting.findViewById(R.id.driverch8);
        edtDriverCH9 = viewchannelsetting.findViewById(R.id.driverch9);
        edtDriverCH10 = viewchannelsetting.findViewById(R.id.driverch10);
        edtDriverCH11 = viewchannelsetting.findViewById(R.id.driverch11);
        edtDriverCH12 = viewchannelsetting.findViewById(R.id.driverch12);
        edtDriverCH13 = viewchannelsetting.findViewById(R.id.driverch13);
        edtDriverCH14 = viewchannelsetting.findViewById(R.id.driverch14);
        edtDriverCH15 = viewchannelsetting.findViewById(R.id.driverch15);
        edtDriverCH16 = viewchannelsetting.findViewById(R.id.driverch16);
        edtDriverCH17 = viewchannelsetting.findViewById(R.id.driverch17);
        edtDriverCH18 = viewchannelsetting.findViewById(R.id.driverch18);
        edtDriverCH19 = viewchannelsetting.findViewById(R.id.driverch19);
        edtDriverCH20 = viewchannelsetting.findViewById(R.id.driverch20);
        edtDriverCH21 = viewchannelsetting.findViewById(R.id.driverch21);
        edtDriverCH22 = viewchannelsetting.findViewById(R.id.driverch22);
        edtDriverCH23 = viewchannelsetting.findViewById(R.id.driverch23);
        edtDriverCH24 = viewchannelsetting.findViewById(R.id.driverch24);
        edtDriverCH25 = viewchannelsetting.findViewById(R.id.driverch25);
        edtDriverCH26 = viewchannelsetting.findViewById(R.id.driverch26);
        edtDriverCH27 = viewchannelsetting.findViewById(R.id.driverch27);
        edtDriverCH28 = viewchannelsetting.findViewById(R.id.driverch28);
        edtDriverCH29 = viewchannelsetting.findViewById(R.id.driverch29);
        edtDriverCH30 = viewchannelsetting.findViewById(R.id.driverch30);
        edtDriverCH31 = viewchannelsetting.findViewById(R.id.driverch31);
        edtDriverCH32 = viewchannelsetting.findViewById(R.id.driverch32);
        edtDriverCH33 = viewchannelsetting.findViewById(R.id.driverch33);
        edtDriverCH34 = viewchannelsetting.findViewById(R.id.driverch34);
        edtDriverCH35 = viewchannelsetting.findViewById(R.id.driverch35);
        edtDriverCH36 = viewchannelsetting.findViewById(R.id.driverch36);
        edtDriverCH37 = viewchannelsetting.findViewById(R.id.driverch37);
        edtDriverCH38 = viewchannelsetting.findViewById(R.id.driverch38);
        edtDriverCH39 = viewchannelsetting.findViewById(R.id.driverch39);
        edtDriverCH40 = viewchannelsetting.findViewById(R.id.driverch40);
        edtDriverCH41 = viewchannelsetting.findViewById(R.id.driverch41);
        edtDriverStart = viewchannelsetting.findViewById(R.id.driverstart);
        edtDriverEnd = viewchannelsetting.findViewById(R.id.driverend);
        btnDriverRev = viewchannelsetting.findViewById(R.id.btndriverrev);
        btnDriverRev.setOnClickListener(this);
        btnAllDriverChannels = viewchannelsetting.findViewById(R.id.alldriverchannels);
        btnAllDriverChannels.setOnClickListener(this);
    }

    private void initPenSettingSpin(){
        cbPenEn = viewpensetting.findViewById(R.id.penen);
        cbOnlyFingerEn = viewpensetting.findViewById(R.id.onlyfingeren);
        edtPenLowSize = viewpensetting.findViewById(R.id.penlowsize);
        edtPenHighSize = viewpensetting.findViewById(R.id.penhighsize);
        edtRectsumPLowL = viewpensetting.findViewById(R.id.rectsumplowl);
        edtRectsumPHighL = viewpensetting.findViewById(R.id.rectsumphighl);
        edtRectsumFLowL = viewpensetting.findViewById(R.id.rectsumflowl);
        edtPRectMaxDiffLimit = viewpensetting.findViewById(R.id.prectmaxdifflimit);
        edtPRectAreaLimit = viewpensetting.findViewById(R.id.prectarealimit);
        edtFLeavelevel = viewpensetting.findViewById(R.id.fleavelevel);
        edtPTouchHighlevel = viewpensetting.findViewById(R.id.ptouchhighlevel);
        spinFingerRestrainPen = viewpensetting.findViewById(R.id.fingerrestrainpen);
    }

    private void initPlamRestrainSpin(){
        cbAllPlamRestrain = viewplamrestrain.findViewById(R.id.allplamrestrain);
        edtLargeTouch = viewplamrestrain.findViewById(R.id.largetouch);
        edtExpanNumOutX = viewplamrestrain.findViewById(R.id.expannumoutx);
        edtExpanNumOutY = viewplamrestrain.findViewById(R.id.expannumouty);
        edtExpanNumInX = viewplamrestrain.findViewById(R.id.expannuminx);
        edtExpanNumInY = viewplamrestrain.findViewById(R.id.expannuminy);
        edtSingleRectTopSignNum = viewplamrestrain.findViewById(R.id.singlerecttopsignnum);
        edtAllRectTopSignSum = viewplamrestrain.findViewById(R.id.allrecttopsignsum);
        cbWaterLargeRestrainEn = viewplamrestrain.findViewById(R.id.waterlargerestrainen);
    }

    private void initKeySettingSpin(){
        cbTouchKey = viewkeysetting.findViewById(R.id.touchkey);
        edtKeyArea = viewkeysetting.findViewById(R.id.keyarea);
        edtKey1 = viewkeysetting.findViewById(R.id.key1);
        edtKey2 = viewkeysetting.findViewById(R.id.key2);
        edtKey3 = viewkeysetting.findViewById(R.id.key3);
        edtKey4 = viewkeysetting.findViewById(R.id.key4);
        edtKeyTouchLevel = viewkeysetting.findViewById(R.id.keytouchlevel);
        edtKeyLeaveLevel = viewkeysetting.findViewById(R.id.keyleavelevel);
        edtKeySens1and2 = viewkeysetting.findViewById(R.id.keysens1and2);
        edtKeySens3and4 = viewkeysetting.findViewById(R.id.keysens3and4);
        edtKeyRestrain = viewkeysetting.findViewById(R.id.keyrestrain);
        edtKeyRestrainTime = viewkeysetting.findViewById(R.id.keyrestraintime);
    }

    private void initHoppingSettingSpin(){
        cbHoppingEn = viewhoppingsetting.findViewById(R.id.hoppingen);
        cbRangeExt = viewhoppingsetting.findViewById(R.id.rangeext);
        edtFreqStart = viewhoppingsetting.findViewById(R.id.freqstart);
        edtFreqEnd = viewhoppingsetting.findViewById(R.id.freqend);
        edtDetectStayTimes = viewhoppingsetting.findViewById(R.id.detectstaytimes);
        edtDetectConfirmTimes = viewhoppingsetting.findViewById(R.id.detectconfirmtimes);
        cbDisForceRef = viewhoppingsetting.findViewById(R.id.disforceref);
        cbDelayHopping = viewhoppingsetting.findViewById(R.id.delayhopping);
        edtFastHopLimit = viewhoppingsetting.findViewById(R.id.fasthoplimit);
        edtHopThreshold = viewhoppingsetting.findViewById(R.id.hopthreshold);
        edtNoiseMinTh = viewhoppingsetting.findViewById(R.id.noiseminth);
        edtSensorGroup = viewhoppingsetting.findViewById(R.id.sensorgroup);
        edtSeg1Normalize = viewhoppingsetting.findViewById(R.id.seg1normalize);
        edtSeg1Factor = viewhoppingsetting.findViewById(R.id.seg1factor);
        edtMainClockAjdust = viewhoppingsetting.findViewById(R.id.mainclockajdust);
        edtSeg2Normalize = viewhoppingsetting.findViewById(R.id.seg2normalize);
        edtSeg2Factor = viewhoppingsetting.findViewById(R.id.seg2factor);
        edtSeg3Normalize = viewhoppingsetting.findViewById(R.id.seg3normalize);
        edtSeg3Factor = viewhoppingsetting.findViewById(R.id.seg3factor);
        edtSeg4Normalize = viewhoppingsetting.findViewById(R.id.seg4normalize);
        edtSeg4Factor = viewhoppingsetting.findViewById(R.id.seg4factor);
        edtSeg5Normalize = viewhoppingsetting.findViewById(R.id.seg5normalize);
        edtSeg5Factor = viewhoppingsetting.findViewById(R.id.seg5factor);
        edtSeg6Normalize = viewhoppingsetting.findViewById(R.id.seg6normalize);
        edtHopFreqAddr = viewhoppingsetting.findViewById(R.id.hopfreqaddr);
        edtHopDetectTimes = viewhoppingsetting.findViewById(R.id.hopdetecttimes);
    }

    //Cfg Ram 定义
    private void initCfgShow() {
        mCfg8047 = viewcfgram.findViewById(R.id.cfg8047);
        mCfg8048 = viewcfgram.findViewById(R.id.cfg8048);
        mCfg8049 = viewcfgram.findViewById(R.id.cfg8049);
        mCfg804A = viewcfgram.findViewById(R.id.cfg804A);
        mCfg804B = viewcfgram.findViewById(R.id.cfg804B);
        mCfg804C = viewcfgram.findViewById(R.id.cfg804C);
        mCfg804D = viewcfgram.findViewById(R.id.cfg804D);
        mCfg804E = viewcfgram.findViewById(R.id.cfg804E);
        mCfg804F = viewcfgram.findViewById(R.id.cfg804F);

        mCfg8050 = viewcfgram.findViewById(R.id.cfg8050);
        mCfg8051 = viewcfgram.findViewById(R.id.cfg8051);
        mCfg8052 = viewcfgram.findViewById(R.id.cfg8052);
        mCfg8053 = viewcfgram.findViewById(R.id.cfg8053);
        mCfg8054 = viewcfgram.findViewById(R.id.cfg8054);
        mCfg8055 = viewcfgram.findViewById(R.id.cfg8055);
        mCfg8056 = viewcfgram.findViewById(R.id.cfg8056);
        mCfg8057 = viewcfgram.findViewById(R.id.cfg8057);
        mCfg8058 = viewcfgram.findViewById(R.id.cfg8058);
        mCfg8059 = viewcfgram.findViewById(R.id.cfg8059);
        mCfg805A = viewcfgram.findViewById(R.id.cfg805A);
        mCfg805B = viewcfgram.findViewById(R.id.cfg805B);
        mCfg805C = viewcfgram.findViewById(R.id.cfg805C);
        mCfg805D = viewcfgram.findViewById(R.id.cfg805D);
        mCfg805E = viewcfgram.findViewById(R.id.cfg805E);
        mCfg805F = viewcfgram.findViewById(R.id.cfg805F);

        mCfg8060 = viewcfgram.findViewById(R.id.cfg8060);
        mCfg8061 = viewcfgram.findViewById(R.id.cfg8061);
        mCfg8062 = viewcfgram.findViewById(R.id.cfg8062);
        mCfg8063 = viewcfgram.findViewById(R.id.cfg8063);
        mCfg8064 = viewcfgram.findViewById(R.id.cfg8064);
        mCfg8065 = viewcfgram.findViewById(R.id.cfg8065);
        mCfg8066 = viewcfgram.findViewById(R.id.cfg8066);
        mCfg8067 = viewcfgram.findViewById(R.id.cfg8067);
        mCfg8068 = viewcfgram.findViewById(R.id.cfg8068);
        mCfg8069 = viewcfgram.findViewById(R.id.cfg8069);
        mCfg806A = viewcfgram.findViewById(R.id.cfg806A);
        mCfg806B = viewcfgram.findViewById(R.id.cfg806B);
        mCfg806C = viewcfgram.findViewById(R.id.cfg806C);
        mCfg806D = viewcfgram.findViewById(R.id.cfg806D);
        mCfg806E = viewcfgram.findViewById(R.id.cfg806E);
        mCfg806F = viewcfgram.findViewById(R.id.cfg806F);

        mCfg8070 = viewcfgram.findViewById(R.id.cfg8070);
        mCfg8071 = viewcfgram.findViewById(R.id.cfg8071);
        mCfg8072 = viewcfgram.findViewById(R.id.cfg8072);
        mCfg8073 = viewcfgram.findViewById(R.id.cfg8073);
        mCfg8074 = viewcfgram.findViewById(R.id.cfg8074);
        mCfg8075 = viewcfgram.findViewById(R.id.cfg8075);
        mCfg8076 = viewcfgram.findViewById(R.id.cfg8076);
        mCfg8077 = viewcfgram.findViewById(R.id.cfg8077);
        mCfg8078 = viewcfgram.findViewById(R.id.cfg8078);
        mCfg8079 = viewcfgram.findViewById(R.id.cfg8079);
        mCfg807A = viewcfgram.findViewById(R.id.cfg807A);
        mCfg807B = viewcfgram.findViewById(R.id.cfg807B);
        mCfg807C = viewcfgram.findViewById(R.id.cfg807C);
        mCfg807D = viewcfgram.findViewById(R.id.cfg807D);
        mCfg807E = viewcfgram.findViewById(R.id.cfg807E);
        mCfg807F = viewcfgram.findViewById(R.id.cfg807F);

        mCfg8080 = viewcfgram.findViewById(R.id.cfg8080);
        mCfg8081 = viewcfgram.findViewById(R.id.cfg8081);
        mCfg8082 = viewcfgram.findViewById(R.id.cfg8082);
        mCfg8083 = viewcfgram.findViewById(R.id.cfg8083);
        mCfg8084 = viewcfgram.findViewById(R.id.cfg8084);
        mCfg8085 = viewcfgram.findViewById(R.id.cfg8085);
        mCfg8086 = viewcfgram.findViewById(R.id.cfg8086);
        mCfg8087 = viewcfgram.findViewById(R.id.cfg8087);
        mCfg8088 = viewcfgram.findViewById(R.id.cfg8088);
        mCfg8089 = viewcfgram.findViewById(R.id.cfg8089);
        mCfg808A = viewcfgram.findViewById(R.id.cfg808A);
        mCfg808B = viewcfgram.findViewById(R.id.cfg808B);
        mCfg808C = viewcfgram.findViewById(R.id.cfg808C);
        mCfg808D = viewcfgram.findViewById(R.id.cfg808D);
        mCfg808E = viewcfgram.findViewById(R.id.cfg808E);
        mCfg808F = viewcfgram.findViewById(R.id.cfg808F);

        mCfg8090 = viewcfgram.findViewById(R.id.cfg8090);
        mCfg8091 = viewcfgram.findViewById(R.id.cfg8091);
        mCfg8092 = viewcfgram.findViewById(R.id.cfg8092);
        mCfg8093 = viewcfgram.findViewById(R.id.cfg8093);
        mCfg8094 = viewcfgram.findViewById(R.id.cfg8094);
        mCfg8095 = viewcfgram.findViewById(R.id.cfg8095);
        mCfg8096 = viewcfgram.findViewById(R.id.cfg8096);
        mCfg8097 = viewcfgram.findViewById(R.id.cfg8097);
        mCfg8098 = viewcfgram.findViewById(R.id.cfg8098);
        mCfg8099 = viewcfgram.findViewById(R.id.cfg8099);
        mCfg809A = viewcfgram.findViewById(R.id.cfg809A);
        mCfg809B = viewcfgram.findViewById(R.id.cfg809B);
        mCfg809C = viewcfgram.findViewById(R.id.cfg809C);
        mCfg809D = viewcfgram.findViewById(R.id.cfg809D);
        mCfg809E = viewcfgram.findViewById(R.id.cfg809E);
        mCfg809F = viewcfgram.findViewById(R.id.cfg809F);

        mCfg80A0 = viewcfgram.findViewById(R.id.cfg80A0);
        mCfg80A1 = viewcfgram.findViewById(R.id.cfg80A1);
        mCfg80A2 = viewcfgram.findViewById(R.id.cfg80A2);
        mCfg80A3 = viewcfgram.findViewById(R.id.cfg80A3);
        mCfg80A4 = viewcfgram.findViewById(R.id.cfg80A4);
        mCfg80A5 = viewcfgram.findViewById(R.id.cfg80A5);
        mCfg80A6 = viewcfgram.findViewById(R.id.cfg80A6);
        mCfg80A7 = viewcfgram.findViewById(R.id.cfg80A7);
        mCfg80A8 = viewcfgram.findViewById(R.id.cfg80A8);
        mCfg80A9 = viewcfgram.findViewById(R.id.cfg80A9);
        mCfg80AA = viewcfgram.findViewById(R.id.cfg80AA);
        mCfg80AB = viewcfgram.findViewById(R.id.cfg80AB);
        mCfg80AC = viewcfgram.findViewById(R.id.cfg80AC);
        mCfg80AD = viewcfgram.findViewById(R.id.cfg80AD);
        mCfg80AE = viewcfgram.findViewById(R.id.cfg80AE);
        mCfg80AF = viewcfgram.findViewById(R.id.cfg80AF);

        mCfg80B0 = viewcfgram.findViewById(R.id.cfg80B0);
        mCfg80B1 = viewcfgram.findViewById(R.id.cfg80B1);
        mCfg80B2 = viewcfgram.findViewById(R.id.cfg80B2);
        mCfg80B3 = viewcfgram.findViewById(R.id.cfg80B3);
        mCfg80B4 = viewcfgram.findViewById(R.id.cfg80B4);
        mCfg80B5 = viewcfgram.findViewById(R.id.cfg80B5);
        mCfg80B6 = viewcfgram.findViewById(R.id.cfg80B6);
        mCfg80B7 = viewcfgram.findViewById(R.id.cfg80B7);
        mCfg80B8 = viewcfgram.findViewById(R.id.cfg80B8);
        mCfg80B9 = viewcfgram.findViewById(R.id.cfg80B9);
        mCfg80BA = viewcfgram.findViewById(R.id.cfg80BA);
        mCfg80BB = viewcfgram.findViewById(R.id.cfg80BB);
        mCfg80BC = viewcfgram.findViewById(R.id.cfg80BC);
        mCfg80BD = viewcfgram.findViewById(R.id.cfg80BD);
        mCfg80BE = viewcfgram.findViewById(R.id.cfg80BE);
        mCfg80BF = viewcfgram.findViewById(R.id.cfg80BF);

        mCfg80C0 = viewcfgram.findViewById(R.id.cfg80C0);
        mCfg80C1 = viewcfgram.findViewById(R.id.cfg80C1);
        mCfg80C2 = viewcfgram.findViewById(R.id.cfg80C2);
        mCfg80C3 = viewcfgram.findViewById(R.id.cfg80C3);
        mCfg80C4 = viewcfgram.findViewById(R.id.cfg80C4);
        mCfg80C5 = viewcfgram.findViewById(R.id.cfg80C5);
        mCfg80C6 = viewcfgram.findViewById(R.id.cfg80C6);
        mCfg80C7 = viewcfgram.findViewById(R.id.cfg80C7);
        mCfg80C8 = viewcfgram.findViewById(R.id.cfg80C8);
        mCfg80C9 = viewcfgram.findViewById(R.id.cfg80C9);
        mCfg80CA = viewcfgram.findViewById(R.id.cfg80CA);
        mCfg80CB = viewcfgram.findViewById(R.id.cfg80CB);
        mCfg80CC = viewcfgram.findViewById(R.id.cfg80CC);
        mCfg80CD = viewcfgram.findViewById(R.id.cfg80CD);
        mCfg80CE = viewcfgram.findViewById(R.id.cfg80CE);
        mCfg80CF = viewcfgram.findViewById(R.id.cfg80CF);

        mCfg80D0 = viewcfgram.findViewById(R.id.cfg80D0);
        mCfg80D1 = viewcfgram.findViewById(R.id.cfg80D1);
        mCfg80D2 = viewcfgram.findViewById(R.id.cfg80D2);
        mCfg80D3 = viewcfgram.findViewById(R.id.cfg80D3);
        mCfg80D4 = viewcfgram.findViewById(R.id.cfg80D4);
        mCfg80D5 = viewcfgram.findViewById(R.id.cfg80D5);
        mCfg80D6 = viewcfgram.findViewById(R.id.cfg80D6);
        mCfg80D7 = viewcfgram.findViewById(R.id.cfg80D7);
        mCfg80D8 = viewcfgram.findViewById(R.id.cfg80D8);
        mCfg80D9 = viewcfgram.findViewById(R.id.cfg80D9);
        mCfg80DA = viewcfgram.findViewById(R.id.cfg80DA);
        mCfg80DB = viewcfgram.findViewById(R.id.cfg80DB);
        mCfg80DC = viewcfgram.findViewById(R.id.cfg80DC);
        mCfg80DD = viewcfgram.findViewById(R.id.cfg80DD);
        mCfg80DE = viewcfgram.findViewById(R.id.cfg80DE);
        mCfg80DF = viewcfgram.findViewById(R.id.cfg80DF);

        mCfg80E0 = viewcfgram.findViewById(R.id.cfg80E0);
        mCfg80E1 = viewcfgram.findViewById(R.id.cfg80E1);
        mCfg80E2 = viewcfgram.findViewById(R.id.cfg80E2);
        mCfg80E3 = viewcfgram.findViewById(R.id.cfg80E3);
        mCfg80E4 = viewcfgram.findViewById(R.id.cfg80E4);
        mCfg80E5 = viewcfgram.findViewById(R.id.cfg80E5);
        mCfg80E6 = viewcfgram.findViewById(R.id.cfg80E6);
        mCfg80E7 = viewcfgram.findViewById(R.id.cfg80E7);
        mCfg80E8 = viewcfgram.findViewById(R.id.cfg80E8);
        mCfg80E9 = viewcfgram.findViewById(R.id.cfg80E9);
        mCfg80EA = viewcfgram.findViewById(R.id.cfg80EA);
        mCfg80EB = viewcfgram.findViewById(R.id.cfg80EB);
        mCfg80EC = viewcfgram.findViewById(R.id.cfg80EC);
        mCfg80ED = viewcfgram.findViewById(R.id.cfg80ED);
        mCfg80EE = viewcfgram.findViewById(R.id.cfg80EE);
        mCfg80EF = viewcfgram.findViewById(R.id.cfg80EF);

        mCfg80F0 = viewcfgram.findViewById(R.id.cfg80F0);
        mCfg80F1 = viewcfgram.findViewById(R.id.cfg80F1);
        mCfg80F2 = viewcfgram.findViewById(R.id.cfg80F2);
        mCfg80F3 = viewcfgram.findViewById(R.id.cfg80F3);
        mCfg80F4 = viewcfgram.findViewById(R.id.cfg80F4);
        mCfg80F5 = viewcfgram.findViewById(R.id.cfg80F5);
        mCfg80F6 = viewcfgram.findViewById(R.id.cfg80F6);
        mCfg80F7 = viewcfgram.findViewById(R.id.cfg80F7);
        mCfg80F8 = viewcfgram.findViewById(R.id.cfg80F8);
        mCfg80F9 = viewcfgram.findViewById(R.id.cfg80F9);
        mCfg80FA = viewcfgram.findViewById(R.id.cfg80FA);
        mCfg80FB = viewcfgram.findViewById(R.id.cfg80FB);
        mCfg80FC = viewcfgram.findViewById(R.id.cfg80FC);
        mCfg80FD = viewcfgram.findViewById(R.id.cfg80FD);
        mCfg80FE = viewcfgram.findViewById(R.id.cfg80FE);
        mCfg80FF = viewcfgram.findViewById(R.id.cfg80FF);

        mCfg8100 = viewcfgram.findViewById(R.id.cfg8100);
        mCfg8101 = viewcfgram.findViewById(R.id.cfg8101);
        mCfg8102 = viewcfgram.findViewById(R.id.cfg8102);
        mCfg8103 = viewcfgram.findViewById(R.id.cfg8103);
        mCfg8104 = viewcfgram.findViewById(R.id.cfg8104);
        mCfg8105 = viewcfgram.findViewById(R.id.cfg8105);
        mCfg8106 = viewcfgram.findViewById(R.id.cfg8106);
        mCfg8107 = viewcfgram.findViewById(R.id.cfg8107);
        mCfg8108 = viewcfgram.findViewById(R.id.cfg8108);
        mCfg8109 = viewcfgram.findViewById(R.id.cfg8109);
        mCfg810A = viewcfgram.findViewById(R.id.cfg810A);
        mCfg810B = viewcfgram.findViewById(R.id.cfg810B);
        mCfg810C = viewcfgram.findViewById(R.id.cfg810C);
        mCfg810D = viewcfgram.findViewById(R.id.cfg810D);
        mCfg810E = viewcfgram.findViewById(R.id.cfg810E);
        mCfg810F = viewcfgram.findViewById(R.id.cfg810F);

        mCfg8110 = viewcfgram.findViewById(R.id.cfg8110);
        mCfg8111 = viewcfgram.findViewById(R.id.cfg8111);
        mCfg8112 = viewcfgram.findViewById(R.id.cfg8112);
        mCfg8113 = viewcfgram.findViewById(R.id.cfg8113);
        mCfg8114 = viewcfgram.findViewById(R.id.cfg8114);
        mCfg8115 = viewcfgram.findViewById(R.id.cfg8115);
        mCfg8116 = viewcfgram.findViewById(R.id.cfg8116);
        mCfg8117 = viewcfgram.findViewById(R.id.cfg8117);
        mCfg8118 = viewcfgram.findViewById(R.id.cfg8118);
        mCfg8119 = viewcfgram.findViewById(R.id.cfg8119);
        mCfg811A = viewcfgram.findViewById(R.id.cfg811A);
        mCfg811B = viewcfgram.findViewById(R.id.cfg811B);
        mCfg811C = viewcfgram.findViewById(R.id.cfg811C);
        mCfg811D = viewcfgram.findViewById(R.id.cfg811D);
        mCfg811E = viewcfgram.findViewById(R.id.cfg811E);
        mCfg811F = viewcfgram.findViewById(R.id.cfg811F);

        mCfg8120 = viewcfgram.findViewById(R.id.cfg8120);
        mCfg8121 = viewcfgram.findViewById(R.id.cfg8121);
        mCfg8122 = viewcfgram.findViewById(R.id.cfg8122);
        mCfg8123 = viewcfgram.findViewById(R.id.cfg8123);
        mCfg8124 = viewcfgram.findViewById(R.id.cfg8124);
        mCfg8125 = viewcfgram.findViewById(R.id.cfg8125);
        mCfg8126 = viewcfgram.findViewById(R.id.cfg8126);
        mCfg8127 = viewcfgram.findViewById(R.id.cfg8127);
        mCfg8128 = viewcfgram.findViewById(R.id.cfg8128);
        mCfg8129 = viewcfgram.findViewById(R.id.cfg8129);
        mCfg812A = viewcfgram.findViewById(R.id.cfg812A);
        mCfg812B = viewcfgram.findViewById(R.id.cfg812B);
        mCfg812C = viewcfgram.findViewById(R.id.cfg812C);
        mCfg812D = viewcfgram.findViewById(R.id.cfg812D);
        mCfg812E = viewcfgram.findViewById(R.id.cfg812E);
        mCfg812F = viewcfgram.findViewById(R.id.cfg812F);

        mCfg8130 = viewcfgram.findViewById(R.id.cfg8130);
        mCfg8131 = viewcfgram.findViewById(R.id.cfg8131);
        mCfg8132 = viewcfgram.findViewById(R.id.cfg8132);
        mCfg8133 = viewcfgram.findViewById(R.id.cfg8133);
        mCfg8134 = viewcfgram.findViewById(R.id.cfg8134);
        mCfg8135 = viewcfgram.findViewById(R.id.cfg8135);
        mCfg8136 = viewcfgram.findViewById(R.id.cfg8136);
        mCfg8137 = viewcfgram.findViewById(R.id.cfg8137);
        mCfg8138 = viewcfgram.findViewById(R.id.cfg8138);
        mCfg8139 = viewcfgram.findViewById(R.id.cfg8139);
        mCfg813A = viewcfgram.findViewById(R.id.cfg813A);
        mCfg813B = viewcfgram.findViewById(R.id.cfg813B);
        mCfg813C = viewcfgram.findViewById(R.id.cfg813C);
        mCfg813D = viewcfgram.findViewById(R.id.cfg813D);
        mCfg813E = viewcfgram.findViewById(R.id.cfg813E);
        mCfg813F = viewcfgram.findViewById(R.id.cfg813F);

        mCfg8140 = viewcfgram.findViewById(R.id.cfg8140);
        mCfg8141 = viewcfgram.findViewById(R.id.cfg8141);
        mCfg8142 = viewcfgram.findViewById(R.id.cfg8142);
        mCfg8143 = viewcfgram.findViewById(R.id.cfg8143);
        mCfg8144 = viewcfgram.findViewById(R.id.cfg8144);
        mCfg8145 = viewcfgram.findViewById(R.id.cfg8145);
        mCfg8146 = viewcfgram.findViewById(R.id.cfg8146);
        mCfg8147 = viewcfgram.findViewById(R.id.cfg8147);
        mCfg8148 = viewcfgram.findViewById(R.id.cfg8148);
        mCfg8149 = viewcfgram.findViewById(R.id.cfg8149);
        mCfg814A = viewcfgram.findViewById(R.id.cfg814A);
        mCfg814B = viewcfgram.findViewById(R.id.cfg814B);
        mCfg814C = viewcfgram.findViewById(R.id.cfg814C);
        mCfg814D = viewcfgram.findViewById(R.id.cfg814D);
        mCfg814E = viewcfgram.findViewById(R.id.cfg814E);
        mCfg814F = viewcfgram.findViewById(R.id.cfg814F);

        mCfg8150 = viewcfgram.findViewById(R.id.cfg8150);
        mCfg8151 = viewcfgram.findViewById(R.id.cfg8151);
        mCfg8152 = viewcfgram.findViewById(R.id.cfg8152);
        mCfg8153 = viewcfgram.findViewById(R.id.cfg8153);
        mCfg8154 = viewcfgram.findViewById(R.id.cfg8154);
        mCfg8155 = viewcfgram.findViewById(R.id.cfg8155);
        mCfg8156 = viewcfgram.findViewById(R.id.cfg8156);
        mCfg8157 = viewcfgram.findViewById(R.id.cfg8157);
        mCfg8158 = viewcfgram.findViewById(R.id.cfg8158);
        mCfg8159 = viewcfgram.findViewById(R.id.cfg8159);
        mCfg815A = viewcfgram.findViewById(R.id.cfg815A);
        mCfg815B = viewcfgram.findViewById(R.id.cfg815B);
        mCfg815C = viewcfgram.findViewById(R.id.cfg815C);
        mCfg815D = viewcfgram.findViewById(R.id.cfg815D);
        mCfg815E = viewcfgram.findViewById(R.id.cfg815E);
        mCfg815F = viewcfgram.findViewById(R.id.cfg815F);

        mCfg8160 = viewcfgram.findViewById(R.id.cfg8160);
        mCfg8161 = viewcfgram.findViewById(R.id.cfg8161);
        mCfg8162 = viewcfgram.findViewById(R.id.cfg8162);
        mCfg8163 = viewcfgram.findViewById(R.id.cfg8163);
        mCfg8164 = viewcfgram.findViewById(R.id.cfg8164);
        mCfg8165 = viewcfgram.findViewById(R.id.cfg8165);
        mCfg8166 = viewcfgram.findViewById(R.id.cfg8166);
        mCfg8167 = viewcfgram.findViewById(R.id.cfg8167);
        mCfg8168 = viewcfgram.findViewById(R.id.cfg8168);
        mCfg8169 = viewcfgram.findViewById(R.id.cfg8169);
        mCfg816A = viewcfgram.findViewById(R.id.cfg816A);
        mCfg816B = viewcfgram.findViewById(R.id.cfg816B);
        mCfg816C = viewcfgram.findViewById(R.id.cfg816C);
        mCfg816D = viewcfgram.findViewById(R.id.cfg816D);
        mCfg816E = viewcfgram.findViewById(R.id.cfg816E);
        mCfg816F = viewcfgram.findViewById(R.id.cfg816F);

        mCfg8170 = viewcfgram.findViewById(R.id.cfg8170);
        mCfg8171 = viewcfgram.findViewById(R.id.cfg8171);
        mCfg8172 = viewcfgram.findViewById(R.id.cfg8172);
        mCfg8173 = viewcfgram.findViewById(R.id.cfg8173);
        mCfg8174 = viewcfgram.findViewById(R.id.cfg8174);
        mCfg8175 = viewcfgram.findViewById(R.id.cfg8175);
        mCfg8176 = viewcfgram.findViewById(R.id.cfg8176);
        mCfg8177 = viewcfgram.findViewById(R.id.cfg8177);
        mCfg8178 = viewcfgram.findViewById(R.id.cfg8178);
        mCfg8179 = viewcfgram.findViewById(R.id.cfg8179);
        mCfg817A = viewcfgram.findViewById(R.id.cfg817A);
        mCfg817B = viewcfgram.findViewById(R.id.cfg817B);
        mCfg817C = viewcfgram.findViewById(R.id.cfg817C);
        mCfg817D = viewcfgram.findViewById(R.id.cfg817D);
        mCfg817E = viewcfgram.findViewById(R.id.cfg817E);
        mCfg817F = viewcfgram.findViewById(R.id.cfg817F);

        mCfg8180 = viewcfgram.findViewById(R.id.cfg8180);
        mCfg8181 = viewcfgram.findViewById(R.id.cfg8181);
        mCfg8182 = viewcfgram.findViewById(R.id.cfg8182);
        mCfg8183 = viewcfgram.findViewById(R.id.cfg8183);
        mCfg8184 = viewcfgram.findViewById(R.id.cfg8184);
        mCfg8185 = viewcfgram.findViewById(R.id.cfg8185);
        mCfg8186 = viewcfgram.findViewById(R.id.cfg8186);
        mCfg8187 = viewcfgram.findViewById(R.id.cfg8187);
        mCfg8188 = viewcfgram.findViewById(R.id.cfg8188);
        mCfg8189 = viewcfgram.findViewById(R.id.cfg8189);
        mCfg818A = viewcfgram.findViewById(R.id.cfg818A);
        mCfg818B = viewcfgram.findViewById(R.id.cfg818B);
        mCfg818C = viewcfgram.findViewById(R.id.cfg818C);
        mCfg818D = viewcfgram.findViewById(R.id.cfg818D);
        mCfg818E = viewcfgram.findViewById(R.id.cfg818E);
        mCfg818F = viewcfgram.findViewById(R.id.cfg818F);

        mCfg8190 = viewcfgram.findViewById(R.id.cfg8190);
        mCfg8191 = viewcfgram.findViewById(R.id.cfg8191);
        mCfg8192 = viewcfgram.findViewById(R.id.cfg8192);
        mCfg8193 = viewcfgram.findViewById(R.id.cfg8193);
        mCfg8194 = viewcfgram.findViewById(R.id.cfg8194);
        mCfg8195 = viewcfgram.findViewById(R.id.cfg8195);
        mCfg8196 = viewcfgram.findViewById(R.id.cfg8196);
        mCfg8197 = viewcfgram.findViewById(R.id.cfg8197);
        mCfg8198 = viewcfgram.findViewById(R.id.cfg8198);
        mCfg8199 = viewcfgram.findViewById(R.id.cfg8199);
        mCfg819A = viewcfgram.findViewById(R.id.cfg819A);
        mCfg819B = viewcfgram.findViewById(R.id.cfg819B);
        mCfg819C = viewcfgram.findViewById(R.id.cfg819C);
        mCfg819D = viewcfgram.findViewById(R.id.cfg819D);
        mCfg819E = viewcfgram.findViewById(R.id.cfg819E);
        mCfg819F = viewcfgram.findViewById(R.id.cfg819F);

        mCfg81A0 = viewcfgram.findViewById(R.id.cfg81A0);
        mCfg81A1 = viewcfgram.findViewById(R.id.cfg81A1);
        mCfg81A2 = viewcfgram.findViewById(R.id.cfg81A2);
        mCfg81A3 = viewcfgram.findViewById(R.id.cfg81A3);
        mCfg81A4 = viewcfgram.findViewById(R.id.cfg81A4);
        mCfg81A5 = viewcfgram.findViewById(R.id.cfg81A5);
        mCfg81A6 = viewcfgram.findViewById(R.id.cfg81A6);
        mCfg81A7 = viewcfgram.findViewById(R.id.cfg81A7);
        mCfg81A8 = viewcfgram.findViewById(R.id.cfg81A8);
        mCfg81A9 = viewcfgram.findViewById(R.id.cfg81A9);
        mCfg81AA = viewcfgram.findViewById(R.id.cfg81AA);
        mCfg81AB = viewcfgram.findViewById(R.id.cfg81AB);
        mCfg81AC = viewcfgram.findViewById(R.id.cfg81AC);
        mCfg81AD = viewcfgram.findViewById(R.id.cfg81AD);
        mCfg81AE = viewcfgram.findViewById(R.id.cfg81AE);
        mCfg81AF = viewcfgram.findViewById(R.id.cfg81AF);

        mCfg81B0 = viewcfgram.findViewById(R.id.cfg81B0);
        mCfg81B1 = viewcfgram.findViewById(R.id.cfg81B1);
        mCfg81B2 = viewcfgram.findViewById(R.id.cfg81B2);
        mCfg81B3 = viewcfgram.findViewById(R.id.cfg81B3);
        mCfg81B4 = viewcfgram.findViewById(R.id.cfg81B4);
        mCfg81B5 = viewcfgram.findViewById(R.id.cfg81B5);
        mCfg81B6 = viewcfgram.findViewById(R.id.cfg81B6);
        mCfg81B7 = viewcfgram.findViewById(R.id.cfg81B7);
        mCfg81B8 = viewcfgram.findViewById(R.id.cfg81B8);
        mCfg81B9 = viewcfgram.findViewById(R.id.cfg81B9);
        mCfg81BA = viewcfgram.findViewById(R.id.cfg81BA);
        mCfg81BB = viewcfgram.findViewById(R.id.cfg81BB);
        mCfg81BC = viewcfgram.findViewById(R.id.cfg81BC);
        mCfg81BD = viewcfgram.findViewById(R.id.cfg81BD);
        mCfg81BE = viewcfgram.findViewById(R.id.cfg81BE);
        mCfg81BF = viewcfgram.findViewById(R.id.cfg81BF);

        mCfg81C0 = viewcfgram.findViewById(R.id.cfg81C0);
        mCfg81C1 = viewcfgram.findViewById(R.id.cfg81C1);
        mCfg81C2 = viewcfgram.findViewById(R.id.cfg81C2);
        mCfg81C3 = viewcfgram.findViewById(R.id.cfg81C3);
        mCfg81C4 = viewcfgram.findViewById(R.id.cfg81C4);
        mCfg81C5 = viewcfgram.findViewById(R.id.cfg81C5);
        mCfg81C6 = viewcfgram.findViewById(R.id.cfg81C6);
        mCfg81C7 = viewcfgram.findViewById(R.id.cfg81C7);
        mCfg81C8 = viewcfgram.findViewById(R.id.cfg81C8);
        mCfg81C9 = viewcfgram.findViewById(R.id.cfg81C9);
        mCfg81CA = viewcfgram.findViewById(R.id.cfg81CA);
        mCfg81CB = viewcfgram.findViewById(R.id.cfg81CB);
        mCfg81CC = viewcfgram.findViewById(R.id.cfg81CC);
        mCfg81CD = viewcfgram.findViewById(R.id.cfg81CD);
        mCfg81CE = viewcfgram.findViewById(R.id.cfg81CE);
        mCfg81CF = viewcfgram.findViewById(R.id.cfg81CF);

        mCfg81D0 = viewcfgram.findViewById(R.id.cfg81D0);
        mCfg81D1 = viewcfgram.findViewById(R.id.cfg81D1);
        mCfg81D2 = viewcfgram.findViewById(R.id.cfg81D2);
        mCfg81D3 = viewcfgram.findViewById(R.id.cfg81D3);
        mCfg81D4 = viewcfgram.findViewById(R.id.cfg81D4);
        mCfg81D5 = viewcfgram.findViewById(R.id.cfg81D5);
        mCfg81D6 = viewcfgram.findViewById(R.id.cfg81D6);
        mCfg81D7 = viewcfgram.findViewById(R.id.cfg81D7);
        mCfg81D8 = viewcfgram.findViewById(R.id.cfg81D8);
        mCfg81D9 = viewcfgram.findViewById(R.id.cfg81D9);
        mCfg81DA = viewcfgram.findViewById(R.id.cfg81DA);
        mCfg81DB = viewcfgram.findViewById(R.id.cfg81DB);
        mCfg81DC = viewcfgram.findViewById(R.id.cfg81DC);
        mCfg81DD = viewcfgram.findViewById(R.id.cfg81DD);
        mCfg81DE = viewcfgram.findViewById(R.id.cfg81DE);
        mCfg81DF = viewcfgram.findViewById(R.id.cfg81DF);

        mCfg81E0 = viewcfgram.findViewById(R.id.cfg81E0);
        mCfg81E1 = viewcfgram.findViewById(R.id.cfg81E1);
        mCfg81E2 = viewcfgram.findViewById(R.id.cfg81E2);
        mCfg81E3 = viewcfgram.findViewById(R.id.cfg81E3);
        mCfg81E4 = viewcfgram.findViewById(R.id.cfg81E4);
        mCfg81E5 = viewcfgram.findViewById(R.id.cfg81E5);
        mCfg81E6 = viewcfgram.findViewById(R.id.cfg81E6);
        mCfg81E7 = viewcfgram.findViewById(R.id.cfg81E7);
        mCfg81E8 = viewcfgram.findViewById(R.id.cfg81E8);
        mCfg81E9 = viewcfgram.findViewById(R.id.cfg81E9);
        mCfg81EA = viewcfgram.findViewById(R.id.cfg81EA);
        mCfg81EB = viewcfgram.findViewById(R.id.cfg81EB);
        mCfg81EC = viewcfgram.findViewById(R.id.cfg81EC);
        mCfg81ED = viewcfgram.findViewById(R.id.cfg81ED);
        mCfg81EE = viewcfgram.findViewById(R.id.cfg81EE);
        mCfg81EF = viewcfgram.findViewById(R.id.cfg81EF);

        mCfg81F0 = viewcfgram.findViewById(R.id.cfg81F0);
        mCfg81F1 = viewcfgram.findViewById(R.id.cfg81F1);
        mCfg81F2 = viewcfgram.findViewById(R.id.cfg81F2);
        mCfg81F3 = viewcfgram.findViewById(R.id.cfg81F3);
        mCfg81F4 = viewcfgram.findViewById(R.id.cfg81F4);
        mCfg81F5 = viewcfgram.findViewById(R.id.cfg81F5);
        mCfg81F6 = viewcfgram.findViewById(R.id.cfg81F6);
        mCfg81F7 = viewcfgram.findViewById(R.id.cfg81F7);
        mCfg81F8 = viewcfgram.findViewById(R.id.cfg81F8);
        mCfg81F9 = viewcfgram.findViewById(R.id.cfg81F9);
        mCfg81FA = viewcfgram.findViewById(R.id.cfg81FA);
        mCfg81FB = viewcfgram.findViewById(R.id.cfg81FB);
        mCfg81FC = viewcfgram.findViewById(R.id.cfg81FC);
        mCfg81FD = viewcfgram.findViewById(R.id.cfg81FD);
        mCfg81FE = viewcfgram.findViewById(R.id.cfg81FE);
        mCfg81FF = viewcfgram.findViewById(R.id.cfg81FF);

        mCfg8200 = viewcfgram.findViewById(R.id.cfg8200);
        mCfg8201 = viewcfgram.findViewById(R.id.cfg8201);
        mCfg8202 = viewcfgram.findViewById(R.id.cfg8202);
        mCfg8203 = viewcfgram.findViewById(R.id.cfg8203);
        mCfg8204 = viewcfgram.findViewById(R.id.cfg8204);
        mCfg8205 = viewcfgram.findViewById(R.id.cfg8205);
        mCfg8206 = viewcfgram.findViewById(R.id.cfg8206);
        mCfg8207 = viewcfgram.findViewById(R.id.cfg8207);
        mCfg8208 = viewcfgram.findViewById(R.id.cfg8208);
        mCfg8209 = viewcfgram.findViewById(R.id.cfg8209);
        mCfg820A = viewcfgram.findViewById(R.id.cfg820A);
        mCfg820B = viewcfgram.findViewById(R.id.cfg820B);

    }
    //===============================各view中的元素初始化结束===============================================//
    /*
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        switch (parent.getId()){
            case R.id.pgagainspin:
                if(PGAGainSelected){
                    Toast.makeText(mContext,"您的选择是：" + parent.getItemAtPosition(position).toString(),
                            Toast.LENGTH_SHORT).show();
                }else PGAGainSelected = true;
                break;

           default:
                break;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
    */
    /*
    public List<String> loadFile(String fileName){
        List<String> lists = new ArrayList<>();
        try {
            File file = new File(fileName);
            InputStream instream = new FileInputStream(file);
            if (instream != null) {
                InputStreamReader inputreader
                        = new InputStreamReader(instream, "UTF-8");//UTF-8
                BufferedReader buffreader = new BufferedReader(inputreader);
                String line = "";
                while ((line = buffreader.readLine()) != null) {
                    lists.add(line);
                }
                instream.close();
                edit_search.setText(buffreader.toString()); //buffer.toString())就是读出的内容字符
            }
        } catch (Exception e) {
            edit_search.setText(getResources().getString(R.string.invalidfile));
        }
        return lists;
    }
    */

    protected void onActivityResult ( int requestCode, int resultCode, Intent data){
        if (resultCode == Activity.RESULT_OK) {

            int permission_write = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
            int permission_read = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.READ_EXTERNAL_STORAGE);

            if ((permission_write != PackageManager.PERMISSION_GRANTED)
                ||(permission_read != PackageManager.PERMISSION_GRANTED))
            {

                ActivityCompat.requestPermissions(Config.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        android.Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
            }

            StringBuffer buffer = new StringBuffer();
            String configString = "";
            Uri uri = data.getData();
            String fileString = "";
            if (requestCode == 1) {  //U 盘 文 件

                byte[] filebuffer;
                int len;
                try {

                    //String fileString = "";
                    File storage = new File("/storage");
                    File[] files = storage.listFiles();
                    for (final File file : files) {
                        if (file.canRead()) {
                            if (!file.getName().equals(Environment.getExternalStorageDirectory().getName())) {
                                //满足该条件的文件夹就是u盘在手机上的目录
                                fileString = (file.getPath()+"/GTxxxx_wingcool_config.cfg");
                                fileString = fileString.replaceAll(":", "/");  //将:改为/，以防某些系统文件目录读出是:
                                edit_search.setText(fileString);
                            }
                        }
                    }

                    buffer = new StringBuffer();
                    //String storageState = Environment.getExternalStorageState();
                    //if (storageState.equals(Environment.MEDIA_MOUNTED)) {
                        FileInputStream fileInputStream = new FileInputStream(fileString);
                        filebuffer = new byte[1024];
                        len = fileInputStream.read(filebuffer);
                        while (len > 0) {
                            buffer.append(new String(filebuffer, 0, len));
                            len = fileInputStream.read(filebuffer);
                        }
                        fileInputStream.close();
                    //}

                    configString = buffer.toString();

                } catch (IOException ex) {
                    edit_search.setText(uri.getPath() + "——" + getResources().getString(R.string.invalidfile));
                    return;
                }
            }  //end of if (requestCode == 1)
            else if (requestCode == 2) {  //本 地 文 件

                try {
                    File dir = Environment.getExternalStorageDirectory();
                    //Uri uri = data.getData();
                    File dataFile;

                    fileString = dir.getPath() + "/";

                    if (uri.getLastPathSegment().indexOf(":") > 0){
                        String[] stringFileNameArr = uri.getLastPathSegment().split(":");
                        fileString += stringFileNameArr[1];
                    }else{
                        fileString += uri.getLastPathSegment();
                    }

                    //fileString = dir.getPath() + "/" + uri.getLastPathSegment();
                    //edit_search.setText(dir.getPath() + "/GTxxxx_wingcool_config.cfg");


                    //fileString = fileString.replaceAll(":", "/");  //将:改为/，以防某些系统文件目录读出是:
                    edit_search.setText(fileString);

                    //File dir = Environment.getExternalStorageDirectory();
                    //dataFile = new File(dir.getPath(), "GTxxxx_wingcool_config.cfg");
                    dataFile = new File(fileString);

                    FileInputStream fis = new FileInputStream(dataFile);
                    //byte[] bytes = new byte[fis.available()];
                    //fis.read(bytes);
                    //fis.close();
                    //String str = new String(bytes,"utf-8");
                    //edit_search.setText(str);

                    //FileInputStream fis = new FileInputStream(uri.getPath().toString());
                    InputStreamReader isr = new InputStreamReader(fis, "UTF-8");//文件编码Unicode,UTF-8,ASCII,GB2312,Big5
                    Reader in = new BufferedReader(isr);
                    int ch;
                    while ((ch = in.read()) > -1) {
                        buffer.append((char) ch);
                    }
                    in.close();

                    configString = buffer.toString();

                } catch (IOException c) {
                    edit_search.setText(uri.getPath() + "——" + getResources().getString(R.string.invalidfile));
                    return;
                }
            }  //end of else if (requestCode == 2)

    /*
                Uri uri = data.getData();
                File file = new File(uri.getPath());

                edit_search.setText(uri.getPath().toString());
                //loadFile(uri.getPath().toString());
                ActivityCompat.requestPermissions(  Config.this, new String[]{android
                        .Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);


                String str = null;
                try {
                    InputStream is = new FileInputStream(file);
                    InputStreamReader input = new InputStreamReader(is, "UTF-8");
                    BufferedReader reader = new BufferedReader(input);
                    while ((str = reader.readLine()) != null) {
                        edit_search.setText(str);
                    }

                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    //e.printStackTrace();
                    edit_search.setText(getResources().getString(R.string.invalidfile));
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    */
    /*
                Uri uri = data.getData();
                File file = new File(uri.getPath());

                edit_search.setText(uri.getPath().toString());

                ActivityCompat.requestPermissions(  Config.this, new String[]{android
                        .Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);

                loadFile(uri.getPath().toString());
    */
            edtConfigDataShow.setText(configString);
    /*
            //value = value.trim();  //去除空格
            configString = configString.replaceAll("0x", ""); //0x转换为没有
            //editdetail.setText(configString.toString()); //buffer.toString())就是读出的内容字符

            String[] stringCfgArr = configString.split(",");
            //byte bcfgarr[] = new byte[188];

            int i;
            for (i = 0; i < 186; i++){
                mBytes[i] = (byte) Integer.parseInt(stringCfgArr[i], 16);
            }
            if (byProductType == GT7) {
                for (; i < 444; i++) {
                    mBytes[i] = (byte) Integer.parseInt(stringCfgArr[i], 16);
                }
            }

            if (byProductType == GT9) {
                ReadCfgSample(mBytes);
                ReadCfgModuleSwitch(mBytes);
                ReadCfgNormalSetting(mBytes);
                ReadCfgChannelSetting(mBytes);
                ReadCfgPenSetting(mBytes);
                ReadCfgPlamRestrain(mBytes);
                ReadCfgKeySetting(mBytes);
                ReadCfgHoppingSetting(mBytes);
            }

            ReadCfgRam(stringCfgArr);
    */

        }  //end of if (resultCode == Activity.RESULT_OK)
    }

    private void initListener() {
        mReadCfg.setOnClickListener(this);
        mSendCfg.setOnClickListener(this);
    }

    private void initData() {
        mContext = getApplicationContext();
        mReadCfg.setEnabled(false);    //

        mSendCfg.setEnabled(false);

        mThreadPool = Executors.newFixedThreadPool(5);

        mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    }

    /**
     * 打开设备 , 让车机和手机端连起来
     */
    private void openDevices() {

        //列举设备(手机)
        cfgOpenDevicesReceiver = new OpenDevicesReceiver(this);
        mThreadPool.execute(new Runnable() {
            @Override
            public void run() {
            SystemClock.sleep(1000);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
            IntentFilter intentFilter = new IntentFilter(USB_ACTION);

            registerReceiver(cfgOpenDevicesReceiver, intentFilter);
        while(isNeedFindDevice) {
            SystemClock.sleep(100);
            HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
            if (deviceList != null) {
                for (UsbDevice usbDevice : deviceList.values()) {
                    //int productId = usbDevice.getProductId();
                    int vendorId = usbDevice.getVendorId();
                    if ((vendorId == 0x27C0)          //之前VID错误了，做兼容
                            ||(vendorId == 0x27C6)    //汇顶的VID
                            ||(vendorId == 0x222A)    //奕力的VID
                            ||(vendorId == 0x056A))   //8191主动笔和Wacom主动笔
                    {
                        //这里说明下,这里的377 , 7205是我这台机子上独有,因为我这上面有多台设备,所以我在这里
                        //判断了下.只有一台设备的无需这一步.
                        //mUsbManager.requestPermission(usbDevice, pendingIntent);
                        //SystemClock.sleep(100);
                        if (mUsbManager.hasPermission(usbDevice)) {
                                    initDevice();

                                } else {
                                    mUsbManager.requestPermission(usbDevice, pendingIntent);
                                    break;
                                }
                                break;
                            }
                        }
                    } else {
                        //mError.setText("请连接USB");
                    }
                    // }
                }
            }   //ThreadPool
        });   //ThreadPool
    }

    /**
     * 初始化设备(手机) , 当手机进入Accessory模式后 , 手机的PID会变为Google定义的2个常量值其中的一个 ,
     */
    private void initDevice() {

        HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
        Collection<UsbDevice> values = deviceList.values();
        if (!values.isEmpty()) {
            for (UsbDevice usbDevice : values) {
                //int productId = usbDevice.getProductId();
                int vendorId = usbDevice.getVendorId();
                //if (productId == 0x0818 || productId == 0x0001 )
                if ((vendorId == 0x27C0)          //之前VID错误了，做兼容
                        ||(vendorId == 0x27C6)    //汇顶的VID
                        ||(vendorId == 0x222A)    //奕力的VID
                        ||(vendorId == 0x056A))   //8191主动笔和Wacom主动笔
                {
                    if (mUsbManager.hasPermission(usbDevice)) {

                        UsbInterface usbInterface = usbDevice.getInterface(1);

                        for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
                            UsbEndpoint ep = usbInterface.getEndpoint(i);

                            if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
                                //mUsbEndpointIn = ep;
                                mUsbEndpointOut = ep;
                            } else {
                                //mUsbEndpointOut = ep;
                                mUsbEndpointIn = ep;
                            }
                        }

                        if ((null == mUsbEndpointIn) || (null == mUsbEndpointOut)) {
                            mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
                            if (mUsbDeviceConnection!=null) {
                                int i = mUsbDeviceConnection.controlTransfer(0x00, 0x09,
                                        0x002, 0, null, 0, 100);
                                SystemClock.sleep(1000);
                                if (i >= 0) {
                                    //mHandler.sendEmptyMessage(DEBUG_MESSAGE_SUCCESS);
                                } else {
                                    //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
                                }
                            }
                        } else {
                            isNeedFindDevice = false;
                            mUsbInterface = usbInterface;
                            mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
                            mUsbDeviceConnection.claimInterface(mUsbInterface, true);
                            if(null != mUsbEndpointIn){
                                iProductId = usbDevice.getProductId();
                                if ((iProductId == 0x0819) || (iProductId == 0x8191) || (iProductId == 0x0528) )
                                {
                                    byProductType = GT7;
                                }
                                else{
                                    byProductType = GT9;
                                }
                                mHandler.sendEmptyMessage(CONNECTED_SUCCESS);
                            }


                        }
                    } else {
                        mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, new Intent(""), 0));
                    }
                }
            }
        } else {
            // finish();
        }
    }

    //=====================================读取CFG到各个View开始===================================//
    public void ReadCfgSample(byte[] mBytes){
        int temp;

        cbAllDrivingEn.setChecked(false);
        if ((mBytes[27] & 0x80) == 0x80){
            cbAllDrivingEn.setChecked(true);
        }
        cbDualFreq.setChecked(false);
        if ((mBytes[28] & 0x20) == 0x20){
            cbDualFreq.setChecked(true);
        }
        edtFreqAFactor.setText(Integer.toString(mBytes[30] & 0xFF));
        edtFreqBFactor.setText(Integer.toString(mBytes[31] & 0xFF));

        temp = (int)((mBytes[32] & 0xFF) + mBytes[33] * 256);
        edtPannelBitFreq.setText(Integer.toString(temp & 0xFFFF));

        //edtDuration
        spinDACGain.setSelection(mBytes[36] & 0x07);
        spinDrvOutputR.setSelection((mBytes[36] & 0x18) >> 3);
        spinPGAGain.setSelection(mBytes[37] & 0x07);
        spinRxVcmi.setSelection((mBytes[37] & 0x18) >> 3);
        spinPGAR.setSelection((mBytes[37] & 0x60) >> 5);
        spinPGAC.setSelection((mBytes[37] & 0x80) >> 7);
        edtDumpShift.setText(Integer.toString(mBytes[38] & 0x0F));
        edtSubFrameDrvNum.setText(Integer.toString((mBytes[39] & 0x7C) >> 2));
        spinVoltage.setSelection(mBytes[92] & 0x07);
        spinBoostTime.setSelection((mBytes[92] & 0x70) >> 4);
        cbExtoscen.setChecked(false);
        if ((mBytes[93] & 0x80) == 0x80){
            cbExtoscen.setChecked(true);
        }
        spinAlterCount.setSelection(mBytes[94] & 0x03);
    }

    public void ReadCfgModuleSwitch(byte[] mBytes){
        cbSito.setChecked(false);
        if ((mBytes[6] & 0x04) == 0x04){
            cbSito.setChecked(true);
        }
        cbX2Y.setChecked(false);
        if ((mBytes[6] & 0x08) == 0x08){
            cbX2Y.setChecked(true);
        }

        spinInterrupt.setSelection(mBytes[6] & 0x03);
        spinStretchRank.setSelection((mBytes[6] & 0x30) >> 4);

        cbDiffDivideBy2or4.setChecked(false);
        if ((mBytes[7] & 0x04) == 0x04){
            cbDiffDivideBy2or4.setChecked(true);
        }
        cbFirstFilterDis.setChecked(false);
        if ((mBytes[7] & 0x20) == 0x20){
            cbFirstFilterDis.setChecked(true);
        }
        cbMonitorConsistencyConflictEn.setChecked(false);
        if ((mBytes[7] & 0x40) == 0x40){
            cbMonitorConsistencyConflictEn.setChecked(true);
        }
        cbWaterSpeedLimitEn.setChecked(false);
        if ((mBytes[91] & 0x01) == 0x01){
            cbWaterSpeedLimitEn.setChecked(true);
        }
        cbShapeEn.setChecked(false);
        if ((mBytes[91] & 0x04) == 0x04){
            cbShapeEn.setChecked(true);
        }
        cbWaterProofDis.setChecked(false);
        if ((mBytes[91] & 0x08) == 0x08){
            cbWaterProofDis.setChecked(true);
        }
        cbLcdPlusMinusEn.setChecked(false);
        if ((mBytes[91] & 0x10) == 0x10){
            cbLcdPlusMinusEn.setChecked(true);
        }
        cbX2X.setChecked(false);
        if ((mBytes[104] & 0x01) == 0x01){
            cbX2X.setChecked(true);
        }
        cbY2Y.setChecked(false);
        if ((mBytes[104] & 0x02) == 0x02){
            cbY2Y.setChecked(true);
        }
        cbESDEn.setChecked(false);
        if ((mBytes[104] & 0x10) == 0x10){
            cbESDEn.setChecked(true);
        }
        cbINTWakeup.setChecked(false);
        if ((mBytes[104] & 0x20) == 0x20){
            cbINTWakeup.setChecked(true);
        }
    }

    public void ReadCfgNormalSetting(byte[] mBytes){
        String hv;
        edtConfigVersion.setText(Integer.toString(mBytes[0] & 0xFF));
        edtTouchNumber.setText(Integer.toString(mBytes[5] & 0x0F));

        hv = Integer.toHexString(mBytes[8] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtShakeCnt.setText(hv);

        edtNormalFilter.setText(Integer.toString(mBytes[9] & 0x3F));
        edtFirstFilter.setText(Integer.toString((mBytes[9] & 0xFF) >> 6));
        edtNoiseReduction.setText(Integer.toString(mBytes[11] & 0x0F));
        edtScreenTouchLv.setText(Integer.toString(mBytes[12] & 0xFF));
        edtScreenLeaveLv.setText(Integer.toString(mBytes[13] & 0xFF));
        edtLowPowerControl.setText(Integer.toString(mBytes[14] & 0x0F));
        spinRefreshRate.setSelection(mBytes[15] & 0x0F);
        edtXThreshold.setText(Integer.toString(mBytes[16] & 0xFF));
        edtYThreshold.setText(Integer.toString(mBytes[17] & 0xFF));

        hv = Integer.toHexString(mBytes[20] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtSpaceUpDown.setText(hv);
        hv = Integer.toHexString(mBytes[21] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtSpaceLeftRight.setText(hv);

        edtMiniFilter.setText(Integer.toString(mBytes[22] & 0x0F));
        edtStretchR0.setText(Integer.toString(mBytes[23] & 0xFF));
        edtStretchR1.setText(Integer.toString(mBytes[24] & 0xFF));
        edtStretchR2.setText(Integer.toString(mBytes[25] & 0xFF));
        edtStretchRM.setText(Integer.toString(mBytes[26] & 0xFF));
        edtChargingLevelUp.setText(Integer.toString(mBytes[49] & 0xFF));
        edtLcdPlusMinusValue.setText(Integer.toString(mBytes[58] & 0xFF));
        edtShapeRestrain.setText(Integer.toString(mBytes[87] & 0x7F));
        edtConThreshold.setText(Integer.toString(mBytes[88] & 0xFF));
        edtWaterFrameTime.setText(Integer.toString(mBytes[89] & 0xFF));
        edtWaterUpdateTime.setText(Integer.toString(mBytes[90] & 0xFF));
        edtSlideInEdgeConfig.setText(Integer.toString(mBytes[96] & 0xFF));
        edtSlideOutEdgeConfig.setText(Integer.toString(mBytes[97] & 0xFF));
        edtShapeContrl.setText(Integer.toString(mBytes[105] & 0x1F));

        hv = Integer.toHexString(mBytes[106] & 0x0F);
        hv = "0" + hv;
        edtCombineDis.setText(hv);
        hv = Integer.toHexString(mBytes[107] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtSplitSet.setText(hv);

        edtSitoDiffRefLevel.setText(Integer.toString(mBytes[110] & 0xFF));
    }

    public void ReadCfgChannelSetting(byte[] mBytes){
        int temp;

        temp = (int)((mBytes[1] & 0xFF) + mBytes[2] * 256);
        edtXOutputMax.setText(Integer.toString(temp & 0xFFFF));
        temp = (int)((mBytes[3] & 0xFF) + mBytes[4] * 256);
        edtYOutputMax.setText(Integer.toString(temp & 0xFFFF));

        edtDrvGroupAnumber.setText(Integer.toString(mBytes[27] & 0x1F));
        edtDrvGroupBnumber.setText(Integer.toString(mBytes[28] & 0x1F));
        bDriverNumber = (byte)((mBytes[27] & 0x1F) + (mBytes[28] & 0x1F));

        edtSenGroupANumber.setText(Integer.toString(mBytes[29] & 0x0F));
        edtSenGroupBNumber.setText(Integer.toString((mBytes[29] & 0xF0) >> 4));
        bSensorNumber = (byte)((mBytes[29] & 0x0F) + ((mBytes[29] & 0xF0) >> 4));

        edtSensorCH0.setText(Integer.toString(mBytes[112] & 0xFF));
        edtSensorCH1.setText(Integer.toString(mBytes[113] & 0xFF));
        edtSensorCH2.setText(Integer.toString(mBytes[114] & 0xFF));
        edtSensorCH3.setText(Integer.toString(mBytes[115] & 0xFF));
        edtSensorCH4.setText(Integer.toString(mBytes[116] & 0xFF));
        edtSensorCH5.setText(Integer.toString(mBytes[117] & 0xFF));
        edtSensorCH6.setText(Integer.toString(mBytes[118] & 0xFF));
        edtSensorCH7.setText(Integer.toString(mBytes[119] & 0xFF));
        edtSensorCH8.setText(Integer.toString(mBytes[120] & 0xFF));
        edtSensorCH9.setText(Integer.toString(mBytes[121] & 0xFF));
        edtSensorCH10.setText(Integer.toString(mBytes[122] & 0xFF));
        edtSensorCH11.setText(Integer.toString(mBytes[123] & 0xFF));
        edtSensorCH12.setText(Integer.toString(mBytes[124] & 0xFF));
        edtSensorCH13.setText(Integer.toString(mBytes[125] & 0xFF));
        edtSensorCH14.setText(Integer.toString(mBytes[126] & 0xFF));
        edtSensorCH15.setText(Integer.toString(mBytes[127] & 0xFF));
        edtSensorCH16.setText(Integer.toString(mBytes[128] & 0xFF));
        edtSensorCH17.setText(Integer.toString(mBytes[129] & 0xFF));
        edtSensorCH18.setText(Integer.toString(mBytes[130] & 0xFF));
        edtSensorCH19.setText(Integer.toString(mBytes[131] & 0xFF));
        edtSensorCH20.setText(Integer.toString(mBytes[132] & 0xFF));
        edtSensorCH21.setText(Integer.toString(mBytes[133] & 0xFF));
        edtSensorCH22.setText(Integer.toString(mBytes[134] & 0xFF));
        edtSensorCH23.setText(Integer.toString(mBytes[135] & 0xFF));
        edtSensorCH24.setText(Integer.toString(mBytes[136] & 0xFF));
        edtSensorCH25.setText(Integer.toString(mBytes[137] & 0xFF));
        edtSensorCH26.setText(Integer.toString(mBytes[138] & 0xFF));
        edtSensorCH27.setText(Integer.toString(mBytes[139] & 0xFF));
        edtSensorCH28.setText(Integer.toString(mBytes[140] & 0xFF));
        edtSensorCH29.setText(Integer.toString(mBytes[141] & 0xFF));

        edtDriverCH0.setText(Integer.toString(mBytes[142] & 0xFF));
        edtDriverCH1.setText(Integer.toString(mBytes[143] & 0xFF));
        edtDriverCH2.setText(Integer.toString(mBytes[144] & 0xFF));
        edtDriverCH3.setText(Integer.toString(mBytes[145] & 0xFF));
        edtDriverCH4.setText(Integer.toString(mBytes[146] & 0xFF));
        edtDriverCH5.setText(Integer.toString(mBytes[147] & 0xFF));
        edtDriverCH6.setText(Integer.toString(mBytes[148] & 0xFF));
        edtDriverCH7.setText(Integer.toString(mBytes[149] & 0xFF));
        edtDriverCH8.setText(Integer.toString(mBytes[150] & 0xFF));
        edtDriverCH9.setText(Integer.toString(mBytes[151] & 0xFF));
        edtDriverCH10.setText(Integer.toString(mBytes[152] & 0xFF));
        edtDriverCH11.setText(Integer.toString(mBytes[153] & 0xFF));
        edtDriverCH12.setText(Integer.toString(mBytes[154] & 0xFF));
        edtDriverCH13.setText(Integer.toString(mBytes[155] & 0xFF));
        edtDriverCH14.setText(Integer.toString(mBytes[156] & 0xFF));
        edtDriverCH15.setText(Integer.toString(mBytes[157] & 0xFF));
        edtDriverCH16.setText(Integer.toString(mBytes[158] & 0xFF));
        edtDriverCH17.setText(Integer.toString(mBytes[159] & 0xFF));
        edtDriverCH18.setText(Integer.toString(mBytes[160] & 0xFF));
        edtDriverCH19.setText(Integer.toString(mBytes[161] & 0xFF));
        edtDriverCH20.setText(Integer.toString(mBytes[162] & 0xFF));
        edtDriverCH21.setText(Integer.toString(mBytes[163] & 0xFF));
        edtDriverCH22.setText(Integer.toString(mBytes[164] & 0xFF));
        edtDriverCH23.setText(Integer.toString(mBytes[165] & 0xFF));
        edtDriverCH24.setText(Integer.toString(mBytes[166] & 0xFF));
        edtDriverCH25.setText(Integer.toString(mBytes[167] & 0xFF));
        edtDriverCH26.setText(Integer.toString(mBytes[168] & 0xFF));
        edtDriverCH27.setText(Integer.toString(mBytes[169] & 0xFF));
        edtDriverCH28.setText(Integer.toString(mBytes[170] & 0xFF));
        edtDriverCH29.setText(Integer.toString(mBytes[171] & 0xFF));
        edtDriverCH30.setText(Integer.toString(mBytes[172] & 0xFF));
        edtDriverCH31.setText(Integer.toString(mBytes[173] & 0xFF));
        edtDriverCH32.setText(Integer.toString(mBytes[174] & 0xFF));
        edtDriverCH33.setText(Integer.toString(mBytes[175] & 0xFF));
        edtDriverCH34.setText(Integer.toString(mBytes[176] & 0xFF));
        edtDriverCH35.setText(Integer.toString(mBytes[177] & 0xFF));
        edtDriverCH36.setText(Integer.toString(mBytes[178] & 0xFF));
        edtDriverCH37.setText(Integer.toString(mBytes[179] & 0xFF));
        edtDriverCH38.setText(Integer.toString(mBytes[180] & 0xFF));
        edtDriverCH39.setText(Integer.toString(mBytes[181] & 0xFF));
        edtDriverCH40.setText(Integer.toString(mBytes[182] & 0xFF));
        edtDriverCH41.setText(Integer.toString(mBytes[183] & 0xFF));
    }

    public void ReadCfgPenSetting(byte[] mBytes){
        cbPenEn.setChecked(false);
        if ((mBytes[7] & 0x02) == 2){
            cbPenEn.setChecked(true);
        }
        cbOnlyFingerEn.setChecked(false);
        if ((mBytes[7] & 0x08) == 8){
            cbOnlyFingerEn.setChecked(true);
        }
        edtPenLowSize.setText(Integer.toString(mBytes[40] & 0xFF));
        edtPenHighSize.setText(Integer.toString(mBytes[41] & 0xFF));
        edtRectsumPLowL.setText(Integer.toString(mBytes[42] & 0xFF));
        edtRectsumPHighL.setText(Integer.toString(mBytes[43] & 0xFF));
        edtRectsumFLowL.setText(Integer.toString(mBytes[44] & 0xFF));
        edtPRectMaxDiffLimit.setText(Integer.toString(mBytes[45] & 0xFF));
        edtPRectAreaLimit.setText(Integer.toString(mBytes[46] & 0xFF));
        spinFingerRestrainPen.setSelection((mBytes[104] & 0xC0) >> 6);
        edtFLeavelevel.setText(Integer.toString(mBytes[108] & 0xFF));
        edtPTouchHighlevel.setText(Integer.toString(mBytes[111] & 0xFF));
    }

    public void ReadCfgPlamRestrain(byte[] mBytes){
        cbAllPlamRestrain.setChecked(false);
        if ((mBytes[6] & 0x40) == 0x40){
            cbAllPlamRestrain.setChecked(true);
        }

        edtLargeTouch.setText(Integer.toString(mBytes[10] & 0xFF));
        edtExpanNumOutX.setText(Integer.toString((mBytes[34] & 0xF0) >> 4));
        edtExpanNumOutY.setText(Integer.toString(mBytes[34] & 0x0F));
        edtExpanNumInX.setText(Integer.toString((mBytes[35] & 0xF0) >> 4));
        edtExpanNumInY.setText(Integer.toString(mBytes[35] & 0x0F));
        edtSingleRectTopSignNum.setText(Integer.toString(mBytes[47] & 0xFF));
        edtAllRectTopSignSum.setText(Integer.toString(mBytes[48] & 0xFF));

        cbWaterLargeRestrainEn.setChecked(false);
        if ((mBytes[91] & 0x02) == 0x02){
            cbWaterLargeRestrainEn.setChecked(true);
        }
    }

    public void ReadCfgKeySetting(byte[] mBytes){
        String hv;

        cbTouchKey.setChecked(false);
        if ((mBytes[7] & 0x01) == 1){
            cbTouchKey.setChecked(true);
        }

        hv = Integer.toHexString(mBytes[80] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKeyArea.setText(hv);

        hv = Integer.toHexString(mBytes[76] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKey1.setText(hv);

        hv = Integer.toHexString(mBytes[77] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKey2.setText(hv);

        hv = Integer.toHexString(mBytes[78] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKey3.setText(hv);

        hv = Integer.toHexString(mBytes[79] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKey4.setText(hv);

        hv = Integer.toHexString(mBytes[81] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKeyTouchLevel.setText(hv);

        hv = Integer.toHexString(mBytes[82] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKeyLeaveLevel.setText(hv);

        hv = Integer.toHexString(mBytes[83] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKeySens1and2.setText(hv);

        hv = Integer.toHexString(mBytes[84] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKeySens3and4.setText(hv);

        hv = Integer.toHexString(mBytes[85] & 0xFF);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKeyRestrain.setText(hv);

        hv = Integer.toHexString(mBytes[86] & 0x0F);
        if (hv.length() < 2){
            hv = "0" + hv;
        }
        edtKeyRestrainTime.setText(hv);
    }

    public void ReadCfgHoppingSetting(byte[] mBytes){
        edtFreqStart.setText(Integer.toString(mBytes[51] & 0xFF));
        edtFreqEnd.setText(Integer.toString(mBytes[52] & 0xFF));
        edtDetectStayTimes.setText(Integer.toString((mBytes[53] & 0xC0) >> 6));
        edtDetectConfirmTimes.setText(Integer.toString(mBytes[53] & 0x3F));

        cbHoppingEn.setChecked(false);
        if ((mBytes[54] & 0x80) == 0x80){
            cbHoppingEn.setChecked(true);
        }
        cbRangeExt.setChecked(false);
        if ((mBytes[54] & 0x40) == 0x40){
            cbRangeExt.setChecked(true);
        }
        cbDisForceRef.setChecked(false);
        if ((mBytes[54] & 0x20) == 0x20){
            cbDisForceRef.setChecked(true);
        }
        cbDelayHopping.setChecked(false);
        if ((mBytes[54] & 0x10) == 0x10){
            cbDelayHopping.setChecked(true);
        }
        edtFastHopLimit.setText(Integer.toString((mBytes[55] & 0xF0) >> 4));
        edtHopThreshold.setText(Integer.toString(mBytes[55] & 0x0F));
        edtNoiseMinTh.setText(Integer.toString(mBytes[57] & 0xFF));
        edtSensorGroup.setText(Integer.toString(mBytes[59] & 0xFF));
        edtSeg1Normalize.setText(Integer.toString(mBytes[60] & 0xFF));
        edtSeg1Factor.setText(Integer.toString(mBytes[61] & 0xFF));
        edtMainClockAjdust.setText(Integer.toString(mBytes[62] & 0xFF));
        edtSeg2Normalize.setText(Integer.toString(mBytes[63] & 0xFF));
        edtSeg2Factor.setText(Integer.toString(mBytes[64] & 0xFF));
        edtSeg3Normalize.setText(Integer.toString(mBytes[66] & 0xFF));
        edtSeg3Factor.setText(Integer.toString(mBytes[67] & 0xFF));
        edtSeg4Normalize.setText(Integer.toString(mBytes[69] & 0xFF));
        edtSeg4Factor.setText(Integer.toString(mBytes[70] & 0xFF));
        edtSeg5Normalize.setText(Integer.toString(mBytes[72] & 0xFF));
        edtSeg5Factor.setText(Integer.toString(mBytes[73] & 0xFF));
        edtSeg6Normalize.setText(Integer.toString(mBytes[75] & 0xFF));
        //edtHopFreqAddr.setText("C6E6");
        edtHopDetectTimes.setText(Integer.toString((mBytes[105] & 0xE0) >> 5));
    }

    public void ReadCfgRam(String[] mConfigShow){
        int showid = 0;

        if (byProductType == GT9) {
            mCfg8047.setText(mConfigShow[showid++]);
            mCfg8048.setText(mConfigShow[showid++]);
            mCfg8049.setText(mConfigShow[showid++]);
            mCfg804A.setText(mConfigShow[showid++]);
            mCfg804B.setText(mConfigShow[showid++]);
            mCfg804C.setText(mConfigShow[showid++]);
            mCfg804D.setText(mConfigShow[showid++]);
            mCfg804E.setText(mConfigShow[showid++]);
            mCfg804F.setText(mConfigShow[showid++]);//9
        }

        mCfg8050.setText(mConfigShow[showid++]);
        mCfg8051.setText(mConfigShow[showid++]);
        mCfg8052.setText(mConfigShow[showid++]);
        mCfg8053.setText(mConfigShow[showid++]);
        mCfg8054.setText(mConfigShow[showid++]);
        mCfg8055.setText(mConfigShow[showid++]);
        mCfg8056.setText(mConfigShow[showid++]);
        mCfg8057.setText(mConfigShow[showid++]);
        mCfg8058.setText(mConfigShow[showid++]);
        mCfg8059.setText(mConfigShow[showid++]);
        mCfg805A.setText(mConfigShow[showid++]);
        mCfg805B.setText(mConfigShow[showid++]);
        mCfg805C.setText(mConfigShow[showid++]);
        mCfg805D.setText(mConfigShow[showid++]);
        mCfg805E.setText(mConfigShow[showid++]);
        mCfg805F.setText(mConfigShow[showid++]);

        mCfg8060.setText(mConfigShow[showid++]);
        mCfg8061.setText(mConfigShow[showid++]);
        mCfg8062.setText(mConfigShow[showid++]);
        mCfg8063.setText(mConfigShow[showid++]);
        mCfg8064.setText(mConfigShow[showid++]);
        mCfg8065.setText(mConfigShow[showid++]);
        mCfg8066.setText(mConfigShow[showid++]);
        mCfg8067.setText(mConfigShow[showid++]);
        mCfg8068.setText(mConfigShow[showid++]);
        mCfg8069.setText(mConfigShow[showid++]);
        mCfg806A.setText(mConfigShow[showid++]);
        mCfg806B.setText(mConfigShow[showid++]);
        mCfg806C.setText(mConfigShow[showid++]);
        mCfg806D.setText(mConfigShow[showid++]);
        mCfg806E.setText(mConfigShow[showid++]);
        mCfg806F.setText(mConfigShow[showid++]);

        mCfg8070.setText(mConfigShow[showid++]);
        mCfg8071.setText(mConfigShow[showid++]);
        mCfg8072.setText(mConfigShow[showid++]);
        mCfg8073.setText(mConfigShow[showid++]);
        mCfg8074.setText(mConfigShow[showid++]);
        mCfg8075.setText(mConfigShow[showid++]);
        mCfg8076.setText(mConfigShow[showid++]);
        mCfg8077.setText(mConfigShow[showid++]);
        mCfg8078.setText(mConfigShow[showid++]);
        mCfg8079.setText(mConfigShow[showid++]);
        mCfg807A.setText(mConfigShow[showid++]);
        mCfg807B.setText(mConfigShow[showid++]);
        mCfg807C.setText(mConfigShow[showid++]);
        mCfg807D.setText(mConfigShow[showid++]);
        mCfg807E.setText(mConfigShow[showid++]);
        mCfg807F.setText(mConfigShow[showid++]);

        mCfg8080.setText(mConfigShow[showid++]);
        mCfg8081.setText(mConfigShow[showid++]);
        mCfg8082.setText(mConfigShow[showid++]);
        mCfg8083.setText(mConfigShow[showid++]);
        mCfg8084.setText(mConfigShow[showid++]);
        mCfg8085.setText(mConfigShow[showid++]);
        mCfg8086.setText(mConfigShow[showid++]);
        mCfg8087.setText(mConfigShow[showid++]);
        mCfg8088.setText(mConfigShow[showid++]);
        mCfg8089.setText(mConfigShow[showid++]);
        mCfg808A.setText(mConfigShow[showid++]);
        mCfg808B.setText(mConfigShow[showid++]);
        mCfg808C.setText(mConfigShow[showid++]);
        mCfg808D.setText(mConfigShow[showid++]);
        mCfg808E.setText(mConfigShow[showid++]);
        mCfg808F.setText(mConfigShow[showid++]);

        mCfg8090.setText(mConfigShow[showid++]);
        mCfg8091.setText(mConfigShow[showid++]);
        mCfg8092.setText(mConfigShow[showid++]);
        mCfg8093.setText(mConfigShow[showid++]);
        mCfg8094.setText(mConfigShow[showid++]);
        mCfg8095.setText(mConfigShow[showid++]);
        mCfg8096.setText(mConfigShow[showid++]);
        mCfg8097.setText(mConfigShow[showid++]);
        mCfg8098.setText(mConfigShow[showid++]);
        mCfg8099.setText(mConfigShow[showid++]);
        mCfg809A.setText(mConfigShow[showid++]);
        mCfg809B.setText(mConfigShow[showid++]);
        mCfg809C.setText(mConfigShow[showid++]);
        mCfg809D.setText(mConfigShow[showid++]);
        mCfg809E.setText(mConfigShow[showid++]);
        mCfg809F.setText(mConfigShow[showid++]);

        mCfg80A0.setText(mConfigShow[showid++]);
        mCfg80A1.setText(mConfigShow[showid++]);
        mCfg80A2.setText(mConfigShow[showid++]);
        mCfg80A3.setText(mConfigShow[showid++]);
        mCfg80A4.setText(mConfigShow[showid++]);
        mCfg80A5.setText(mConfigShow[showid++]);
        mCfg80A6.setText(mConfigShow[showid++]);
        mCfg80A7.setText(mConfigShow[showid++]);
        mCfg80A8.setText(mConfigShow[showid++]);
        mCfg80A9.setText(mConfigShow[showid++]);
        mCfg80AA.setText(mConfigShow[showid++]);
        mCfg80AB.setText(mConfigShow[showid++]);
        mCfg80AC.setText(mConfigShow[showid++]);
        mCfg80AD.setText(mConfigShow[showid++]);
        mCfg80AE.setText(mConfigShow[showid++]);
        mCfg80AF.setText(mConfigShow[showid++]);

        mCfg80B0.setText(mConfigShow[showid++]);
        mCfg80B1.setText(mConfigShow[showid++]);
        mCfg80B2.setText(mConfigShow[showid++]);
        mCfg80B3.setText(mConfigShow[showid++]);
        mCfg80B4.setText(mConfigShow[showid++]);
        mCfg80B5.setText(mConfigShow[showid++]);
        mCfg80B6.setText(mConfigShow[showid++]);
        mCfg80B7.setText(mConfigShow[showid++]);
        mCfg80B8.setText(mConfigShow[showid++]);
        mCfg80B9.setText(mConfigShow[showid++]);
        mCfg80BA.setText(mConfigShow[showid++]);
        mCfg80BB.setText(mConfigShow[showid++]);
        mCfg80BC.setText(mConfigShow[showid++]);
        mCfg80BD.setText(mConfigShow[showid++]);
        mCfg80BE.setText(mConfigShow[showid++]);
        mCfg80BF.setText(mConfigShow[showid++]);

        mCfg80C0.setText(mConfigShow[showid++]);
        mCfg80C1.setText(mConfigShow[showid++]);
        mCfg80C2.setText(mConfigShow[showid++]);
        mCfg80C3.setText(mConfigShow[showid++]);
        mCfg80C4.setText(mConfigShow[showid++]);
        mCfg80C5.setText(mConfigShow[showid++]);
        mCfg80C6.setText(mConfigShow[showid++]);
        mCfg80C7.setText(mConfigShow[showid++]);
        mCfg80C8.setText(mConfigShow[showid++]);
        mCfg80C9.setText(mConfigShow[showid++]);
        mCfg80CA.setText(mConfigShow[showid++]);
        mCfg80CB.setText(mConfigShow[showid++]);
        mCfg80CC.setText(mConfigShow[showid++]);
        mCfg80CD.setText(mConfigShow[showid++]);
        mCfg80CE.setText(mConfigShow[showid++]);
        mCfg80CF.setText(mConfigShow[showid++]);

        mCfg80D0.setText(mConfigShow[showid++]);
        mCfg80D1.setText(mConfigShow[showid++]);
        mCfg80D2.setText(mConfigShow[showid++]);
        mCfg80D3.setText(mConfigShow[showid++]);
        mCfg80D4.setText(mConfigShow[showid++]);
        mCfg80D5.setText(mConfigShow[showid++]);
        mCfg80D6.setText(mConfigShow[showid++]);
        mCfg80D7.setText(mConfigShow[showid++]);
        mCfg80D8.setText(mConfigShow[showid++]);
        mCfg80D9.setText(mConfigShow[showid++]);
        mCfg80DA.setText(mConfigShow[showid++]);
        mCfg80DB.setText(mConfigShow[showid++]);
        mCfg80DC.setText(mConfigShow[showid++]);
        mCfg80DD.setText(mConfigShow[showid++]);
        mCfg80DE.setText(mConfigShow[showid++]);
        mCfg80DF.setText(mConfigShow[showid++]);

        mCfg80E0.setText(mConfigShow[showid++]);
        mCfg80E1.setText(mConfigShow[showid++]);
        mCfg80E2.setText(mConfigShow[showid++]);
        mCfg80E3.setText(mConfigShow[showid++]);
        mCfg80E4.setText(mConfigShow[showid++]);
        mCfg80E5.setText(mConfigShow[showid++]);
        mCfg80E6.setText(mConfigShow[showid++]);
        mCfg80E7.setText(mConfigShow[showid++]);
        mCfg80E8.setText(mConfigShow[showid++]);
        mCfg80E9.setText(mConfigShow[showid++]);
        mCfg80EA.setText(mConfigShow[showid++]);
        mCfg80EB.setText(mConfigShow[showid++]);
        mCfg80EC.setText(mConfigShow[showid++]);
        mCfg80ED.setText(mConfigShow[showid++]);
        mCfg80EE.setText(mConfigShow[showid++]);
        mCfg80EF.setText(mConfigShow[showid++]);

        mCfg80F0.setText(mConfigShow[showid++]);
        mCfg80F1.setText(mConfigShow[showid++]);
        mCfg80F2.setText(mConfigShow[showid++]);
        mCfg80F3.setText(mConfigShow[showid++]);
        mCfg80F4.setText(mConfigShow[showid++]);
        mCfg80F5.setText(mConfigShow[showid++]);
        mCfg80F6.setText(mConfigShow[showid++]);
        mCfg80F7.setText(mConfigShow[showid++]);
        mCfg80F8.setText(mConfigShow[showid++]);
        mCfg80F9.setText(mConfigShow[showid++]);
        mCfg80FA.setText(mConfigShow[showid++]);
        mCfg80FB.setText(mConfigShow[showid++]);
        mCfg80FC.setText(mConfigShow[showid++]);
        mCfg80FD.setText(mConfigShow[showid++]);
        mCfg80FE.setText(mConfigShow[showid++]);
        mCfg80FF.setText(mConfigShow[showid++]);

        mCfg8100.setText(mConfigShow[showid++]);

        if (byProductType == GT7) {  //GT7
            mCfg8101.setText(mConfigShow[showid++]);
            mCfg8102.setText(mConfigShow[showid++]);
            mCfg8103.setText(mConfigShow[showid++]);
            mCfg8104.setText(mConfigShow[showid++]);
            mCfg8105.setText(mConfigShow[showid++]);
            mCfg8106.setText(mConfigShow[showid++]);
            mCfg8107.setText(mConfigShow[showid++]);
            mCfg8108.setText(mConfigShow[showid++]);
            mCfg8109.setText(mConfigShow[showid++]);
            mCfg810A.setText(mConfigShow[showid++]);
            mCfg810B.setText(mConfigShow[showid++]);
            mCfg810C.setText(mConfigShow[showid++]);
            mCfg810D.setText(mConfigShow[showid++]);
            mCfg810E.setText(mConfigShow[showid++]);
            mCfg810F.setText(mConfigShow[showid++]);

            mCfg8110.setText(mConfigShow[showid++]);
            mCfg8111.setText(mConfigShow[showid++]);
            mCfg8112.setText(mConfigShow[showid++]);
            mCfg8113.setText(mConfigShow[showid++]);
            mCfg8114.setText(mConfigShow[showid++]);
            mCfg8115.setText(mConfigShow[showid++]);
            mCfg8116.setText(mConfigShow[showid++]);
            mCfg8117.setText(mConfigShow[showid++]);
            mCfg8118.setText(mConfigShow[showid++]);
            mCfg8119.setText(mConfigShow[showid++]);
            mCfg811A.setText(mConfigShow[showid++]);
            mCfg811B.setText(mConfigShow[showid++]);
            mCfg811C.setText(mConfigShow[showid++]);
            mCfg811D.setText(mConfigShow[showid++]);
            mCfg811E.setText(mConfigShow[showid++]);
            mCfg811F.setText(mConfigShow[showid++]);

            mCfg8120.setText(mConfigShow[showid++]);
            mCfg8121.setText(mConfigShow[showid++]);
            mCfg8122.setText(mConfigShow[showid++]);
            mCfg8123.setText(mConfigShow[showid++]);
            mCfg8124.setText(mConfigShow[showid++]);
            mCfg8125.setText(mConfigShow[showid++]);
            mCfg8126.setText(mConfigShow[showid++]);
            mCfg8127.setText(mConfigShow[showid++]);
            mCfg8128.setText(mConfigShow[showid++]);
            mCfg8129.setText(mConfigShow[showid++]);
            mCfg812A.setText(mConfigShow[showid++]);
            mCfg812B.setText(mConfigShow[showid++]);
            mCfg812C.setText(mConfigShow[showid++]);
            mCfg812D.setText(mConfigShow[showid++]);
            mCfg812E.setText(mConfigShow[showid++]);
            mCfg812F.setText(mConfigShow[showid++]);

            mCfg8130.setText(mConfigShow[showid++]);
            mCfg8131.setText(mConfigShow[showid++]);
            mCfg8132.setText(mConfigShow[showid++]);
            mCfg8133.setText(mConfigShow[showid++]);
            mCfg8134.setText(mConfigShow[showid++]);
            mCfg8135.setText(mConfigShow[showid++]);
            mCfg8136.setText(mConfigShow[showid++]);
            mCfg8137.setText(mConfigShow[showid++]);
            mCfg8138.setText(mConfigShow[showid++]);
            mCfg8139.setText(mConfigShow[showid++]);
            mCfg813A.setText(mConfigShow[showid++]);
            mCfg813B.setText(mConfigShow[showid++]);
            mCfg813C.setText(mConfigShow[showid++]);
            mCfg813D.setText(mConfigShow[showid++]);
            mCfg813E.setText(mConfigShow[showid++]);
            mCfg813F.setText(mConfigShow[showid++]);

            mCfg8140.setText(mConfigShow[showid++]);
            mCfg8141.setText(mConfigShow[showid++]);
            mCfg8142.setText(mConfigShow[showid++]);
            mCfg8143.setText(mConfigShow[showid++]);
            mCfg8144.setText(mConfigShow[showid++]);
            mCfg8145.setText(mConfigShow[showid++]);
            mCfg8146.setText(mConfigShow[showid++]);
            mCfg8147.setText(mConfigShow[showid++]);
            mCfg8148.setText(mConfigShow[showid++]);
            mCfg8149.setText(mConfigShow[showid++]);
            mCfg814A.setText(mConfigShow[showid++]);
            mCfg814B.setText(mConfigShow[showid++]);
            mCfg814C.setText(mConfigShow[showid++]);
            mCfg814D.setText(mConfigShow[showid++]);
            mCfg814E.setText(mConfigShow[showid++]);
            mCfg814F.setText(mConfigShow[showid++]);

            mCfg8150.setText(mConfigShow[showid++]);
            mCfg8151.setText(mConfigShow[showid++]);
            mCfg8152.setText(mConfigShow[showid++]);
            mCfg8153.setText(mConfigShow[showid++]);
            mCfg8154.setText(mConfigShow[showid++]);
            mCfg8155.setText(mConfigShow[showid++]);
            mCfg8156.setText(mConfigShow[showid++]);
            mCfg8157.setText(mConfigShow[showid++]);
            mCfg8158.setText(mConfigShow[showid++]);
            mCfg8159.setText(mConfigShow[showid++]);
            mCfg815A.setText(mConfigShow[showid++]);
            mCfg815B.setText(mConfigShow[showid++]);
            mCfg815C.setText(mConfigShow[showid++]);
            mCfg815D.setText(mConfigShow[showid++]);
            mCfg815E.setText(mConfigShow[showid++]);
            mCfg815F.setText(mConfigShow[showid++]);

            mCfg8160.setText(mConfigShow[showid++]);
            mCfg8161.setText(mConfigShow[showid++]);
            mCfg8162.setText(mConfigShow[showid++]);
            mCfg8163.setText(mConfigShow[showid++]);
            mCfg8164.setText(mConfigShow[showid++]);
            mCfg8165.setText(mConfigShow[showid++]);
            mCfg8166.setText(mConfigShow[showid++]);
            mCfg8167.setText(mConfigShow[showid++]);
            mCfg8168.setText(mConfigShow[showid++]);
            mCfg8169.setText(mConfigShow[showid++]);
            mCfg816A.setText(mConfigShow[showid++]);
            mCfg816B.setText(mConfigShow[showid++]);
            mCfg816C.setText(mConfigShow[showid++]);
            mCfg816D.setText(mConfigShow[showid++]);
            mCfg816E.setText(mConfigShow[showid++]);
            mCfg816F.setText(mConfigShow[showid++]);

            mCfg8170.setText(mConfigShow[showid++]);
            mCfg8171.setText(mConfigShow[showid++]);
            mCfg8172.setText(mConfigShow[showid++]);
            mCfg8173.setText(mConfigShow[showid++]);
            mCfg8174.setText(mConfigShow[showid++]);
            mCfg8175.setText(mConfigShow[showid++]);
            mCfg8176.setText(mConfigShow[showid++]);
            mCfg8177.setText(mConfigShow[showid++]);
            mCfg8178.setText(mConfigShow[showid++]);
            mCfg8179.setText(mConfigShow[showid++]);
            mCfg817A.setText(mConfigShow[showid++]);
            mCfg817B.setText(mConfigShow[showid++]);
            mCfg817C.setText(mConfigShow[showid++]);
            mCfg817D.setText(mConfigShow[showid++]);
            mCfg817E.setText(mConfigShow[showid++]);
            mCfg817F.setText(mConfigShow[showid++]);

            mCfg8180.setText(mConfigShow[showid++]);
            mCfg8181.setText(mConfigShow[showid++]);
            mCfg8182.setText(mConfigShow[showid++]);
            mCfg8183.setText(mConfigShow[showid++]);
            mCfg8184.setText(mConfigShow[showid++]);
            mCfg8185.setText(mConfigShow[showid++]);
            mCfg8186.setText(mConfigShow[showid++]);
            mCfg8187.setText(mConfigShow[showid++]);
            mCfg8188.setText(mConfigShow[showid++]);
            mCfg8189.setText(mConfigShow[showid++]);
            mCfg818A.setText(mConfigShow[showid++]);
            mCfg818B.setText(mConfigShow[showid++]);
            mCfg818C.setText(mConfigShow[showid++]);
            mCfg818D.setText(mConfigShow[showid++]);
            mCfg818E.setText(mConfigShow[showid++]);
            mCfg818F.setText(mConfigShow[showid++]);

            mCfg8190.setText(mConfigShow[showid++]);
            mCfg8191.setText(mConfigShow[showid++]);
            mCfg8192.setText(mConfigShow[showid++]);
            mCfg8193.setText(mConfigShow[showid++]);
            mCfg8194.setText(mConfigShow[showid++]);
            mCfg8195.setText(mConfigShow[showid++]);
            mCfg8196.setText(mConfigShow[showid++]);
            mCfg8197.setText(mConfigShow[showid++]);
            mCfg8198.setText(mConfigShow[showid++]);
            mCfg8199.setText(mConfigShow[showid++]);
            mCfg819A.setText(mConfigShow[showid++]);
            mCfg819B.setText(mConfigShow[showid++]);
            mCfg819C.setText(mConfigShow[showid++]);
            mCfg819D.setText(mConfigShow[showid++]);
            mCfg819E.setText(mConfigShow[showid++]);
            mCfg819F.setText(mConfigShow[showid++]);

            mCfg81A0.setText(mConfigShow[showid++]);
            mCfg81A1.setText(mConfigShow[showid++]);
            mCfg81A2.setText(mConfigShow[showid++]);
            mCfg81A3.setText(mConfigShow[showid++]);
            mCfg81A4.setText(mConfigShow[showid++]);
            mCfg81A5.setText(mConfigShow[showid++]);
            mCfg81A6.setText(mConfigShow[showid++]);
            mCfg81A7.setText(mConfigShow[showid++]);
            mCfg81A8.setText(mConfigShow[showid++]);
            mCfg81A9.setText(mConfigShow[showid++]);
            mCfg81AA.setText(mConfigShow[showid++]);
            mCfg81AB.setText(mConfigShow[showid++]);
            mCfg81AC.setText(mConfigShow[showid++]);
            mCfg81AD.setText(mConfigShow[showid++]);
            mCfg81AE.setText(mConfigShow[showid++]);
            mCfg81AF.setText(mConfigShow[showid++]);

            mCfg81B0.setText(mConfigShow[showid++]);
            mCfg81B1.setText(mConfigShow[showid++]);
            mCfg81B2.setText(mConfigShow[showid++]);
            mCfg81B3.setText(mConfigShow[showid++]);
            mCfg81B4.setText(mConfigShow[showid++]);
            mCfg81B5.setText(mConfigShow[showid++]);
            mCfg81B6.setText(mConfigShow[showid++]);
            mCfg81B7.setText(mConfigShow[showid++]);
            mCfg81B8.setText(mConfigShow[showid++]);
            mCfg81B9.setText(mConfigShow[showid++]);
            mCfg81BA.setText(mConfigShow[showid++]);
            mCfg81BB.setText(mConfigShow[showid++]);
            mCfg81BC.setText(mConfigShow[showid++]);
            mCfg81BD.setText(mConfigShow[showid++]);
            mCfg81BE.setText(mConfigShow[showid++]);
            mCfg81BF.setText(mConfigShow[showid++]);

            mCfg81C0.setText(mConfigShow[showid++]);
            mCfg81C1.setText(mConfigShow[showid++]);
            mCfg81C2.setText(mConfigShow[showid++]);
            mCfg81C3.setText(mConfigShow[showid++]);
            mCfg81C4.setText(mConfigShow[showid++]);
            mCfg81C5.setText(mConfigShow[showid++]);
            mCfg81C6.setText(mConfigShow[showid++]);
            mCfg81C7.setText(mConfigShow[showid++]);
            mCfg81C8.setText(mConfigShow[showid++]);
            mCfg81C9.setText(mConfigShow[showid++]);
            mCfg81CA.setText(mConfigShow[showid++]);
            mCfg81CB.setText(mConfigShow[showid++]);
            mCfg81CC.setText(mConfigShow[showid++]);
            mCfg81CD.setText(mConfigShow[showid++]);
            mCfg81CE.setText(mConfigShow[showid++]);
            mCfg81CF.setText(mConfigShow[showid++]);

            mCfg81D0.setText(mConfigShow[showid++]);
            mCfg81D1.setText(mConfigShow[showid++]);
            mCfg81D2.setText(mConfigShow[showid++]);
            mCfg81D3.setText(mConfigShow[showid++]);
            mCfg81D4.setText(mConfigShow[showid++]);
            mCfg81D5.setText(mConfigShow[showid++]);
            mCfg81D6.setText(mConfigShow[showid++]);
            mCfg81D7.setText(mConfigShow[showid++]);
            mCfg81D8.setText(mConfigShow[showid++]);
            mCfg81D9.setText(mConfigShow[showid++]);
            mCfg81DA.setText(mConfigShow[showid++]);
            mCfg81DB.setText(mConfigShow[showid++]);
            mCfg81DC.setText(mConfigShow[showid++]);
            mCfg81DD.setText(mConfigShow[showid++]);
            mCfg81DE.setText(mConfigShow[showid++]);
            mCfg81DF.setText(mConfigShow[showid++]);

            mCfg81E0.setText(mConfigShow[showid++]);
            mCfg81E1.setText(mConfigShow[showid++]);
            mCfg81E2.setText(mConfigShow[showid++]);
            mCfg81E3.setText(mConfigShow[showid++]);
            mCfg81E4.setText(mConfigShow[showid++]);
            mCfg81E5.setText(mConfigShow[showid++]);
            mCfg81E6.setText(mConfigShow[showid++]);
            mCfg81E7.setText(mConfigShow[showid++]);
            mCfg81E8.setText(mConfigShow[showid++]);
            mCfg81E9.setText(mConfigShow[showid++]);
            mCfg81EA.setText(mConfigShow[showid++]);
            mCfg81EB.setText(mConfigShow[showid++]);
            mCfg81EC.setText(mConfigShow[showid++]);
            mCfg81ED.setText(mConfigShow[showid++]);
            mCfg81EE.setText(mConfigShow[showid++]);
            mCfg81EF.setText(mConfigShow[showid++]);

            mCfg81F0.setText(mConfigShow[showid++]);
            mCfg81F1.setText(mConfigShow[showid++]);
            mCfg81F2.setText(mConfigShow[showid++]);
            mCfg81F3.setText(mConfigShow[showid++]);
            mCfg81F4.setText(mConfigShow[showid++]);
            mCfg81F5.setText(mConfigShow[showid++]);
            mCfg81F6.setText(mConfigShow[showid++]);
            mCfg81F7.setText(mConfigShow[showid++]);
            mCfg81F8.setText(mConfigShow[showid++]);
            mCfg81F9.setText(mConfigShow[showid++]);
            mCfg81FA.setText(mConfigShow[showid++]);
            mCfg81FB.setText(mConfigShow[showid++]);
            mCfg81FC.setText(mConfigShow[showid++]);
            mCfg81FD.setText(mConfigShow[showid++]);
            mCfg81FE.setText(mConfigShow[showid++]);
            mCfg81FF.setText(mConfigShow[showid++]);

            mCfg8200.setText(mConfigShow[showid++]);
            mCfg8201.setText(mConfigShow[showid++]);
            mCfg8202.setText(mConfigShow[showid++]);
            mCfg8203.setText(mConfigShow[showid++]);
            mCfg8204.setText(mConfigShow[showid++]);
            mCfg8205.setText(mConfigShow[showid++]);
            mCfg8206.setText(mConfigShow[showid++]);
            mCfg8207.setText(mConfigShow[showid++]);
            mCfg8208.setText(mConfigShow[showid++]);
            mCfg8209.setText(mConfigShow[showid++]);
            mCfg820A.setText(mConfigShow[showid++]);
            mCfg820B.setText(mConfigShow[showid++]);
        }
    }
    //=====================================读取CFG到各个View结束===================================//

    //======================================合并配置开始===========================================//
    public void CombineCfg(){

        for (int i = 0; i < 186; i++){
            mBytes[i] = 0;
        }

        mBytes[0] = (byte)Integer.parseInt(edtConfigVersion.getText().toString(),10);
        mBytes[1] = (byte)(Integer.parseInt(edtXOutputMax.getText().toString(),10) & 0x00ff);
        mBytes[2] = (byte)(Integer.parseInt(edtXOutputMax.getText().toString(),10) >> 8);
        mBytes[3] = (byte)(Integer.parseInt(edtYOutputMax.getText().toString(),10) & 0x00ff);
        mBytes[4] = (byte)(Integer.parseInt(edtYOutputMax.getText().toString(),10) >> 8);
        mBytes[5] = (byte)(Integer.parseInt(edtTouchNumber.getText().toString(),10) & 0x0f);
        //mBytes[6]
        mBytes[6] = (byte)spinInterrupt.getSelectedItemPosition();
        if (cbSito.isChecked()){
            mBytes[6] += 4;
        }
        if (cbX2Y.isChecked()){
            mBytes[6] += 8;
        }
        mBytes[6] += (byte)(spinStretchRank.getSelectedItemPosition() * 16);
        if (cbAllPlamRestrain.isChecked()){
            mBytes[6] += 64;
        }
        //mBytes[7]
        if (cbTouchKey.isChecked()){
            mBytes[7] = 1;
        }
        if (cbPenEn.isChecked()){
            mBytes[7] += 2;
        }
        if (cbDiffDivideBy2or4.isChecked()){
            mBytes[7] += 4;
        }
        if (cbOnlyFingerEn.isChecked()){
            mBytes[7] += 8;
        }
        if (cbFirstFilterDis.isChecked()){
            mBytes[7] += 32;
        }
        if (cbMonitorConsistencyConflictEn.isChecked()){
            mBytes[7] += 64;
        }
        mBytes[8] = (byte)Integer.parseInt(edtShakeCnt.getText().toString(),16);
        mBytes[9] = (byte)(Integer.parseInt(edtNormalFilter.getText().toString(),10) +
                Integer.parseInt(edtFirstFilter.getText().toString(),10) * 64);
        mBytes[10] = (byte)Integer.parseInt(edtLargeTouch.getText().toString(),10);
        mBytes[11] = (byte)(Integer.parseInt(edtNoiseReduction.getText().toString(),10) & 0x0f);
        mBytes[12] = (byte)Integer.parseInt(edtScreenTouchLv.getText().toString(),10);
        mBytes[13] = (byte)Integer.parseInt(edtScreenLeaveLv.getText().toString(),10);
        mBytes[14] = (byte)(Integer.parseInt(edtLowPowerControl.getText().toString(),10) & 0x0f);
        mBytes[15] = (byte)(spinRefreshRate.getSelectedItemPosition());
        mBytes[16] = (byte)Integer.parseInt(edtXThreshold.getText().toString(),10);
        mBytes[17] = (byte)Integer.parseInt(edtYThreshold.getText().toString(),10);
        //mBytes[18]
        //mBytes[19]
        mBytes[20] = (byte)Integer.parseInt(edtSpaceUpDown.getText().toString(),16);
        mBytes[21] = (byte)Integer.parseInt(edtSpaceLeftRight.getText().toString(),16);
        mBytes[22] = (byte)(Integer.parseInt(edtMiniFilter.getText().toString(),10) & 0x0f);
        mBytes[23] = (byte)Integer.parseInt(edtStretchR0.getText().toString(),10);
        mBytes[24] = (byte)Integer.parseInt(edtStretchR1.getText().toString(),10);
        mBytes[25] = (byte)Integer.parseInt(edtStretchR2.getText().toString(),10);
        mBytes[26] = (byte)Integer.parseInt(edtStretchRM.getText().toString(),10);
        //mBytes[27]
        mBytes[27] = (byte)Integer.parseInt(edtDrvGroupAnumber.getText().toString(),10);
        if (cbAllDrivingEn.isChecked()){
            mBytes[27] += 128;
        }
        //mBytes[28]
        mBytes[28] = (byte)Integer.parseInt(edtDrvGroupBnumber.getText().toString(),10);
        if (cbDualFreq.isChecked()){
            mBytes[28] += 32;
        }
        mBytes[29] = (byte)(Integer.parseInt(edtSenGroupANumber.getText().toString(),10) +
                Integer.parseInt(edtSenGroupBNumber.getText().toString(),10) * 16);
        mBytes[30] = (byte)Integer.parseInt(edtFreqAFactor.getText().toString(),10);
        mBytes[31] = (byte)Integer.parseInt(edtFreqBFactor.getText().toString(),10);
        mBytes[32] = (byte)(Integer.parseInt(edtPannelBitFreq.getText().toString(),10) & 0x00ff);
        mBytes[33] = (byte)(Integer.parseInt(edtPannelBitFreq.getText().toString(),10) >> 8);
        mBytes[34] = (byte)((Integer.parseInt(edtExpanNumOutY.getText().toString(),10) & 0x0f) +
                Integer.parseInt(edtExpanNumOutX.getText().toString(),10) * 16);
        mBytes[35] = (byte)((Integer.parseInt(edtExpanNumInY.getText().toString(),10) & 0x0f) +
                Integer.parseInt(edtExpanNumInX.getText().toString(),10) * 16);
        mBytes[36] = (byte)(spinDACGain.getSelectedItemPosition() +
                spinDrvOutputR.getSelectedItemPosition() * 8);
        mBytes[37] = (byte)(spinPGAGain.getSelectedItemPosition() +
                spinRxVcmi.getSelectedItemPosition() * 8 +
                spinPGAR.getSelectedItemPosition() * 32 +
                spinPGAC.getSelectedItemPosition() * 128);
        mBytes[38] = (byte)(Integer.parseInt(edtDumpShift.getText().toString(),10) & 0x0f);
        mBytes[39] = (byte)(Integer.parseInt(edtSubFrameDrvNum.getText().toString(),10) << 2);
        mBytes[40] = (byte)Integer.parseInt(edtPenLowSize.getText().toString(),10);
        mBytes[41] = (byte)Integer.parseInt(edtPenHighSize.getText().toString(),10);
        mBytes[42] = (byte)Integer.parseInt(edtRectsumPLowL.getText().toString(),10);
        mBytes[43] = (byte)Integer.parseInt(edtRectsumPHighL.getText().toString(),10);
        mBytes[44] = (byte)Integer.parseInt(edtRectsumFLowL.getText().toString(),10);
        mBytes[45] = (byte)Integer.parseInt(edtPRectMaxDiffLimit.getText().toString(),10);
        mBytes[46] = (byte)Integer.parseInt(edtPRectAreaLimit.getText().toString(),10);
        mBytes[47] = (byte)Integer.parseInt(edtSingleRectTopSignNum.getText().toString(),10);
        mBytes[48] = (byte)Integer.parseInt(edtAllRectTopSignSum.getText().toString(),10);
        mBytes[49] = (byte)Integer.parseInt(edtChargingLevelUp.getText().toString(),10);
        //mBytes[50]
        mBytes[51] = (byte)Integer.parseInt(edtFreqStart.getText().toString(),10);
        mBytes[52] = (byte)Integer.parseInt(edtFreqEnd.getText().toString(),10);
        mBytes[53] = (byte)(Integer.parseInt(edtDetectConfirmTimes.getText().toString(),10) +
                Integer.parseInt(edtDetectStayTimes.getText().toString(),10) * 64);
        //mBytes[54]
        if (cbDelayHopping.isChecked()){
            mBytes[54] = 16;
        }
        if (cbDisForceRef.isChecked()){
            mBytes[54] += 32;
        }
        if (cbRangeExt.isChecked()){
            mBytes[54] += 64;
        }
        if (cbHoppingEn.isChecked()){
            mBytes[54] += 128;
        }
        mBytes[55] = (byte)(Integer.parseInt(edtHopThreshold.getText().toString(),10) +
                Integer.parseInt(edtFastHopLimit.getText().toString(),10) * 16);
        //mBytes[56]
        mBytes[57] = (byte)Integer.parseInt(edtNoiseMinTh.getText().toString(),10);
        mBytes[58] = (byte)Integer.parseInt(edtLcdPlusMinusValue.getText().toString(),10);
        mBytes[59] = (byte)Integer.parseInt(edtSensorGroup.getText().toString(),10);
        mBytes[60] = (byte)Integer.parseInt(edtSeg1Normalize.getText().toString(),10);
        mBytes[61] = (byte)Integer.parseInt(edtSeg1Factor.getText().toString(),10);
        mBytes[62] = (byte)Integer.parseInt(edtMainClockAjdust.getText().toString(),10);
        mBytes[63] = (byte)Integer.parseInt(edtSeg2Normalize.getText().toString(),10);
        mBytes[64] = (byte)Integer.parseInt(edtSeg2Factor.getText().toString(),10);
        //mBytes[65]
        mBytes[66] = (byte)Integer.parseInt(edtSeg3Normalize.getText().toString(),10);
        mBytes[67] = (byte)Integer.parseInt(edtSeg3Factor.getText().toString(),10);
        //mBytes[68]
        mBytes[69] = (byte)Integer.parseInt(edtSeg4Normalize.getText().toString(),10);
        mBytes[70] = (byte)Integer.parseInt(edtSeg4Factor.getText().toString(),10);
        //mBytes[71]
        mBytes[72] = (byte)Integer.parseInt(edtSeg5Normalize.getText().toString(),10);
        mBytes[73] = (byte)Integer.parseInt(edtSeg5Factor.getText().toString(),10);
        //mBytes[74]
        mBytes[75] = (byte)Integer.parseInt(edtSeg6Normalize.getText().toString(),10);
        mBytes[76] = (byte)Integer.parseInt(edtKey1.getText().toString(),16);
        mBytes[77] = (byte)Integer.parseInt(edtKey2.getText().toString(),16);
        mBytes[78] = (byte)Integer.parseInt(edtKey3.getText().toString(),16);
        mBytes[79] = (byte)Integer.parseInt(edtKey4.getText().toString(),16);
        mBytes[80] = (byte)Integer.parseInt(edtKeyArea.getText().toString(),16);
        mBytes[81] = (byte)Integer.parseInt(edtKeyTouchLevel.getText().toString(),16);
        mBytes[82] = (byte)Integer.parseInt(edtKeyLeaveLevel.getText().toString(),16);
        mBytes[83] = (byte)Integer.parseInt(edtKeySens1and2.getText().toString(),16);
        mBytes[84] = (byte)Integer.parseInt(edtKeySens3and4.getText().toString(),16);
        mBytes[85] = (byte)Integer.parseInt(edtKeyRestrain.getText().toString(),16);
        mBytes[86] = (byte)(Integer.parseInt(edtKeyRestrainTime.getText().toString(),16) & 0x0f);
        mBytes[87] = (byte)(Integer.parseInt(edtShapeRestrain.getText().toString(),10) & 0x7f);
        mBytes[88] = (byte)Integer.parseInt(edtConThreshold.getText().toString(),10);
        mBytes[89] = (byte)Integer.parseInt(edtWaterFrameTime.getText().toString(),10);
        mBytes[90] = (byte)Integer.parseInt(edtWaterUpdateTime.getText().toString(),10);
        //mBytes[91]
        if (cbWaterSpeedLimitEn.isChecked()){
            mBytes[91] = 1;
        }
        if (cbWaterLargeRestrainEn.isChecked()){
            mBytes[91] += 2;
        }
        if (cbShapeEn.isChecked()){
            mBytes[91] += 4;
        }
        if (cbWaterProofDis.isChecked()){
            mBytes[91] += 8;
        }
        if (cbLcdPlusMinusEn.isChecked()){
            mBytes[91] += 16;
        }
        //mBytes[92]
        mBytes[92] = (byte)(spinVoltage.getSelectedItemPosition() +
                spinBoostTime.getSelectedItemPosition() * 16);
        if (cbExtoscen.isChecked()){
            mBytes[93] = (byte)128;
        }
        mBytes[94] = (byte)spinAlterCount.getSelectedItemPosition();
        //mBytes[95]
        mBytes[96] = (byte)Integer.parseInt(edtSlideInEdgeConfig.getText().toString(),10);
        mBytes[97] = (byte)Integer.parseInt(edtSlideOutEdgeConfig.getText().toString(),10);
        //mBytes[98]
        //mBytes[99]
        //mBytes[100]
        //mBytes[101]
        //mBytes[102]
        //mBytes[103]
        //mBytes[104]
        if (cbX2X.isChecked()){
            mBytes[104] = 1;
        }
        if (cbY2Y.isChecked()){
            mBytes[104] += 2;
        }
        if (cbESDEn.isChecked()){
            mBytes[104] += 16;
        }
        if (cbINTWakeup.isChecked()){
            mBytes[104] += 32;
        }
        mBytes[104] += (byte)(spinFingerRestrainPen.getSelectedItemPosition() * 64);
        mBytes[105] = (byte)(Integer.parseInt(edtShapeContrl.getText().toString(),10) +
                Integer.parseInt(edtHopDetectTimes.getText().toString(),10) * 32);
        mBytes[106] = (byte)(Integer.parseInt(edtCombineDis.getText().toString(),16) & 0x0f);
        mBytes[107] = (byte)Integer.parseInt(edtSplitSet.getText().toString(),16);
        mBytes[108] = (byte)Integer.parseInt(edtFLeavelevel.getText().toString(),10);
        //mBytes[109]
        mBytes[110] = (byte)Integer.parseInt(edtSitoDiffRefLevel.getText().toString(),10);
        mBytes[111] = (byte)Integer.parseInt(edtPTouchHighlevel.getText().toString(),10);
        mBytes[112] = (byte)Integer.parseInt(edtSensorCH0.getText().toString(),10);
        mBytes[113] = (byte)Integer.parseInt(edtSensorCH1.getText().toString(),10);
        mBytes[114] = (byte)Integer.parseInt(edtSensorCH2.getText().toString(),10);
        mBytes[115] = (byte)Integer.parseInt(edtSensorCH3.getText().toString(),10);
        mBytes[116] = (byte)Integer.parseInt(edtSensorCH4.getText().toString(),10);
        mBytes[117] = (byte)Integer.parseInt(edtSensorCH5.getText().toString(),10);
        mBytes[118] = (byte)Integer.parseInt(edtSensorCH6.getText().toString(),10);
        mBytes[119] = (byte)Integer.parseInt(edtSensorCH7.getText().toString(),10);
        mBytes[120] = (byte)Integer.parseInt(edtSensorCH8.getText().toString(),10);
        mBytes[121] = (byte)Integer.parseInt(edtSensorCH9.getText().toString(),10);
        mBytes[122] = (byte)Integer.parseInt(edtSensorCH10.getText().toString(),10);
        mBytes[123] = (byte)Integer.parseInt(edtSensorCH11.getText().toString(),10);
        mBytes[124] = (byte)Integer.parseInt(edtSensorCH12.getText().toString(),10);
        mBytes[125] = (byte)Integer.parseInt(edtSensorCH13.getText().toString(),10);
        mBytes[126] = (byte)Integer.parseInt(edtSensorCH14.getText().toString(),10);
        mBytes[127] = (byte)Integer.parseInt(edtSensorCH15.getText().toString(),10);
        mBytes[128] = (byte)Integer.parseInt(edtSensorCH16.getText().toString(),10);
        mBytes[129] = (byte)Integer.parseInt(edtSensorCH17.getText().toString(),10);
        mBytes[130] = (byte)Integer.parseInt(edtSensorCH18.getText().toString(),10);
        mBytes[131] = (byte)Integer.parseInt(edtSensorCH19.getText().toString(),10);
        mBytes[132] = (byte)Integer.parseInt(edtSensorCH20.getText().toString(),10);
        mBytes[133] = (byte)Integer.parseInt(edtSensorCH21.getText().toString(),10);
        mBytes[134] = (byte)Integer.parseInt(edtSensorCH22.getText().toString(),10);
        mBytes[135] = (byte)Integer.parseInt(edtSensorCH23.getText().toString(),10);
        mBytes[136] = (byte)Integer.parseInt(edtSensorCH24.getText().toString(),10);
        mBytes[137] = (byte)Integer.parseInt(edtSensorCH25.getText().toString(),10);
        mBytes[138] = (byte)Integer.parseInt(edtSensorCH26.getText().toString(),10);
        mBytes[139] = (byte)Integer.parseInt(edtSensorCH27.getText().toString(),10);
        mBytes[140] = (byte)Integer.parseInt(edtSensorCH28.getText().toString(),10);
        mBytes[141] = (byte)Integer.parseInt(edtSensorCH29.getText().toString(),10);
        mBytes[142] = (byte)Integer.parseInt(edtDriverCH0.getText().toString(),10);
        mBytes[143] = (byte)Integer.parseInt(edtDriverCH1.getText().toString(),10);
        mBytes[144] = (byte)Integer.parseInt(edtDriverCH2.getText().toString(),10);
        mBytes[145] = (byte)Integer.parseInt(edtDriverCH3.getText().toString(),10);
        mBytes[146] = (byte)Integer.parseInt(edtDriverCH4.getText().toString(),10);
        mBytes[147] = (byte)Integer.parseInt(edtDriverCH5.getText().toString(),10);
        mBytes[148] = (byte)Integer.parseInt(edtDriverCH6.getText().toString(),10);
        mBytes[149] = (byte)Integer.parseInt(edtDriverCH7.getText().toString(),10);
        mBytes[150] = (byte)Integer.parseInt(edtDriverCH8.getText().toString(),10);
        mBytes[151] = (byte)Integer.parseInt(edtDriverCH9.getText().toString(),10);
        mBytes[152] = (byte)Integer.parseInt(edtDriverCH10.getText().toString(),10);
        mBytes[153] = (byte)Integer.parseInt(edtDriverCH11.getText().toString(),10);
        mBytes[154] = (byte)Integer.parseInt(edtDriverCH12.getText().toString(),10);
        mBytes[155] = (byte)Integer.parseInt(edtDriverCH13.getText().toString(),10);
        mBytes[156] = (byte)Integer.parseInt(edtDriverCH14.getText().toString(),10);
        mBytes[157] = (byte)Integer.parseInt(edtDriverCH15.getText().toString(),10);
        mBytes[158] = (byte)Integer.parseInt(edtDriverCH16.getText().toString(),10);
        mBytes[159] = (byte)Integer.parseInt(edtDriverCH17.getText().toString(),10);
        mBytes[160] = (byte)Integer.parseInt(edtDriverCH18.getText().toString(),10);
        mBytes[161] = (byte)Integer.parseInt(edtDriverCH19.getText().toString(),10);
        mBytes[162] = (byte)Integer.parseInt(edtDriverCH20.getText().toString(),10);
        mBytes[163] = (byte)Integer.parseInt(edtDriverCH21.getText().toString(),10);
        mBytes[164] = (byte)Integer.parseInt(edtDriverCH22.getText().toString(),10);
        mBytes[165] = (byte)Integer.parseInt(edtDriverCH23.getText().toString(),10);
        mBytes[166] = (byte)Integer.parseInt(edtDriverCH24.getText().toString(),10);
        mBytes[167] = (byte)Integer.parseInt(edtDriverCH25.getText().toString(),10);
        mBytes[168] = (byte)Integer.parseInt(edtDriverCH26.getText().toString(),10);
        mBytes[169] = (byte)Integer.parseInt(edtDriverCH27.getText().toString(),10);
        mBytes[170] = (byte)Integer.parseInt(edtDriverCH28.getText().toString(),10);
        mBytes[171] = (byte)Integer.parseInt(edtDriverCH29.getText().toString(),10);
        mBytes[172] = (byte)Integer.parseInt(edtDriverCH30.getText().toString(),10);
        mBytes[173] = (byte)Integer.parseInt(edtDriverCH31.getText().toString(),10);
        mBytes[174] = (byte)Integer.parseInt(edtDriverCH32.getText().toString(),10);
        mBytes[175] = (byte)Integer.parseInt(edtDriverCH33.getText().toString(),10);
        mBytes[176] = (byte)Integer.parseInt(edtDriverCH34.getText().toString(),10);
        mBytes[177] = (byte)Integer.parseInt(edtDriverCH35.getText().toString(),10);
        mBytes[178] = (byte)Integer.parseInt(edtDriverCH36.getText().toString(),10);
        mBytes[179] = (byte)Integer.parseInt(edtDriverCH37.getText().toString(),10);
        mBytes[180] = (byte)Integer.parseInt(edtDriverCH38.getText().toString(),10);
        mBytes[181] = (byte)Integer.parseInt(edtDriverCH39.getText().toString(),10);
        mBytes[182] = (byte)Integer.parseInt(edtDriverCH40.getText().toString(),10);
        mBytes[183] = (byte)Integer.parseInt(edtDriverCH41.getText().toString(),10);

        int checksum = 0;
        for (int i = 0; i < 184; i++) {
            int k = mBytes[i] & 0xFF;
            checksum = checksum + k;
        }
        mBytes[184] = (byte)(256 - (checksum % 256));

        mBytes[185] = 1;

    }
    //======================================合并配置结束===========================================//

    @Override
    public void onClick(final View v) {
        byte starttemp;
        byte endtemp;
        byte revtemp;
        byte[] ichanneldata = new byte[44];
        StringBuilder configBuilder = new StringBuilder("");
        String[] stringArr;
        String value;
        byte addressH;
        byte addressL;
        int checksum;
        int checksum2;
        int ichecksumhead;
        long lchecksum;

        mShow.setText("");

        switch (v.getId()) {
            /*
            case R.id.tvsample:
                vpagerCfg.setCurrentItem(0);
                iChooseVPager = 0;
                break;
            case R.id.tvmoduleswitch:
                vpagerCfg.setCurrentItem(1);
                iChooseVPager = 1;
                break;
            case R.id.tvnormal:
                vpagerCfg.setCurrentItem(2);
                iChooseVPager = 2;
                break;
            case R.id.tvchannel:
                vpagerCfg.setCurrentItem(3);
                iChooseVPager = 3;
                break;
            case R.id.tvpen:
                vpagerCfg.setCurrentItem(4);
                iChooseVPager = 4;
                break;
            case R.id.tvplamrestrain:
                vpagerCfg.setCurrentItem(5);
                iChooseVPager = 5;
                break;
            case R.id.tvkey:
                vpagerCfg.setCurrentItem(6);
                iChooseVPager = 6;
                break;
            case R.id.tvhopping:
                vpagerCfg.setCurrentItem(7);
                iChooseVPager = 7;
                break;
            case R.id.tvcfgram:
                vpagerCfg.setCurrentItem(8);
                iChooseVPager = 8;
                break;

             */
            case R.id.btnsensorrev:
                configBuilder.append(edtSensorCH0.getText().toString()+",");
                configBuilder.append(edtSensorCH1.getText().toString()+",");
                configBuilder.append(edtSensorCH2.getText().toString()+",");
                configBuilder.append(edtSensorCH3.getText().toString()+",");
                configBuilder.append(edtSensorCH4.getText().toString()+",");
                configBuilder.append(edtSensorCH5.getText().toString()+",");
                configBuilder.append(edtSensorCH6.getText().toString()+",");
                configBuilder.append(edtSensorCH7.getText().toString()+",");
                configBuilder.append(edtSensorCH8.getText().toString()+",");
                configBuilder.append(edtSensorCH9.getText().toString()+",");
                configBuilder.append(edtSensorCH10.getText().toString()+",");
                configBuilder.append(edtSensorCH11.getText().toString()+",");
                configBuilder.append(edtSensorCH12.getText().toString()+",");
                configBuilder.append(edtSensorCH13.getText().toString()+",");
                configBuilder.append(edtSensorCH14.getText().toString()+",");
                configBuilder.append(edtSensorCH15.getText().toString()+",");
                configBuilder.append(edtSensorCH16.getText().toString()+",");
                configBuilder.append(edtSensorCH17.getText().toString()+",");
                configBuilder.append(edtSensorCH18.getText().toString()+",");
                configBuilder.append(edtSensorCH19.getText().toString()+",");
                configBuilder.append(edtSensorCH20.getText().toString()+",");
                configBuilder.append(edtSensorCH21.getText().toString()+",");
                configBuilder.append(edtSensorCH22.getText().toString()+",");
                configBuilder.append(edtSensorCH23.getText().toString()+",");
                configBuilder.append(edtSensorCH24.getText().toString()+",");
                configBuilder.append(edtSensorCH25.getText().toString()+",");
                configBuilder.append(edtSensorCH26.getText().toString()+",");
                configBuilder.append(edtSensorCH27.getText().toString()+",");
                configBuilder.append(edtSensorCH28.getText().toString()+",");
                configBuilder.append(edtSensorCH29.getText().toString()+",");
                configBuilder.append(edtSensorStart.getText().toString()+",");
                configBuilder.append(edtSensorEnd.getText().toString()+",");

                value = configBuilder.toString();
                stringArr = value.split(",");

                for (int b = 0; b < stringArr.length; b++) {
                    byte aByte = (byte) Integer.parseInt(stringArr[b], 10);
                    ichanneldata[b] = aByte;
                }

                starttemp = ichanneldata[30];
                endtemp = ichanneldata[31];
                if ((endtemp == 0) || (starttemp > endtemp)){
                    starttemp = 0;
                    if (bSensorNumber == 0){
                        endtemp = 29;
                    }else{
                        endtemp = (byte)(bSensorNumber - 1);
                    }
                }

                for(int i = starttemp,j = 0; i < (endtemp + 1) / 2; i++,j++){
                    revtemp = ichanneldata[i];
                    ichanneldata[i] = ichanneldata[endtemp - j];
                    ichanneldata[endtemp - j] = revtemp;
                }

                edtSensorCH0.setText(Integer.toString(ichanneldata[0] & 0xFF));
                edtSensorCH1.setText(Integer.toString(ichanneldata[1] & 0xFF));
                edtSensorCH2.setText(Integer.toString(ichanneldata[2] & 0xFF));
                edtSensorCH3.setText(Integer.toString(ichanneldata[3] & 0xFF));
                edtSensorCH4.setText(Integer.toString(ichanneldata[4] & 0xFF));
                edtSensorCH5.setText(Integer.toString(ichanneldata[5] & 0xFF));
                edtSensorCH6.setText(Integer.toString(ichanneldata[6] & 0xFF));
                edtSensorCH7.setText(Integer.toString(ichanneldata[7] & 0xFF));
                edtSensorCH8.setText(Integer.toString(ichanneldata[8] & 0xFF));
                edtSensorCH9.setText(Integer.toString(ichanneldata[9] & 0xFF));
                edtSensorCH10.setText(Integer.toString(ichanneldata[10] & 0xFF));
                edtSensorCH11.setText(Integer.toString(ichanneldata[11] & 0xFF));
                edtSensorCH12.setText(Integer.toString(ichanneldata[12] & 0xFF));
                edtSensorCH13.setText(Integer.toString(ichanneldata[13] & 0xFF));
                edtSensorCH14.setText(Integer.toString(ichanneldata[14] & 0xFF));
                edtSensorCH15.setText(Integer.toString(ichanneldata[15] & 0xFF));
                edtSensorCH16.setText(Integer.toString(ichanneldata[16] & 0xFF));
                edtSensorCH17.setText(Integer.toString(ichanneldata[17] & 0xFF));
                edtSensorCH18.setText(Integer.toString(ichanneldata[18] & 0xFF));
                edtSensorCH19.setText(Integer.toString(ichanneldata[19] & 0xFF));
                edtSensorCH20.setText(Integer.toString(ichanneldata[20] & 0xFF));
                edtSensorCH21.setText(Integer.toString(ichanneldata[21] & 0xFF));
                edtSensorCH22.setText(Integer.toString(ichanneldata[22] & 0xFF));
                edtSensorCH23.setText(Integer.toString(ichanneldata[23] & 0xFF));
                edtSensorCH24.setText(Integer.toString(ichanneldata[24] & 0xFF));
                edtSensorCH25.setText(Integer.toString(ichanneldata[25] & 0xFF));
                edtSensorCH26.setText(Integer.toString(ichanneldata[26] & 0xFF));
                edtSensorCH27.setText(Integer.toString(ichanneldata[27] & 0xFF));
                edtSensorCH28.setText(Integer.toString(ichanneldata[28] & 0xFF));
                edtSensorCH29.setText(Integer.toString(ichanneldata[29] & 0xFF));
                break;
            case R.id.allsensorchannels:
                edtSensorCH0.setText("00");edtSensorCH1.setText("01");edtSensorCH2.setText("02");edtSensorCH3.setText("03");edtSensorCH4.setText("04");
                edtSensorCH5.setText("05");edtSensorCH6.setText("06");edtSensorCH7.setText("07");edtSensorCH8.setText("08");edtSensorCH9.setText("09");
                edtSensorCH10.setText("10");edtSensorCH11.setText("11");edtSensorCH12.setText("12");edtSensorCH13.setText("13");edtSensorCH14.setText("14");
                edtSensorCH15.setText("15");edtSensorCH16.setText("16");edtSensorCH17.setText("17");edtSensorCH18.setText("18");edtSensorCH19.setText("19");
                edtSensorCH20.setText("20");edtSensorCH21.setText("21");edtSensorCH22.setText("22");edtSensorCH23.setText("23");edtSensorCH24.setText("24");
                edtSensorCH25.setText("25");edtSensorCH26.setText("26");edtSensorCH27.setText("27");edtSensorCH28.setText("28");edtSensorCH29.setText("29");
                break;
            case R.id.btndriverrev:
                configBuilder.append(edtDriverCH0.getText().toString()+",");
                configBuilder.append(edtDriverCH1.getText().toString()+",");
                configBuilder.append(edtDriverCH2.getText().toString()+",");
                configBuilder.append(edtDriverCH3.getText().toString()+",");
                configBuilder.append(edtDriverCH4.getText().toString()+",");
                configBuilder.append(edtDriverCH5.getText().toString()+",");
                configBuilder.append(edtDriverCH6.getText().toString()+",");
                configBuilder.append(edtDriverCH7.getText().toString()+",");
                configBuilder.append(edtDriverCH8.getText().toString()+",");
                configBuilder.append(edtDriverCH9.getText().toString()+",");
                configBuilder.append(edtDriverCH10.getText().toString()+",");
                configBuilder.append(edtDriverCH11.getText().toString()+",");
                configBuilder.append(edtDriverCH12.getText().toString()+",");
                configBuilder.append(edtDriverCH13.getText().toString()+",");
                configBuilder.append(edtDriverCH14.getText().toString()+",");
                configBuilder.append(edtDriverCH15.getText().toString()+",");
                configBuilder.append(edtDriverCH16.getText().toString()+",");
                configBuilder.append(edtDriverCH17.getText().toString()+",");
                configBuilder.append(edtDriverCH18.getText().toString()+",");
                configBuilder.append(edtDriverCH19.getText().toString()+",");
                configBuilder.append(edtDriverCH20.getText().toString()+",");
                configBuilder.append(edtDriverCH21.getText().toString()+",");
                configBuilder.append(edtDriverCH22.getText().toString()+",");
                configBuilder.append(edtDriverCH23.getText().toString()+",");
                configBuilder.append(edtDriverCH24.getText().toString()+",");
                configBuilder.append(edtDriverCH25.getText().toString()+",");
                configBuilder.append(edtDriverCH26.getText().toString()+",");
                configBuilder.append(edtDriverCH27.getText().toString()+",");
                configBuilder.append(edtDriverCH28.getText().toString()+",");
                configBuilder.append(edtDriverCH29.getText().toString()+",");
                configBuilder.append(edtDriverCH30.getText().toString()+",");
                configBuilder.append(edtDriverCH31.getText().toString()+",");
                configBuilder.append(edtDriverCH32.getText().toString()+",");
                configBuilder.append(edtDriverCH33.getText().toString()+",");
                configBuilder.append(edtDriverCH34.getText().toString()+",");
                configBuilder.append(edtDriverCH35.getText().toString()+",");
                configBuilder.append(edtDriverCH36.getText().toString()+",");
                configBuilder.append(edtDriverCH37.getText().toString()+",");
                configBuilder.append(edtDriverCH38.getText().toString()+",");
                configBuilder.append(edtDriverCH39.getText().toString()+",");
                configBuilder.append(edtDriverCH40.getText().toString()+",");
                configBuilder.append(edtDriverCH41.getText().toString()+",");
                configBuilder.append(edtDriverStart.getText().toString()+",");
                configBuilder.append(edtDriverEnd.getText().toString()+",");

                value = configBuilder.toString();
                stringArr = value.split(",");

                for (int b = 0; b < stringArr.length; b++) {
                    byte aByte = (byte) Integer.parseInt(stringArr[b], 10);
                    ichanneldata[b] = aByte;
                }

                starttemp = ichanneldata[42];
                endtemp = ichanneldata[43];
                if ((endtemp == 0) || (starttemp > endtemp)){
                    starttemp = 0;
                    if (bDriverNumber == 0){
                        endtemp = 41;
                    }else{
                        endtemp = (byte)(bDriverNumber - 1);
                    }
                }

                for(int i = starttemp,j = 0; i < (endtemp + 1) / 2; i++,j++){
                    revtemp = ichanneldata[i];
                    ichanneldata[i] = ichanneldata[endtemp - j];
                    ichanneldata[endtemp - j] = revtemp;
                }

                edtDriverCH0.setText(Integer.toString(ichanneldata[0] & 0xFF));
                edtDriverCH1.setText(Integer.toString(ichanneldata[1] & 0xFF));
                edtDriverCH2.setText(Integer.toString(ichanneldata[2] & 0xFF));
                edtDriverCH3.setText(Integer.toString(ichanneldata[3] & 0xFF));
                edtDriverCH4.setText(Integer.toString(ichanneldata[4] & 0xFF));
                edtDriverCH5.setText(Integer.toString(ichanneldata[5] & 0xFF));
                edtDriverCH6.setText(Integer.toString(ichanneldata[6] & 0xFF));
                edtDriverCH7.setText(Integer.toString(ichanneldata[7] & 0xFF));
                edtDriverCH8.setText(Integer.toString(ichanneldata[8] & 0xFF));
                edtDriverCH9.setText(Integer.toString(ichanneldata[9] & 0xFF));
                edtDriverCH10.setText(Integer.toString(ichanneldata[10] & 0xFF));
                edtDriverCH11.setText(Integer.toString(ichanneldata[11] & 0xFF));
                edtDriverCH12.setText(Integer.toString(ichanneldata[12] & 0xFF));
                edtDriverCH13.setText(Integer.toString(ichanneldata[13] & 0xFF));
                edtDriverCH14.setText(Integer.toString(ichanneldata[14] & 0xFF));
                edtDriverCH15.setText(Integer.toString(ichanneldata[15] & 0xFF));
                edtDriverCH16.setText(Integer.toString(ichanneldata[16] & 0xFF));
                edtDriverCH17.setText(Integer.toString(ichanneldata[17] & 0xFF));
                edtDriverCH18.setText(Integer.toString(ichanneldata[18] & 0xFF));
                edtDriverCH19.setText(Integer.toString(ichanneldata[19] & 0xFF));
                edtDriverCH20.setText(Integer.toString(ichanneldata[20] & 0xFF));
                edtDriverCH21.setText(Integer.toString(ichanneldata[21] & 0xFF));
                edtDriverCH22.setText(Integer.toString(ichanneldata[22] & 0xFF));
                edtDriverCH23.setText(Integer.toString(ichanneldata[23] & 0xFF));
                edtDriverCH24.setText(Integer.toString(ichanneldata[24] & 0xFF));
                edtDriverCH25.setText(Integer.toString(ichanneldata[25] & 0xFF));
                edtDriverCH26.setText(Integer.toString(ichanneldata[26] & 0xFF));
                edtDriverCH27.setText(Integer.toString(ichanneldata[27] & 0xFF));
                edtDriverCH28.setText(Integer.toString(ichanneldata[28] & 0xFF));
                edtDriverCH29.setText(Integer.toString(ichanneldata[29] & 0xFF));
                edtDriverCH30.setText(Integer.toString(ichanneldata[30] & 0xFF));
                edtDriverCH31.setText(Integer.toString(ichanneldata[31] & 0xFF));
                edtDriverCH32.setText(Integer.toString(ichanneldata[32] & 0xFF));
                edtDriverCH33.setText(Integer.toString(ichanneldata[33] & 0xFF));
                edtDriverCH34.setText(Integer.toString(ichanneldata[34] & 0xFF));
                edtDriverCH35.setText(Integer.toString(ichanneldata[35] & 0xFF));
                edtDriverCH36.setText(Integer.toString(ichanneldata[36] & 0xFF));
                edtDriverCH37.setText(Integer.toString(ichanneldata[37] & 0xFF));
                edtDriverCH38.setText(Integer.toString(ichanneldata[38] & 0xFF));
                edtDriverCH39.setText(Integer.toString(ichanneldata[39] & 0xFF));
                edtDriverCH40.setText(Integer.toString(ichanneldata[40] & 0xFF));
                edtDriverCH41.setText(Integer.toString(ichanneldata[41] & 0xFF));
                break;
            case R.id.alldriverchannels:
                edtDriverCH0.setText("00");edtDriverCH1.setText("01");edtDriverCH2.setText("02");edtDriverCH3.setText("03");edtDriverCH4.setText("04");
                edtDriverCH5.setText("05");edtDriverCH6.setText("06");edtDriverCH7.setText("07");edtDriverCH8.setText("08");edtDriverCH9.setText("09");
                edtDriverCH10.setText("10");edtDriverCH11.setText("11");edtDriverCH12.setText("12");edtDriverCH13.setText("13");edtDriverCH14.setText("14");
                edtDriverCH15.setText("15");edtDriverCH16.setText("16");edtDriverCH17.setText("17");edtDriverCH18.setText("18");edtDriverCH19.setText("19");
                edtDriverCH20.setText("20");edtDriverCH21.setText("21");edtDriverCH22.setText("22");edtDriverCH23.setText("23");edtDriverCH24.setText("24");
                edtDriverCH25.setText("25");edtDriverCH26.setText("26");edtDriverCH27.setText("27");edtDriverCH28.setText("28");edtDriverCH29.setText("29");
                edtDriverCH30.setText("30");edtDriverCH31.setText("31");edtDriverCH32.setText("32");edtDriverCH33.setText("33");edtDriverCH34.setText("34");
                edtDriverCH35.setText("35");edtDriverCH36.setText("36");edtDriverCH37.setText("37");edtDriverCH38.setText("38");edtDriverCH39.setText("39");
                edtDriverCH40.setText("40");edtDriverCH41.setText("41");
                break;
            case R.id.sendcfg:   //send cfg
                bottonMode = 1;

                if (byProductType == GT7) {
                    byte[] mBufferData = new byte[128];
                    byte aByte;

                    value = "80 00 80 00";
                    stringArr = value.split(" ");

                    addressH = (byte) 0x80;
                    addressL = (byte) 0x40;

                    for (int i = 0; i < stringArr.length; i++) {
                        aByte = (byte) Integer.parseInt(stringArr[i], 16);
                        mBufferData[i] = aByte;
                    }

                    iicWrite(addressH, addressL, mBufferData, 0, 3);
                    addressH = (byte) 0x82;
                    addressL = (byte) 0x4E;
                    iicWrite(addressH, addressL, mBufferData, 3, 1);
                }

                if (iChooseVPager == 8) {

                    if (byProductType == GT9) {
                        configBuilder.append(mCfg8047.getText().toString() + ",");
                        configBuilder.append(mCfg8048.getText().toString() + ",");
                        configBuilder.append(mCfg8049.getText().toString() + ",");
                        configBuilder.append(mCfg804A.getText().toString() + ",");
                        configBuilder.append(mCfg804B.getText().toString() + ",");
                        configBuilder.append(mCfg804C.getText().toString() + ",");
                        configBuilder.append(mCfg804D.getText().toString() + ",");
                        configBuilder.append(mCfg804E.getText().toString() + ",");
                        configBuilder.append(mCfg804F.getText().toString() + ",");
                    }

                    configBuilder.append(mCfg8050.getText().toString() + ",");
                    configBuilder.append(mCfg8051.getText().toString() + ",");
                    configBuilder.append(mCfg8052.getText().toString() + ",");
                    configBuilder.append(mCfg8053.getText().toString() + ",");
                    configBuilder.append(mCfg8054.getText().toString() + ",");
                    configBuilder.append(mCfg8055.getText().toString() + ",");
                    configBuilder.append(mCfg8056.getText().toString() + ",");
                    configBuilder.append(mCfg8057.getText().toString() + ",");
                    configBuilder.append(mCfg8058.getText().toString() + ",");
                    configBuilder.append(mCfg8059.getText().toString() + ",");
                    configBuilder.append(mCfg805A.getText().toString() + ",");
                    configBuilder.append(mCfg805B.getText().toString() + ",");
                    configBuilder.append(mCfg805C.getText().toString() + ",");
                    configBuilder.append(mCfg805D.getText().toString() + ",");
                    configBuilder.append(mCfg805E.getText().toString() + ",");
                    configBuilder.append(mCfg805F.getText().toString() + ",");

                    configBuilder.append(mCfg8060.getText().toString() + ",");
                    configBuilder.append(mCfg8061.getText().toString() + ",");
                    configBuilder.append(mCfg8062.getText().toString() + ",");
                    configBuilder.append(mCfg8063.getText().toString() + ",");
                    configBuilder.append(mCfg8064.getText().toString() + ",");
                    configBuilder.append(mCfg8065.getText().toString() + ",");
                    configBuilder.append(mCfg8066.getText().toString() + ",");
                    configBuilder.append(mCfg8067.getText().toString() + ",");
                    configBuilder.append(mCfg8068.getText().toString() + ",");
                    configBuilder.append(mCfg8069.getText().toString() + ",");
                    configBuilder.append(mCfg806A.getText().toString() + ",");
                    configBuilder.append(mCfg806B.getText().toString() + ",");
                    configBuilder.append(mCfg806C.getText().toString() + ",");
                    configBuilder.append(mCfg806D.getText().toString() + ",");
                    configBuilder.append(mCfg806E.getText().toString() + ",");
                    configBuilder.append(mCfg806F.getText().toString() + ",");

                    configBuilder.append(mCfg8070.getText().toString() + ",");
                    configBuilder.append(mCfg8071.getText().toString() + ",");
                    configBuilder.append(mCfg8072.getText().toString() + ",");
                    configBuilder.append(mCfg8073.getText().toString() + ",");
                    configBuilder.append(mCfg8074.getText().toString() + ",");
                    configBuilder.append(mCfg8075.getText().toString() + ",");
                    configBuilder.append(mCfg8076.getText().toString() + ",");
                    configBuilder.append(mCfg8077.getText().toString() + ",");
                    configBuilder.append(mCfg8078.getText().toString() + ",");
                    configBuilder.append(mCfg8079.getText().toString() + ",");
                    configBuilder.append(mCfg807A.getText().toString() + ",");
                    configBuilder.append(mCfg807B.getText().toString() + ",");
                    configBuilder.append(mCfg807C.getText().toString() + ",");
                    configBuilder.append(mCfg807D.getText().toString() + ",");
                    configBuilder.append(mCfg807E.getText().toString() + ",");
                    configBuilder.append(mCfg807F.getText().toString() + ",");

                    configBuilder.append(mCfg8080.getText().toString() + ",");
                    configBuilder.append(mCfg8081.getText().toString() + ",");
                    configBuilder.append(mCfg8082.getText().toString() + ",");
                    configBuilder.append(mCfg8083.getText().toString() + ",");
                    configBuilder.append(mCfg8084.getText().toString() + ",");
                    configBuilder.append(mCfg8085.getText().toString() + ",");
                    configBuilder.append(mCfg8086.getText().toString() + ",");
                    configBuilder.append(mCfg8087.getText().toString() + ",");
                    configBuilder.append(mCfg8088.getText().toString() + ",");
                    configBuilder.append(mCfg8089.getText().toString() + ",");
                    configBuilder.append(mCfg808A.getText().toString() + ",");
                    configBuilder.append(mCfg808B.getText().toString() + ",");
                    configBuilder.append(mCfg808C.getText().toString() + ",");
                    configBuilder.append(mCfg808D.getText().toString() + ",");
                    configBuilder.append(mCfg808E.getText().toString() + ",");
                    configBuilder.append(mCfg808F.getText().toString() + ",");

                    configBuilder.append(mCfg8090.getText().toString() + ",");
                    configBuilder.append(mCfg8091.getText().toString() + ",");
                    configBuilder.append(mCfg8092.getText().toString() + ",");
                    configBuilder.append(mCfg8093.getText().toString() + ",");
                    configBuilder.append(mCfg8094.getText().toString() + ",");
                    configBuilder.append(mCfg8095.getText().toString() + ",");
                    configBuilder.append(mCfg8096.getText().toString() + ",");
                    configBuilder.append(mCfg8097.getText().toString() + ",");
                    configBuilder.append(mCfg8098.getText().toString() + ",");
                    configBuilder.append(mCfg8099.getText().toString() + ",");
                    configBuilder.append(mCfg809A.getText().toString() + ",");
                    configBuilder.append(mCfg809B.getText().toString() + ",");
                    configBuilder.append(mCfg809C.getText().toString() + ",");
                    configBuilder.append(mCfg809D.getText().toString() + ",");
                    configBuilder.append(mCfg809E.getText().toString() + ",");
                    configBuilder.append(mCfg809F.getText().toString() + ",");

                    configBuilder.append(mCfg80A0.getText().toString() + ",");
                    configBuilder.append(mCfg80A1.getText().toString() + ",");
                    configBuilder.append(mCfg80A2.getText().toString() + ",");
                    configBuilder.append(mCfg80A3.getText().toString() + ",");
                    configBuilder.append(mCfg80A4.getText().toString() + ",");
                    configBuilder.append(mCfg80A5.getText().toString() + ",");
                    configBuilder.append(mCfg80A6.getText().toString() + ",");
                    configBuilder.append(mCfg80A7.getText().toString() + ",");
                    configBuilder.append(mCfg80A8.getText().toString() + ",");
                    configBuilder.append(mCfg80A9.getText().toString() + ",");
                    configBuilder.append(mCfg80AA.getText().toString() + ",");
                    configBuilder.append(mCfg80AB.getText().toString() + ",");
                    configBuilder.append(mCfg80AC.getText().toString() + ",");
                    configBuilder.append(mCfg80AD.getText().toString() + ",");
                    configBuilder.append(mCfg80AE.getText().toString() + ",");
                    configBuilder.append(mCfg80AF.getText().toString() + ",");

                    configBuilder.append(mCfg80B0.getText().toString() + ",");
                    configBuilder.append(mCfg80B1.getText().toString() + ",");
                    configBuilder.append(mCfg80B2.getText().toString() + ",");
                    configBuilder.append(mCfg80B3.getText().toString() + ",");
                    configBuilder.append(mCfg80B4.getText().toString() + ",");
                    configBuilder.append(mCfg80B5.getText().toString() + ",");
                    configBuilder.append(mCfg80B6.getText().toString() + ",");
                    configBuilder.append(mCfg80B7.getText().toString() + ",");
                    configBuilder.append(mCfg80B8.getText().toString() + ",");
                    configBuilder.append(mCfg80B9.getText().toString() + ",");
                    configBuilder.append(mCfg80BA.getText().toString() + ",");
                    configBuilder.append(mCfg80BB.getText().toString() + ",");
                    configBuilder.append(mCfg80BC.getText().toString() + ",");
                    configBuilder.append(mCfg80BD.getText().toString() + ",");
                    configBuilder.append(mCfg80BE.getText().toString() + ",");
                    configBuilder.append(mCfg80BF.getText().toString() + ",");

                    configBuilder.append(mCfg80C0.getText().toString() + ",");
                    configBuilder.append(mCfg80C1.getText().toString() + ",");
                    configBuilder.append(mCfg80C2.getText().toString() + ",");
                    configBuilder.append(mCfg80C3.getText().toString() + ",");
                    configBuilder.append(mCfg80C4.getText().toString() + ",");
                    configBuilder.append(mCfg80C5.getText().toString() + ",");
                    configBuilder.append(mCfg80C6.getText().toString() + ",");
                    configBuilder.append(mCfg80C7.getText().toString() + ",");
                    configBuilder.append(mCfg80C8.getText().toString() + ",");
                    configBuilder.append(mCfg80C9.getText().toString() + ",");
                    configBuilder.append(mCfg80CA.getText().toString() + ",");
                    configBuilder.append(mCfg80CB.getText().toString() + ",");
                    configBuilder.append(mCfg80CC.getText().toString() + ",");
                    configBuilder.append(mCfg80CD.getText().toString() + ",");
                    configBuilder.append(mCfg80CE.getText().toString() + ",");
                    configBuilder.append(mCfg80CF.getText().toString() + ",");

                    configBuilder.append(mCfg80D0.getText().toString() + ",");
                    configBuilder.append(mCfg80D1.getText().toString() + ",");
                    configBuilder.append(mCfg80D2.getText().toString() + ",");
                    configBuilder.append(mCfg80D3.getText().toString() + ",");
                    configBuilder.append(mCfg80D4.getText().toString() + ",");
                    configBuilder.append(mCfg80D5.getText().toString() + ",");
                    configBuilder.append(mCfg80D6.getText().toString() + ",");
                    configBuilder.append(mCfg80D7.getText().toString() + ",");
                    configBuilder.append(mCfg80D8.getText().toString() + ",");
                    configBuilder.append(mCfg80D9.getText().toString() + ",");
                    configBuilder.append(mCfg80DA.getText().toString() + ",");
                    configBuilder.append(mCfg80DB.getText().toString() + ",");
                    configBuilder.append(mCfg80DC.getText().toString() + ",");
                    configBuilder.append(mCfg80DD.getText().toString() + ",");
                    configBuilder.append(mCfg80DE.getText().toString() + ",");
                    configBuilder.append(mCfg80DF.getText().toString() + ",");

                    configBuilder.append(mCfg80E0.getText().toString() + ",");
                    configBuilder.append(mCfg80E1.getText().toString() + ",");
                    configBuilder.append(mCfg80E2.getText().toString() + ",");
                    configBuilder.append(mCfg80E3.getText().toString() + ",");
                    configBuilder.append(mCfg80E4.getText().toString() + ",");
                    configBuilder.append(mCfg80E5.getText().toString() + ",");
                    configBuilder.append(mCfg80E6.getText().toString() + ",");
                    configBuilder.append(mCfg80E7.getText().toString() + ",");
                    configBuilder.append(mCfg80E8.getText().toString() + ",");
                    configBuilder.append(mCfg80E9.getText().toString() + ",");
                    configBuilder.append(mCfg80EA.getText().toString() + ",");
                    configBuilder.append(mCfg80EB.getText().toString() + ",");
                    configBuilder.append(mCfg80EC.getText().toString() + ",");
                    configBuilder.append(mCfg80ED.getText().toString() + ",");
                    configBuilder.append(mCfg80EE.getText().toString() + ",");
                    configBuilder.append(mCfg80EF.getText().toString() + ",");

                    configBuilder.append(mCfg80F0.getText().toString() + ",");
                    configBuilder.append(mCfg80F1.getText().toString() + ",");
                    configBuilder.append(mCfg80F2.getText().toString() + ",");
                    configBuilder.append(mCfg80F3.getText().toString() + ",");
                    configBuilder.append(mCfg80F4.getText().toString() + ",");
                    configBuilder.append(mCfg80F5.getText().toString() + ",");
                    configBuilder.append(mCfg80F6.getText().toString() + ",");
                    configBuilder.append(mCfg80F7.getText().toString() + ",");
                    configBuilder.append(mCfg80F8.getText().toString() + ",");
                    configBuilder.append(mCfg80F9.getText().toString() + ",");
                    configBuilder.append(mCfg80FA.getText().toString() + ",");
                    configBuilder.append(mCfg80FB.getText().toString() + ",");
                    configBuilder.append(mCfg80FC.getText().toString() + ",");
                    configBuilder.append(mCfg80FD.getText().toString() + ",");
                    configBuilder.append(mCfg80FE.getText().toString() + ",");
                    configBuilder.append(mCfg80FF.getText().toString() + ",");

                    if (byProductType == GT9) {
                        configBuilder.append(mCfg8100.getText().toString());
                    }else {  //GT7
                        configBuilder.append(mCfg8100.getText().toString() + ",");
                        configBuilder.append(mCfg8101.getText().toString() + ",");
                        configBuilder.append(mCfg8102.getText().toString() + ",");
                        configBuilder.append(mCfg8103.getText().toString() + ",");
                        configBuilder.append(mCfg8104.getText().toString() + ",");
                        configBuilder.append(mCfg8105.getText().toString() + ",");
                        configBuilder.append(mCfg8106.getText().toString() + ",");
                        configBuilder.append(mCfg8107.getText().toString() + ",");
                        configBuilder.append(mCfg8108.getText().toString() + ",");
                        configBuilder.append(mCfg8109.getText().toString() + ",");
                        configBuilder.append(mCfg810A.getText().toString() + ",");
                        configBuilder.append(mCfg810B.getText().toString() + ",");
                        configBuilder.append(mCfg810C.getText().toString() + ",");
                        configBuilder.append(mCfg810D.getText().toString() + ",");
                        configBuilder.append(mCfg810E.getText().toString() + ",");
                        configBuilder.append(mCfg810F.getText().toString() + ",");

                        configBuilder.append(mCfg8110.getText().toString() + ",");
                        configBuilder.append(mCfg8111.getText().toString() + ",");
                        configBuilder.append(mCfg8112.getText().toString() + ",");
                        configBuilder.append(mCfg8113.getText().toString() + ",");
                        configBuilder.append(mCfg8114.getText().toString() + ",");
                        configBuilder.append(mCfg8115.getText().toString() + ",");
                        configBuilder.append(mCfg8116.getText().toString() + ",");
                        configBuilder.append(mCfg8117.getText().toString() + ",");
                        configBuilder.append(mCfg8118.getText().toString() + ",");
                        configBuilder.append(mCfg8119.getText().toString() + ",");
                        configBuilder.append(mCfg811A.getText().toString() + ",");
                        configBuilder.append(mCfg811B.getText().toString() + ",");
                        configBuilder.append(mCfg811C.getText().toString() + ",");
                        configBuilder.append(mCfg811D.getText().toString() + ",");
                        configBuilder.append(mCfg811E.getText().toString() + ",");
                        configBuilder.append(mCfg811F.getText().toString() + ",");

                        configBuilder.append(mCfg8120.getText().toString() + ",");
                        configBuilder.append(mCfg8121.getText().toString() + ",");
                        configBuilder.append(mCfg8122.getText().toString() + ",");
                        configBuilder.append(mCfg8123.getText().toString() + ",");
                        configBuilder.append(mCfg8124.getText().toString() + ",");
                        configBuilder.append(mCfg8125.getText().toString() + ",");
                        configBuilder.append(mCfg8126.getText().toString() + ",");
                        configBuilder.append(mCfg8127.getText().toString() + ",");
                        configBuilder.append(mCfg8128.getText().toString() + ",");
                        configBuilder.append(mCfg8129.getText().toString() + ",");
                        configBuilder.append(mCfg812A.getText().toString() + ",");
                        configBuilder.append(mCfg812B.getText().toString() + ",");
                        configBuilder.append(mCfg812C.getText().toString() + ",");
                        configBuilder.append(mCfg812D.getText().toString() + ",");
                        configBuilder.append(mCfg812E.getText().toString() + ",");
                        configBuilder.append(mCfg812F.getText().toString() + ",");

                        configBuilder.append(mCfg8130.getText().toString() + ",");
                        configBuilder.append(mCfg8131.getText().toString() + ",");
                        configBuilder.append(mCfg8132.getText().toString() + ",");
                        configBuilder.append(mCfg8133.getText().toString() + ",");
                        configBuilder.append(mCfg8134.getText().toString() + ",");
                        configBuilder.append(mCfg8135.getText().toString() + ",");
                        configBuilder.append(mCfg8136.getText().toString() + ",");
                        configBuilder.append(mCfg8137.getText().toString() + ",");
                        configBuilder.append(mCfg8138.getText().toString() + ",");
                        configBuilder.append(mCfg8139.getText().toString() + ",");
                        configBuilder.append(mCfg813A.getText().toString() + ",");
                        configBuilder.append(mCfg813B.getText().toString() + ",");
                        configBuilder.append(mCfg813C.getText().toString() + ",");
                        configBuilder.append(mCfg813D.getText().toString() + ",");
                        configBuilder.append(mCfg813E.getText().toString() + ",");
                        configBuilder.append(mCfg813F.getText().toString() + ",");

                        configBuilder.append(mCfg8140.getText().toString() + ",");
                        configBuilder.append(mCfg8141.getText().toString() + ",");
                        configBuilder.append(mCfg8142.getText().toString() + ",");
                        configBuilder.append(mCfg8143.getText().toString() + ",");
                        configBuilder.append(mCfg8144.getText().toString() + ",");
                        configBuilder.append(mCfg8145.getText().toString() + ",");
                        configBuilder.append(mCfg8146.getText().toString() + ",");
                        configBuilder.append(mCfg8147.getText().toString() + ",");
                        configBuilder.append(mCfg8148.getText().toString() + ",");
                        configBuilder.append(mCfg8149.getText().toString() + ",");
                        configBuilder.append(mCfg814A.getText().toString() + ",");
                        configBuilder.append(mCfg814B.getText().toString() + ",");
                        configBuilder.append(mCfg814C.getText().toString() + ",");
                        configBuilder.append(mCfg814D.getText().toString() + ",");
                        configBuilder.append(mCfg814E.getText().toString() + ",");
                        configBuilder.append(mCfg814F.getText().toString() + ",");

                        configBuilder.append(mCfg8150.getText().toString() + ",");
                        configBuilder.append(mCfg8151.getText().toString() + ",");
                        configBuilder.append(mCfg8152.getText().toString() + ",");
                        configBuilder.append(mCfg8153.getText().toString() + ",");
                        configBuilder.append(mCfg8154.getText().toString() + ",");
                        configBuilder.append(mCfg8155.getText().toString() + ",");
                        configBuilder.append(mCfg8156.getText().toString() + ",");
                        configBuilder.append(mCfg8157.getText().toString() + ",");
                        configBuilder.append(mCfg8158.getText().toString() + ",");
                        configBuilder.append(mCfg8159.getText().toString() + ",");
                        configBuilder.append(mCfg815A.getText().toString() + ",");
                        configBuilder.append(mCfg815B.getText().toString() + ",");
                        configBuilder.append(mCfg815C.getText().toString() + ",");
                        configBuilder.append(mCfg815D.getText().toString() + ",");
                        configBuilder.append(mCfg815E.getText().toString() + ",");
                        configBuilder.append(mCfg815F.getText().toString() + ",");

                        configBuilder.append(mCfg8160.getText().toString() + ",");
                        configBuilder.append(mCfg8161.getText().toString() + ",");
                        configBuilder.append(mCfg8162.getText().toString() + ",");
                        configBuilder.append(mCfg8163.getText().toString() + ",");
                        configBuilder.append(mCfg8164.getText().toString() + ",");
                        configBuilder.append(mCfg8165.getText().toString() + ",");
                        configBuilder.append(mCfg8166.getText().toString() + ",");
                        configBuilder.append(mCfg8167.getText().toString() + ",");
                        configBuilder.append(mCfg8168.getText().toString() + ",");
                        configBuilder.append(mCfg8169.getText().toString() + ",");
                        configBuilder.append(mCfg816A.getText().toString() + ",");
                        configBuilder.append(mCfg816B.getText().toString() + ",");
                        configBuilder.append(mCfg816C.getText().toString() + ",");
                        configBuilder.append(mCfg816D.getText().toString() + ",");
                        configBuilder.append(mCfg816E.getText().toString() + ",");
                        configBuilder.append(mCfg816F.getText().toString() + ",");

                        configBuilder.append(mCfg8170.getText().toString() + ",");
                        configBuilder.append(mCfg8171.getText().toString() + ",");
                        configBuilder.append(mCfg8172.getText().toString() + ",");
                        configBuilder.append(mCfg8173.getText().toString() + ",");
                        configBuilder.append(mCfg8174.getText().toString() + ",");
                        configBuilder.append(mCfg8175.getText().toString() + ",");
                        configBuilder.append(mCfg8176.getText().toString() + ",");
                        configBuilder.append(mCfg8177.getText().toString() + ",");
                        configBuilder.append(mCfg8178.getText().toString() + ",");
                        configBuilder.append(mCfg8179.getText().toString() + ",");
                        configBuilder.append(mCfg817A.getText().toString() + ",");
                        configBuilder.append(mCfg817B.getText().toString() + ",");
                        configBuilder.append(mCfg817C.getText().toString() + ",");
                        configBuilder.append(mCfg817D.getText().toString() + ",");
                        configBuilder.append(mCfg817E.getText().toString() + ",");
                        configBuilder.append(mCfg817F.getText().toString() + ",");

                        configBuilder.append(mCfg8180.getText().toString() + ",");
                        configBuilder.append(mCfg8181.getText().toString() + ",");
                        configBuilder.append(mCfg8182.getText().toString() + ",");
                        configBuilder.append(mCfg8183.getText().toString() + ",");
                        configBuilder.append(mCfg8184.getText().toString() + ",");
                        configBuilder.append(mCfg8185.getText().toString() + ",");
                        configBuilder.append(mCfg8186.getText().toString() + ",");
                        configBuilder.append(mCfg8187.getText().toString() + ",");
                        configBuilder.append(mCfg8188.getText().toString() + ",");
                        configBuilder.append(mCfg8189.getText().toString() + ",");
                        configBuilder.append(mCfg818A.getText().toString() + ",");
                        configBuilder.append(mCfg818B.getText().toString() + ",");
                        configBuilder.append(mCfg818C.getText().toString() + ",");
                        configBuilder.append(mCfg818D.getText().toString() + ",");
                        configBuilder.append(mCfg818E.getText().toString() + ",");
                        configBuilder.append(mCfg818F.getText().toString() + ",");

                        configBuilder.append(mCfg8190.getText().toString() + ",");
                        configBuilder.append(mCfg8191.getText().toString() + ",");
                        configBuilder.append(mCfg8192.getText().toString() + ",");
                        configBuilder.append(mCfg8193.getText().toString() + ",");
                        configBuilder.append(mCfg8194.getText().toString() + ",");
                        configBuilder.append(mCfg8195.getText().toString() + ",");
                        configBuilder.append(mCfg8196.getText().toString() + ",");
                        configBuilder.append(mCfg8197.getText().toString() + ",");
                        configBuilder.append(mCfg8198.getText().toString() + ",");
                        configBuilder.append(mCfg8199.getText().toString() + ",");
                        configBuilder.append(mCfg819A.getText().toString() + ",");
                        configBuilder.append(mCfg819B.getText().toString() + ",");
                        configBuilder.append(mCfg819C.getText().toString() + ",");
                        configBuilder.append(mCfg819D.getText().toString() + ",");
                        configBuilder.append(mCfg819E.getText().toString() + ",");
                        configBuilder.append(mCfg819F.getText().toString() + ",");

                        configBuilder.append(mCfg81A0.getText().toString() + ",");
                        configBuilder.append(mCfg81A1.getText().toString() + ",");
                        configBuilder.append(mCfg81A2.getText().toString() + ",");
                        configBuilder.append(mCfg81A3.getText().toString() + ",");
                        configBuilder.append(mCfg81A4.getText().toString() + ",");
                        configBuilder.append(mCfg81A5.getText().toString() + ",");
                        configBuilder.append(mCfg81A6.getText().toString() + ",");
                        configBuilder.append(mCfg81A7.getText().toString() + ",");
                        configBuilder.append(mCfg81A8.getText().toString() + ",");
                        configBuilder.append(mCfg81A9.getText().toString() + ",");
                        configBuilder.append(mCfg81AA.getText().toString() + ",");
                        configBuilder.append(mCfg81AB.getText().toString() + ",");
                        configBuilder.append(mCfg81AC.getText().toString() + ",");
                        configBuilder.append(mCfg81AD.getText().toString() + ",");
                        configBuilder.append(mCfg81AE.getText().toString() + ",");
                        configBuilder.append(mCfg81AF.getText().toString() + ",");

                        configBuilder.append(mCfg81B0.getText().toString() + ",");
                        configBuilder.append(mCfg81B1.getText().toString() + ",");
                        configBuilder.append(mCfg81B2.getText().toString() + ",");
                        configBuilder.append(mCfg81B3.getText().toString() + ",");
                        configBuilder.append(mCfg81B4.getText().toString() + ",");
                        configBuilder.append(mCfg81B5.getText().toString() + ",");
                        configBuilder.append(mCfg81B6.getText().toString() + ",");
                        configBuilder.append(mCfg81B7.getText().toString() + ",");
                        configBuilder.append(mCfg81B8.getText().toString() + ",");
                        configBuilder.append(mCfg81B9.getText().toString() + ",");
                        configBuilder.append(mCfg81BA.getText().toString() + ",");
                        configBuilder.append(mCfg81BB.getText().toString() + ",");
                        configBuilder.append(mCfg81BC.getText().toString() + ",");
                        configBuilder.append(mCfg81BD.getText().toString() + ",");
                        configBuilder.append(mCfg81BE.getText().toString() + ",");
                        configBuilder.append(mCfg81BF.getText().toString() + ",");

                        configBuilder.append(mCfg81C0.getText().toString() + ",");
                        configBuilder.append(mCfg81C1.getText().toString() + ",");
                        configBuilder.append(mCfg81C2.getText().toString() + ",");
                        configBuilder.append(mCfg81C3.getText().toString() + ",");
                        configBuilder.append(mCfg81C4.getText().toString() + ",");
                        configBuilder.append(mCfg81C5.getText().toString() + ",");
                        configBuilder.append(mCfg81C6.getText().toString() + ",");
                        configBuilder.append(mCfg81C7.getText().toString() + ",");
                        configBuilder.append(mCfg81C8.getText().toString() + ",");
                        configBuilder.append(mCfg81C9.getText().toString() + ",");
                        configBuilder.append(mCfg81CA.getText().toString() + ",");
                        configBuilder.append(mCfg81CB.getText().toString() + ",");
                        configBuilder.append(mCfg81CC.getText().toString() + ",");
                        configBuilder.append(mCfg81CD.getText().toString() + ",");
                        configBuilder.append(mCfg81CE.getText().toString() + ",");
                        configBuilder.append(mCfg81CF.getText().toString() + ",");

                        configBuilder.append(mCfg81D0.getText().toString() + ",");
                        configBuilder.append(mCfg81D1.getText().toString() + ",");
                        configBuilder.append(mCfg81D2.getText().toString() + ",");
                        configBuilder.append(mCfg81D3.getText().toString() + ",");
                        configBuilder.append(mCfg81D4.getText().toString() + ",");
                        configBuilder.append(mCfg81D5.getText().toString() + ",");
                        configBuilder.append(mCfg81D6.getText().toString() + ",");
                        configBuilder.append(mCfg81D7.getText().toString() + ",");
                        configBuilder.append(mCfg81D8.getText().toString() + ",");
                        configBuilder.append(mCfg81D9.getText().toString() + ",");
                        configBuilder.append(mCfg81DA.getText().toString() + ",");
                        configBuilder.append(mCfg81DB.getText().toString() + ",");
                        configBuilder.append(mCfg81DC.getText().toString() + ",");
                        configBuilder.append(mCfg81DD.getText().toString() + ",");
                        configBuilder.append(mCfg81DE.getText().toString() + ",");
                        configBuilder.append(mCfg81DF.getText().toString() + ",");

                        configBuilder.append(mCfg81E0.getText().toString() + ",");
                        configBuilder.append(mCfg81E1.getText().toString() + ",");
                        configBuilder.append(mCfg81E2.getText().toString() + ",");
                        configBuilder.append(mCfg81E3.getText().toString() + ",");
                        configBuilder.append(mCfg81E4.getText().toString() + ",");
                        configBuilder.append(mCfg81E5.getText().toString() + ",");
                        configBuilder.append(mCfg81E6.getText().toString() + ",");
                        configBuilder.append(mCfg81E7.getText().toString() + ",");
                        configBuilder.append(mCfg81E8.getText().toString() + ",");
                        configBuilder.append(mCfg81E9.getText().toString() + ",");
                        configBuilder.append(mCfg81EA.getText().toString() + ",");
                        configBuilder.append(mCfg81EB.getText().toString() + ",");
                        configBuilder.append(mCfg81EC.getText().toString() + ",");
                        configBuilder.append(mCfg81ED.getText().toString() + ",");
                        configBuilder.append(mCfg81EE.getText().toString() + ",");
                        configBuilder.append(mCfg81EF.getText().toString() + ",");

                        configBuilder.append(mCfg81F0.getText().toString() + ",");
                        configBuilder.append(mCfg81F1.getText().toString() + ",");
                        configBuilder.append(mCfg81F2.getText().toString() + ",");
                        configBuilder.append(mCfg81F3.getText().toString() + ",");
                        configBuilder.append(mCfg81F4.getText().toString() + ",");
                        configBuilder.append(mCfg81F5.getText().toString() + ",");
                        configBuilder.append(mCfg81F6.getText().toString() + ",");
                        configBuilder.append(mCfg81F7.getText().toString() + ",");
                        configBuilder.append(mCfg81F8.getText().toString() + ",");
                        configBuilder.append(mCfg81F9.getText().toString() + ",");
                        configBuilder.append(mCfg81FA.getText().toString() + ",");
                        configBuilder.append(mCfg81FB.getText().toString() + ",");
                        configBuilder.append(mCfg81FC.getText().toString() + ",");
                        configBuilder.append(mCfg81FD.getText().toString() + ",");
                        configBuilder.append(mCfg81FE.getText().toString() + ",");
                        configBuilder.append(mCfg81FF.getText().toString() + ",");

                        configBuilder.append(mCfg8200.getText().toString() + ",");
                        configBuilder.append(mCfg8201.getText().toString() + ",");
                        configBuilder.append(mCfg8202.getText().toString() + ",");
                        configBuilder.append(mCfg8203.getText().toString() + ",");
                        configBuilder.append(mCfg8204.getText().toString() + ",");
                        configBuilder.append(mCfg8205.getText().toString() + ",");
                        configBuilder.append(mCfg8206.getText().toString() + ",");
                        configBuilder.append(mCfg8207.getText().toString() + ",");
                        configBuilder.append(mCfg8208.getText().toString() + ",");
                        configBuilder.append(mCfg8209.getText().toString() + ",");
                        configBuilder.append(mCfg820A.getText().toString() + ",");
                        configBuilder.append(mCfg820B.getText().toString());
                    }
                }else{ //在其他界面则保存
                    if (byProductType == GT9) {
                        CombineCfg();
                        for (int i = 0; i < 185; i++) {
                            String hv = Integer.toHexString(mBytes[i] & 0xFF);
                            if (hv.length() < 2) {
                                hv = "0" + hv;
                            }
                            configBuilder.append(hv + ",");
                        }

                        configBuilder.append("01");  //mBytes[185]，最后置上1
                    }
                }
                //mShow.setText(configBuilder.toString());

                //send 0x00 to [0x10174]，清楚标志
                mBytes[0] = 0x00;
                iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes,0,1);
                SystemClock.sleep(15);

                //send 0x00 0x00 0x04 0x04 0x08 0x00 to [0x10174]，通知GT29XX,send cfg
                mBytes[0] = 0x00;
                mBytes[1] = 0x00;
                mBytes[2] = 0x04;
                mBytes[3] = 0x04;
                mBytes[4] = 0x08;
                mBytes[5] = 0x00;
                iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes,0,6);

                //30ms一次轮询[0x10174]，如果是0x80，说明GT29XX已准备好，可以send cfg
                do {
                    SystemClock.sleep(30);
                    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
                }while(mBytes[0] != (byte)0x80);

                //value = configBuilder.toString();
                value = edtConfigDataShow.getText().toString();
                value = value.replaceAll("0x", ""); //0x转换为没有
                stringArr = value.split(",");

                //value = value.replace(',', ' '); //逗号转换为空格

                //value = value.trim();  //去除空格
                //value = value.replaceAll(" ", ""); //逗号转换为空格
                //char mTextData[] = value.toCharArray();
                byte[] mBufferData = new byte[2048];

                for (int b = 0; b < stringArr.length; b++) {
                    byte aByte = (byte) Integer.parseInt(stringArr[b], 16);
                    mBufferData[b] = aByte;
                }
                //mBufferData = value.getBytes();
                mSendData = new byte[2048];

                //重新计算checksum

                    //head buffer长度为64字节，最后两个字节是checksum，低位在前存放
                    ichecksumhead = 0;
                    for (int i = 0; i < 62; i++) {
                        int vb = mBufferData[i] & 0xFF;
                        ichecksumhead = ichecksumhead + vb;
                    }

                    mBufferData[62] = (byte)(ichecksumhead & 0x00ff);
                    mBufferData[63] = (byte)((ichecksumhead & 0xff00) >> 8);

                    //配置长度（不含head buffer长度）
                    int iconfiglen = (int)(mBufferData[60] & 0xFF) * 256 + (mBufferData[59] & 0xFF);

                    //计算配置的checksum，不含64字节的head buffer
                    lchecksum = 0;
                    for (int i = 64; i < (iconfiglen + 64 - 4); i += 2) {
                        int vb = ((mBufferData[i + 1] & 0xFF) << 8) + (mBufferData[i] & 0xFF);
                        lchecksum = lchecksum + vb;
                    }

                    mBufferData[iconfiglen + 64 - 4] = (byte)(lchecksum & 0x000000ff);
                    mBufferData[iconfiglen + 64 - 3] = (byte)((lchecksum & 0x0000ff00) >> 8);
                    mBufferData[iconfiglen + 64 - 2] = (byte)((lchecksum & 0x00ff0000) >> 16);
                    mBufferData[iconfiglen + 64 - 1] = (byte)((lchecksum & 0xff000000) >> 24);

                    iicWrite32Bits((byte)0x01, (byte)0x3B, (byte)0x74, mBufferData,0,iconfiglen + 64);
                    SystemClock.sleep(8);

                    //send 0x00 0x00 0x04 0x05 0x09 0x00 to [0x10174]，通知GT29XX,cfg发送完毕
                    mBytes[0] = 0x00;
                    mBytes[1] = 0x00;
                    mBytes[2] = 0x04;
                    mBytes[3] = 0x05;
                    mBytes[4] = 0x09;
                    mBytes[5] = 0x00;
                    iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes,0,6);

                    //30ms一次轮询[0x10174]，如果是0x80，说明GT29XX已接收配置
                    do {
                        SystemClock.sleep(30);
                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
                    }while(mBytes[0] != (byte)0x80);

                    SystemClock.sleep(15);

                    //send 0x00 0x00 0x04 0x06 0x0A 0x00 to [0x10174]，通知GT29XX,流程完成
                    mBytes[0] = 0x00;
                    mBytes[1] = 0x00;
                    mBytes[2] = 0x04;
                    mBytes[3] = 0x06;
                    mBytes[4] = 0x0A;
                    mBytes[5] = 0x00;
                    iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes,0,6);

                    //30ms一次轮询[0x10174]，如果是0x80，说明GT29XX已完成
                    do {
                        SystemClock.sleep(30);
                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
                    }while(mBytes[0] != (byte)0x80);

                    mShow.setText("Send cfg success!!");

                    //将checksum填入配置中
                    //if (checksum % 256 == 0)  //校验和正确
                    {
                        //mBufferData[184] = (byte) (256 - checksum % 256);
                        // mShow.setText("Cfg Checksum  re-calculation!");
                    }

                    //更新配置标志位
                    //mBufferData[185] = 0x01;

                    //mSendData = mBufferData;
                    //mHandler.sendEmptyMessage(DEBUG_MESSAGE_SUCCESS);

                    //扩展命令  0x03,0x01,0x0f,-128,0x47,0x00,0x39,
                    //addressH = (byte) 0x80;
                    //addressL = (byte) 0x47;
                    //iicWrite(addressH, addressL, mBufferData, 0, 186);
                    //if (!recallCheck(addressH, addressL, mBufferData, 0, 185)) {
                    //    mShow.setText("Recall check error,Send cfg failed");
                        // return false;
                    //} else {
                    //    mShow.setText("Recall check success,Send cfg success");
                    //}

                    //if (iChooseVPager == 8) {
                    //    mCfg80FF.setText(Integer.toHexString(mBufferData[184] & 0xff));
                    //}

                break;
            case R.id.readcfg:  //read cfg
                bottonMode = 2;
                mSendData = mSendGetGt9ConfigData;
                StringBuilder stringBuilder = new StringBuilder("");
                checksum = 0;
                checksum2 = 0;

                if (byProductType == GT9)
                {
                    /*
                    //read [0x10174] = 0x80 or 0x01，表示上条命令已执行完毕，或当前固件处于空闲状态
                    do {
                        SystemClock.sleep(1);
                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
                    }while((mBytes[0] != 0x80) && (mBytes[0] != 0x01));
                    */

                    //send 0x00 0x00 0x04 0x07 0x0B 0x00 to [0x10174]，通知GT79XX,要读cfg
                    mBytes[0] = 0x00;
                    mBytes[1] = 0x00;
                    mBytes[2] = 0x04;
                    mBytes[3] = 0x07;
                    mBytes[4] = 0x0B;
                    mBytes[5] = 0x00;
                    iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes,0,6);


                    //read [0x10175] = 0x80,config is ready
                    //do {
                    //    SystemClock.sleep(30);
                    //    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x75, mBytes, 1);
                    //}while(mBytes[0] != (byte)0x80);

                    do {
                        SystemClock.sleep(30);
                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
                    }while(mBytes[0] != (byte)0x80);

                    //SystemClock.sleep(2);

                    //read buffer [0x13B74]
                    iicRead32Bits((byte)0x01, (byte)0x3B, (byte)0x74, mBytes, 63);  //read config head

                    int iConfigSize = 64 + (int)(mBytes[60] & 0xFF) * 256 + (mBytes[59] & 0xFF);   //the head lend is 64

                    iicRead32Bits((byte)0x01, (byte)0x3B, (byte)0x74, mBytes, iConfigSize);  //read config

                    for (int i = 0; i < iConfigSize; i++) {

                        int k = mBytes[i] & 0xFF;
                        checksum =checksum+ k;
                        String hv = Integer.toHexString(k);
                        if (hv.length() < 2){
                            hv = "0" + hv;
                        }
                        mConfigShow[i] = hv;
                        stringBuilder.append("0x" + hv);
                        stringBuilder.append(",");
                    }

                    ReadCfgRam(mConfigShow);

                    edtConfigDataShow.setText(stringBuilder.toString());

                    SystemClock.sleep(5);

                    //send 0x00 0x00 0x04 0x08 0x0C 0x00 to [0x10174]，通知GT79XX,通信结束
                    mBytes[0] = 0x00;
                    mBytes[1] = 0x00;
                    mBytes[2] = 0x04;
                    mBytes[3] = 0x08;
                    mBytes[4] = 0x0C;
                    mBytes[5] = 0x00;
                    iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 0, 6);

                    //read [0x10175] = 0x80,config is ready
                    //do {
                    //    SystemClock.sleep(30);
                    //    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x75, mBytes, 1);
                    //}while(mBytes[0] != (byte)0x80);

                    do {
                        SystemClock.sleep(30);
                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
                    }while(mBytes[0] != (byte)0x80);

                    //SystemClock.sleep(2);

                    iicRead32Bits((byte)0x01, (byte)0x00, (byte)0x2B, mBytes, 4);  //read Sensor ID
                    tvVenderID.setText("VenderID:"+Integer.toString(mBytes[0] & 0xFF));

                    /*
                    addressH = (byte)0x80;
                    addressL = (byte)0x47;
                    iicRead(addressH,addressL,mBytes,186);

                    for (int i = 0; i < 186; i++) {

                        int k = mBytes[i] & 0xFF;
                        checksum =checksum+ k;
                        String hv = Integer.toHexString(k);
                        if (hv.length() < 2){
                            hv = "0" + hv;
                        }
                        mConfigShow[i] = hv;
                        stringBuilder.append(hv);
                        stringBuilder.append(",");
                    }
                    if(checksum % 256 == 0)  //校验和正确
                    {
                        mShow.setText("Cfg Checksum is correct!");
                    }
                    else {
                        mShow.setText("Cfg Checksum is error!");
                    }

                    ReadCfgSample(mBytes);
                    ReadCfgModuleSwitch(mBytes);
                    ReadCfgNormalSetting(mBytes);
                    ReadCfgChannelSetting(mBytes);
                    ReadCfgPenSetting(mBytes);
                    ReadCfgPlamRestrain(mBytes);
                    ReadCfgKeySetting(mBytes);
                    ReadCfgHoppingSetting(mBytes);

                     */
                }else{  //GT7
                    addressH = (byte)0x80;
                    addressL = (byte)0x50;
                    iicRead(addressH,addressL,mBytes,444);

                    for (int i = 0; i < 444; i++) {

                        int k = mBytes[i] & 0xFF;
                        if (i < 213)
                        {
                            checksum = checksum + k;
                        }
                        else {
                            checksum2 = checksum2 + k;
                        }

                        String hv = Integer.toHexString(k);
                        if (hv.length() < 2){
                            hv = "0" + hv;
                        }
                        mConfigShow[i] = hv;
                        stringBuilder.append(hv);
                        stringBuilder.append(",");
                    }
                    if((checksum % 256 == 0) && (checksum2 % 256 == 0))  //校验和正确
                    {
                        mShow.setText("Cfg Checksum is correct!");
                    }
                    else {
                        mShow.setText("Cfg Checksum is error!");
                    }
                }

                //ReadCfgRam(mConfigShow);

                //addressH = (byte)0x81;
                //if (byProductType == GT7)
                //{
                //    addressH = (byte)0x82;
                //}
                //addressL = (byte)0x40;
                //iicRead(addressH,addressL,mBytes,32);
                //tvVenderID.setText("VenderID:"+Integer.toString(mBytes[10] & 0xFF));

                break;
            case R.id.savecfg:

                if (editname.getText().length() == 0){
                    Toast.makeText(this, getResources().getString(R.string.nameandformat), Toast.LENGTH_SHORT).show();
                }else{
                    ActivityCompat.requestPermissions(  Config.this, new String[]{android
                            .Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);

                    //String filePath = Environment.getExternalStorageDirectory() + "/saveconfig/";
                    //String fileName = editname.getText().toString();
                    //writeTxtToFile(editdetail.getText().toString().trim(), filePath, fileName);
                }

                break;
            default:
                break;
        }
    }

    @Override
    public void onPageSelected(int index) {

        Animation animation = null;
        switch (index) {
            case 0:
                /*
                if (currIndex == 1) {
                    animation = new TranslateAnimation(one, 0, 0, 0);
                } else if (currIndex == 2) {
                    animation = new TranslateAnimation(two, 0, 0, 0);
                }
                */
                animation = new TranslateAnimation(one * currIndex, 0, 0, 0);
                break;
            case 1:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, one, 0, 0);
                } else {// if (currIndex == 2) {
                    //animation = new TranslateAnimation(two, one, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, one, 0, 0);
                }
                break;
            case 2:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, two, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, two, 0, 0);
                }
                break;
            case 3:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, three, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, three, 0, 0);
                }
                break;
            case 4:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, four, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, four, 0, 0);
                }
                break;
            case 5:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, five, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, five, 0, 0);
                }
                break;
            case 6:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, six, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, six, 0, 0);
                }
                break;
            case 7:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, seven, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, seven, 0, 0);
                }
                break;
            case 8:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, eight, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, eight, 0, 0);
                }
                break;
            case 9:
                if (currIndex == 0) {
                    animation = new TranslateAnimation(offset, nine, 0, 0);
                } else {//if (currIndex == 1) {
                    //animation = new TranslateAnimation(one, two, 0, 0);
                    animation = new TranslateAnimation(one * currIndex, nine, 0, 0);
                }
                break;
            default:
                break;
        }
        currIndex = index;
        animation.setFillAfter(true);// true表示图片停在动画结束位置
        animation.setDuration(300); //设置动画时间为300毫秒
        img_cursor.startAnimation(animation);//开始动画
        iChooseVPager = index; //获取当前Vpager的索引，以便知道在哪个pager
    }

    @Override
    public void onPageScrollStateChanged(int i) {
        switch (i){
            case 0:

                break;
            case 1:

                break;
            case 2:

                break;
        }
    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {
        //edtshow3.setText("333");
        switch (i){
            case 0:

                break;
            case 1:

                break;
            case 2:
                break;
        }
    }

    private byte iicByteData[]={
            //0    1   2     3    4    5    6
            0x03,0x00,0x0f,0x00,0x00,0x00,0x01,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    };
    private byte iicWriteData[]={
            //0    1   2     3    4    5    6
            0x03,0x00,0x0f,0x00,0x00,0x00,0x39,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    };

    //发送命令，使得S818可以通过IIC向GT9的固定地址读取任意bytes的数据
    private boolean iicRead(byte addressHigh,byte addressLow,byte[] wBuffer,int length) {

        int i;
        iicByteData[1] = 0x00; //read GT9 command
        iicByteData[2] = 0x0f; //no command
        iicByteData[3] = addressHigh;
        iicByteData[4] = addressLow;
        iicByteData[5] = 0x00;
        iicByteData[6] = 63;  //length 一次接收63个数据

        for (int j = 7; j < 64; j++) {
            iicWriteData[j] = 0x00;
        }

        int address1 = ((addressHigh&0xff)<<8);
        int address2 = addressLow&0xff;
        int address = address1|address2;

        int sendTimes = length/63 + 1;  //预计是向下取整，所以+1

        for (int k = 0; k < sendTimes; k++) {
            int finalOffset = k*63; //每次只能发57bytes数据
            int offset = k*64;

            if(length - (finalOffset ) < 63) {

                iicByteData[6] = (byte) (length - (finalOffset));  //length
            }
            else
            {
                iicByteData[6] = 63;
            }

            //发送读取命令
            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicByteData, 0, 0x40, 100);
            if (i != 0x40)
                return false;  //传输失败
            // SystemClock.sleep(1);

            //接收数据
            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 3000);

            if (i != 0x40) {
                editname.setText("IIC Read Failed!!");
                return false;

            }

            address = address + 63;
            iicByteData[3] = (byte)(address>>8);
            iicByteData[4] = (byte)address;
        }

        //将report id从数组中去除
        //byte[] temperBuffer =new byte[length];
        if(true) {
            int count1 = 0;
            for (int k = 0; k < length; k++) {
                if (k % 63 == 0) {
                    count1++;
                }

                wBuffer[k] = wBuffer[k + count1];

            }
        }
        return true;
    }

    //发送命令，使得S8xx可以通过IIC向GT79xx的固定地址读取任意bytes的数据
    private boolean iicRead32Bits(byte addrfirstbyte,byte addrsecondbyte,byte addrthirdbyte,byte[] wBuffer,int length) {

        int i;

        iicByteData[1] = 0x0f; //7bit:0-read,1-write;other:command
        //iicByteData[2] = 0x0f; //no command
        iicByteData[2] = addrfirstbyte;
        iicByteData[3] = addrsecondbyte;
        iicByteData[4] = addrthirdbyte;
        iicByteData[5] = 0x00;
        iicByteData[6] = 63;  //length 一次接收63个数据

        for (int j = 7; j < 64; j++) {
            iicByteData[j] = 0x00;
        }

        int address1 = ((addrsecondbyte & 0xff) << 8);
        int address2 = addrthirdbyte & 0xff;
        int address = address1 | address2;

        int sendTimes = length/63;  //预计是向下取整，所以+1

        if ((length % 63) != 0)
        {
            sendTimes += 1;   //预计是向下取整，所以+1
        }
        //iicByteData[5] = (byte)(length>>8);
        //iicByteData[6] = (byte)length;  //length 一次接收63个数据

        for (int k = 0; k < sendTimes; k++)
        {
            int finalOffset = k*63; //每次只能发57bytes数据
            int offset = k * 64;

              if(length - (finalOffset ) < 63) {

             iicByteData[6] = (byte) (length - (finalOffset));  //length
            }
               else
              {
              iicByteData[6] = 63;
              }

            //发送读取命令
            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicByteData, 0, 0x40, 100);
            if (i != 0x40)
                return false;  //传输失败

            // SystemClock.sleep(1);

            //接收数据
            // i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 100);
            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 100);

            //if (i != 0x40) {
            if (i != 0x40) {
                editname.setText("IIC Read Failed!!");
                return false;

            }

            address = address + 63;
            iicByteData[3] = (byte)(address>>8);
            iicByteData[4] = (byte)address;
        }

        //将report id从数组中去除
        //byte[] temperBuffer =new byte[length];
        if(true) {
            int count1 = 0;
            for (int k = 0; k < length; k++) {
                if (k % 63 == 0) {
                    count1++;
                }

                wBuffer[k] = wBuffer[k + count1];

            }
        }
        return true;
    }

    //发送命令，使得S818可以通过IIC向GT9的固定地址写任意bytes的数据
    private  boolean iicWrite(byte addressHigh,byte addressLow,byte[] wBuffer,int offset,int length) {
        int i;

        iicWriteData[1] = 0x01; //write GT9 command
        iicWriteData[2] = 0x0f; //no command
        iicWriteData[3] = addressHigh;
        iicWriteData[4] = addressLow;
        iicWriteData[5] = 0x00;
        iicWriteData[6] = 0x39;  //length

        int address1 = ((addressHigh&0xff)<<8);
        int address2 = addressLow&0xff;
        int address = address1|address2;

        int sendTimes = length/57 + 1;  //预计是向下取整，所以+1

        for (int k = 0; k < sendTimes; k++) {
            int finalOffset = offset + k*57; //每次只能发57bytes数据

            if(length - (finalOffset -offset) < 57) {

                iicWriteData[6] = (byte) (length - (finalOffset -offset));  //length
            }
            else
            {
                iicWriteData[6] = 0x39;
            }

            for (int j = 7; j < 64; j++) {
                iicWriteData[j] = wBuffer[finalOffset + j -7];
            }
            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicWriteData, 0, 0x40, 100);

            if (i != 0x40) {
                editname.setText("iicWrite Failed");
                return false;

            }

            address = address + 57;
            iicWriteData[3] = (byte)(address>>8);
            iicWriteData[4] = (byte)address;
        }

        return true;
    }

    //发送命令，使得S8xx可以通过IIC向GT79xx的固定地址写任意bytes的数据
    private  boolean iicWrite32Bits(byte addrfirstbyte,byte addrsecondbyte,byte addrthirdbyte,byte[] wBuffer,int offset, int length) {

        int i;

        iicWriteData[1] = (byte)0x8f; //7bit:0-read,1-write;other:command
        //iicWriteData[2] = 0x0f; //no command
        iicWriteData[2] = addrfirstbyte;
        iicWriteData[3] = addrsecondbyte;
        iicWriteData[4] = addrthirdbyte;
        iicWriteData[5] = 0x00;
        iicWriteData[6] = 63;  //length 一次接收63个数据

        for (int j = 7; j < 64; j++) {
            iicWriteData[j] = 0x00;
        }

        //int address1 = ((addressHigh&0xff)<<8);
        //int address2 = addressLow&0xff;
        long address = ((long)addrfirstbyte << 16) | ((long)addrsecondbyte << 8) | addrthirdbyte;

        int sendTimes = length/57 + 1;  //预计是向下取整，所以+1

        //iicByteData[5] = (byte)(length>>8);
        //iicByteData[6] = (byte)length;  //length 一次接收63个数据

        for (int k = 0; k < sendTimes; k++) {
            int finalOffset = offset + k*57; //每次只能发57bytes数据

            if(length - (finalOffset -offset) < 57) {

                iicWriteData[6] = (byte) (length - (finalOffset -offset));  //length
            }
            else
            {
                iicWriteData[6] = 0x39;
            }

            for (int j = 7; j < 64; j++) {
                iicWriteData[j] = wBuffer[finalOffset + j -7];
            }
            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicWriteData, 0, 0x40, 100);

            if (i != 0x40) {
                editname.setText("iicWrite Failed");
                return false;

            }

            address = address + 57;
            iicWriteData[2] = (byte)(address >> 16);
            iicWriteData[3] = (byte)(address>>8);
            iicWriteData[4] = (byte)address;
        }

        return true;
    }

    boolean memCmp(byte[] sBuffer,byte[] dBuffer,int offset,int length) {
        try {

            for (int i = 0; i < length; i++) {
                if (sBuffer[i] != dBuffer[offset + i]) {
                    // FwUpdateMessage(L"Recall frame data fail,not equal.", MSG_ERR);
                    // mError.setText("Recall frame data fail,not equal.");
                    return false;
                }
            }
        } catch (ArithmeticException e) {
            mShow.setText("ArithmeticException!");
            e.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException e) {
            mShow.setText("ArrayIndexOutOfBoundsException!");
            e.printStackTrace();
        }

        return true;
    }

    boolean recallCheck(byte addressHigh,byte addressLow,byte[] wBuffer,int offset,int length)
    {
        //BYTE* pbBuf = new BYTE[wLen];
        byte[] pbBuf =new byte[length+0x3000];

        //if(false)
        {
            if (!iicRead(addressHigh, addressLow, pbBuf, length)) {
                //FwUpdateMessage(L"recall i2c error failed", MSG_ERR);
                mShow.setText("recall i2c error failed");
                return false;
            }
            if (!memCmp(pbBuf, wBuffer, offset, length)) {

                // FwUpdateMessage(L"Recall frame data fail,not equal.", MSG_ERR);
                //mMessage.setText("Recall frame data fail,not equal.");
                return false;
            }
        }
        return true;

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mUsbDeviceConnection != null) {
            mUsbDeviceConnection.releaseInterface(mUsbInterface);
            mUsbDeviceConnection.close();
            mUsbDeviceConnection = null;
        }
        mUsbEndpointIn = null;
        mUsbEndpointOut = null;
        isNeedFindDevice = false;
        mThreadPool.shutdownNow();
       // unregisterReceiver(mUsbDetachedReceiver);
        unregisterReceiver(cfgOpenDevicesReceiver);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            case 1:
                String filePath;// = Environment.getExternalStorageDirectory() + "/saveconfig/";
                String fileName;
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    //创建文件夹
                    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

                        StringBuilder configBuilder = new StringBuilder("");

                        if (iChooseVPager == 8){ //在ram cfg界面

                            if (byProductType == GT9) {
                                configBuilder.append("0x" + mCfg8047.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg8048.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg8049.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg804A.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg804B.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg804C.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg804D.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg804E.getText().toString() + ",");
                                configBuilder.append("0x" + mCfg804F.getText().toString() + ",");
                            }

                            configBuilder.append("0x"+mCfg8050.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8051.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8052.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8053.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8054.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8055.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8056.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8057.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8058.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8059.getText().toString()+",");
                            configBuilder.append("0x"+mCfg805A.getText().toString()+",");
                            configBuilder.append("0x"+mCfg805B.getText().toString()+",");
                            configBuilder.append("0x"+mCfg805C.getText().toString()+",");
                            configBuilder.append("0x"+mCfg805D.getText().toString()+",");
                            configBuilder.append("0x"+mCfg805E.getText().toString()+",");
                            configBuilder.append("0x"+mCfg805F.getText().toString()+",");

                            configBuilder.append("0x"+mCfg8060.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8061.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8062.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8063.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8064.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8065.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8066.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8067.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8068.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8069.getText().toString()+",");
                            configBuilder.append("0x"+mCfg806A.getText().toString()+",");
                            configBuilder.append("0x"+mCfg806B.getText().toString()+",");
                            configBuilder.append("0x"+mCfg806C.getText().toString()+",");
                            configBuilder.append("0x"+mCfg806D.getText().toString()+",");
                            configBuilder.append("0x"+mCfg806E.getText().toString()+",");
                            configBuilder.append("0x"+mCfg806F.getText().toString()+",");

                            configBuilder.append("0x"+mCfg8070.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8071.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8072.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8073.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8074.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8075.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8076.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8077.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8078.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8079.getText().toString()+",");
                            configBuilder.append("0x"+mCfg807A.getText().toString()+",");
                            configBuilder.append("0x"+mCfg807B.getText().toString()+",");
                            configBuilder.append("0x"+mCfg807C.getText().toString()+",");
                            configBuilder.append("0x"+mCfg807D.getText().toString()+",");
                            configBuilder.append("0x"+mCfg807E.getText().toString()+",");
                            configBuilder.append("0x"+mCfg807F.getText().toString()+",");

                            configBuilder.append("0x"+mCfg8080.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8081.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8082.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8083.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8084.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8085.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8086.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8087.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8088.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8089.getText().toString()+",");
                            configBuilder.append("0x"+mCfg808A.getText().toString()+",");
                            configBuilder.append("0x"+mCfg808B.getText().toString()+",");
                            configBuilder.append("0x"+mCfg808C.getText().toString()+",");
                            configBuilder.append("0x"+mCfg808D.getText().toString()+",");
                            configBuilder.append("0x"+mCfg808E.getText().toString()+",");
                            configBuilder.append("0x"+mCfg808F.getText().toString()+",");

                            configBuilder.append("0x"+mCfg8090.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8091.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8092.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8093.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8094.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8095.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8096.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8097.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8098.getText().toString()+",");
                            configBuilder.append("0x"+mCfg8099.getText().toString()+",");
                            configBuilder.append("0x"+mCfg809A.getText().toString()+",");
                            configBuilder.append("0x"+mCfg809B.getText().toString()+",");
                            configBuilder.append("0x"+mCfg809C.getText().toString()+",");
                            configBuilder.append("0x"+mCfg809D.getText().toString()+",");
                            configBuilder.append("0x"+mCfg809E.getText().toString()+",");
                            configBuilder.append("0x"+mCfg809F.getText().toString()+",");

                            configBuilder.append("0x"+mCfg80A0.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A1.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A2.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A3.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A4.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A5.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A6.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A7.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A8.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80A9.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80AA.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80AB.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80AC.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80AD.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80AE.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80AF.getText().toString()+",");

                            configBuilder.append("0x"+mCfg80B0.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B1.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B2.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B3.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B4.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B5.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B6.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B7.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B8.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80B9.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80BA.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80BB.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80BC.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80BD.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80BE.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80BF.getText().toString()+",");

                            configBuilder.append("0x"+mCfg80C0.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C1.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C2.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C3.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C4.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C5.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C6.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C7.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C8.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80C9.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80CA.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80CB.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80CC.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80CD.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80CE.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80CF.getText().toString()+",");

                            configBuilder.append("0x"+mCfg80D0.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D1.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D2.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D3.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D4.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D5.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D6.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D7.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D8.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80D9.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80DA.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80DB.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80DC.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80DD.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80DE.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80DF.getText().toString()+",");

                            configBuilder.append("0x"+mCfg80E0.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E1.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E2.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E3.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E4.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E5.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E6.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E7.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E8.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80E9.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80EA.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80EB.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80EC.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80ED.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80EE.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80EF.getText().toString()+",");

                            configBuilder.append("0x"+mCfg80F0.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F1.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F2.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F3.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F4.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F5.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F6.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F7.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F8.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80F9.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80FA.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80FB.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80FC.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80FD.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80FE.getText().toString()+",");
                            configBuilder.append("0x"+mCfg80FF.getText().toString()+",");

                            if (byProductType == GT9) {
                                configBuilder.append("0x01");
                            }else{ //GT7
                                configBuilder.append("0x"+mCfg8100.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8101.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8102.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8103.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8104.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8105.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8106.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8107.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8108.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8109.getText().toString()+",");
                                configBuilder.append("0x"+mCfg810A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg810B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg810C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg810D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg810E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg810F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8110.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8111.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8112.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8113.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8114.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8115.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8116.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8117.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8118.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8119.getText().toString()+",");
                                configBuilder.append("0x"+mCfg811A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg811B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg811C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg811D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg811E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg811F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8120.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8121.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8122.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8123.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8124.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8125.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8126.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8127.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8128.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8129.getText().toString()+",");
                                configBuilder.append("0x"+mCfg812A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg812B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg812C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg812D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg812E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg812F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8130.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8131.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8132.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8133.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8134.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8135.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8136.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8137.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8138.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8139.getText().toString()+",");
                                configBuilder.append("0x"+mCfg813A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg813B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg813C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg813D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg813E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg813F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8140.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8141.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8142.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8143.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8144.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8145.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8146.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8147.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8148.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8149.getText().toString()+",");
                                configBuilder.append("0x"+mCfg814A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg814B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg814C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg814D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg814E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg814F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8150.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8151.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8152.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8153.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8154.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8155.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8156.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8157.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8158.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8159.getText().toString()+",");
                                configBuilder.append("0x"+mCfg815A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg815B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg815C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg815D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg815E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg815F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8160.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8161.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8162.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8163.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8164.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8165.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8166.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8167.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8168.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8169.getText().toString()+",");
                                configBuilder.append("0x"+mCfg816A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg816B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg816C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg816D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg816E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg816F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8170.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8171.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8172.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8173.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8174.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8175.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8176.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8177.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8178.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8179.getText().toString()+",");
                                configBuilder.append("0x"+mCfg817A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg817B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg817C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg817D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg817E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg817F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8180.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8181.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8182.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8183.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8184.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8185.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8186.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8187.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8188.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8189.getText().toString()+",");
                                configBuilder.append("0x"+mCfg818A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg818B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg818C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg818D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg818E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg818F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8190.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8191.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8192.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8193.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8194.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8195.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8196.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8197.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8198.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8199.getText().toString()+",");
                                configBuilder.append("0x"+mCfg819A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg819B.getText().toString()+",");
                                configBuilder.append("0x"+mCfg819C.getText().toString()+",");
                                configBuilder.append("0x"+mCfg819D.getText().toString()+",");
                                configBuilder.append("0x"+mCfg819E.getText().toString()+",");
                                configBuilder.append("0x"+mCfg819F.getText().toString()+",");

                                configBuilder.append("0x"+mCfg81A0.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A1.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A2.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A3.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A4.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A5.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A6.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A7.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A8.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81A9.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81AA.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81AB.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81AC.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81AD.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81AE.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81AF.getText().toString()+",");

                                configBuilder.append("0x"+mCfg81B0.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B1.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B2.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B3.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B4.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B5.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B6.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B7.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B8.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81B9.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81BA.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81BB.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81BC.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81BD.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81BE.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81BF.getText().toString()+",");

                                configBuilder.append("0x"+mCfg81C0.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C1.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C2.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C3.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C4.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C5.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C6.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C7.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C8.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81C9.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81CA.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81CB.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81CC.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81CD.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81CE.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81CF.getText().toString()+",");

                                configBuilder.append("0x"+mCfg81D0.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D1.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D2.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D3.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D4.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D5.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D6.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D7.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D8.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81D9.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81DA.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81DB.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81DC.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81DD.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81DE.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81DF.getText().toString()+",");

                                configBuilder.append("0x"+mCfg81E0.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E1.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E2.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E3.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E4.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E5.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E6.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E7.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E8.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81E9.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81EA.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81EB.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81EC.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81ED.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81EE.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81EF.getText().toString()+",");

                                configBuilder.append("0x"+mCfg81F0.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F1.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F2.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F3.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F4.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F5.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F6.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F7.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F8.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81F9.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81FA.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81FB.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81FC.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81FD.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81FE.getText().toString()+",");
                                configBuilder.append("0x"+mCfg81FF.getText().toString()+",");

                                configBuilder.append("0x"+mCfg8200.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8201.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8202.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8203.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8204.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8205.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8206.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8207.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8208.getText().toString()+",");
                                configBuilder.append("0x"+mCfg8209.getText().toString()+",");
                                configBuilder.append("0x"+mCfg820A.getText().toString()+",");
                                configBuilder.append("0x"+mCfg820B.getText().toString()+",");
                            }
                        }else{ //在其他界面则保存
                            if (byProductType == GT9) {
                                CombineCfg();
                                for (int i = 0; i < 185; i++) {
                                    String hv = Integer.toHexString(mBytes[i] & 0xFF);
                                    if (hv.length() < 2) {
                                        hv = "0" + hv;
                                    }
                                    configBuilder.append("0x" + hv + ",");
                                }

                                configBuilder.append("0x01");  //mBytes[185]，最后置上1
                            }
                        }

                        filePath = Environment.getExternalStorageDirectory() + "/saveconfig/";
                        //File file = new File(filePath);
                        fileName = editname.getText().toString();
                        writeTxtToFile(configBuilder.toString().trim(), filePath, fileName);

                        mShow.setText(fileName + getResources().getString(R.string.saveto) + filePath.toString());

                    }
                }
                break;
            case 2:
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    //创建文件夹
                    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

                    }
                }
                break;

            case 3:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
                    //权限已成功申请
                }else{
                    //用户拒绝授权
                    Toast.makeText(this,getResources().getString(R.string.nopermission), Toast.LENGTH_SHORT).show();
                    finish();
                }
                break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
                break;
        }
    }
    // 将字符串写入到文本文件中
    public void writeTxtToFile(String strcontent, String filePath, String fileName) {
        // 生成文件夹之后，再生成文件，不然会出错
        makeFilePath(filePath, fileName);

        String strFilePath = filePath + fileName;
        // 每次写入时，都换行写
        String strContent = strcontent + "\r\n";
        try {
            File file = new File(strFilePath);
            if (!file.exists()) {
                Log.d("TestFile", "Create the file:" + strFilePath);
                file.getParentFile().mkdirs();
                file.createNewFile();
            }
            RandomAccessFile raf = new RandomAccessFile(file, "rwd");
            raf.seek(file.length());
            raf.write(strContent.getBytes());
            raf.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 生成文件
    public File makeFilePath(String filePath, String fileName) {
        File file = null;
        makeRootDirectory(filePath);
        try {
            file = new File(filePath + fileName);
            if (!file.exists()) {
                file.createNewFile();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return file;
    }

    // 生成文件夹
    public static void makeRootDirectory(String filePath) {
        File file = null;
        try {
            file = new File(filePath);
            if (!file.exists()) {
                file.mkdir();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

