|
@@ -50,7 +50,6 @@ public class TuyaUtilsSo {
|
|
|
public boolean isUser = false; //避免重复上报问题
|
|
|
|
|
|
|
|
|
-
|
|
|
public static TuyaUtilsSo getInstance() {
|
|
|
if (singleton == null) {
|
|
|
synchronized (TuyaUtilsSo.class) {
|
|
@@ -195,11 +194,11 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
|
|
|
//加热方式调整
|
|
|
- if (enumValue==2){
|
|
|
+ if (enumValue == 2) {
|
|
|
heatType = 1;
|
|
|
- }else if (enumValue==10){
|
|
|
+ } else if (enumValue == 10) {
|
|
|
heatType = 2;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
heatType = 0;
|
|
|
}
|
|
|
autoMaticType = enumValue;
|
|
@@ -209,12 +208,12 @@ public class TuyaUtilsSo {
|
|
|
break;
|
|
|
case TuyaSoDp.COOKING_TEMPERATURE:
|
|
|
byte mode = HeatModes.PU_TONG;
|
|
|
- if (heatType==1){
|
|
|
+ if (heatType == 1) {
|
|
|
mode = HeatModes.ZHENG_QI;
|
|
|
- }else if (heatType==2){
|
|
|
- mode = HeatModes.SAP_SHUI;
|
|
|
- }else {
|
|
|
- mode =HeatModes.PU_TONG;
|
|
|
+ } else if (heatType == 2) {
|
|
|
+ mode = HeatModes.SAP_SHUI;
|
|
|
+ } else {
|
|
|
+ mode = HeatModes.PU_TONG;
|
|
|
}
|
|
|
|
|
|
isUser = true;
|
|
@@ -247,7 +246,7 @@ public class TuyaUtilsSo {
|
|
|
case TuyaSoDp.SPEED:
|
|
|
isUser = true;
|
|
|
//速度
|
|
|
- CofarSDK.cfgMotorGear((byte) intValue );
|
|
|
+ CofarSDK.cfgMotorGear((byte) intValue);
|
|
|
break;
|
|
|
case TuyaSoDp.REVERSIBLE:
|
|
|
isUser = true;
|
|
@@ -268,6 +267,7 @@ public class TuyaUtilsSo {
|
|
|
case TuyaSoDp.CURRENT_RECIPE_NUMBER:
|
|
|
//当前食谱编号
|
|
|
CommonTuyaSoUtils.INSTANCE.navigateToRemoteRecipe(strValue);
|
|
|
+ wakeUpScreen(context);
|
|
|
break;
|
|
|
case TuyaSoDp.CURRENT_RECIPE_STEP:
|
|
|
//当前食谱编号
|
|
@@ -284,6 +284,7 @@ public class TuyaUtilsSo {
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
+// CommonTuyaSoUtils.INSTANCE.tuyaSoEvent();
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -360,7 +361,7 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
|
|
|
CommonTuyaSoUtils.INSTANCE.navigateToAdaptedCooking(type);
|
|
|
-
|
|
|
+ wakeUpScreen(context);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -453,7 +454,7 @@ public class TuyaUtilsSo {
|
|
|
|
|
|
|
|
|
public void uploadData() {
|
|
|
- if (!tuyaNetwork||!isUser) {
|
|
|
+ if (!tuyaNetwork || !isUser) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -464,7 +465,7 @@ public class TuyaUtilsSo {
|
|
|
DevInfo info = CofarSDK.devInfo();
|
|
|
BaseDevMode mode = info.getMode();
|
|
|
int time = (int) System.currentTimeMillis();
|
|
|
- if (getAutoMaticModes(info.getRunningInstId())!=autoMaticType){
|
|
|
+ if (getAutoMaticModes(info.getRunningInstId()) != autoMaticType) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -508,39 +509,6 @@ public class TuyaUtilsSo {
|
|
|
|
|
|
int automatic = getModes(info.getRunningInstId());
|
|
|
|
|
|
-// DPEvent[] dpEvents = new DPEvent[]{
|
|
|
-// new DPEvent(TuyaSoDp.ON_OFF, (byte) DPEvent.Type.PROP_BOOL, 1, 0),
|
|
|
-// new DPEvent(TuyaSoDp.START_STOP, (byte) DPEvent.Type.PROP_BOOL, start_stop, 0),
|
|
|
-// new DPEvent(TuyaSoDp.AUTOMATIC_PROGRAM, (byte) DPEvent.Type.PROP_ENUM, automatic, 0),
|
|
|
-// new DPEvent(TuyaSoDp.WORK_STATE, (byte) DPEvent.Type.PROP_ENUM, work_state, 0),
|
|
|
-// new DPEvent(TuyaSoDp.COOKING_TEMPERATURE, (byte) DPEvent.Type.PROP_VALUE, (int) (info.getTargetTempBuffer() != -1 ? info.getTargetTempBuffer() : info.getTargetTemp()), 0),
|
|
|
-// new DPEvent(TuyaSoDp.CURRENT_TEMPERATURE, (byte) DPEvent.Type.PROP_VALUE, (int) CofarUtils.parseTemp(info.getTemp()), 0),
|
|
|
-//// new DPEvent(TuyaSoDp.COOKING_TIME, (byte) DPEvent.Type.PROP_VALUE, 1, 0),
|
|
|
-//// new DPEvent(TuyaSoDp.REMAINING_TIME, (byte) DPEvent.Type.PROP_VALUE,1, 0),
|
|
|
-//
|
|
|
-// new DPEvent(TuyaSoDp.COOKING_TIME, (byte) DPEvent.Type.PROP_VALUE, info.getTargetTimeBuffer() != -1 ? info.getTargetTimeBuffer() : info.getTargetTime(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.REMAINING_TIME, (byte) DPEvent.Type.PROP_VALUE, info.getRemainTime(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.PAUSE, (byte) DPEvent.Type.PROP_BOOL, pause, 0),
|
|
|
-// new DPEvent(TuyaSoDp.SPEED, (byte) DPEvent.Type.PROP_VALUE, (int) (info.getMotorGearBuffer() != -1 ? info.getMotorGearBuffer() : info.getMotorGear()), 0),
|
|
|
-// new DPEvent(TuyaSoDp.REVERSIBLE, (byte) DPEvent.Type.PROP_BOOL, (int) (info.getMotorDirectionBuffer() != -1 ? info.getMotorDirectionBuffer() : info.getMotorDirection()), 0),
|
|
|
-// new DPEvent(TuyaSoDp.POT_STATUS, (byte) DPEvent.Type.PROP_VALUE, pot_status, 0),
|
|
|
-// new DPEvent(TuyaSoDp.WEIGHT_NUMBER, (byte) DPEvent.Type.PROP_VALUE, info.getWeight(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.POT_CLOVER_STATUS, (byte) DPEvent.Type.PROP_VALUE, (int) info.getPotCloverStatus(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.MAX_TIME, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMaxTime(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.MIN_TIME, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMinTime(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.MAX_TEMP, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMaxTemp(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.MIN_TEMP, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMinTemp(), 0),
|
|
|
-//
|
|
|
-//// new DPEvent(TuyaSoDp.MAX_TEMP, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : 88, 0),
|
|
|
-//// new DPEvent(TuyaSoDp.MIN_TEMP, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : 50, 0),
|
|
|
-// new DPEvent(TuyaSoDp.MAX_MOTOR_GEAR, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMaxMotorGear(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.MIN_MOTOR_GEAR, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMinMotorGear(), 0),
|
|
|
-// new DPEvent(TuyaSoDp.TIME_CHANGE, (byte) DPEvent.Type.PROP_BOOL, timeChange, 0),
|
|
|
-// new DPEvent(TuyaSoDp.TEMP_CHANGE, (byte) DPEvent.Type.PROP_BOOL, tempChange, 0),
|
|
|
-// new DPEvent(TuyaSoDp.MOTOR_GEAR_CHANGE, (byte) DPEvent.Type.PROP_BOOL, motorGearChange, 0),
|
|
|
-// new DPEvent(TuyaSoDp.MOTOR_DIRECTION_CHANGE, (byte) DPEvent.Type.PROP_BOOL, motorDirectionChange, 0)
|
|
|
-//
|
|
|
-// };
|
|
|
|
|
|
List<DPEvent> dpEvents = new ArrayList<>(Arrays.asList(
|
|
|
new DPEvent(TuyaSoDp.ON_OFF, (byte) DPEvent.Type.PROP_BOOL, 1, 0),
|
|
@@ -596,16 +564,16 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
|
|
|
if (event.type == DPEvent.Type.PROP_BOOL) {
|
|
|
- sendDpBool(event.dpid, value,time);
|
|
|
+ sendDpBool(event.dpid, value, time);
|
|
|
}
|
|
|
if (event.type == DPEvent.Type.PROP_VALUE) {
|
|
|
- sendDpValue(event.dpid, value,time);
|
|
|
+ sendDpValue(event.dpid, value, time);
|
|
|
}
|
|
|
if (event.type == DPEvent.Type.PROP_STR) {
|
|
|
- sendDpStr(event.dpid, String.valueOf(value),time);
|
|
|
+ sendDpStr(event.dpid, String.valueOf(value), time);
|
|
|
}
|
|
|
if (event.type == DPEvent.Type.PROP_ENUM) {
|
|
|
- sendDpEnum(event.dpid, value,time);
|
|
|
+ sendDpEnum(event.dpid, value, time);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -627,7 +595,7 @@ public class TuyaUtilsSo {
|
|
|
DevInfo info = CofarSDK.devInfo();
|
|
|
BaseDevMode mode = info.getMode();
|
|
|
int time = (int) System.currentTimeMillis();
|
|
|
- Log.v("tuya_iot",info.toString());
|
|
|
+ Log.v("tuya_iot", info.toString());
|
|
|
// BaseDevMode mode = baseDevMode;
|
|
|
// Log.e("tuya_iot",mode.toString());
|
|
|
int status = info.getStatus();
|
|
@@ -757,16 +725,16 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
|
|
|
if (event.type == DPEvent.Type.PROP_BOOL) {
|
|
|
- sendDpBool(event.dpid, value,time);
|
|
|
+ sendDpBool(event.dpid, value, time);
|
|
|
}
|
|
|
if (event.type == DPEvent.Type.PROP_VALUE) {
|
|
|
- sendDpValue(event.dpid, value,time);
|
|
|
+ sendDpValue(event.dpid, value, time);
|
|
|
}
|
|
|
if (event.type == DPEvent.Type.PROP_STR) {
|
|
|
- sendDpStr(event.dpid, String.valueOf(value),time);
|
|
|
+ sendDpStr(event.dpid, String.valueOf(value), time);
|
|
|
}
|
|
|
if (event.type == DPEvent.Type.PROP_ENUM) {
|
|
|
- sendDpEnum(event.dpid, value,time);
|
|
|
+ sendDpEnum(event.dpid, value, time);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -926,15 +894,11 @@ public class TuyaUtilsSo {
|
|
|
// }
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
private int getModes(String enumValue) {
|
|
|
|
|
|
|
|
|
- if (autoMaticType!=-1){
|
|
|
- return autoMaticType;
|
|
|
+ if (autoMaticType != -1) {
|
|
|
+ return autoMaticType;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1007,7 +971,7 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private int getAutoMaticModes(String enumValue){
|
|
|
+ private int getAutoMaticModes(String enumValue) {
|
|
|
/**
|
|
|
* 0 DIY,1 和面(Knead) ,2 蒸汽(Steam), 3 低温慢煮(Sous_vide) ,4 煮米饭(Rice) ,
|
|
|
* 5 搅碎(Chop) , 6 奶昔(Smoothie),7 称重(Weight) ,8 切丁(Dive), 9 去皮(Peeling) ,10 烧水(Boil_water),11 切丝切片 (Food_processor)
|
|
@@ -1082,7 +1046,7 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void sendDpEnum(int dpid, int value,int time_stamp) {
|
|
|
+ public void sendDpEnum(int dpid, int value, int time_stamp) {
|
|
|
Integer mapInt = map.get(dpid);
|
|
|
if (mapInt != null) {
|
|
|
int mapValue = mapInt.intValue();
|
|
@@ -1091,7 +1055,7 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- int code = getTuyaApi().send_dp_enum(dpid, value,time_stamp);
|
|
|
+ int code = getTuyaApi().send_dp_enum(dpid, value, time_stamp);
|
|
|
//上报成功,避免同一个值重复上报,估在这加map做缓存
|
|
|
if (code == 0) {
|
|
|
map.put(dpid, value);
|
|
@@ -1100,12 +1064,12 @@ public class TuyaUtilsSo {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void sendDpStr(int dpid, String value,int time_stamp) {
|
|
|
+ public void sendDpStr(int dpid, String value, int time_stamp) {
|
|
|
|
|
|
- getTuyaApi().send_dp_str(dpid, value,time_stamp);
|
|
|
+ getTuyaApi().send_dp_str(dpid, value, time_stamp);
|
|
|
}
|
|
|
|
|
|
- public void sendDpValue(int dpid, int value,int time_stamp) {
|
|
|
+ public void sendDpValue(int dpid, int value, int time_stamp) {
|
|
|
Integer mapInt = map.get(dpid);
|
|
|
if (mapInt != null) {
|
|
|
int mapValue = mapInt.intValue();
|
|
@@ -1113,7 +1077,7 @@ public class TuyaUtilsSo {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- int code = getTuyaApi().send_dp_value(dpid, value,time_stamp);
|
|
|
+ int code = getTuyaApi().send_dp_value(dpid, value, time_stamp);
|
|
|
//上报成功,避免同一个值重复上报,估在这加map做缓存
|
|
|
if (code == 0) {
|
|
|
map.put(dpid, value);
|
|
@@ -1121,7 +1085,7 @@ public class TuyaUtilsSo {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void sendDpBool(int dpid, int value,int time_stamp) {
|
|
|
+ public void sendDpBool(int dpid, int value, int time_stamp) {
|
|
|
Integer mapInt = map.get(dpid);
|
|
|
if (mapInt != null) {
|
|
|
int mapValue = mapInt.intValue();
|
|
@@ -1131,7 +1095,7 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
|
|
|
|
|
|
- int code = getTuyaApi().send_dp_bool(dpid, value,time_stamp);
|
|
|
+ int code = getTuyaApi().send_dp_bool(dpid, value, time_stamp);
|
|
|
|
|
|
//上报成功,避免同一个值重复上报,估在这加map做缓存
|
|
|
if (code == 0) {
|
|
@@ -1139,8 +1103,9 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void setDpTemp() {
|
|
|
- getTuyaApi().send_dp_temp();
|
|
|
+ public void setDpCurrentActivity() {
|
|
|
+ int time = (int)System.currentTimeMillis();
|
|
|
+ getTuyaApi().send_dp_bool(TuyaSoDp.CURRENT_ACTIVITY,1,time);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1186,4 +1151,25 @@ public class TuyaUtilsSo {
|
|
|
getTuyaApi().log_message(tag, msg);
|
|
|
}
|
|
|
|
|
|
+ public void wakeUpScreen(Context context) {
|
|
|
+ PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
|
+ //判断是否息屏,避免重复调用
|
|
|
+ if (!powerManager.isInteractive()) {
|
|
|
+ PowerManager.WakeLock wakeLock = null;
|
|
|
+ // 获取电源管理器的唤醒锁
|
|
|
+ if (powerManager != null) {
|
|
|
+ wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyApp::MyWakelockTag");
|
|
|
+ // 唤醒屏幕
|
|
|
+ wakeLock.acquire(0);
|
|
|
+
|
|
|
+ if (wakeLock != null && wakeLock.isHeld()) {
|
|
|
+ wakeLock.release();
|
|
|
+ wakeLock = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|