| | |
| | | package com.hdl.sdk.hdl_sdk.activity; |
| | | |
| | | |
| | | import android.app.ProgressDialog; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | |
| | | import android.widget.TextView; |
| | | |
| | | import com.hdl.sdk.hdl_core.HDLAppliances.Config.HDLApConfig; |
| | | import com.hdl.sdk.hdl_core.HDLAppliances.HDLFreshAir.Parser.FreshAirParser; |
| | | import com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.GeothermalBackInfo; |
| | | import com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.Parser.GeothermalParser; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLCommand; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DeviceStateEvent; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.EventCode; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.GeothermalFeedBackEvent; |
| | | import com.hdl.sdk.hdl_sdk.R; |
| | | import com.hdl.sdk.hdl_sdk.base.BaseActivity; |
| | |
| | | private int gModeState; |
| | | private int gTempState; |
| | | private int ctrlId; |
| | | |
| | | private ProgressDialog proDialog; |
| | | /** |
| | | * 要注册使用EventBus,这里要设置返回true |
| | | * |
| | |
| | | HDLCommand.getDeviceState(appliancesInfo); |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | proDialog.dismiss(); |
| | | HDLLog.I("onDestroy: GeothermalActivity"); |
| | | } |
| | | |
| | | private void initcurState() { |
| | | appliancesInfo = (AppliancesInfo) getIntent().getSerializableExtra("hdl"); |
| | | } |
| | |
| | | btn_temp = findViewById(R.id.btn_temp); |
| | | tempEditText = findViewById(R.id.et_temp); |
| | | |
| | | proDialog = new ProgressDialog(this); |
| | | proDialog.setTitle("正在发送控制命令..."); |
| | | proDialog.setMessage("请耐心等待"); |
| | | proDialog.onStart(); |
| | | } |
| | | |
| | | private void initClickOnEvent() { |
| | | btn_switch.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | proDialog.show(); |
| | | ctrlId = GeothermalParser.gSwich; |
| | | //演示当前状态为关,设置为开。开,设置为关。 |
| | | if (gSwitchState == 0) { |
| | |
| | | btn_mode.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | proDialog.show(); |
| | | ctrlId = GeothermalParser.gMode; |
| | | switch (gModeState) { |
| | | case 1: |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | }); |
| | | |
| | |
| | | public void onClick(View view) { |
| | | |
| | | String tempStr = tempEditText.getText().toString(); |
| | | if (TextUtils.isEmpty(tempStr) || TextUtils.isEmpty(tempStr)) { |
| | | if (TextUtils.isEmpty(tempStr)) { |
| | | showToast("设置的温度不能为空"); |
| | | return; |
| | | } |
| | |
| | | showToast("温度设置范围为:16~35摄氏度(℃)"); |
| | | return; |
| | | } |
| | | proDialog.show(); |
| | | // HDLCommand.geothermalCtrlTemp(appliancesInfo, tempInt);//自动根据当前模式设置当前模式的温度。 |
| | | |
| | | switch (gModeState) { |
| | | |
| | | case 1: |
| | | |
| | | //当前地热模式为普通 |
| | | HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gNormalTemp, tempInt);//普通温度 |
| | | ctrlId = GeothermalParser.gNormalTemp; |
| | | break; |
| | | case 2: |
| | | //当前地热模式为白天 |
| | | HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gDayTemp, tempInt);//白天温度 |
| | | ctrlId = GeothermalParser.gDayTemp; |
| | | break; |
| | | case 3: |
| | | //当前地热模式为夜间 |
| | | HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gNightTemp, tempInt);//夜间温度 |
| | | ctrlId = GeothermalParser.gNightTemp; |
| | | break; |
| | | case 4: |
| | | //当前地热模式为离开 |
| | | HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gLeaveTemp, tempInt);//离开温度 |
| | | ctrlId = GeothermalParser.gLeaveTemp; |
| | | HDLCommand.geothermalCtrlTemp(appliancesInfo, tempInt);//自动根据当前模式设置当前模式的温度。 |
| | | break; |
| | | case 5: |
| | | proDialog.dismiss(); |
| | | //当前地热模式为自动 |
| | | showToast("自动模式不能控制温度"); |
| | | showToast("自动模式,不能控制温度"); |
| | | break; |
| | | default: |
| | | proDialog.dismiss(); |
| | | //当前地热模式为自动 |
| | | showToast("未知模式,不能控制温度"); |
| | | break; |
| | | |
| | | } |
| | | |
| | | // switch (gModeState) { |
| | | // |
| | | // case 1: |
| | | // //当前地热模式为普通 |
| | | // HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gNormalTemp, tempInt);//普通温度 |
| | | // ctrlId = GeothermalParser.gNormalTemp; |
| | | // break; |
| | | // case 2: |
| | | // //当前地热模式为白天 |
| | | // HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gDayTemp, tempInt);//白天温度 |
| | | // ctrlId = GeothermalParser.gDayTemp; |
| | | // break; |
| | | // case 3: |
| | | // //当前地热模式为夜间 |
| | | // HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gNightTemp, tempInt);//夜间温度 |
| | | // ctrlId = GeothermalParser.gNightTemp; |
| | | // break; |
| | | // case 4: |
| | | // //当前地热模式为离开 |
| | | // HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gLeaveTemp, tempInt);//离开温度 |
| | | // ctrlId = GeothermalParser.gLeaveTemp; |
| | | // break; |
| | | // case 5: |
| | | // proDialog.dismiss(); |
| | | // //当前地热模式为自动 |
| | | // showToast("自动模式,不能控制温度"); |
| | | // break; |
| | | // default: |
| | | // proDialog.dismiss(); |
| | | // //当前地热模式为自动 |
| | | // showToast("未知模式,不能控制温度"); |
| | | // break; |
| | | // |
| | | // } |
| | | |
| | | |
| | | } |
| | |
| | | GeothermalBackInfo mGeothermalBackInfo = new GeothermalBackInfo(appliancesInfo, false); |
| | | |
| | | String stringState = ""; |
| | | if (mGeothermalBackInfo.getIsOn() == 0) { |
| | | if (mGeothermalBackInfo.getIsOn() == GeothermalParser.gSwichOff) { |
| | | stringState = "地热模块:关闭"; |
| | | } else if (mGeothermalBackInfo.getIsOn() == 1) { |
| | | } else if (mGeothermalBackInfo.getIsOn() == GeothermalParser.gSwichOn) { |
| | | stringState = "地热模块:打开"; |
| | | |
| | | stringState += "\n" + getModeStateString(mGeothermalBackInfo.getgMode()); |
| | |
| | | String mStrState = "未知"; |
| | | gSwitchState = mState; //更新开关状态 |
| | | switch (mState) { |
| | | case FreshAirParser.freshAirOn: |
| | | case GeothermalParser.gSwichOn: |
| | | mStrState = "地热模块:打开"; |
| | | break; |
| | | case FreshAirParser.freshAirOff: |
| | | case GeothermalParser.gSwichOff: |
| | | mStrState = "地热模块:关闭"; |
| | | break; |
| | | |
| | |
| | | gModeState = mState; //更新模式状态 |
| | | switch (mState) { |
| | | case GeothermalParser.gModeNormal: |
| | | mStrState = " 模式:普通"; |
| | | mStrState = "模式:普通"; |
| | | break; |
| | | case GeothermalParser.gModeDay: |
| | | mStrState = " 模式:白天"; |
| | | mStrState = "模式:白天"; |
| | | break; |
| | | case GeothermalParser.gModeNight: |
| | | mStrState = " 模式:夜间"; |
| | | mStrState = "模式:夜间"; |
| | | break; |
| | | case GeothermalParser.gModeLeave: |
| | | mStrState = " 模式:离开"; |
| | | mStrState = "模式:离开"; |
| | | break; |
| | | case GeothermalParser.gModeAuto: |
| | | mStrState = " 模式:自动"; |
| | | mStrState = "模式:自动"; |
| | | break; |
| | | |
| | | default: |
| | |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void onGeothermalFeedBackEventMain(GeothermalFeedBackEvent event) { |
| | | proDialog.dismiss(); |
| | | if (event.getGeothermalBackInfo().getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID() |
| | | && event.getGeothermalBackInfo().getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID() |
| | | && event.getGeothermalBackInfo().getAppliancesInfo().getChannelNum() == appliancesInfo.getChannelNum() |
| | | ) { |
| | | //先判断是否超时 |
| | | if (!event.isSuccess()) { |
| | | if (event.getStatusID() == EventCode.FAILURE) { |
| | | showToast("地热模块控制超时,请重新再试"); |
| | | return; |
| | | } |
| | | |
| | | String message = ""; |
| | | GeothermalBackInfo mGeothermalBackInfo = event.getGeothermalBackInfo(); |
| | | |
| | | switch (ctrlId) { //ctrlId 当前控制类型,只反馈控制的状态 |
| | | case GeothermalParser.gSwich: |
| | | message = getSwichStateString(mGeothermalBackInfo.getIsOn()); |
| | | break; |
| | | case GeothermalParser.gMode: |
| | | message = getModeStateString(mGeothermalBackInfo.getgMode()); |
| | | break; |
| | | case GeothermalParser.gNormalTemp: |
| | | // gTempState = mGeothermalBackInfo.getgNormalTemp(); |
| | | message = "普通模式温度:" + mGeothermalBackInfo.getgNormalTemp(); |
| | | break; |
| | | |
| | | |
| | | case GeothermalParser.gDayTemp: |
| | | message = "白天模式温度:" + mGeothermalBackInfo.getgDayTemp(); |
| | | break; |
| | | case GeothermalParser.gNightTemp: |
| | | message = "夜间模式温度:" + mGeothermalBackInfo.getgNightTemp(); |
| | | break; |
| | | case GeothermalParser.gLeaveTemp: |
| | | message = "离开模式温度:" + mGeothermalBackInfo.getgLeaveTemp(); |
| | | break; |
| | | default: |
| | | break; |
| | | |
| | | if (event.getStatusID() == EventCode.DATAEMPTY) { |
| | | showToast("地热模块,返回数据为空"); |
| | | return; |
| | | } |
| | | GeothermalBackInfo mGeothermalBackInfo = event.getGeothermalBackInfo(); |
| | | showGeothermalBackInfo(mGeothermalBackInfo); |
| | | |
| | | // String message = ""; |
| | | // GeothermalBackInfo mGeothermalBackInfo = event.getGeothermalBackInfo(); |
| | | |
| | | mTextView.setText(message); |
| | | showToast(message); |
| | | HDLLog.I(message); |
| | | // switch (ctrlId) { //ctrlId 当前控制类型,只反馈控制的状态 |
| | | // case GeothermalParser.gSwich: |
| | | // message = getSwichStateString(mGeothermalBackInfo.getIsOn()); |
| | | // break; |
| | | // case GeothermalParser.gMode: |
| | | // message = getModeStateString(mGeothermalBackInfo.getgMode()); |
| | | // break; |
| | | // case GeothermalParser.gNormalTemp: |
| | | //// gTempState = mGeothermalBackInfo.getgNormalTemp(); |
| | | // message = "普通模式温度:" + mGeothermalBackInfo.getgNormalTemp(); |
| | | // break; |
| | | // |
| | | // |
| | | // case GeothermalParser.gDayTemp: |
| | | // message = "白天模式温度:" + mGeothermalBackInfo.getgDayTemp(); |
| | | // break; |
| | | // case GeothermalParser.gNightTemp: |
| | | // message = "夜间模式温度:" + mGeothermalBackInfo.getgNightTemp(); |
| | | // break; |
| | | // case GeothermalParser.gLeaveTemp: |
| | | // message = "离开模式温度:" + mGeothermalBackInfo.getgLeaveTemp(); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // |
| | | // } |
| | | // |
| | | // |
| | | // mTextView.setText(message); |
| | | // showToast(message); |
| | | // HDLLog.I(message); |
| | | } |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void onDeviceStateEventMain(DeviceStateEvent event) { |
| | | proDialog.dismiss(); |
| | | if (event.getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID() |
| | | && event.getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID() |
| | | ) { |
| | |
| | | return; |
| | | } |
| | | |
| | | message += "\n" + getSwichStateString(mGeothermalBackInfo.getIsOn()); |
| | | message += "\n" + getModeStateString(mGeothermalBackInfo.getgMode()); |
| | | message += "\n" + "普通模式温度:" + mGeothermalBackInfo.getgNormalTemp(); |
| | | message += "\n" + "白天模式温度:" + mGeothermalBackInfo.getgDayTemp(); |
| | | message += "\n" + "夜间模式温度:" + mGeothermalBackInfo.getgNightTemp(); |
| | | message += "\n" + "离开模式温度:" + mGeothermalBackInfo.getgLeaveTemp(); |
| | | |
| | | |
| | | mTextView.setText(message); |
| | | showToast(message); |
| | | HDLLog.I(message); |
| | | showGeothermalBackInfo(mGeothermalBackInfo); |
| | | |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * showGeothermalBackInfo |
| | | * @param mGeothermalBackInfo |
| | | */ |
| | | private void showGeothermalBackInfo(GeothermalBackInfo mGeothermalBackInfo){ |
| | | String message = ""; |
| | | if(mGeothermalBackInfo.getIsOn() == GeothermalParser.gSwichOn) { |
| | | message = getSwichStateString(mGeothermalBackInfo.getIsOn()); |
| | | |
| | | message += "\n" + getModeStateString(mGeothermalBackInfo.getgMode()); |
| | | message += "\n" + "室内温度:" + mGeothermalBackInfo.getgCurrentTemp(); |
| | | message += "\n" + "普通模式温度:" + mGeothermalBackInfo.getgNormalTemp(); |
| | | message += "\n" + "白天模式温度:" + mGeothermalBackInfo.getgDayTemp(); |
| | | message += "\n" + "夜间模式温度:" + mGeothermalBackInfo.getgNightTemp(); |
| | | message += "\n" + "离开模式温度:" + mGeothermalBackInfo.getgLeaveTemp(); |
| | | }else { |
| | | message = getSwichStateString(mGeothermalBackInfo.getIsOn()); |
| | | } |
| | | |
| | | |
| | | mTextView.setText(message); |
| | | showToast(message); |
| | | HDLLog.I(message); |
| | | } |
| | | } |