diff --git a/CompleteApps/SmartFanApp/README_zh.md b/CompleteApps/SmartFanApp/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..e7af7e25cabac6229660bc61bab0203728591010 --- /dev/null +++ b/CompleteApps/SmartFanApp/README_zh.md @@ -0,0 +1,34 @@ +# 智能电风扇手机端代码介绍 + +### 简介 + +本Sample是手机端应用,结合智能电风扇设备端[参考](https://gitee.com/openharmony/app_samples/tree/master/CompleteApps/SmartFanDevice/),模拟开发一个手机应用和电风扇的联动方案。手机端主要包括:手机端给设备端配网、发送控制消息给设备端、并接受设备侧消息等。 + +### 使用说明 + +##### 1.代码编译运行步骤 + +1)提前准备好搭载HarmonyOS系统的手机; + +2)下载此项目,编译构建请参考[链接]( https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_overview-0000001055075201 ); + +3)真机运行应用请参考[链接]( https://developer.harmonyos.com/cn/docs/documentation/doc-guides/run_phone_tablat-0000001064774652 )。 + +##### 2.与设备端联动步骤 + +1)提前准备好[智能电风扇设备端](https://gitee.com/openharmony/app_samples/tree/master/CompleteApps/SmartFanDevice/),可参考智能热水壶设备端介绍; + +2)打开FA,在热点连接列表中找到SmartFan_AP热点并连接,点击开始配网,选择好热点并输入密码点击确定给设备端配网; + +3)在设备端配网成功后,可控制设备开关机、风速,并根据时间和环境温度来设置用户想要的风速的模式,并同时具备定时开关机功能; + +### 约束限制 + +1. 提前准好已实名认证的开发者联盟账号 ,具体[参考](https://developer.huawei.com/consumer/cn/) + +2. 开发工具:DevEcoStudio [参考](https://developer.harmonyos.com/cn/develop/deveco-studio#download /) + +3. 本示例需在真机运行,请提前准备好搭载HarmonyOS系统的手机。 + +4. 更多资料请登录HarmonyOS应用开发官网: https://developer.harmonyos.com/cn/ + diff --git a/CompleteApps/SmartFanApp/build.gradle b/CompleteApps/SmartFanApp/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..bdcc1aaaa48521294e0947d0954ec5e5ca0bb002 --- /dev/null +++ b/CompleteApps/SmartFanApp/build.gradle @@ -0,0 +1,38 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.4.2' + classpath 'com.huawei.ohos:decctest:1.2.4.0' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/CompleteApps/SmartFanApp/entry/build.gradle b/CompleteApps/SmartFanApp/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..f6c8444fa737c652033ba6fc09ca05ed8852baaa --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/CompleteApps/SmartFanApp/entry/node_modules/fa-softaputil.js b/CompleteApps/SmartFanApp/entry/node_modules/fa-softaputil.js new file mode 100644 index 0000000000000000000000000000000000000000..ac17f720aece4632e644e9e0cdec0b9e77d9b6cf --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/node_modules/fa-softaputil.js @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') +const CONSTANT = { + BUNDLE_NAME: "ohos.samples.smartfan", + ABILITY_NAME_FOR_BM: "ohos.samples.smartfan.ControlAbility", + ABILITY_NAME_FOR_MAIN: "ohos.samples.smartfan.MainAbility", + ABILITY_NAME_FOR_CONTROLSERVICE: "ohos.samples.smartfan.ControlServiceAbility", + TAG:"[Demo]:" +} + +const ABILITY_TYPE_EXTERNAL = 0; +const ABILITY_TYPE_INTERNAL = 1; +const ACTION_SYNC = 0; +const ACTION_ASYNC = 1; + +var FASoftapUtil = { + info: function (info) { + console.info(CONSTANT.TAG + info); + }, + + // Call PA to send command + sendMessage:async function(data, code){ + var action = {}; + action.bundleName = CONSTANT.BUNDLE_NAME; + action.abilityName = CONSTANT.ABILITY_NAME_FOR_CONTROLSERVICE; + action.messageCode = code; + action.data = data; + action.abilityType = ABILITY_TYPE_EXTERNAL; + action.syncOption = ACTION_SYNC; + var result = await FeatureAbility.callAbility(action); + return result; + }, + + // Pull up FA + callNewFa: async function (dataInfo, flag) { + var action = {}; + action.bundleName = CONSTANT.BUNDLE_NAME; + if (flag === 0) { + action.abilityName = CONSTANT.ABILITY_NAME_FOR_BM; + } else if (flag === 1) { + action.abilityName = CONSTANT.ABILITY_NAME_FOR_MAIN; + } + action.data = dataInfo; + await FeatureAbility.startAbility(action); + }, + + subscribe: async function (code, callback){ + let action = {}; + action.bundleName = CONSTANT.BUNDLE_NAME; + action.abilityName = CONSTANT.ABILITY_NAME_FOR_CONTROLSERVICE; + action.messageCode = code; + action.abilityType = ABILITY_TYPE_EXTERNAL; + action.syncOption = ACTION_SYNC; + + var result = await FeatureAbility.subscribeAbilityEvent(action, function(callbackData) { + callback(callbackData); + }); + } +}; + +module.exports = { + FASoftapUtil +}; \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/node_modules/fan-constants.js b/CompleteApps/SmartFanApp/entry/node_modules/fan-constants.js new file mode 100644 index 0000000000000000000000000000000000000000..a45a01156df70203990a6c33272d94ee1c8759c5 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/node_modules/fan-constants.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const CONSTANTS = { + CONTROL_CODE: 1001, + GET_CURRENT_WIFI_CODE: 2001, + SET_WIFI_CODE: 2002, + GET_AVAILABLE_WIFI_CODE: 2003, + SUBSCRIBE_CONTROL_STATE: 3001, + SMARTFAN_WIFI: "SmartFan_AP", + CMD_POWER: 1, + CMD_CHANGE_GEAR: 2, + CMD_CHANGE_WINDMODE: 3, + + // Temperature control + CMD_TEMP: 6, + // Control on time + CMD_TIME: 7 +} + +module.exports = { + CONSTANTS +}; \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/config.json b/CompleteApps/SmartFanApp/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a60de84662aa1398ed46aaa924984fe674122dff --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/config.json @@ -0,0 +1,124 @@ +{ + "app": { + "bundleName": "ohos.samples.smartfan", + "vendor": "sample", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.smartfan", + "name": ".MyApplication", + "mainAbility": "ohos.samples.smartfan.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.Translucent.NoTitleBar" + } + ] + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "ohos.samples.smartfan.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "visible": true, + "name": "ohos.samples.smartfan.ControlAbility", + "icon": "$media:icon", + "description": "$string:controlability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "name": "ohos.samples.smartfan.ControlServiceAbility", + "icon": "$media:icon", + "description": "$string:controlserviceability_description", + "type": "service" + } + ], + "js": [ + { + "pages": [ + "pages/index/index", + "pages/phone/index", + "pages/confignet/index", + "pages/locationset/index", + "pages/otherWifi/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index", + "pages/powerControl/index", + "pages/temperatureControl/index", + "pages/timeControl/index", + "pages/addPower/index", + "pages/addTimer/index", + "pages/addTemperature/index" + ], + "name": "control", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name": "ohos.permission.GET_WIFI_INFO" + }, + { + "reason": "get Local Location", + "name": "ohos.permission.LOCATION", + "usedScene": { + "ability": [ + "ohos.samples.smartfan.MainAbility", + "ohos.samples.smartfan.ControlAbility", + "ohos.samples.smartfan.ControlServiceAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.SET_WIFI_INFO" + } + ] + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/Const.java b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/Const.java new file mode 100644 index 0000000000000000000000000000000000000000..e60be490f05033facd3283b2368fc080ba76643e --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/Const.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.smartfan; + +/** + * Const + * + * @since 2021--1-19 + */ +public class Const { + /** + * device IP + */ + public static final String IP = "192.168.5.1"; + + /** + * control port + */ + public static final int CONTROL_PORT = 8787; + + /** + * control port + */ + public static final int CONFIG_PORT = 8686; + + /** + * TWO means Full mode when FeatureAbility start + */ + public static final int TWO = 2; + + /** + * THREE means pop-up mode when FeatureAbility start + */ + public static final int THREE = 3; + + /** + * Key code + */ + public static final String KEY_CODE = "code"; + + /** + * error message + */ + public static final String KEY_ERROR = "errMsg"; +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/ControlAbility.java b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/ControlAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..86f175dec6b2e8636fadacaf4cce39d440dbcdee --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/ControlAbility.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.smartfan; + +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.IntentParams; +import ohos.ace.ability.AceAbility; +import ohos.utils.zson.ZSONObject; + +/** + * ControlAbility + * + * @since 2021-01-19 + */ +public class ControlAbility extends AceAbility { + private static final String TAG = "[Demo]:ControlAbility"; + + @Override + public void onStart(Intent intent) { + try { + // Start the current ability using Full mode, 2 means Full mode when FeatureAbility start. + intent.setParam("window_modal", Const.TWO); + + // Start control FeatureAbility. + setInstanceName("control"); + + String data = ZSONObject.toZSONString(intent); + LogUtil.info(TAG, "data==" + data); + + // JS pull up this FeatureAbility , __startParams means default ability pull up control ability + Object reBackObj = intent.getParams().getParam("__startParams"); + + // Get dataInfo value sessionId and set to control page. + if (reBackObj != null) { + ZSONObject reBackInfo = ZSONObject.stringToZSON((String) reBackObj); + String dataInfo = reBackInfo.getString("serverIp"); + LogUtil.info(TAG, "dataInfo= " + dataInfo); + if (dataInfo != null) { + setParams(intent, "dataInfo", dataInfo); + } + } + } catch (Error e) { + LogUtil.error(TAG, "", e); + } + super.onStart(intent); + } + + @Override + public void onStop() { + super.onStop(); + } + + private void setParams(Intent intent, String tag, String tagInfo) { + try { + IntentParams intentParams = intent.getParams(); + if (intentParams != null) { + intentParams.setParam(tag, tagInfo); + + // Set params to control FeatureAbility home page. + setPageParams(null, intentParams); + } + } catch (Error e) { + LogUtil.error(TAG, "", e); + } + + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/ControlServiceAbility.java b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/ControlServiceAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..0c4bbc1ab3e9b8ae7d40cfad4689151d1a2124b0 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/ControlServiceAbility.java @@ -0,0 +1,391 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.smartfan; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.global.resource.NotExistException; +import ohos.global.resource.WrongTypeException; +import ohos.rpc.IRemoteBroker; +import ohos.rpc.IRemoteObject; +import ohos.rpc.MessageOption; +import ohos.rpc.MessageParcel; +import ohos.rpc.RemoteException; +import ohos.rpc.RemoteObject; +import ohos.utils.zson.ZSONArray; +import ohos.utils.zson.ZSONObject; +import ohos.wifi.WifiDevice; +import ohos.wifi.WifiLinkedInfo; +import ohos.wifi.WifiScanInfo; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.Socket; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +/** + * ControlServiceAbility + * + * @since 2021-01-19 + */ +public class ControlServiceAbility extends Ability { + private static final String TAG = "[Demo]:ControlServiceAbility"; + + private static final int SUCCESS = 200; + private static final int ERROR = 1; + private static final int GET_CURRENT_WIFI_CODE = 2001; + private static final int GET_AVAILABLE_WIFI_CODE = 2003; + private static final int SET_WIFI_CODE = 2002; + private static final int CONTROL_CODE = 1001; + private static final int SUBSCRIBE_CONTROL_STATE = 3001; + private static final int NUMBER_FF = 0xff; + private static final int NUMBER_55 = 0x55; + private static final int NUMBER_AA = 0xaa; + private static final int NUMBER_00 = 0x00; + + + private final MyRemote remote = new MyRemote(); + + private Socket socketDeviceListener = null; + + private IRemoteObject controlStateRemoteObj = null; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onBackground() { + super.onBackground(); + } + + @Override + public void onStop() { + super.onStop(); + if (socketDeviceListener != null) { + try { + socketDeviceListener.close(); + socketDeviceListener = null; + } catch (IOException e) { + LogUtil.error(TAG, "", e); + } + } + } + + @Override + public void onCommand(Intent intent, boolean isRestart, int startId) { + } + + @Override + public void onDisconnect(Intent intent) { + } + + @Override + protected IRemoteObject onConnect(Intent intent) { + super.onConnect(intent); + return remote.asObject(); + } + + /** + * MyRemote + * + * @since 2021-01-19 + */ + class MyRemote extends RemoteObject implements IRemoteBroker { + MyRemote() { + super("ControlServiceAbility_MyRemote"); + } + + @Override + public boolean onRemoteRequest(int code, MessageParcel data, MessageParcel reply, MessageOption option) { + Map result = new HashMap(); + String dataStr = data.readString(); + LogUtil.info("onRemoteRequest: code=", String.valueOf(code) + ";data=" + dataStr); + switch (code) { + // controlling device + case CONTROL_CODE: { + try { + reply.writeString(controlDevice(dataStr)); + break; + } catch (IOException e) { + LogUtil.error(TAG, "", e); + LogUtil.error(TAG, e.getMessage()); + result.put(Const.KEY_CODE, ERROR); + result.put(Const.KEY_ERROR, e.getMessage()); + reply.writeString(ZSONObject.toZSONString(result)); + return false; + } + } + + // Get current wifi + case GET_CURRENT_WIFI_CODE: + // Get WLAN management objects + reply.writeString(getCurrentWifi()); + break; + + // Get available wifi + case GET_AVAILABLE_WIFI_CODE: + reply.writeString(getAvialableWifi()); + break; + + // Distribution network + case SET_WIFI_CODE: + try { + reply.writeString(configNet(dataStr)); + } catch (IOException e) { + LogUtil.error(TAG, "", e); + } + break; + case SUBSCRIBE_CONTROL_STATE: { + // If only single FA subscription is supported, it can be directly covered: + controlStateRemoteObj = data.readRemoteObject(); + result.put(Const.KEY_CODE, 0); + reply.writeString(ZSONObject.toZSONString(result)); + break; + } + default: { + result.put(Const.KEY_CODE, ERROR); + result.put(Const.KEY_ERROR, "Invalid code :" + code); + reply.writeString(ZSONObject.toZSONString(result)); + return false; + } + } + return true; + } + + @Override + public IRemoteObject asObject() { + return this; + } + } + + /** + * Get available wifi + * + * @return + */ + private String getAvialableWifi() { + // Get WLAN management objects + WifiDevice wifiDevice = WifiDevice.getInstance(this); + + // Call the WLAN scanning interface + try { + boolean isScanSuccess = wifiDevice.scan(); + if (!isScanSuccess) { + ZSONObject jsonObj = new ZSONObject(); + jsonObj.put(Const.KEY_CODE, ERROR); + jsonObj.put(Const.KEY_ERROR, "Fail to getAvialableWifi scan result false"); + return jsonObj.toString(); + } + + // Call to get scan results + List scanInfos = wifiDevice.getScanInfoList(); + + ZSONObject jsonObj = new ZSONObject(); + jsonObj.put(Const.KEY_CODE, SUCCESS); + ZSONArray wifiArray = new ZSONArray(); + + Map result = new HashMap(); + + // Take the BSSID as the dimension, so ssid is needed to remove duplicates + Set wifiSet = new HashSet<>(); + ohos.global.resource.ResourceManager resManager = this.getResourceManager(); + for (WifiScanInfo scanInfo : scanInfos) { + if (scanInfo.getSsid() == null || scanInfo.getSsid().trim().equals("") + || wifiSet.contains(scanInfo.getSsid())) { + continue; + } + ZSONObject jsonWifi = new ZSONObject(); + jsonWifi.put("ssid", scanInfo.getSsid()); + if (scanInfo.getSecurityType() == 0) { + jsonWifi.put("security", + this.getResourceManager().getElement(ResourceTable.String_forpublic).getString()); + } else { + jsonWifi.put("security", + this.getResourceManager().getElement(ResourceTable.String_encrypt).getString()); + } + wifiSet.add(scanInfo.getSsid()); + wifiArray.add(jsonWifi); + } + jsonObj.put("wifi", wifiArray); + return ZSONObject.toZSONString(jsonObj); + } catch (Error | IOException | NotExistException | WrongTypeException e) { + ZSONObject jsonObj = new ZSONObject(); + jsonObj.put(Const.KEY_CODE, ERROR); + jsonObj.put(Const.KEY_ERROR, "Fail to getAvialableWifi" + e.getMessage()); + LogUtil.error(TAG,"fail to getAvialableWifi", e.getMessage()); + return jsonObj.toString(); + } + } + + /** + * controlling device + * + * @param dataStr The json string passed in from the front end, including the device serverIp + * @return Device response + * @throws IOException e + */ + private String controlDevice(String dataStr) throws IOException { + LogUtil.info(TAG, "" + dataStr); + ZSONObject obj = ZSONObject.stringToZSON(dataStr); + + // Device IP obtained using the interface + String serverIp = obj.getString("serverIp"); + LogUtil.info(TAG, "" + serverIp); + obj.remove("serverIp"); + Socket socket = new Socket(serverIp, Const.CONTROL_PORT); + dataStr = obj.toString(); + OutputStream out = socket.getOutputStream(); + out.write(dataStr.getBytes("UTF-8")); + + BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + String str = in.readLine(); + in.close(); + LogUtil.info("onRemoteRequest controlDevice receive:", str); + socket.close(); + + if (socketDeviceListener == null) { + // Initialize device monitoring + initDeviceListener(serverIp); + } + + // The returned result currently only supports String. For complex structures, + // it can be serialized as a ZSON string and reported + Map result = new HashMap(); + result.put(Const.KEY_CODE, SUCCESS); + return ZSONObject.toZSONString(result); + } + + /** + * Get the currently connected wifi name + * + * @return name + */ + private String getCurrentWifi() { + WifiDevice wifiDevice = WifiDevice.getInstance(getContext()); + + // Call the WLAN connection status interface to determine whether the current device is connected to WLAN + boolean isConnected = wifiDevice.isConnected(); + if (isConnected) { + // Get Wi-Fi connection information + Optional linkedInfo = wifiDevice.getLinkedInfo(); + + // Get the SSID in the connection information + return linkedInfo.get().getSsid(); + } else { + return ""; + } + } + + /** + * Call socket to complete network configuration + * + * @param dataStr wifi account and password + * @return return + */ + private String configNet(String dataStr) throws IOException { + Socket socket = null; + OutputStream out = null; + BufferedReader in = null; + try { + // Fixed use on the device side192.168.10.1 + socket = new Socket(Const.IP, Const.CONFIG_PORT); + out = socket.getOutputStream(); + out.write(dataStr.getBytes("UTF-8")); + + in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + String str = in.readLine(); + LogUtil.info("configNet receive:", str); + + return str; + } catch (IOException e) { + LogUtil.error(TAG,"",e); + LogUtil.error("configNet:", e.getMessage()); + return String.format("{\"code\":500,\"errmsg\":\"%s\"}", e.getMessage()); + } finally { + socket.close(); + out.close(); + in.close(); + } + } + + /** + * Initialize the device to monitor, + * send 0xff, 0x55, 0xaa, 0x55, 0x00 to tell the device to use this connection to feedback the status + * + * @param serverIp serverIp + */ + private void initDeviceListener(String serverIp) { + if (serverIp == null || "".equals(serverIp)) { + return; + } + try { + socketDeviceListener = new Socket(serverIp, Const.CONTROL_PORT); + OutputStream out = socketDeviceListener.getOutputStream(); + byte[] cmds = {(byte) NUMBER_FF, (byte) NUMBER_55, (byte) NUMBER_AA, (byte) NUMBER_55, (byte) NUMBER_00}; + out.write(cmds); + + BufferedReader in = new BufferedReader(new InputStreamReader(socketDeviceListener.getInputStream())); + DeviceControlThread deviceControlThread = new DeviceControlThread(in); + deviceControlThread.start(); + } catch (IOException e) { + LogUtil.error(TAG,"",e); + } + } + + /** + * Thread monitoring device report + * + * @since 2021-01-19 + */ + class DeviceControlThread extends Thread { + private BufferedReader input; + + DeviceControlThread(BufferedReader in) { + this.input = in; + } + + @Override + public void run() { + try { + while (true) { + String str = this.input.readLine(); + LogUtil.info("initDeviceListener controlDevice receive:", str); + if (controlStateRemoteObj != null) { + LogUtil.info("initDeviceListener controlDevice success send111:", ""); + MessageParcel data = MessageParcel.obtain(); + MessageParcel reply = MessageParcel.obtain(); + MessageOption option = new MessageOption(); + data.writeString(ZSONObject.toZSONString(str)); + controlStateRemoteObj.sendRequest(100, data, reply, option); + LogUtil.info("initDeviceListener controlDevice success send22:", ""); + } + } + } catch (IOException | RemoteException e) { + LogUtil.error(TAG, "", e); + LogUtil.error("initDeviceListener controlDevice receive:", e.getMessage()); + } + } + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/LogUtil.java b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/LogUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..7c8ff7dbfc73870f0ffdb524a351391a5b0455fb --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/LogUtil.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.smartfan; + +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +import java.util.Locale; + +public class LogUtil { + private static final String TAG_LOG = ""; + + private static final int DOMAIN_ID = 0xD000F00; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, DOMAIN_ID, LogUtil.TAG_LOG); + + private static final String LOG_FORMAT = "%{public}s: %{public}s"; + + private static final boolean DEBUG = true; + + private LogUtil() { + } + + /** + * Print debug log + * + * @param tag log tag + * @param msg log message + */ + public static void debug(String tag, String msg) { + if (DEBUG) { + HiLog.debug(LABEL_LOG, LOG_FORMAT, tag, msg); + } + } + + /** + * Print info log + * + * @param tag log tag + * @param msg log message + */ + public static void info(String tag, String msg) { + if (DEBUG) { + HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg); + } + } + + /** + * Print warn log + * + * @param tag log tag + * @param msg log message + */ + public static void warn(String tag, String msg) { + if (DEBUG) { + HiLog.warn(LABEL_LOG, LOG_FORMAT, tag, msg); + } + } + + /** + * Print error log + * + * @param tag log tag + * @param msg log message + */ + public static void error(String tag, String msg) { + if (DEBUG) { + HiLog.error(LABEL_LOG, LOG_FORMAT, tag, msg); + } + + } + + public static void error(String tag, final String format, Object... args) { + if (DEBUG) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.error(LABEL_LOG, LOG_FORMAT, tag, buffMsg); + } + } + + public static void info(String tag, final String format, Object... args) { + if (DEBUG) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.info(LABEL_LOG, LOG_FORMAT, tag, buffMsg); + } + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/MainAbility.java b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..c800a7a2a6e8b759862f57fa42d4b83755410134 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/MainAbility.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.smartfan; + +import ohos.aafwk.content.Intent; +import ohos.ace.ability.AceAbility; + +/** + * MainAbility + * + * @since 2021-01-19 + */ +public class MainAbility extends AceAbility { + + /** + * This is the default FeatureAbility entrance. + */ + @Override + public void onStart(Intent intent) { + // Start the current ability using half mode, 3 means pop-up mode when FeatureAbility start. + intent.setParam("window_modal",Const.THREE); + + // Start default FeatureAbility. + setInstanceName("default"); + this.requestPermissionsFromUser(new String[]{ohos.security.SystemPermission.LOCATION}, 0); + super.onStart( intent ); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/MyApplication.java b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..a23c2d3b635bf8c0e20af66b9b3f8c3b07db0efc --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/java/ohos/samples/smartfan/MyApplication.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.smartfan; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/app.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/app.js new file mode 100644 index 0000000000000000000000000000000000000000..fa4cc6002fc5c45bc413e3f5198f02b2445c9d43 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/app.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + gearsArray:[], + featuresArray:[], + timerData:[],// Control data on time + temperatureData:[],// Control data on demand + powerData:[],// Time switch data + weekDic:[], + // The ServerIp after the device is successfully configured + ServerIp:"", + + onInit(){ + + }, + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + }, + + getHourDiff(hour){ + let currentDate = new Date() + let targetDate = new Date() + targetDate.setHours(hour) + targetDate.setMinutes(0) + targetDate.setSeconds(0) + if (hour <= currentDate.getHours()){ + targetDate.setDate(targetDate.getDate() + 1) + } + return targetDate.getTime() - currentDate.getTime() + }, + // Get the week difference, including the hour and minute + getDayDiff(day, hour, min){ + let currentDate = new Date() + let targetDate = new Date() + targetDate.setHours(hour) + targetDate.setMinutes(min) + targetDate.setSeconds(0) + let dayDiff = day - currentDate.getDay() + targetDate.setDate(targetDate.getDate() + dayDiff) + + let ms = 0 + ms = targetDate.getTime() - currentDate.getTime() + if (ms <= 0) { + ms += 1000 * 60 * 60 * 24 * 7 + } + return ms + }, +}; diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/common.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/common.css new file mode 100644 index 0000000000000000000000000000000000000000..60f373e109c0b10b1e55a674bc5d99366d7ccb0c --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/common.css @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +.card{ + background-color: white; + border-radius:20px; + padding: 40px; + margin:30px 0; +/* box-shadow:0 0px 3px 3px #333;*/ +} + +.flex-between{ + display:flex; + justify-content: space-between; +} + +.flex-center{ + display: flex; + justify-content: center; + align-items: center; +} + +.flex-column { + display:flex; + flex-direction:column; +} + +.grey{ + color: #969CA1; +} + +.white{ + color: #ffffff ; +} + +.blue{ + color:#2C68FF; +} + +.horizontal-margin-20{ + margin:0 20px; +} + +.background-grey{ + background-color: #F6F7F9; +} + +.background-blue{ + background-color: #2C68FF; +} + +.font42{ + font-size: 42px; +} + +.font32{ + font-size: 32px; +} + +.font28{ + font-size: 28px; +} + +.font24{ + font-size: 24px; +} + +.block{ + display: block; + +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.css new file mode 100644 index 0000000000000000000000000000000000000000..658fec80e24b5033f5e6df29942948f47542b53b --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.css @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../../common/common.css'; +.container { + flex-direction: column; + justify-content: center; + align-items: center; + margin: 0 32px; +} +.param-box{ + width: 150px; + height: 56px; + background-color: #2C68FF; + border-radius:25px; + margin-right:20px; +} +.param-box .text{ + text-align: center; + line-height: 0px; +} +.subtitle{ + margin : 10px 0; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..453eb6a75e55de912409f8caf5ea08690e0dda5e --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.hml @@ -0,0 +1,32 @@ + + +
+
+
+
+ {{title}} +
+
+ {{subtitle}} +
+
+
{{gears}}
+
{{features}}
+
+
+ +
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.js new file mode 100644 index 0000000000000000000000000000000000000000..fb3ebbbfb0dd6f505951a60699ca1616fbb1ea6a --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/card/index.js @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + data: { + isCheck: false, + }, + props:{ + gears:{ + defalut:'' + }, + features:{ + defalut:'' + }, + subtitle:{ + // type:String, + defalut:'' + }, + title:{ + // type:String, + defalut:'' + }, + index:{ + defalut:0 + }, + timer:{ + defalut:'' + } + }, + onInit(){ + console.info("this.onInit " + this.title + this.timer) + if (this.timer && this.timer != 0) { + this.isCheck = true + } + }, + onShow() { + + }, + clickCard(){ + console.info('card click event' + this.index) + this.$emit('hasClick',{index:this.index}) + }, + changeSwitch({ checked }){ + this.$emit('changeSwitch',{checked:checked,index:this.index}) + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.css new file mode 100644 index 0000000000000000000000000000000000000000..c05e2dbd1597eedabbc8288776852d64a6ac310f --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.css @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../../common/common.css'; +.container { + flex-direction: column; + justify-content: center; + align-items: center; + margin: 0 32px; +} +.week-box{ + width: 80px; + height: 40px; + background-color: #2C68FF; + border-radius:25px; + margin-right:20px; + text-align: center; + line-height: 40px; +} +.week-text{ + margin-right:10px; +} +.param-box .text{ + text-align: center; + line-height: 40px; +} +.subtitle{ + margin : 10px 0; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..966dbf64d8ddef949910f4de923464f0b4ed4c6b --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.hml @@ -0,0 +1,32 @@ + + +
+
+
+
+ {{start}}-{{end}} +
+
+ {{$t('strings.openPeriod')}} + {{$app.$def.weekDic[value]}} +
+
+ +
+
+ {{subTitle}} +
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.js new file mode 100644 index 0000000000000000000000000000000000000000..5bf63fb2a540c1cbbf0fb341dc46f497884cd4cd --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/component/week/index.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + data: { + isCheck: false, + + showWeeks:[] + }, + props:{ + start:{ + defalut:'' + }, + end:{ + defalut:'' + }, + weeks:{ + defalut:'' + }, + index:{ + defalut:0 + }, + timer:{ + defalut:'' + } + }, + onInit() { + console.info(JSON.stringify(this.$app.$def.powerData) + 'wwwb') + console.info("this.onInit " + this.timer) + if (this.timer && this.timer != 0) { + this.isCheck = true; + } + this.showWeeks = this.weeks + if (this.weeks.length == 7) { + // Show this one every day + this.showWeeks = [7] + } + }, + onShow(){ + console.info(JSON.stringify(this.$app.$def.powerData) + 'wwwc'); + }, + onDestroy(){ + }, + changeSwitch({ checked }){ + console.info("changeSwitch week") + this.$emit('changeWeekSwitch',{checked:checked,index:this.index}) + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/back.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/back.png new file mode 100644 index 0000000000000000000000000000000000000000..5f0c565c85816201c27be59d36071773cb0f4b43 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/back.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/button_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/button_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..499b52b332d835b101f351a601b500219245396a Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/button_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_banner.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_banner.png new file mode 100644 index 0000000000000000000000000000000000000000..f7bb7754830c0bbf1e0ac75f0a1cebe36f30b7a3 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_banner.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_Timing switch.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_Timing switch.png new file mode 100644 index 0000000000000000000000000000000000000000..0f9e5f4fad45f160236ceb8d12aa5c0fb3fdbd79 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_Timing switch.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_automatic_switch.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_automatic_switch.png new file mode 100644 index 0000000000000000000000000000000000000000..3ab58dbac4407fd3a2542289f9ee5f93952ca330 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_automatic_switch.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_chuifeng_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_chuifeng_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..2cec3fb42a175834786e2a37e487157a7dc9073d Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_chuifeng_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_chuifeng_unselected copy.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_chuifeng_unselected copy.png new file mode 100644 index 0000000000000000000000000000000000000000..adda171af9f230c831749fc4003f04614948af15 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_chuifeng_unselected copy.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_clock.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_clock.png new file mode 100644 index 0000000000000000000000000000000000000000..2058a6bb8cee09562cb0dc180326198408e96deb Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_clock.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_control.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_control.png new file mode 100644 index 0000000000000000000000000000000000000000..92745ad3f6daea50decd1f51485be87f0774647a Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_control.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_fengshan.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_fengshan.png new file mode 100644 index 0000000000000000000000000000000000000000..f55ecfdad342b998799458467d0fdfb946512987 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_fengshan.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_sleepwind_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_sleepwind_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..b62adb1289b72da847fa84b392461e6af1e56376 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_sleepwind_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_sleepwind_unselected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_sleepwind_unselected.png new file mode 100644 index 0000000000000000000000000000000000000000..1b3691800dd23283bf91cffc377e2d2104234d76 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_sleepwind_unselected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_temp.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_temp.png new file mode 100644 index 0000000000000000000000000000000000000000..83f0c1e91f484c5e24be1b4f1a6aa82c2bbeedca Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_temp.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_temprature.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_temprature.png new file mode 100644 index 0000000000000000000000000000000000000000..30988e8c5d0e540c1b68024544bc43469baa8ea3 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_temprature.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_wind one_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_wind one_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..66f471f722c9306357ebfc68d8782b3b091035de Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_wind one_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_wind one_unselected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_wind one_unselected.png new file mode 100644 index 0000000000000000000000000000000000000000..b2b5026f26c2bee0673f94965a646063203d1fdd Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_wind one_unselected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windfour_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windfour_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..72bbc77d6d3235c3e955349de4be905d6f0de2da Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windfour_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windfour_unselected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windfour_unselected.png new file mode 100644 index 0000000000000000000000000000000000000000..5f1b233e8011c837550d4e1723013f677d777af0 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windfour_unselected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windthree_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windthree_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..9afa38188d05e889ac470926bf24d8330b65c9ae Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windthree_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windthree_unselected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windthree_unselected.png new file mode 100644 index 0000000000000000000000000000000000000000..b2e94f831ebbe32793959f6df626068077567a2c Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windthree_unselected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windtwo_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windtwo_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..d9d420b9a7837fe471a23a30676cd1ae2e170e9a Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windtwo_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windtwo_unselected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windtwo_unselected.png new file mode 100644 index 0000000000000000000000000000000000000000..7316e619dadc7ef954137bdd844125a26a5af472 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_icon_windtwo_unselected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_task switch_off.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_task switch_off.png new file mode 100644 index 0000000000000000000000000000000000000000..044983032f6f458123d24b6665f9df20f1d95ecf Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_task switch_off.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_task switch_on.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_task switch_on.png new file mode 100644 index 0000000000000000000000000000000000000000..d3006ee685278862979ea4b8df7611e59ac8540b Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/home_task switch_on.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/icon_back.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/icon_back.png new file mode 100644 index 0000000000000000000000000000000000000000..c238ff5f995f07555e2f588f1e0369924354bd11 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/icon_back.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/setting button_selected.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/setting button_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..20a9f2c2f917d9a3cad58b4af0da461a98c4fe38 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/setting button_selected.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/switch_off.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/switch_off.png new file mode 100644 index 0000000000000000000000000000000000000000..669c9c43de950e888586e13ff5cb19d251d4dc34 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/switch_off.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/switch_on.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/switch_on.png new file mode 100644 index 0000000000000000000000000000000000000000..b74dae79d9bc2663c4e0fd784eb69efda136ae46 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/images/switch_on.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/common/logo.png b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..8ff99801a568aba384af790d7af48f83d9cf1603 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/control/common/logo.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/i18n/en-US.json b/CompleteApps/SmartFanApp/entry/src/main/js/control/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0ae80215fa79c40cefbbe472668e31553c4c5554 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/i18n/en-US.json @@ -0,0 +1,57 @@ +{ + "strings": { + "appName": "SmartFan", + "switchOn": "On", + "switchOff": "Off", + "openPeriod": "OpenPeriod", + "gears":"Gear", + "firstGear": "FirstGear", + "secondGear":"SecondGear", + "thirdGear":"ThirdGear", + "fourthGear":"FourthGear", + "temperatureControl":"ControlByTemperature", + "enterName": "EnterName", + "name": "Name", + "controlTime": "TimelyControl", + "retry": "Retry", + "skipNetwork": "SkipNetwork", + "tips": "MakeSureDeviceIsLocatedNearTheMobilePhone", + "equipmentName": "EquipmentName", + "smartFan": "IntelligentElectricFan", + "shakeHead": "ShakeHead", + "orientation": "Directional", + "stirAir": "AgitateAir", + "day":"Day", + "one":"One", + "two":"Two", + "three":"Three", + "four":"Four", + "five":"Five", + "six":"Six", + + "monday": "Monday", + "tuesday": "Tuesday", + "wednesday": "Wednesday", + "thursday": "Thursday", + "friday": "Friday", + "saturday": "Saturday", + "sunday": "Sunday", + "everyday": "Everyday", + "timerSwitch":"TimingSwitch", + "save": "Save", + "week": "Week", + "startingTime": "StartTime", + "endTime": "EndTime", + "straightBlow":"NaturalWind", + "sleepWind": "SleepWind", + "gearSetting":"GearSetting", + "customTask":"CustomTask", + "message": "CannotBeLessThanCurrentTime", + "tip": "GearAlreadyExists", + "error":"JustDemo,OnlyOneRecordCanBeSet" + + }, + "files": { + "banner": "common/images/home_banner.png" + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/i18n/zh-CN.json b/CompleteApps/SmartFanApp/entry/src/main/js/control/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..00b2951ab31961d5d108aadd0d7ebdb1f16ffbf4 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/i18n/zh-CN.json @@ -0,0 +1,57 @@ +{ + "strings": { + "appName": "智能电风扇", + "switchOn": "已开启", + "switchOff": "已关闭", + "openPeriod": "开启时段", + "gears":"档位", + "firstGear": "一档", + "secondGear":"二档", + "thirdGear":"三档", + "fourthGear":"四档", + "temperatureControl":"随温控制", + "enterName": "输入名称", + "name": "名称", + "controlTime": "按时控制", + "retry": "重试", + "skipNetwork": "跳过配网", + "tips": "请确保智能设备已连接电源,且位于手机附近", + "equipmentName": "设备名称", + "smartFan": "智能电风扇", + "shakeHead": "摇头", + "orientation": "定向", + "stirAir": "搅动空气", + "day":"天", + "one":"一", + "two":"二", + "three":"三", + "four":"四", + "five":"五", + "six":"六", + + "monday": "周一", + "tuesday": "周二", + "wednesday": "周三", + "thursday": "周四", + "friday": "周五", + "saturday": "周六", + "sunday": "周日", + "everyday": "每天", + "timerSwitch":"定时开关机", + "save": "保存", + "week": "星期", + "startingTime": "开始时间", + "endTime": "结束时间", + "straightBlow":"自然风", + "sleepWind": "睡眠风", + "gearSetting":"档位设置", + "customTask":"自定义任务", + "message": "不能小于当前时间", + "tip": "档位已存在", + "error":"demo演示,只能设置一条记录" + + }, + "files": { + "banner": "common/images/home_banner.png" + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.css new file mode 100644 index 0000000000000000000000000000000000000000..5b277ab27f0ea9554794cf819f9a184d7208cf38 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.css @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/common.css'; +.container { + flex-direction: column; + justify-content: flex-start; + background-color: #F6F7F9; + padding:0 20px; +} +.button{ + width:100px; + height:60px; + background-color: #F6F7F9; + text-align:center; +} + +.box{ + width:680px; + background-color:#FFF; + flex-direction: column; + justify-content: center; +} +.background-white{ + background-color: #FFFFFF; +} +.back{ + width:48px; + height:48px; +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..ba28cd7755f6b4d36ca2989e1f3fa0852d1328d5 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.hml @@ -0,0 +1,36 @@ + + +
+
+ + {{$t('strings.timerSwitch')}} + {{$t('strings.save')}} +
+
+
+
+ + +
+
+
+ {{$t('strings.week')}} +
+
+ {{weekArray[index]}} +
+
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.js new file mode 100644 index 0000000000000000000000000000000000000000..9b82f9a1cd54d252cc18830f0c6a45a27203838d --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addPower/index.js @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' +import prompt from '@system.prompt'; +export default { + data: { + weekArray: ["","","","", "", "",""], + startTime:'', + endTime:'', + start:'', + end:'', + hasSelectWeek:new Set(), + hasWeekArray:[], + weekBackgroundColor:['#F6F7F9','#F6F7F9','#F6F7F9','#F6F7F9','#F6F7F9','#F6F7F9','#F6F7F9'], + weekTextColor:['#969CA1','#969CA1','#969CA1','#969CA1','#969CA1','#969CA1','#969CA1'], + }, + onInit() { + this.start = this.$t('strings.startingTime'); + this.end = this.$t('strings.endTime'); + this.weekArray[0] = this.$t('strings.day'); + this.weekArray[1] = this.$t('strings.one'); + this.weekArray[2] = this.$t('strings.two'); + this.weekArray[3] = this.$t('strings.three'); + this.weekArray[4] = this.$t('strings.four'); + this.weekArray[5] = this.$t('strings.five'); + this.weekArray[6] = this.$t('strings.six'); + }, + clickWeek(index){ + + let hasDay = this.hasSelectWeek.has(index) + + let weekBackgroundColor = JSON.parse(JSON.stringify(this.weekBackgroundColor)) + let weekTextColor = JSON.parse(JSON.stringify(this.weekTextColor)) + + if (hasDay) { + this.hasSelectWeek.delete(index) + weekBackgroundColor[index] = '#F6F7F9'; + weekTextColor[index] = "#969CA1" + }else{ + this.hasSelectWeek.add(index) + weekBackgroundColor[index] = '#2C68FF' + weekTextColor[index] = "#FFFFFF" + } + + this.weekBackgroundColor = weekBackgroundColor + this.weekTextColor = weekTextColor + console.info(JSON.stringify(this.weekBackgroundColor) + 'weekBackgroundColor' ) + this.getWeek() + }, + getWeek(){ + let arr = [] + this.hasSelectWeek.forEach(function (i) { + arr.push(i) + }) + arr = arr.sort() + console.info(JSON.stringify(arr) + 'week arr') + this.hasWeekArray = arr + + }, + startChange(e){ + console.info(JSON.stringify(e) + 'dateChange'); + this.startTime = e.hour + ":" + e.minute; + // If it is less than 10, ten digits are supplemented by 0 + if(e.hour < 10) + { + e.hour = '0' + e.hour; + } + // If it is less than 10, ten digits are supplemented by 0 + if(e.minute < 10) + { + e.minute = '0' + e.minute; + } + this.start = e.hour + ":" + e.minute; + }, + endChange(e){ + this.endTime = e.hour + ":" + e.minute + // If it is less than 10, ten digits are supplemented by 0 + if(e.hour < 10) + { + e.hour = '0' + e.hour; + } + //If it is less than 10, ten digits are supplemented by 0 + if(e.minute < 10) + { + e.minute = '0' + e.minute; + } + + this.end = e.hour + ":" + e.minute + }, + hasClick(index){ + let color = "#F6F7F9" + return color + }, + save(){ + if (this.start == this.$t('strings.startingTime') || this.end == this.$t('strings.endTime')) { + prompt.showToast({ + message: 'Please choose a time ' + }); + return + } + let startArr = this.start.split(':') + let endArr = this.end.split(':') + if (startArr[0] > endArr[0] || (startArr[0] == endArr[0] && startArr[1] > endArr[1]) ) { + prompt.showToast({ + message: 'Start time cannot be later than end time ' + }); + return + } + this.$app.$def.powerData.push({ + startTime:this.startTime, + endTime:this.endTime, + + start:this.start, + end:this.end, + hasWeekArray:this.hasWeekArray, + timer: false + }) + console.info("sendsave" + JSON.stringify(this.$app.$def.powerData)) + router.replace({ + uri:"pages/powerControl/index", + }) + }, + back(){ + router.replace({ + uri:"pages/powerControl/index", + }) + }, +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.css new file mode 100644 index 0000000000000000000000000000000000000000..4144e9c7ed2b005ef92c0c5a808af085d6ecdd03 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.css @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/common.css'; +.container { + flex-direction: column; + justify-content: flex-start; + background-color: #F6F7F9; + padding:0 20px; +} +.input{ + width:550px; + height:80px; + background-color:#FFF; + padding-left:0; +} +.param-box{ + text-align:center; + width:125px; + height:56px; + line-height:0; + border-radius:30px; + background-color:#F6F7F9; + margin-right:20px; +} +.vertical-margin-10{ + margin:10px 0; +} +.vertical-margin-20{ + margin:20px 0; +} +.box{ + width:680px; + background-color:#FFF; + flex-direction: column; + justify-content: center; +} +.slider{ + width:480px; +} +.back{ + width:48px; + height:48px; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..a57c70188f95ec2473dbe1875b98339c6a42857c --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.hml @@ -0,0 +1,53 @@ + + +
+
+ + {{$t('strings.temperatureControl')}} + {{$t('strings.save')}} +
+
+
+ + + +
+
+ 12℃ + + 40℃ +
+
+ 12℃ + + 40℃ +
+ {{startTemp}}℃ ~ {{endTemp}}℃ +
+ {{$t('strings.gears')}} +
+
+ {{value}} + +
+
+ {{$t('strings.shakeHead')}} +
+
+ {{value}} +
+
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.js new file mode 100644 index 0000000000000000000000000000000000000000..b3b750af94029283c8f74abc938764150d26207f --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTemperature/index.js @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' +import prompt from '@system.prompt'; + +export default { + data: { + startTemp: 12, + endTemp: 40, + gearsValue: 0, + featuresValue: 0, + name: '', + gearsBackgroundColor: [ + '#2C68FF', + '#F6F7F9', + '#F6F7F9', + '#F6F7F9', + ], + gearsTextColor: [ + '#FFFFFF', + '#969CA1', + '#969CA1', + '#969CA1', + ], + featuresBackgroundColor: ['#2C68FF', '#F6F7F9', '#F6F7F9',], + featuresTextColor: ['#FFFFFF', '#969CA1', '#969CA1',] + }, + onInit() { + }, + changeStartTemp(e) { + console.info("test value : " + e.progress); + this.startTemp = Number(e.progress) + }, + changeEndTemp(e) { + console.info("test value : " + e.progress); + this.endTemp = Number(e.progress) + }, + clickGears(index) { + this.gearsValue = index; + console.info("gearsValue" + this.gearsValue) + let gearsBackgroundColor = [ + '#F6F7F9', + '#F6F7F9', + '#F6F7F9', + '#F6F7F9', + ] + let gearsTextColor = [ + '#969CA1', + '#969CA1', + '#969CA1', + '#969CA1', + ] + gearsBackgroundColor[index] = '#2C68FF' + gearsTextColor[index] = '#FFFFFF' + + this.gearsBackgroundColor = gearsBackgroundColor + this.gearsTextColor = gearsTextColor + }, + getGearsColor(index) { + if (index == this.gearsValue) { + return '#2C68FF ' + } + return '#969CA1' + }, + clickFeatures(index) { + this.featuresValue = index + let featuresBackgroundColor = ['#F6F7F9', '#F6F7F9', '#F6F7F9'] + let featuresTextColor = ['#969CA1', '#969CA1', '#969CA1'] + featuresBackgroundColor[index] = '#2C68FF' + featuresTextColor[index] = '#FFFFFF' + + this.featuresBackgroundColor = featuresBackgroundColor + this.featuresTextColor = featuresTextColor + }, + getFeaturesColor(index) { + if (index == this.gearsValue) { + return '#2C68FF ' + } + return '#969CA1' + }, + save() { + let sameFlag = 0; + for (var i = 0; i < this.$app.$def.temperatureData.length; i++) { + if (this.gearsValue == this.$app.$def.temperatureData[i].gearsValue) { + prompt.showToast({ + message: this.$t('strings.tip'), + duration: 2000, // Show for 2 seconds + }); + sameFlag = 1; + break; + } + } + if(sameFlag == 0) { + this.$app.$def.temperatureData.push({ + name: this.name ? this.name : this.$t('strings.name'), + startTemp: this.startTemp, + endTemp: this.endTemp, + gearsValue: this.gearsValue, + featuresValue: this.featuresValue, + timer: false + }) + console.info("sendsave" + JSON.stringify(this.$app.$def.temperatureData)) + router.replace({ + uri: "pages/temperatureControl/index", + }) + } + }, + back() { + router.replace({ + uri: "pages/temperatureControl/index", + }) + }, + setName(e) { + this.name = e.text; + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.css new file mode 100644 index 0000000000000000000000000000000000000000..499b380492429e73b83cf4b0177cc9681d49f098 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.css @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/common.css'; +.container { + flex-direction: column; + justify-content: flex-start; + background-color: #F6F7F9; + padding:0 20px; +} +.input{ + width:550px; + height:80px; + background-color:#FFF; + padding-left:0; +} +.param-box{ + text-align:center; + width:125px; + height:56px; + line-height:0; + border-radius:30px; + background-color:#F6F7F9; + margin-right:20px; +} +.param-box:focus{ + background-color:#2C68FF; +} +.vertical-margin-10{ + margin:10px 0; +} +.vertical-margin-20{ + margin:20px 0; +} +.box{ + width:680px; + background-color:#FFF; + flex-direction: column; + justify-content: center; +} +.slider{ + width:520px; +} +.back{ + width:48px; + height:48px; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..77546ecf917255f338c24eb9c9f86e795b7f8e23 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.hml @@ -0,0 +1,51 @@ + + +
+
+ + {{$t('strings.controlTime')}} + {{$t('strings.save')}} +
+
+
+ + +
+
+ 0h + + 24h +
+
+ 0h + + 24h +
+ {{startHour}} ~ {{endHour}} +
+ {{$t('strings.gears')}} +
+
+ {{value}} +
+
+ {{$t('strings.shakeHead')}} +
+
+ {{value}} +
+
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.js new file mode 100644 index 0000000000000000000000000000000000000000..06c86aa178ebb82d4db35f52a7da3e1294902d54 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/addTimer/index.js @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' +import prompt from '@system.prompt'; + +export default { + data: { + startHour: 0, + endHour: 24, + + gearsValue:0, + featuresValue:0, + name:'', + gearsBackgroundColor:[ + '#2C68FF', + '#F6F7F9', + '#F6F7F9', + '#F6F7F9', + ], + gearsTextColor:[ + '#FFFFFF', + '#969CA1', + '#969CA1', + '#969CA1', + ], + featuresBackgroundColor:['#2C68FF', '#F6F7F9', '#F6F7F9',], + featuresTextColor:['#FFFFFF', '#969CA1', '#969CA1',] + }, + onInit() { + }, + changStartHour(e){ + console.info("test value : "+e.progress); + this.startHour = Number(e.progress) + }, + changEndHour(e){ + console.info("test value : "+e.progress); + this.endHour = Number(e.progress) + }, + + clickGears(index){ + this.gearsValue = index; + let gearsBackgroundColor = [ + '#F6F7F9', + '#F6F7F9', + '#F6F7F9', + '#F6F7F9', + ] + let gearsTextColor = [ + '#969CA1', + '#969CA1', + '#969CA1', + '#969CA1', + ] + gearsBackgroundColor[index] = '#2C68FF' + gearsTextColor[index] = '#FFFFFF' + + this.gearsBackgroundColor = gearsBackgroundColor + this.gearsTextColor = gearsTextColor + + }, + getGearsColor(index){ + if (index == this.gearsValue) { + return '#2C68FF ' + } + return '#969CA1' + }, + clickFeatures(index){ + this.featuresValue = index + + let featuresBackgroundColor = ['#F6F7F9', '#F6F7F9', '#F6F7F9'] + let featuresTextColor = ['#969CA1', '#969CA1', '#969CA1'] + featuresBackgroundColor[index] = '#2C68FF' + featuresTextColor[index] = '#FFFFFF' + + this.featuresBackgroundColor = featuresBackgroundColor + this.featuresTextColor = featuresTextColor + }, + getFeaturesColor(index){ + if (index == this.gearsValue) { + return '#2C68FF ' + } + return '#969CA1' + }, + save(){ + let flag = 0; + if(this.$app.$def.timerData.length >= 1) { + prompt.showToast({ + message: this.$t('strings.error'), + duration: 2000, // Show for 2 seconds + }); + } + else{ + this.$app.$def.timerData.push({ + name: this.name ? this.name : this.$t('strings.name'), + startHour:this.startHour, + endHour:this.endHour, + gearsValue: this.gearsValue, + featuresValue: this.featuresValue, + timer: false + }) + console.info("sendsave" + JSON.stringify(this.$app.$def.timerData)) + router.replace({ + uri: "pages/timeControl/index", + }) + } + }, + back(){ + router.replace({ + uri:"pages/timeControl/index", + }) + }, + setName(e){ + this.name = e.text; + }, + getBackground(index,featuresValue){ + console.info('featuresValue-index' + index + featuresValue) + return "background-color: #2C68FF;" + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..77f9dc36788cad36996c9f9c971977727c05d738 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.css @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/common.css'; + +.index{ + flex-direction: column; + justify-content: flex-start; + align-items: center; + background-color: #F6F7F9; +} +.container { + flex-direction: column; + justify-content: center; + align-items: center; + margin: 0 32px; +} +.back-img{ + width: 50px; + height: 50px; + margin: 30px 30px 30px 0; +} +.title{ + margin: 30px 0; +} +.fan_img{ + width: 240px; + height: 400px; + +} +.card{ + background-color: white; + border-radius:20px; + padding: 40px; + margin:30px 0; + align-items: center; +} +.card .switch_img{ + width: 88px; + height: 88px; + border-radius:44px; +} +.winds_card{ + margin:20px 0; + border-radius:20px; + width: 300px; + padding: 20px 0; +} +.winds_card .winds_type_img{ + width: 70px; + height: 70px; +} +.card .task_img{ + width: 72px; + height: 72px; + margin-right: 20px; +} +.gears-title{ + margin: 30px 0 25px 0px; +} +.gears_sub_title{ + margin: 30px 0 25px 25px; + margin-left: 24px; +} +.gears_box{ + width: 140px; + height: 110px; +} +.gears_box .gears_img{ + width:70px; + height:70px; +} +.task-title{ + margin-top: 10px; + margin-bottom: 10px; +} + diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..54637ab4f4ffc9f4bae1c58c68e164a68605bc8c --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.hml @@ -0,0 +1,84 @@ + + +
+
+
+ {{$t('strings.appName')}} +
+ +
+ + {{isOn?$t('strings.switchOn'):$t('strings.switchOff')}} + + +
+ +
+
+ + {{$t('strings.sleepWind')}} +
+ +
+ + {{$t('strings.straightBlow')}} +
+ +
+
+ + {{$t('strings.gearSetting')}} + + + {{gears[gearValue]}} + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ + {{$t('strings.customTask')}} + +
+
+ + {{$t('strings.controlTime')}} +
+
+ + {{$t('strings.temperatureControl')}} +
+
+ + {{$t('strings.timerSwitch')}} +
+
+
+ +
+
\ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..4ec3a8afd86ea4c70c90210d054b099117de717f --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/index/index.js @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' + +var faSoftapUtil = require('fa-softaputil'); +var fan_constants = require("fan-constants"); + +export default { + data: { + serverIp: "", + stateButton: "/common/images/switch_on.png", + isOn: true, + gears: ["", "", "", "",], + isCheckTask: false, + windsImg: [ + "/common/images/home_icon_wind one_selected.png", + "/common/images/home_icon_windtwo_unselected.png", + "/common/images/home_icon_windthree_unselected.png", + "/common/images/home_icon_windfour_unselected.png", + ], + sleepWindsImg: "/common/images/home_icon_sleepwind_selected.png", + // Whether to choose sleep style + isSleepWind: 1, + // Gear value starting value is 0 + gearValue: 0, + isSubscribeControlState: false, + color: "#FFFFFF", + // Classification of received messages + classification: 0 + }, + onInit() { + // Successful network ServerIp + this.$app.$def.ServerIp = this.dataInfo; + this.serverIp = this.$app.$def.ServerIp; + + this.initSubscribeControlState(); + + this.gears[0] = this.$t('strings.firstGear'); + this.gears[1] = this.$t('strings.secondGear'); + this.gears[2] = this.$t('strings.thirdGear'); + this.gears[3] = this.$t('strings.fourthGear'); + + this.$app.$def.gearsArray[0] = this.$t('strings.firstGear'); + this.$app.$def.gearsArray[1] = this.$t('strings.secondGear'); + this.$app.$def.gearsArray[2] = this.$t('strings.thirdGear'); + this.$app.$def.gearsArray[3] = this.$t('strings.fourthGear'); + + this.$app.$def.featuresArray[0] = this.$t('strings.orientation'); + this.$app.$def.featuresArray[1] = this.$t('strings.stirAir'); + this.$app.$def.featuresArray[2] = this.$t('strings.shakeHead'); + + + this.$app.$def.weekDic[0] = this.$t('strings.sunday'); + this.$app.$def.weekDic[1] = this.$t('strings.monday'); + this.$app.$def.weekDic[2] = this.$t('strings.tuesday'); + this.$app.$def.weekDic[3] = this.$t('strings.wednesday'); + this.$app.$def.weekDic[4] = this.$t('strings.thursday'); + this.$app.$def.weekDic[5] = this.$t('strings.friday'); + this.$app.$def.weekDic[6] = this.$t('strings.saturday'); + this.$app.$def.weekDic[7] = this.$t('strings.everyday'); + }, + // Monitor device response + initSubscribeControlState(){ + if (this.isSubscribeControlState==false){ + let that = this; + faSoftapUtil.FASoftapUtil.subscribe(fan_constants.CONSTANTS.SUBSCRIBE_CONTROL_STATE, function (callbackData) { + var callbackJson = JSON.parse(callbackData); + console.info("aaaaa:" + callbackJson.data); + var event = JSON.parse(callbackJson.data); + + if (event.cmd == 2) { // Control wind speed + that.setWindGear(event.param.value); + } + that.isSubscribeControlState = true; + }); + } + }, + setWindGear(windGear) { + this.gearValue = windGear - 1; + let windsImg = [ + "/common/images/home_icon_wind one_unselected.png", + "/common/images/home_icon_windtwo_unselected.png", + "/common/images/home_icon_windthree_unselected.png", + "/common/images/home_icon_windfour_unselected.png", + ] + let windsImgWhite = [ + "/common/images/home_icon_wind one_selected.png", + "/common/images/home_icon_windtwo_selected.png", + "/common/images/home_icon_windthree_selected.png", + "/common/images/home_icon_windfour_selected.png", + ] + windsImg[this.gearValue] = windsImgWhite[this.gearValue]; + this.windsImg = windsImg; + + if (this.gearValue >= 2) { // Less than gear 2 is sleep wind + this.isSleepWind = 0; + } else { + this.isSleepWind = 1; + } + }, + async clickStateButton() { + this.initSubscribeControlState(); + + this.isOn = !this.isOn + let on = "/common/images/switch_on.png" + let off = "/common/images/switch_off.png" + console.info("NetConfig#" + "log printf") + if (this.stateButton == on) { + this.stateButton = off + let param = {}; + param.value = 0; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_POWER, param); + } else { + this.stateButton = on + let param = {}; + param.value = 1; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_POWER, param); + } + }, + sendControlMessage(cmd, param) { + let data = {}; + data.cmd = cmd; + data.param = param; + data.serverIp = this.serverIp; + data.type = 0; + faSoftapUtil.FASoftapUtil.sendMessage(data, fan_constants.CONSTANTS.CONTROL_CODE); + }, + toTimeControl() { + router.push({ + uri: "pages/timeControl/index" + }) + }, + toTemperatureControl() { + router.push({ + uri: "pages/temperatureControl/index" + }) + }, + toPowerControl() { + router.push({ + uri: "pages/powerControl/index" + }) + }, + async changeGear(index) { + if (this.gearValue == index) { + return; + } + + let windsImg = [ + "/common/images/home_icon_wind one_unselected.png", + "/common/images/home_icon_windtwo_unselected.png", + "/common/images/home_icon_windthree_unselected.png", + "/common/images/home_icon_windfour_unselected.png", + ] + let windsImgWhite = [ + "/common/images/home_icon_wind one_selected.png", + "/common/images/home_icon_windtwo_selected.png", + "/common/images/home_icon_windthree_selected.png", + "/common/images/home_icon_windfour_selected.png", + ] + if (index == '1' || index == '0') { + this.isSleepWind = 1; + } + else if (index == '2' || index == '3') { + this.isSleepWind = 0; + } + + windsImg[index] = windsImgWhite[index]; + this.windsImg = windsImg; + this.gearValue = index; + + + let param = {}; + param.value = index + 1; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_CHANGE_GEAR, param); + + }, + clickWind(value) { + if (this.isSleepWind == value) { + return; + } + if (this.isSleepWind == 0) { + let param = {}; + param.value = 1; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_CHANGE_WINDMODE, param); + this.setGearMessage(0); + } else { + let param = {}; + param.value = 2; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_CHANGE_WINDMODE, param); + this.setGearMessage(2); + } + }, + getWindColor(value) { + let color = "#2C68FF"; + color = value == this.isSleepWind ? "#2C68FF" : "#FFFFFF"; + return color; + }, + getGearColor(index) { + console.info(index + 'getGearColor'); + let color = "#FFFFFF"; + color = index == this.gearValue ? "#2C68FF" : "#FFFFFF"; + return color; + }, + setGearMessage(index) { + let windsImg = [ + "/common/images/home_icon_wind one_unselected.png", + "/common/images/home_icon_windtwo_unselected.png", + "/common/images/home_icon_windthree_unselected.png", + "/common/images/home_icon_windfour_unselected.png", + ] + let windsImgWhite = [ + "/common/images/home_icon_wind one_selected.png", + "/common/images/home_icon_windtwo_selected.png", + "/common/images/home_icon_windthree_selected.png", + "/common/images/home_icon_windfour_selected.png", + ] + windsImg[index] = windsImgWhite[index]; + this.windsImg = windsImg; + this.gearValue = index; + if (index == '1' || index == '0') { + this.isSleepWind = 1; + } + else if (index == '2' || index == '3') { + this.isSleepWind = 0; + } + + }, + setWindMessage(index) { + this.isSleepWind = (index == 1) + if (this.isSleepWind) { + this.setGearMessage(0); + } else { + this.setGearMessage(2); + } + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.css new file mode 100644 index 0000000000000000000000000000000000000000..4ca1413e5e5076294c7cdce119cde17d72186233 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.css @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/common.css'; + +.container { + flex-direction: column; + justify-content: flex-start; + background-color: #F6F7F9; +} + +.add-box { + width:110px; + height:110px; + border-radius:110px; + background-color: #FFF; + margin-top: 60px; +} +.add{ + font-size:50px; + color:#2C68FF; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..a434ec5f64e60a8d51a8f220e5688439dabb77ff --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.hml @@ -0,0 +1,26 @@ + + + +
+ +
+
+ + +
+
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.js new file mode 100644 index 0000000000000000000000000000000000000000..4212a9113ca532ce1b08d7d8771977e6d71d0de8 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/powerControl/index.js @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' +import prompt from '@system.prompt'; + +var faSoftapUtil = require('fa-softaputil'); +var fan_constants = require("fan-constants"); + + +export default { + data: { + weekArray:[], + serverIp:"" + }, + onInit() { + console.info("getsave" + JSON.stringify(this.$app.$def.powerData)); + this.serverIp = this.$app.$def.ServerIp; + + let time = setInterval(()=>{ + this.checkTime() + }, 1000); // Once a second + }, + addTimer(){ + router.replace({ + uri:"pages/addPower/index" + }) + }, + checkTime(){ + let flag =0; + let date = new Date(); + let hour = date.getHours(); + let minute = date.getMinutes(); + let seconds =date.getSeconds(); + let week = date.getDay(); // week is an integer between 0 (Sunday) and 6 (Saturday). + + for (let index = 0; index < this.$app.$def.powerData.length; index++) { + for (let i = 0; i < this.$app.$def.powerData[index].hasWeekArray.length; i++) { + if(week == this.$app.$def.powerData[index].hasWeekArray[i]){ + flag = i; + break; + } + } + if( flag < this.$app.$def.powerData.length){ + let startTime = this.$app.$def.powerData[index].startTime; // start of time + let start = startTime.split(":"); + + let endTime = this.$app.$def.powerData[index].endTime; // end of time + let end = endTime.split(":"); + + if (this.$app.$def.powerData[index].timer == true) { + + if ((hour == start[0]) && (minute == start[1]) && (seconds == 0) ) { + console.info("power start====="); + let param = {}; + param.value = 1; // turn on + this.sendControlMessage(fan_constants.CONSTANTS.CMD_POWER, param); + prompt.showToast({ + message: 'send power on', + duration: 2000, // Show for 2 seconds + }); + + } + else if ((hour == end[0]) && (minute == end[1]) && (seconds == 0) ) { + console.info("power end ============"); + let param = {}; + param.value = 0; // turn off + this.sendControlMessage(fan_constants.CONSTANTS.CMD_POWER, param); + prompt.showToast({ + message: 'send power off', + duration: 2000, // Show for 2 seconds + }); + } + } + } + } + }, + + // Accept the event sent by the card + changeSwitch({detail}){ + console.info("power changeSwitch week2") + if (detail.index == undefined || detail.index == null) { + console.error("NetConfig# not index vlue") + return + } + console.info("power NetConfig# startTime" + JSON.stringify(this.$app.$def.powerData) + "index:" + detail.index) + console.info("power NetConfig# changeSwitch" + detail.checked + detail.index) + + if (detail.checked){ + this.$app.$def.powerData[detail.index].timer = true; + + + }else{ + this.$app.$def.powerData[detail.index].timer = false; + } + }, + sendControlMessage(cmd, param) { + let data = {}; + data.cmd = cmd; + data.param = param; + data.serverIp = this.serverIp; + data.type = 0; + faSoftapUtil.FASoftapUtil.sendMessage(data, fan_constants.CONSTANTS.CONTROL_CODE); + }, +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.css new file mode 100644 index 0000000000000000000000000000000000000000..4ca1413e5e5076294c7cdce119cde17d72186233 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.css @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/common.css'; + +.container { + flex-direction: column; + justify-content: flex-start; + background-color: #F6F7F9; +} + +.add-box { + width:110px; + height:110px; + border-radius:110px; + background-color: #FFF; + margin-top: 60px; +} +.add{ + font-size:50px; + color:#2C68FF; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..3b82accb163fa21af74e2b838b3a170b61adf690 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.hml @@ -0,0 +1,28 @@ + + + +
+ +
+
+ + +
+
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.js new file mode 100644 index 0000000000000000000000000000000000000000..defbc56073d9bf29027f13a7c82649c54d67e5be --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/temperatureControl/index.js @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' + +var faSoftapUtil = require('fa-softaputil'); +var fan_constants = require("fan-constants"); + +export default { + data: { + serverIp:"" + }, + onInit() { + this.serverIp = this.$app.$def.ServerIp; + }, + addTimer(){ + router.replace({ + uri:"pages/addTemperature/index" + }) + }, + // Accept the event sent by the card + async changeSwitch({detail}){ + if (detail.index == undefined || detail.index == null) { + console.error("NetConfig# not index value"); + return; + } + console.info("NetConfig# changeSwitch" + detail.checked + detail.index); + + let startTemp = this.$app.$def.temperatureData[detail.index].startTemp; + let endTemp = this.$app.$def.temperatureData[detail.index].endTemp; + let gearsValue = this.$app.$def.temperatureData[detail.index].gearsValue; + let featuresValue = this.$app.$def.temperatureData[detail.index].featuresValue; + + if (detail.checked){ + this.$app.$def.temperatureData[detail.index].timer = true; + let param = {}; + param.value = 1; + param.tempMin = startTemp; + param.tempMax = endTemp; + param.speed = gearsValue+1; + param.shark = featuresValue; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_TEMP, param); + + + }else{ + this.$app.$def.temperatureData[detail.index].timer = false; + let param = {}; + param.value = 0; + param.tempMin = startTemp; + param.tempMax = endTemp; + param.speed = gearsValue+1; + param.shark = featuresValue; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_TEMP, param); + } + }, + sendControlMessage(cmd, param) { + let data = {}; + data.cmd = cmd; + data.param = param; + data.serverIp = this.serverIp; + data.type = 0; + faSoftapUtil.FASoftapUtil.sendMessage(data, fan_constants.CONSTANTS.CONTROL_CODE); + }, +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.css new file mode 100644 index 0000000000000000000000000000000000000000..4ca1413e5e5076294c7cdce119cde17d72186233 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.css @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/common.css'; + +.container { + flex-direction: column; + justify-content: flex-start; + background-color: #F6F7F9; +} + +.add-box { + width:110px; + height:110px; + border-radius:110px; + background-color: #FFF; + margin-top: 60px; +} +.add{ + font-size:50px; + color:#2C68FF; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..9c68b892ccb60db7a5efcb9bca616e504e1f6f72 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.hml @@ -0,0 +1,27 @@ + + + +
+ +
+
+ + +
+
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.js new file mode 100644 index 0000000000000000000000000000000000000000..deac3d12b4e41397aaf502570e7d5b4f2fefa9d9 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/control/pages/timeControl/index.js @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' + +var faSoftapUtil = require('fa-softaputil'); +var fan_constants = require("fan-constants"); + +export default { + data: { + serverIp:"" + }, + onInit() { + console.info("time control init" ); + this.serverIp = this.$app.$def.ServerIp; + }, + addTimer(){ + router.replace({ + uri:"pages/addTimer/index" + }) + }, + editTimer(index, e){ + console.info("editTimer1 " + index + e) + console.info("editTimer1 " + JSON.stringify(index)) + router.replace({ + uri:"pages/addTimer/index" + }) + }, + // Accept the event sent by the card + async changeSwitch({detail}){ + + + if (detail.index == undefined || detail.index == null) { + console.error("NetConfig# not index value"); + return + } + console.info("NetConfig# changeSwitch" + detail.checked + detail.index); + + var d = new Date(); + var hour= d.getHours(); + var minute= d.getMinutes(); + + let startHour = this.$app.$def.timerData[detail.index].startHour; + let endHour = this.$app.$def.timerData[detail.index].endHour; + + let time = startHour * 60; + let total = (endHour - startHour) * 60; + + let gearsValue = this.$app.$def.timerData[detail.index].gearsValue; + let featuresValue = this.$app.$def.timerData[detail.index].featuresValue; + + if (detail.checked){ + this.$app.$def.timerData[detail.index].timer = true + let param = {}; + param.id = detail.index+1; + param.value = 1; + param.time = time; + param.total = total; + param.speed = gearsValue+1; + param.shark = featuresValue; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_TIME, param); + + }else{ + console.info("NetConfig# cancle timer") + this.$app.$def.timerData[detail.index].timer = false + let param = {}; + param.id = detail.index+1; + param.value = 0; + param.time = time; + param.total = total; + param.speed = gearsValue+1; + param.shark = featuresValue; + this.sendControlMessage(fan_constants.CONSTANTS.CMD_TIME, param); + } + }, + sendControlMessage(cmd, param) { + let data = {}; + data.cmd = cmd; + data.param = param; + data.serverIp = this.serverIp; + data.type = 0; + faSoftapUtil.FASoftapUtil.sendMessage(data, fan_constants.CONSTANTS.CONTROL_CODE); + }, + // Delete one an AlarmList object. + deleteItem() { + console.info("==========long=="); + this.$app.$def.timerData.pop(); + router.replace({ + uri:"pages/timeControl/index" + }) + }, +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/app.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..611940d2460ba77370a5e5ab53acb0439df513ce --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/app.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var FaSoftapUtil = require('fa-softaputil'); + +export default { + onCreate() { + }, + onDestroy() { + }, + faSoftapUtil: FaSoftapUtil.FASoftapUtil, +}; diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/css/common.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/css/common.css new file mode 100644 index 0000000000000000000000000000000000000000..1adfbcf1c4b0bdfa9bc981a1dea8f02c7c94270b --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/css/common.css @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +.color_gray{ + color:#a0a0a0; +} + +.color_black{ + color: #000000; +} + +.color_blue { + color: #007dff; +} + +.text_blue{ + text-color:#007dff; +} + +.text_white{ + text-color:#ffffff; +} + +.font32{ + font-size: 32px; +} + +.font25{ + font-size: 25px; +} + +.font35{ + font-size: 35px; +} + +.back_color{ + background-color: #f7f7f7; +} +.back_gray{ + background-color:#f0f0f0; +} + +.back_blue{ + background-color:#007dff; +} + +.flexcol{ + flex-direction: column; +} + +.flexrow{ + flex-direction: row; +} + +.jcenter{ + justify-content: center; +} +.acenter{ + align-items: center; +} +.astart{ + align-items: flex-start; +} +.jstart{ + justify-content: flex-start; +} + +.bradius36{ + border-radius: 36px; +} + +.mbottom20{ + margin-bottom: 20px; +} + +.mbottom40{ + margin-bottom: 40px; +} + +.logoimgsrc { + margin-top: 106px; + width: 187px; + height: 187px; + margin-bottom: 70px; +} + +.imgsrc { + margin-top: 48px; + width: 314px; + height: 314px; + margin-bottom: 44px; +} + +.dividerux { + width: 1px; + height: 100%; + background-color: rgba(0, 0, 0, 0.2); +} +.flexrow_around { + height: 60px; + justify-content: space-around; + align-items: center; + margin-bottom: 32px; + flex-direction: row; +} + +.textux{ + width: 300px; + background-color:transparent; +} + diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/CPlogo.png b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/CPlogo.png new file mode 100644 index 0000000000000000000000000000000000000000..e35d16c8d0273bb7a41bd34c8b2151a594c8c1b8 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/CPlogo.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_about.png b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_about.png new file mode 100644 index 0000000000000000000000000000000000000000..8aace76d60e7983c1ce667bdd8d6e00267f86555 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_about.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_normal.png b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..883cfe9e535ad4ce2383c409994a92b8ad81adde Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_normal.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_wlan.png b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_wlan.png new file mode 100644 index 0000000000000000000000000000000000000000..9c97c823f86a661a21c62cec8f29dc1672fd8667 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/ic_wlan.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/icon.png b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..fda12474e825ec9bedf78d6faac072976c0134a8 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/icon.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/light_on.png b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/light_on.png new file mode 100644 index 0000000000000000000000000000000000000000..440509f0b496026017159847606b4ec096d43d53 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/light_on.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/right_grey.png b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/right_grey.png new file mode 100644 index 0000000000000000000000000000000000000000..99733b2fe98246a4d7b8de2831b616de7a4e5b3c Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/img/right_grey.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.css new file mode 100644 index 0000000000000000000000000000000000000000..96c686f25e9d54dd3cb45743979f7c6f54485b9b --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.css @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../css/common.css'; +.devicenameux{ + color: #000000; + font-size: 40px; + margin-bottom: 20px; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.hml b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.hml new file mode 100644 index 0000000000000000000000000000000000000000..40f2753f75065e07603a2ba3fa0b065e5dbfeb46 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.hml @@ -0,0 +1,21 @@ + + +
+
+ + {{device_name}} +
+
\ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.js new file mode 100644 index 0000000000000000000000000000000000000000..6068b39504baccd24144fddfaa235011bb26631d --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/devicelogo/devicelogo.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + props: [ + 'logo_img', + 'device_name', + ], + +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.css new file mode 100644 index 0000000000000000000000000000000000000000..171a5c8eb7df111b4fc7f6d6ba316b1b0eab2d83 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.css @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../css/common.css'; +.titleux{ + font-size: 45px; + margin-bottom: 70px; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.hml b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.hml new file mode 100644 index 0000000000000000000000000000000000000000..4f3d6045f56e3930b0c823fb7e27bc0bd8928a14 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.hml @@ -0,0 +1,21 @@ + + +
+
+ + {{title_text}} +
+
\ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.js new file mode 100644 index 0000000000000000000000000000000000000000..d63a6894a8c382da86d5611f4bab6e9f607d03ee --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/common/pages/logotitle/logotitle.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + props: [ + 'logo_src', + 'title_text', + ], + +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/i18n/en-US.json b/CompleteApps/SmartFanApp/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e949beaa2e94016c72f2747c412f18f1514d16ed --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,51 @@ +{ + "strings": { + "versionNum": "Version1.0.0", + "deviceName": "SmartFan", + "authorizeDescription": "YouNeedToAuthorizeAndLogInWithYourMobilePhone", + "login":"HuaweiAccountLogin", + "cancle":"Cancel", + "determine":"YouAgree", + "privacyStatement":"xxxUserAgreementAndPrivacyStatement", + "apply": "Apply", + "setWifi":"SetWiFi", + "getPhoneNum": "GetYourMobileNumber", + "phoneNum": "18112367889", + "authorization": "Authorization", + "tip": "TheDataSharedToXXXIsGovernedByTheThirdPartyPrivacyStatement.YouCanCancelTheAuthorizationInThePrivacyCenterOfHuaweiAccount", + "networkSet":"NetworkSettings", + "otherNet": "UseOtherWirelessNetworks", + "support": "WLANNetworkSupportedHasBeenProvided", + "buttonOk": "Determine", + "locationSet": "LocationSetting", + "family":"Family", + "myHouse":"MyHome", + "noSupport": "NotSupport", + "getWifiFailed": "FailedToGetWiFiList", + "findFailed":"DeviceDiscoveryFailed", + "connectFailed":"FailedToConnectDevice", + "configFailed": "DeviceDistributionNetworkFailure", + "livingRoom": "LivingRoom", + "bedroom": "BedRoom", + "secondBedroom": "S'BedRoom", + "restaurant": "Restaurant", + "study": "Study", + "Restroom": "Restroom", + "bathroom": "Bathroom", + "balcony": "Balcony", + "readytoconnectInfo": "PleaseConfirmThatTheDeviceHasBeenReset,ClickSetWiFiAndConnect'SmartFan_AP'Hotpot,ClickTheStartDistributionButton", + "readytoconnect": "DistributionNetwork", + "notConnectHotSpot": "NotConnected'SmartFan_AP'Hotpot", + "configNetError": "DistributionNetworkFailure", + "connectBackInfo": "PleaseConnectBackToTheHotspot" + + }, + "files": { + "logoImg": "/common/img/icon.png", + "icSrc": "/common/img/ic_normal.png", + "aboutSrc":"/common/img/ic_about.png", + "lightOn":"/common/img/light_on.png", + "logoSrc": "/common/img/icon.png", + "rightSrc":"/common/img/right_grey.png" + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/i18n/zh-CN.json b/CompleteApps/SmartFanApp/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..748e99d9925b0970fc9b33e79a4661d4d95a28db --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,51 @@ +{ + "strings": { + "versionNum": "版本1.0.0", + "deviceName": "智能电风扇", + "authorizeDescription": "继续使用需要授权并用手机号登录", + "login":"华为账号快速登录", + "setWifi":"设置wifi", + "cancle":"取消", + "determine":"登录表示您同意", + "privacyStatement":"xxx用户协议和隐私声明", + "apply": "申请", + "getPhoneNum": "获取您的手机号码", + "phoneNum": "18112367889", + "authorization": "授权", + "tip": "分享给xxx的数据由第三方隐私声明管辖。您可以随时在华为账号的隐私中心中取消授权", + "networkSet":"网络设置", + "otherNet": "使用其它无线网络", + "support": "已为您提供设备支持的WLAN网络", + "buttonOk": "确定", + "locationSet": "位置设置", + "family":"家庭", + "myHouse":"我的家", + "noSupport": "不支持", + "getWifiFailed": "获取wifi列表失败", + "findFailed":"发现设备失败", + "connectFailed":"连接设备失败", + "configFailed": "设备配网失败", + "livingRoom": "客厅", + "bedroom": "卧室", + "secondBedroom": "次卧", + "restaurant": "餐厅", + "study": "书房", + "Restroom": "洗手间", + "bathroom": "浴室", + "balcony": "阳台", + "readytoconnectInfo": "请确定设备已经复位后,点击设置wifi 并连接SmartFan_AP热点后,再点击开始配网按钮", + "readytoconnect": "开始配网", + "notConnectHotSpot": "尚未连接SmartFan_AP热点", + "configNetError": "配网失败", + "connectBackInfo": "请连接回热点" + + }, + "files": { + "logoImg": "/common/img/icon.png", + "icSrc": "/common/img/ic_normal.png", + "aboutSrc":"/common/img/ic_about.png", + "lightOn":"/common/img/light_on.png", + "logoSrc": "/common/img/icon.png", + "rightSrc":"/common/img/right_grey.png" + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6cfe249eb754f22b3d448a8f44e5901442baf90d --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.css @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/css/common.css'; + +.buttonux{ + margin-left: 32px; + width: 90%; + height: 80px; + background-color: transparent; + margin-bottom: 60px; + border-bottom-style: solid; + border-bottom-width: 2px; + border-bottom-color:rgba(0, 0, 0, 0.2); +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..b4546f36fac52cb1004002a19f8543d4c8ac8262 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.hml @@ -0,0 +1,33 @@ + + + +
+ +
+
+ +
+
+ +
+ {{$t('strings.otherNet')}} +
+
+ +
+ +
+
\ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.js new file mode 100644 index 0000000000000000000000000000000000000000..bb21e7ba6c9682b09fb5e3efd732823cf3906a49 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/confignet/index.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router'; +import prompt from '@system.prompt'; + +var fan_constants = require("fan-constants"); + +export default { + data: { + oldWifi:"", + wifiName:"", + wifiPassword:"", + NetworkFlag: false, + text:'' + }, + onInit() { + this.text = this.$t('strings.buttonOk'), + this.wifiName = this.oldWifi; + }, + + // goto locationset page. + goBack() { + router.push({ + uri: "pages/phone/index" + }) + }, + + // Call find Device interface. + goNext() { + let that = this; + this.NetworkFlag = true; + let wifiName = this.wifiName; + + let data = {}; + data.cmd = 0x20; + let param ={}; + param.wifiName = this.wifiName; + param.wifiPassword = this.wifiPassword; + data.param = param; + let toastConfigNetError = this.$t("strings").configNetError; + this.$app.$def.faSoftapUtil.sendMessage(data, fan_constants.CONSTANTS.SET_WIFI_CODE).then(function(res){ + let result = JSON.parse(res); + if (result.code == 200) { + // get serverip + let serverIp = ""; + router.push({ + uri: "pages/locationset/index", + params: { + serverIp: result.result.ip, + wifiName: wifiName + } + }) + } else { + prompt.showToast({ + message: toastConfigNetError + result.errmsg + }); + that.NetworkFlag = false; + } + }); + }, + changeWifiName(e){ + this.wifiName = e.value; + }, + changeWifiPassword(e){ + this.wifiPassword = e.value; + }, + useOtherNet(){ + router.push({ + uri: "pages/otherWifi/index", + }) + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..8137f36d3100c8bd55b2f3c9a64653deed3842f9 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/css/common.css'; + +.imageux{ + margin-right: 20px; + width: 60px; + height:60px; +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..6af10ad799e47359086e76c6162251c38d931cf7 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,35 @@ + + + +
+
+ + {{$t('strings.versionNum')}} + {{$t('strings.authorizeDescription')}} + +
+ + {{$t('strings.login')}} +
+
+ {{$t('strings.cancle')}} +
+
+ {{$t('strings.determine')}} + {{$t('strings.privacyStatement')}} +
+
+
\ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..87e64a4894745bf195e1006465e8ffc8f54e6115 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from "@system.router" +import app from '@system.app'; +export default { + data: { + + }, + onInit() { + }, + + // Goto phone page. + goNext() { + router.push({ + uri: "pages/phone/index" + }) + }, + + // Exit the current ability. + goBack() { + app.terminate(); + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.css new file mode 100644 index 0000000000000000000000000000000000000000..7994e31f515cf1379fb180c9211e5edbb457876c --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.css @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/css/common.css'; + +.rightsrcux{ + width: 15px; + height: 27px; + margin-top: 10px; +} + +.homeux{ + margin-left: 32px; + margin-right: 32px; + justify-content: space-around; + margin-top: 48px; + flex-wrap: wrap; + margin-bottom: 48px; +} + +.homeitemux{ + font-weight: 500; + font-size: 24px; + width:138px; + height: 50px; + margin-top: 20px; + text-color:#000000; + margin-right:2px; + +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..4a7d6ae7fd86603e7feadc9b140f2838657aaa3c --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.hml @@ -0,0 +1,39 @@ + + + +
+ +
+ {{$t('strings.family')}} +
+ {{ + $t('strings.myHouse') }} + +
+ +
+
+
+ +
+
+ +
+ +
+ +
+
diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.js new file mode 100644 index 0000000000000000000000000000000000000000..53baf1b4c4f27d17e681490cf21161bef7e38e9a --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/locationset/index.js @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import prompt from '@system.prompt'; +import app from '@system.app'; + +var fan_constants = require("fan-constants"); + +export default { + data: { + wifiName: "", + serverIp: "", + DeviceSettings: [{ + name: '', + backcolor: "rgba(0, 175, 255, 0.2)" + }, { + name: '', + backcolor: "rgba(0, 0, 0, 0.1)" + }, { + name: '', + backcolor: "rgba(0, 0, 0, 0.1)" + }, { + name: '', + backcolor: "rgba(0, 0, 0, 0.1)" + }, { + name: '', + backcolor: "rgba(0, 0, 0, 0.1)" + }, { + name: '', + backcolor: "rgba(0, 0, 0, 0.1)" + }, { + name: '', + backcolor: "rgba(0, 0, 0, 0.1)" + }, { + name: '', + backcolor: "rgba(0, 0, 0, 0.1)" + }], + }, + onInit() { + this.DeviceSettings[0].name = this.$t('strings.livingRoom'); + this.DeviceSettings[1].name = this.$t('strings.bedroom'); + this.DeviceSettings[2].name = this.$t('strings.secondBedroom'); + this.DeviceSettings[3].name = this.$t('strings.restaurant'); + + this.DeviceSettings[4].name = this.$t('strings.study'); + this.DeviceSettings[5].name = this.$t('strings.Restroom'); + this.DeviceSettings[6].name = this.$t('strings.bathroom'); + this.DeviceSettings[7].name = this.$t('strings.balcony'); + }, + + // Goback to confignet page. + goBack() { + app.terminate(); + }, + + // Config network successfully entered the control page,and pass parameter:sessionId. + goNext() { + console.info("aaaaa:"+ this.serverIp); + let data = {}; + let wifiName = this.wifiName; + let ToastMes= this.$t('strings.connectBackInfo') + wifiName; + let serverIp = this.serverIp; + let faSoftapUtil = this.$app.$def.faSoftapUtil; + + this.$app.$def.faSoftapUtil.sendMessage(data, fan_constants.CONSTANTS.GET_CURRENT_WIFI_CODE).then(function(res){ + if (res == wifiName) { + let info = { + serverIp: serverIp + } + faSoftapUtil.callNewFa(info,0); + app.terminate(); + } else { + prompt.showToast({ + message: ToastMes + }); + } + }); + }, +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.css new file mode 100644 index 0000000000000000000000000000000000000000..93cb16d567ac7d4eeb63cbef9995fa4762544690 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.css @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/css/common.css'; + +.container { + flex-direction: column; + justify-content: center; + padding-top: 30px; + margin: 0 82px; +} + +.title { + font-size: 42px; +} + +.subtitle { + margin: 20px 0px; + font-size: 24px; + opacity: .8; +} + +.list { +} + +.list-item { + height: 124px; + justify-content: space-between; + align-items: center; + border-bottom: 1px solid #000000; + +} + +.list-text-box { + flex-direction: column; + justify-content: center; +} + +.ssid { + font-size: 32px; +} + +.tag { + font-size: 28px; + padding-top: 10px; + opacity: .8; +} + +.right-image { + width: 48px; + height: 48px; +} +.cancel{ + margin-bottom: 50px; +} + + diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..87f15b671e6bdb5d2f07ec3c5842f1f49fb6f1bc --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.hml @@ -0,0 +1,36 @@ + + +
+ + {{ $t('strings.otherNet') }} + + + {{ $t('strings.support') }} + + + + +
+ {{ $item.ssid }} + {{ $item.security }} +
+ +
+
+
+ +
+ diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.js new file mode 100644 index 0000000000000000000000000000000000000000..67e843564429c8567b1c36075805f4ad3b19ac48 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/otherWifi/index.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router' +import prompt from '@system.prompt'; + +var fan_constants = require("fan-constants"); + +export default { + data: { + wifiList: [] + }, + onInit() { + console.info("time control init") + }, + onShow() { + this.refreshList(); + }, + cancel() { + router.back(); + }, + clickItem(index) { + if (index == 0) { + router.back(); + } + else{ + router.push({ + uri: 'pages/confignet/index', + params: { + oldWifi: this.wifiList[index].ssid + } + }) + } + }, + refreshList(){ + let data = {}; + let that = this; + this.$app.$def.faSoftapUtil.sendMessage(data, fan_constants.CONSTANTS.GET_AVAILABLE_WIFI_CODE).then(function(res){ + let result = JSON.parse(res); + console.info("aaaaa " + res); + if (result.code == 200) { + // get serverip + that.wifiList = result.wifi; + } else { + prompt.showToast({ + message: result.errMsg + }); + } + }); + } +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.css b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.css new file mode 100644 index 0000000000000000000000000000000000000000..e422ea4cb56fac8219ec1e69c7e56055b7a04eba --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.css @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import '../../common/css/common.css'; + +.aboutsrcux{ + margin-left: 10px; + width: 35px; + height: 35px; +} + +.lightonsrcux{ + width: 50px; + height: 50px; +} diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.hml b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..683cb5fffe0ee00db4800938dccd597ea0dfd4bd --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.hml @@ -0,0 +1,29 @@ + + + +
+ +
+ {{$t('strings.readytoconnectInfo')}} +
+
+ {{$t('strings.setWifi')}} +
+
+ + +
+
\ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.js b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.js new file mode 100644 index 0000000000000000000000000000000000000000..a9123dc1399037e41bb7f2a4e03eb95f56431cb4 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/js/default/pages/phone/index.js @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@system.router'; +import prompt from '@system.prompt'; +import app from '@system.app'; + +var fan_constants = require("fan-constants"); + +export default { + data: { + oldWifi: "" + }, + onInit: async function(){ + let data = {}; + let wifi = await this.$app.$def.faSoftapUtil.sendMessage(data, fan_constants.CONSTANTS.GET_CURRENT_WIFI_CODE); + if (wifi != fan_constants.CONSTANTS.SMARTFAN_WIFI) { + this.oldWifi = wifi; // Record the wifi name before + } + }, + + /** + * Call isSupportWifiAware interface + * + * @return result.code + */ + onReady: function () { + }, + +// Support wifiware and goto confignet page. + goNext: function () { + let data = {}; + let wifi = this.oldWifi; + let ToastMes = this.$t('strings.notConnectHotSpot'); + this.$app.$def.faSoftapUtil.sendMessage(data, fan_constants.CONSTANTS.GET_CURRENT_WIFI_CODE).then(function (res) { + if (res == fan_constants.CONSTANTS.SMARTFAN_WIFI) { + router.push({ + uri: "pages/confignet/index", + params: { + oldWifi: wifi + } + }) + } else { + prompt.showToast({ + message: ToastMes + }); + } + }); + }, + + // Exit the current ability. + goBack() { + app.terminate(); + }, + async goSetWifi(){ + var action = {}; + action.bundleName = "com.android.settings"; + action.abilityName = "com.android.settings.Settings$WifiSettingsActivity"; + action.flag = 16; //Intent.FLAG_NOT_OHOS_COMPONENT + action.data = {}; + await FeatureAbility.startAbility(action); + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/resources/base/element/string.json b/CompleteApps/SmartFanApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b06f430c7479b9c8f9c129abc3ed56cc2eb3c84b --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,31 @@ +{ + "string": [ + { + "name": "app_name", + "value": "智能电风扇" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "controlability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "sockcketability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "controlserviceability_description", + "value": "hap sample empty service" + }, + { + "name": "forpublic", + "value": "公开" + }, { + "name": "encrypt", + "value": "加密" + } + ] +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/resources/base/media/icon.png b/CompleteApps/SmartFanApp/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..afa850c941c877272b96805e1a35ac2eafca0108 Binary files /dev/null and b/CompleteApps/SmartFanApp/entry/src/main/resources/base/media/icon.png differ diff --git a/CompleteApps/SmartFanApp/entry/src/main/resources/en/element/string.json b/CompleteApps/SmartFanApp/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..92f72770d5c5cb55eba40c34b03d74ce3523531f --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/resources/en/element/string.json @@ -0,0 +1,31 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SmartFan" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "controlability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "sockcketability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "controlserviceability_description", + "value": "hap sample empty service" + }, + { + "name": "forpublic", + "value": "public" + }, { + "name": "encrypt", + "value": "encrypt" + } + ] +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/main/resources/zh/element/string.json b/CompleteApps/SmartFanApp/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b06f430c7479b9c8f9c129abc3ed56cc2eb3c84b --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,31 @@ +{ + "string": [ + { + "name": "app_name", + "value": "智能电风扇" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "controlability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "sockcketability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "controlserviceability_description", + "value": "hap sample empty service" + }, + { + "name": "forpublic", + "value": "公开" + }, { + "name": "encrypt", + "value": "加密" + } + ] +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/ohosTest/java/ohos/samples/smartfan/ExampleOhosTest.java b/CompleteApps/SmartFanApp/entry/src/ohosTest/java/ohos/samples/smartfan/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e4c684ab1b966ee2a11ad37c0d0fc6d3447dbb2a --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/ohosTest/java/ohos/samples/smartfan/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package ohos.samples.smartfan; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("ohos.samples.smartfan", actualBundleName); + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanApp/entry/src/test/java/ohos/samples/smartfan/ExampleTest.java b/CompleteApps/SmartFanApp/entry/src/test/java/ohos/samples/smartfan/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..55f2f1c1b8e431fbe3e316b062a2bb96ef388109 --- /dev/null +++ b/CompleteApps/SmartFanApp/entry/src/test/java/ohos/samples/smartfan/ExampleTest.java @@ -0,0 +1,9 @@ +package ohos.samples.smartfan; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_1.png b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_1.png new file mode 100644 index 0000000000000000000000000000000000000000..fd4b9c6a6b8ff512254a5d811d12190af4ddb536 Binary files /dev/null and b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_1.png differ diff --git a/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_2.png b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_2.png new file mode 100644 index 0000000000000000000000000000000000000000..91b6b635c50519e249f7d2d4ee9d5604636908db Binary files /dev/null and b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_2.png differ diff --git a/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_3.png b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_3.png new file mode 100644 index 0000000000000000000000000000000000000000..748fd00bf1ec509c2dfbd7331c05be9da37aaee0 Binary files /dev/null and b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_3.png differ diff --git a/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_4.jpg b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b110646f413166b578bfa77e3662f14e6f12c827 Binary files /dev/null and b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_4.jpg differ diff --git a/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_control.png b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_control.png new file mode 100644 index 0000000000000000000000000000000000000000..d39c61cf6cd81509a1b65331496473b5e4493255 Binary files /dev/null and b/CompleteApps/SmartFanApp/screenshoot/phone/smartfan_control.png differ diff --git a/CompleteApps/SmartFanApp/settings.gradle b/CompleteApps/SmartFanApp/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/CompleteApps/SmartFanApp/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/CompleteApps/SmartFanDevice/README_zh.md b/CompleteApps/SmartFanDevice/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..7e5192ba8bda72eebf1784029eaddb526cafc78f --- /dev/null +++ b/CompleteApps/SmartFanDevice/README_zh.md @@ -0,0 +1,60 @@ +# 智能风扇设备端代码介绍 + +### 简介 + +本Sample是基于OpenHarmony轻量级系统,利用内核的实时性和丰富的外设拓展功能,模拟智能风扇设备跟[手机侧智能风扇](https://gitee.com/openharmony/app_samples/tree/master/CompleteApps/SmartFanApp/)应用通信,实现风扇开关,档位,模式以及按温按时控制等功能。 + + + +### 使用说明 + +##### 1. 编译步骤 + +1)拷贝本Sample目录下的common、smartfan 文件夹到OpenHarmony 系统源码中的applications/sample/wifi-iot/app目录下。 + +2) 修改applications/sample/wifi-iot/app/BUILD.gn 文件,在features字段中增加索引,使目标模块参与编译。features字段指定业务模块的路径和目标,具体配置如下。 + +``` + import("//build/lite/config/component/lite_component.gni") + + lite_component("app") { + features = [ + "smartfan", + ] + deps = [ "//applications/sample/wifi-iot/app/common/hals:hals", + "//applications/sample/wifi-iot/app/common/netcfg:netcfg"] +} + +``` + +3)修改hi3861 内核配置文件 + +​ 打开 device/hisilicon/hispark_pegasus/sdk_liteos/build/config/usr_config.mk 文件 + +​ 将 CONFIG_I2C_SUPPORT is not set这一行, 改为CONFIG_I2C_SUPPORT=y + +​ 将 CONFIG_PWM_SUPPORT is not set这一行, 改为CONFIG_PWM_SUPPORT=y + +4) 代码编译和烧录请参考:[链接](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3861-connection.md) + +##### 2. 与手机应用联动 + +1)准备一个wifi热点A,密码和热点名称自定义。 + +2)提前在手机上安装好[智能风扇手机端](https://gitee.com/openharmony/app_samples/tree/master/CompleteApps/SmartFanApp/)软件,然后在设置应用中连接热点A。 + +3) 打开手机端智能风扇软件,在热点连接列表中找到SmartFan_AP热点并连接,随后点击配网发送热点A相关信息给到风扇设备端完成配网。 + +4)待配网完成后,可以在手机端自由设置风扇的工作状态和相应模式。 + + + +### 约束限制 + +硬件:HiSpark Wi-Fi IoT 开发套件(本sample会用到 主控板、OLED拓展板、温度传感器拓展板) + +软件:OpenHarmony 2.0 Canary版本。[链接](https://device.harmonyos.com/cn/docs/start/get-code/sourcecode-acquire-0000001050769927) + +OpenHarmony轻量级开发指导:[链接](https://device.harmonyos.com/cn/docs/start/introduce/quickstart-lite-overview-0000001105598722) + +开发工具下载:[链接](https://device.harmnyos.com/cn/ide) diff --git a/CompleteApps/SmartFanDevice/common/hals/BUILD.gn b/CompleteApps/SmartFanDevice/common/hals/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b82f85f4bbff5b0827cfd0a59fc4f6bfa3a777b6 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/hals/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +static_library("hals") { + sources = [ + "src/peripheral_hal.c", + "src/utils_hal.c" + ] + + include_dirs = [ + "//applications/sample/wifi-iot/app/common/include", + "//base/iot_hardware/peripheral/interfaces/kits", + "//device/hisilicon/hispark_pegasus/sdk_liteos/include", + ] +} \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/common/hals/src/peripheral_hal.c b/CompleteApps/SmartFanDevice/common/hals/src/peripheral_hal.c new file mode 100644 index 0000000000000000000000000000000000000000..20c20912570b331b02a7ac8a6cace6763e6e0917 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/hals/src/peripheral_hal.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "peripheral_hal.h" +#include "iot_errno.h" +#include "hi_io.h" +#include "hi_adc.h" +#include "hi_types_base.h" +#include "hi_watchdog.h" +#include "hi_pwm.h" + +unsigned int HalIoSetFunc(HalWifiIotIoName id, const char *val) +{ + if (id == HAL_WIFI_IOT_IO_NAME_MAX) { + return IOT_FAILURE; + } + return hi_io_set_func((hi_io_name)id, val); +} + +unsigned int HalAdcRead(HalWifiIotAdcChannelIndex channel, unsigned short *data, HalWifiIotAdcEquModelSel equModel, + HalWifiIotAdcCurBais curBais, unsigned short rstCnt) +{ + return hi_adc_read((hi_adc_channel_index)channel, (hi_u16*)data, (hi_adc_equ_model_sel)equModel, + (hi_adc_cur_bais)curBais, (hi_u16)rstCnt); +} + +void HalSetWatchDogEnable(int enable) +{ + if (enable == 0) { + hi_watchdog_disable(); + } else { + hi_watchdog_enable(); + } +} + +unsigned int HalPwmStart(uint32 id, uint16 duty, uint16 freq) +{ + return hi_pwm_start((hi_pwm_port)id, (hi_u16)duty, (hi_u16)freq); +} \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/common/hals/src/utils_hal.c b/CompleteApps/SmartFanDevice/common/hals/src/utils_hal.c new file mode 100644 index 0000000000000000000000000000000000000000..ef34078b38618fb154a9eee05d30d31ab7026cbd --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/hals/src/utils_hal.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos_types.h" +#include "hi_time.h" +#include "hi_types_base.h" +#include "utils_hal.h" + +void hal_udelay(uint32 us) +{ + hi_udelay((hi_u32)us); +} \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/common/include/common_log.h b/CompleteApps/SmartFanDevice/common/include/common_log.h new file mode 100644 index 0000000000000000000000000000000000000000..4f6406e09c15ac66e08b361f9dd4eebd4e69d8bf --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/include/common_log.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __COMMON_LOG_H__ +#define __COMMON_LOG_H__ + +#include + +#define LOG_D(fmt, args...) printf("[DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) +#define LOG_I(fmt, args...) printf("[INFO][%s|%d]" fmt, __func__, __LINE__, ##args) +#define LOG_E(fmt, args...) printf("[ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) + +#endif // __COMMON_LOG_H__ \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/common/include/network_manager_service.h b/CompleteApps/SmartFanDevice/common/include/network_manager_service.h new file mode 100644 index 0000000000000000000000000000000000000000..856c524798bb8398e277b704012b6494ff8dbab0 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/include/network_manager_service.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NETWORK_MANAGER_SERVICE_H__ +#define __NETWORK_MANAGER_SERVICE_H__ + +typedef enum { + NET_EVENT_NULL, + NET_EVENT_CONFIG, // Config wifi + NET_EVENT_CONFIG_FAIL, // Config wifi failed + NET_EVENT_CONFIG_SUCC, // Config wifi success + NET_EVENT_CONNECTTING, // connectting wifi + NET_EVENT_CONN_FAILED, // connect wifi failed + NET_EVENT_CONNECTTED, // Wifi connected + NET_EVENT_DISCONNECT, // Wifi disconnected + NET_EVENT_RECV_DATA, // Recv message from FA + + NET_EVENT_TYPE_NBR +}NET_EVENT_TYPE; + +typedef enum { + NET_MODE_IDLE, // the idle mode + NET_MODE_CONFIG, // the netcfg in the AP mode + NET_MODE_STA, // the netcfg int the STA mode + + NET_MODE_NBR +}NET_MODE_TYPE; + +typedef enum { + NET_STA_NULL, + NET_STA_CONFIG, // Config wifi + NET_STA_CONNECTTING, // connectting wifi + NET_STA_CONNECTTED, // Wifi connected + NET_STA_DISCONNECT, // Wifi disconnected + + NET_STA_TYPE_NBR +}NET_STA_TYPE; + +/** + * @brief: the network config service callback + * + * @param event reference {@link NET_EVENT_TYPE} + * @param data The data of the event: NET_EVENT_RECV_DATA or NET_EVENT_SEND_DATA + * @since 1.0 + * @version 1.0 + */ +typedef int (*NetManagerEventCallback)(NET_EVENT_TYPE event, void *data); + +/** + * @brief Register the network config task + * + * @param apName -- the name of the device for AP mode + * nEventCallback -- The callback of netcfg module + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int NetManagerRegister(const char *apName, NetManagerEventCallback nEventCallback); + +/** + * @brief Set the network mode. + * + * @param mode : the network module, reference {@NET_MODE_TYPE} + * @since 1.0 + * @version 1.0 + */ +void NetManagerSetNetMode(int mode); + +/** + * @brief Send msg to FA. + * + * @param msg : the msg to send + * @since 1.0 + * @version 1.0 + * + * @return 0 -- success, others -- failed + */ +int NetManagerSendMsg(const char *msg); + +/** + * @brief UnRegister the network config task + * + * @since 1.0 + * @version 1.0 + * + */ +void NetManagerDeinit(void); + +#endif // __NETWORK_MANAGER_SERVICE_H__ \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/common/include/peripheral_hal.h b/CompleteApps/SmartFanDevice/common/include/peripheral_hal.h new file mode 100644 index 0000000000000000000000000000000000000000..778594eb534c1c553c41f57ec30d0851c2e56af2 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/include/peripheral_hal.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PERIPHERAL_HAL_H +#define PERIPHERAL_HAL_H + +#include "ohos_types.h" + +/* gpio start */ +typedef enum { + /** GPIO hardware pin 0 */ + HAL_WIFI_IOT_IO_NAME_GPIO_0, + /** GPIO hardware pin 1 */ + HAL_WIFI_IOT_IO_NAME_GPIO_1, + /** GPIO hardware pin 2 */ + HAL_WIFI_IOT_IO_NAME_GPIO_2, + /** GPIO hardware pin 3 */ + HAL_WIFI_IOT_IO_NAME_GPIO_3, + /** GPIO hardware pin 4 */ + HAL_WIFI_IOT_IO_NAME_GPIO_4, + /** GPIO hardware pin 5 */ + HAL_WIFI_IOT_IO_NAME_GPIO_5, + /** GPIO hardware pin 6 */ + HAL_WIFI_IOT_IO_NAME_GPIO_6, + /** GPIO hardware pin 7 */ + HAL_WIFI_IOT_IO_NAME_GPIO_7, + /** GPIO hardware pin 8 */ + HAL_WIFI_IOT_IO_NAME_GPIO_8, + /** GPIO hardware pin 9 */ + HAL_WIFI_IOT_IO_NAME_GPIO_9, + /** GPIO hardware pin 10 */ + HAL_WIFI_IOT_IO_NAME_GPIO_10, + /** GPIO hardware pin 11 */ + HAL_WIFI_IOT_IO_NAME_GPIO_11, + /** GPIO hardware pin 12 */ + HAL_WIFI_IOT_IO_NAME_GPIO_12, + /** GPIO hardware pin 13 */ + HAL_WIFI_IOT_IO_NAME_GPIO_13, + /** GPIO hardware pin 14 */ + HAL_WIFI_IOT_IO_NAME_GPIO_14, + /** Maximum value */ + HAL_WIFI_IOT_IO_NAME_MAX, +} HalWifiIotIoName; + +/** + * @brief set IO function. + * + * @param id -- IO number, reference {@ HalWifiIotIoName}. + * @param val -- the io function value which defined in {@ hi_io.h}. + * + * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link wifiiot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int HalIoSetFunc(HalWifiIotIoName id, const char *val); +/* gpio end */ + + +/* adc start */ + +/** + * @brief Enumerates ADC channel indexes. + * + */ +typedef enum { + /** Channel 0 */ + HAL_WIFI_IOT_ADC_CHANNEL_0, + /** Channel 1 */ + HAL_WIFI_IOT_ADC_CHANNEL_1, + /** Channel 2 */ + HAL_WIFI_IOT_ADC_CHANNEL_2, + /** Channel 3 */ + HAL_WIFI_IOT_ADC_CHANNEL_3, + /** Channel 4 */ + HAL_WIFI_IOT_ADC_CHANNEL_4, + /** Channel 5 */ + HAL_WIFI_IOT_ADC_CHANNEL_5, + /** Channel 6 */ + HAL_WIFI_IOT_ADC_CHANNEL_6, + /** Channel 7 */ + HAL_WIFI_IOT_ADC_CHANNEL_7, + /** Button value */ + HAL_WIFI_IOT_ADC_CHANNEL_BUTT, +} HalWifiIotAdcChannelIndex; + +/** + * @brief Enumerates analog power control modes. + */ +typedef enum { + /** Automatic control */ + HAL_WIFI_IOT_ADC_CUR_BAIS_DEFAULT, + /** Automatic control */ + HAL_WIFI_IOT_ADC_CUR_BAIS_AUTO, + /** Manual control (AVDD = 1.8 V) */ + HAL_WIFI_IOT_ADC_CUR_BAIS_1P8V, + /** Manual control (AVDD = 3.3 V) */ + HAL_WIFI_IOT_ADC_CUR_BAIS_3P3V, + /** Button value */ + HAL_WIFI_IOT_ADC_CUR_BAIS_BUTT, +} HalWifiIotAdcCurBais; + +/** + * @brief Enumerates equation models. + */ +typedef enum { + /** One-equation model */ + HAL_WIFI_IOT_ADC_EQU_MODEL_1, + /** Two-equation model */ + HAL_WIFI_IOT_ADC_EQU_MODEL_2, + /** Four-equation model */ + HAL_WIFI_IOT_ADC_EQU_MODEL_4, + /** Eight-equation model */ + HAL_WIFI_IOT_ADC_EQU_MODEL_8, + /** Button value */ + HAL_WIFI_IOT_ADC_EQU_MODEL_BUTT, +} HalWifiIotAdcEquModelSel; + +/** + * @brief Reads a piece of sampled data from a specified ADC channel based on the input parameters. + * + * + * + * @param channel Indicates the ADC channel index. + * @param data Indicates the pointer to the address for storing the read data. + * @param equModel Indicates the equation model. + * @param curBais Indicates the analog power control mode. + * @param rstCnt Indicates the count of the time from reset to conversion start. + * One count is equal to 334 ns. The value must range from 0 to 0xFF0. + * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link wifiiot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int HalAdcRead(HalWifiIotAdcChannelIndex channel, unsigned short *data, HalWifiIotAdcEquModelSel equModel, + HalWifiIotAdcCurBais curBais, unsigned short rstCnt); +/** adc end ****/ + +/** + * @brief set WatchDog enable or disable. + * + * @param enable -- 1 enable, 0 disable. + * + * @since 1.0 + * @version 1.0 + */ +void HalSetWatchDogEnable(int enable); + +/** + * @brief start the pwm. + * + * @param id Port id of PWM + * @param duty The usefull cycles of PWM + * @param freq The total cycles of PWM + * + * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful; + * returns an error code defined in {@link wifiiot_errno.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +unsigned int HalPwmStart(uint32 id, uint16 duty, uint16 freq); + +#endif // PERIPHERAL_HAL_H \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/common/include/utils_hal.h b/CompleteApps/SmartFanDevice/common/include/utils_hal.h new file mode 100644 index 0000000000000000000000000000000000000000..fb158c285296d1f53a06127802d4137125f91a4e --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/include/utils_hal.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTILS_HAL_H__ +#define __UTILS_HAL_H__ + +void hal_udelay(uint32 us); + +#endif // __UTILS_HAL_H__ \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/common/netcfg/BUILD.gn b/CompleteApps/SmartFanDevice/common/netcfg/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7375d33fa8447e4f8276a135d832e46452c45ffb --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +static_library("netcfg") { + sources = [ + "src/network_config.c", + "src/network_server.c", + "src/network_manager_service.c", + "src/softap.c", + "src/wifi_sta.c" + ] + + include_dirs = [ + "include", + "//applications/sample/wifi-iot/app/common/include", + "//base/iot_hardware/peripheral/interfaces/kits", + "//foundation/communication/wifi_lite/interfaces/wifiservice", + "//kernel/liteos_m/kal/cmsis", + "//kernel/liteos_m/cmsis", + "//third_party/mbedtls/include/mbedtls", + "//utils/native/lite/include", + "//device/hisilicon/hispark_pegasus/sdk_liteos/third_party/lwip_sack/include", + "//device/hisilicon/hispark_pegasus/sdk_liteos/platform/os/Huawei_LiteOS/components/lib/libsec/include", + "//base/security/deviceauth/frameworks/deviceauth_lite/source", + ] +} diff --git a/CompleteApps/SmartFanDevice/common/netcfg/include/defines.h b/CompleteApps/SmartFanDevice/common/netcfg/include/defines.h new file mode 100644 index 0000000000000000000000000000000000000000..8be21413704a21cd45248f6bc626d712095b6721 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/include/defines.h @@ -0,0 +1,52 @@ + + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __DEFINES_H__ +#define __DEFINES_H__ + +#include +#include + +#include + +#define LOG_E(fmt, arg...) printf("[ERROR][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define LOG_D(fmt, arg...) printf("[DEBUG][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define LOG_I(fmt, arg...) printf("[INFO ][%s|%d]" fmt, __func__, __LINE__, ##arg) + +#define REQUEST_OK 200 +#define REQUEST_ERR 401 + +#define BUF_SHORT_SIZE 256 +#define AP_NAME "HmosAP" + +#define DELAY_100MS 10 // for function osDelay(), unit 10ms +#define DELAY_200MS (DELAY_100MS * 2) +#define DELAY_500MS (DELAY_100MS * 5) +#define DELAY_1000MS (DELAY_100MS * 10) +#define DELAY_2000MS (DELAY_100MS * 20) +#define DELAY_5000MS (DELAY_100MS * 50) + +#define USLEEP_100MS 100000 // for function usleep(), unit 1us +#define USLEEP_200MS (USLEEP_100MS * 2) +#define USLEEP_500MS (USLEEP_100MS * 5) +#define USLEEP_1000MS (USLEEP_100MS * 10) +#define USLEEP_2000MS (USLEEP_100MS * 20) +#define USLEEP_2500MS (USLEEP_100MS * 25) +#define USLEEP_5000MS (USLEEP_100MS * 50) + +#define ARRAYSIZE(a) (sizeof((a)) / sizeof((a)[0])) + +#endif /* __DEFINES_H__ */ diff --git a/CompleteApps/SmartFanDevice/common/netcfg/include/network_config.h b/CompleteApps/SmartFanDevice/common/netcfg/include/network_config.h new file mode 100644 index 0000000000000000000000000000000000000000..7810492a0e4790951c2c66610a1e4bd28b83f05f --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/include/network_config.h @@ -0,0 +1,67 @@ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NETWORK_CONFIG_H__ +#define __NETWORK_CONFIG_H__ + +#include "network_manager_service.h" + +#define NET_TASK_STACK_SIZE (1024*8) +#define NET_TASK_PRIO 31 + +/** + * @brief start net config task + * + * @param apName -- the name of the device for AP mode + * nEventCallback -- The NetEvent callback. event reference {@NET_EVENT_TYPE} + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int NetCfgStart(const char *apName, NetManagerEventCallback nEventCallback); + +/** + * @brief stop net config task + * + * @since 1.0 + * @version 1.0 + * + */ +void NetCfgStop(void); + +/** + * @brief set net config mode + * @param mode -- reference {@NET_MODE_TYPE} + * + * @since 1.0 + * @version 1.0 + * + */ +void NetCfgSetMode(int mode); + +/** + * @brief start connect the wifi + * @param ssid -- wifi ssid, pwd -- wifi password + * + * @since 1.0 + * @version 1.0 + * + */ +void NetCfgStartConnect(const char *ssid, const char *pwd); + +#endif /* __NETWORK_CONFIG_H__ */ diff --git a/CompleteApps/SmartFanDevice/common/netcfg/include/network_server.h b/CompleteApps/SmartFanDevice/common/netcfg/include/network_server.h new file mode 100644 index 0000000000000000000000000000000000000000..798ab3e9b37632e0c408a2b41b5361aa4167f09e --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/include/network_server.h @@ -0,0 +1,87 @@ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NETWORK_SERVER_H__ +#define __NETWORK_SERVER_H__ + +#include "network_manager_service.h" + +#define NETSERVER_TASK_STACK_SIZE (1024*4) +#define NETSERVER_TASK_PRIO 33 + + +/** + * @brief start netserver task + * + * @param nEventCallback -- The NetEvent callback, + * when the server recv data, + * it will be called with (@NET_EVENT_RECV_DATA) + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int NetServerInit(NetManagerEventCallback nEventCallback); + +/** + * @brief stop netserver task + * + * @since 1.0 + * @version 1.0 + * + */ +void NetServerDeinit(void); + +/** + * @brief set netserver task resume + * + * @since 1.0 + * @version 1.0 + * + */ +void NetServerStart(void); + +/** + * @brief set netserver task suspend + * + * @since 1.0 + * @version 1.0 + * + */ +void NetServerStop(void); + +/** + * @brief check the netserver when suspend or not. + * + * @since 1.0 + * @version 1.0 + * + * @return true -- netserver task is activity, false -- netserver is suspend + */ +bool NetServerIsRun(void); + +/** + * @brief send msg to client + * @param msg -- The message to send + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int NetServerSendMsg(const char *msg); + +#endif /* __NETWORK_SERVER_H__ */ diff --git a/CompleteApps/SmartFanDevice/common/netcfg/include/softap.h b/CompleteApps/SmartFanDevice/common/netcfg/include/softap.h new file mode 100644 index 0000000000000000000000000000000000000000..020d475a3fd5c30d76f2fc8e3d228fa95de51290 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/include/softap.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SOFT_AP_H__ +#define __SOFT_AP_H__ + +/** + * @brief start ap mode. + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int SoftApStart(const char *ap_name); + +/** + * @brief stop ap mode. + * + * @since 1.0 + * @version 1.0 + * + */ +void SoftApStop(void); + +#endif /* __SOFT_AP_H__ */ diff --git a/CompleteApps/SmartFanDevice/common/netcfg/include/wifi_sta.h b/CompleteApps/SmartFanDevice/common/netcfg/include/wifi_sta.h new file mode 100644 index 0000000000000000000000000000000000000000..a1a698787b19064bc1e600e458b630148cc38752 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/include/wifi_sta.h @@ -0,0 +1,63 @@ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WIFI_STA_H__ +#define __WIFI_STA_H__ + +#include "wifi_device.h" + +/** + * @brief wifi state change callback. + * @param state -- wifi state, 0 -- wifi not connect, 1 -- wifi connectted + * + * @since 1.0 + * @version 1.0 + * + */ +typedef void (*WifiChangeEvent)(int state); + +/** + * @brief start sta mode. + * @param WifiChange--wifi state changed callback + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int WifiStaStart(WifiChangeEvent WifiChange); + +/** + * @brief start connect wifi. + * @param ssid -- wifi ssid, pwd -- wifi password + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int WifiStaConnect(const char *ssid, const char *pwd); + +/** + * @brief stop sta mode. + * + * @since 1.0 + * @version 1.0 + * + */ +void WifiStaStop(void); + +#endif /* __WIFI_STA_H__ */ diff --git a/CompleteApps/SmartFanDevice/common/netcfg/src/network_config.c b/CompleteApps/SmartFanDevice/common/netcfg/src/network_config.c new file mode 100644 index 0000000000000000000000000000000000000000..87309328e809eb6dc777889058df7514a26c5066 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/src/network_config.c @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "errno.h" +#include "cmsis_os2.h" +#include "base64.h" +#include "sys/time.h" +#include "sys/socket.h" +#include "netinet/in.h" +#include "lwip/inet.h" +#include "lwip/netdb.h" + +#include "json/jsonutil.h" +#include "ohos_types.h" +#include "common_log.h" +#include "softap.h" +#include "wifi_sta.h" + +#include "network_config.h" +#include "network_server.h" +#include "defines.h" + +#define SSID_MAX_LEN 32 +#define PWD_MAX_LEN 32 + +#define NET_PORT 8686 + +#define RETRY_TIMES 5 +#define CONNECT_TIMEOUT 20 + +#define CMD_KEY "cmd" +#define PAR_KEY "param" +#define VAL_KEY "wifiName" +#define PWD_KEY "wifiPassword" + +#define CMD_CONFIG 0x20 + +typedef struct { + NET_MODE_TYPE mode; + NET_STA_TYPE status; + bool netRun; + int timeCounts; + + NetManagerEventCallback gEventCall; +} NetManagerInfo; + +static NetManagerInfo g_netManager; +const char *g_apName = NULL; + +#define SET_NET_EVENT(s, e, d) ({ \ + if (g_netManager.gEventCall != NULL) { \ + g_netManager.gEventCall(e, d); \ + } \ + g_netManager.status = s; \ +}) + +static void NetCfgConnectStatus(int s) +{ + if (s == 1 && g_netManager.status != NET_STA_CONNECTTED) { + g_netManager.status = NET_STA_CONNECTTED; + } else if (s == 0) { + if (g_netManager.status == NET_STA_CONNECTTED) { + g_netManager.status = NET_STA_DISCONNECT; + } + g_netManager.mode = NET_MODE_IDLE; + } +} + +#define SHIFT_MASK 0xff +#define SHIFT_8BIT(a) (((a) >> 8) & (SHIFT_MASK)) +#define SHIFT_16BIT(a) (((a) >> 16) & (SHIFT_MASK)) +#define SHIFT_24BIT(a) (((a) >> 24) & (SHIFT_MASK)) + +static void GetIpString(uint32_t ip, char *ipAddr, int size) +{ + if (ipAddr == NULL || size <= 0) { + return; + } + + if (sprintf_s(ipAddr, size, "%d.%d.%d.%d", ip & SHIFT_MASK, SHIFT_8BIT(ip), SHIFT_16BIT(ip), SHIFT_24BIT(ip)) < 0) { + LOG_E("GetIpString failed! \n"); + } + LOG_D("ipAddr : %s \n", ipAddr); +} + +int DeviceGetIp(char *buff, int size) +{ + int ret; + long ip; + struct netif *netif_node = netif_find("wlan0"); + if (netif_node == NULL) { + LOG_E("GetLocalWifiIp netif get fail\r\n"); + return -1; + } + + ip4_addr_t ipAddr; + ip4_addr_t netMask; + ip4_addr_t gateWay; + + ret = netifapi_netif_get_addr(netif_node, &ipAddr, &netMask, &gateWay); + if (ret == 0) { + ip = ip4_addr_get_u32(&ipAddr); + GetIpString(ip, buff, size); + return 0; + } + return -1; +} + +static void SendLocalIp(int sockfd, int code) +{ + char ip[BUF_SHORT_SIZE] = {0}; + + if (code == REQUEST_OK) { + if (DeviceGetIp(ip, sizeof(ip)) < 0) { + LOG_E("get local ip failed! \n"); + return; + } + } + + json_pobject json = create_json_object(); + json_pobject obj = add_number_to_object(json, "code", code); + json_pobject obj1, obj2; + + if (code != REQUEST_OK) { + obj1 = add_string_to_object(json, "errmsg", "connect wifi failed!"); + obj1 = add_object_to_object(json, "result"); + } else { + obj1 = add_object_to_object(json, "result"); + obj2 = add_number_to_object(obj1, "cmd", CMD_CONFIG); + obj2 = add_string_to_object(obj1, "ip", (const char *)ip); + } + + char *msg = json_to_string(json); + const char *eof = "\r\n"; + LOG_D("send msg : %s \n", msg); + if (send(sockfd, msg, strlen(msg), 0) < 0) { + LOG_E("send failed! errno : %d \n", errno); + return; + } + send(sockfd, eof, strlen(eof), 0); + + delete_json_object(json); +} + +static int NetCfgConnect(const char *ssid, const char *pwd, bool wait) +{ + int timecnt = 0; + int retval = 0; + if (WifiStaStart(NetCfgConnectStatus) < 0) { + LOG_E("wifista_start \n"); + return -1; + } + + if (WifiStaConnect((const char *)ssid, (const char *)pwd) < 0) { + LOG_E("hal_wifi_start_connect \n"); + return -1; + } + + if (wait) { + while (g_netManager.status != NET_STA_CONNECTTED) { + usleep(USLEEP_500MS); + if (++timecnt > CONNECT_TIMEOUT) { + retval = -1; + break; + } + } + } + + return retval; +} + +static int ParseWifiInfo(const char *psr, char *ssid, int sl, char *pwd, int pl) +{ + json_handle json; + json_pobject sub; + + int cmd; + char *ps = NULL; + char *pw = NULL; + + json = parse_json(psr); + if (json == NULL) { + LOG_E("parse_json\n"); + return -1; + } + + cmd = get_json_int(json, CMD_KEY); + if (cmd != CMD_CONFIG) { + LOG_E("CMD TYPE FAILED! cmd=%d \n", cmd); + return -1; + } + + sub = get_json_obj(json, PAR_KEY); + if (sub == NULL) { + LOG_E("get param obj failed! \n"); + free_json(json); + return -1; + } + ps = get_json_string(sub, VAL_KEY); + if (ps == NULL) { + LOG_E("get ssid failed! \n"); + free_json(json); + return -1; + } + + if (strncpy_s(ssid, sl, ps, strlen(ps)) < 0) { + LOG_E("strncpy_s failed! \n"); + free_json(json); + return -1; + } + pw = get_json_string(sub, PWD_KEY); + if (pw != NULL) { + LOG_D("pw=%s\n", pw); + if (strncpy_s(pwd, pl, pw, strlen(pw)) < 0) { + LOG_E("strncpy_s failed! \n"); + free_json(json); + return -1; + } + } + + free_json(json); + return 0; +} + +static int NetCfgGetSocketValue(int sockfd) +{ + char recvbuf[BUF_SHORT_SIZE] = {0}; + struct sockaddr_in addr; + socklen_t len; + int result = -1; + char ssid[SSID_MAX_LEN + 1] = {0}; + char pwd[PWD_MAX_LEN + 1] = {0}; + while (1) { + int readBytes; + len = sizeof(addr); + if (g_netManager.mode != NET_MODE_CONFIG) { + break; + } + if (memset_s(recvbuf, BUF_SHORT_SIZE, 0, BUF_SHORT_SIZE) < 0) { + break; + } + readBytes = recvfrom(sockfd, recvbuf, sizeof(recvbuf), 0, (struct sockaddr *)&addr, &len); + if (readBytes <= 0) { + LOG_E("socket disconnect! \n"); + break; + } + if (ParseWifiInfo((const char*)recvbuf, ssid, sizeof(ssid), pwd, sizeof(pwd)) == 0) { + result = 0; + break; + } + } + if (result != -1) { + int code = REQUEST_OK; + SET_NET_EVENT(NET_STA_CONNECTTING, NET_EVENT_CONNECTTING, NULL); + if (NetCfgConnect(ssid, pwd, true) < 0) { + code = REQUEST_ERR; + WifiStaStop(); + result = -1; + } + + usleep(USLEEP_2000MS); // wait ip ready + SendLocalIp(sockfd, code); + usleep(USLEEP_1000MS); + if (result != -1) { + NetServerStart(); + usleep(USLEEP_100MS); // wait ip ready + SET_NET_EVENT(NET_STA_CONNECTTED, NET_EVENT_CONNECTTED, NULL); + } else { + SET_NET_EVENT(NET_STA_NULL, NET_EVENT_CONN_FAILED, NULL); + } + } + + if (memset_s(pwd, sizeof(pwd), 0x00, sizeof(pwd)) < 0) { + return -1; + } + return result; +} + +static int NetCfgSocket(void) +{ + int sockfd; + struct sockaddr_in servaddr; + + if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { + LOG_E("socket error! \n"); + return -1; + } + + memset_s(&servaddr, sizeof(servaddr), 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(NET_PORT); + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + + LOG_D("监听%d端口\n", NET_PORT); + if (bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { + LOG_E("bind socket! \n"); + close(sockfd); + return -1; + } + + if (listen(sockfd, 1) < 0) { + LOG_E("listen failed! errno = %d \n", errno); + close(sockfd); + return -1; + } + + while (g_netManager.mode == NET_MODE_CONFIG) { + int newfd, retval; + struct sockaddr_in client_addr; + socklen_t length = sizeof(client_addr); + newfd = accept(sockfd, (struct sockaddr *)&client_addr, &length); + LOG_D("new socket connect!\n"); + retval = NetCfgGetSocketValue(newfd); + close(newfd); + + if (retval == 0) { + LOG_D("config network success! \n"); + g_netManager.mode = NET_MODE_STA; + } + } + + close(sockfd); + + return 0; +} + +static void NetCfgStartConfig(void) +{ + SET_NET_EVENT(NET_STA_CONFIG, NET_EVENT_CONFIG, NULL); + WifiStaStop(); + if (SoftApStart(g_apName) < 0) { + LOG_E("start softap failed! \n"); + SET_NET_EVENT(NET_STA_NULL, NET_EVENT_CONFIG_FAIL, NULL); + return; + } + + if (NetCfgSocket() < 0) { + SET_NET_EVENT(NET_STA_NULL, NET_EVENT_CONFIG_FAIL, NULL); + return; + } + + SoftApStop(); +} + +static void *NetCfgTask(void *arg) +{ + (void)arg; + int netCfgMode = NET_STA_NULL; + while (g_netManager.netRun) { + if (netCfgMode == g_netManager.mode && netCfgMode != NET_MODE_STA) { + usleep(USLEEP_1000MS); + continue; + } + if (netCfgMode != g_netManager.mode) { + netCfgMode = g_netManager.mode; + } + switch (netCfgMode) { + case NET_MODE_CONFIG: + NetCfgStartConfig(); + break; + default: + break; + } + usleep(USLEEP_1000MS); + } + + return NULL; +} + +int NetCfgStart(const char *apName, NetManagerEventCallback nEventCallback) +{ + osThreadAttr_t attr; + + if (memset_s(&g_netManager, sizeof(g_netManager), 0x00, sizeof(g_netManager)) < 0) { + LOG_E("memset_s g_netManager \n"); + return -1; + } + + g_netManager.gEventCall = nEventCallback; + g_netManager.netRun = true; + g_netManager.mode = NET_STA_CONFIG; + g_apName = apName; + attr.name = "NetManagerTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = NET_TASK_STACK_SIZE; + attr.priority = NET_TASK_PRIO; + + if (osThreadNew((osThreadFunc_t)NetCfgTask, NULL, &attr) == NULL) { + LOG_E("Falied to create NetManagerTask!\n"); + return -1; + } + + return 0; +} + +void NetCfgStop(void) +{ + g_netManager.netRun = false; +} + +void NetCfgSetMode(int mode) +{ + g_netManager.mode = mode; +} + +void NetCfgStartConnect(const char *ssid, const char *pwd) +{ + NetCfgConnect(ssid, pwd, false); +} diff --git a/CompleteApps/SmartFanDevice/common/netcfg/src/network_manager_service.c b/CompleteApps/SmartFanDevice/common/netcfg/src/network_manager_service.c new file mode 100644 index 0000000000000000000000000000000000000000..9e9b6770c7fc892ee1a13aa3009dc8cd37233092 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/src/network_manager_service.c @@ -0,0 +1,64 @@ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "cmsis_os2.h" +#include "base64.h" +#include "sys/time.h" +#include "sys/socket.h" +#include "errno.h" +#include "netinet/in.h" +#include "lwip/inet.h" +#include "lwip/netdb.h" + +#include "json/jsonutil.h" +#include "ohos_types.h" +#include "common_log.h" +#include "network_server.h" +#include "network_config.h" +#include "defines.h" + +int NetManagerRegister(const char *apName, NetManagerEventCallback nEventCallback) +{ + if (NetServerInit(nEventCallback) < 0) { + LOG_E("NetServerInit \n"); + return -1; + } + + if (NetCfgStart(apName, nEventCallback) < 0) { + LOG_E("NetCfgStart \n"); + NetServerDeinit(); + return -1; + } + + return 0; +} + +void NetManagerUnRegister(void) +{ + NetServerDeinit(); + NetCfgStop(); +} + +void NetManagerSetNetMode(int mode) +{ + NetCfgSetMode(mode); +} + +int NetManagerSendMsg(const char *msg) +{ + return NetServerSendMsg(msg); +} diff --git a/CompleteApps/SmartFanDevice/common/netcfg/src/network_server.c b/CompleteApps/SmartFanDevice/common/netcfg/src/network_server.c new file mode 100644 index 0000000000000000000000000000000000000000..b61026f9ade90f4bc6c71d72fce33475f2ca82e0 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/src/network_server.c @@ -0,0 +1,327 @@ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "cmsis_os2.h" +#include "base64.h" +#include "sys/time.h" +#include "sys/socket.h" +#include "errno.h" +#include "common_log.h" +#include "netinet/in.h" +#include "lwip/inet.h" +#include "lwip/netdb.h" +#include "json/jsonutil.h" +#include "network_server.h" +#include "defines.h" + +#define SERVER_PORT 8787 +#define MAX_CONNECT 10 + +typedef struct { + int sockfd[MAX_CONNECT]; + int connAmount; + bool isActive; + bool serRun; + + NetManagerEventCallback g_call; +}NetServerInfo; + +static NetServerInfo g_netServer; + +static int NetServerSend(int fd, const char *msg) +{ + const char *eof = "\r\n"; + if (send(fd, msg, strlen(msg), 0) < 0) { + LOG_E("send failed! errno : %d \n", errno); + return -1; + } + LOG_D("send msg : %s \n", msg); + send(fd, eof, strlen(eof), 0); + + return 0; +} + +static void SendRequest(int sockfd, int code) +{ + json_pobject obj; + json_pobject json = create_json_object(); + + obj = add_number_to_object(json, "code", code); + if (code == REQUEST_OK) { + obj = add_string_to_object(json, "errmsg", ""); + } else { + obj = add_string_to_object(json, "errmsg", "explain params error!"); + } + + char *msg = json_to_string(json); + NetServerSend(sockfd, msg); + delete_json_object(json); +} + +static bool IsSpecialSocket(const char *msg) +{ + char buf[] = {0xff, 0x55, 0xaa, 0x55, 0x00}; + bool result = true; + if (msg == NULL || strlen(msg) < strlen(buf)) { + return false; + } + + for (int i = 0; i < strlen(buf); i++) { + if (msg[i] != buf[i]) { + result = false; + break; + } + } + + return result; +} + +static int ReadHandle(int *sockfd, fd_set *fdSet) +{ + char recvbuf[BUF_SHORT_SIZE] = {0}; + int recvbytes; + int fd = *sockfd; + int errcode = -1; + + recvbytes = recv(fd, recvbuf, sizeof(recvbuf) - 1, 0); + if (recvbytes <= 0) { + LOG_E("recv failed! socket may quit!\n"); + FD_CLR(fd, fdSet); + close(fd); + *sockfd = -1; + g_netServer.connAmount--; + return -1; + } + + if (g_netServer.sockfd[0] == -1 && IsSpecialSocket(recvbuf)) { + *sockfd = -1; + g_netServer.sockfd[0] = fd; + return 0; + } + + LOG_D("recv msg[%d] : %s \n", recvbytes, recvbuf); + if (g_netServer.g_call) { + errcode = g_netServer.g_call(NET_EVENT_RECV_DATA, recvbuf); + } + + if (errcode == -1) { + errcode = REQUEST_ERR; + } else { + errcode = REQUEST_OK; + } + + SendRequest(fd, errcode); + + return 0; +} + +static void CheckNewSocket(int sockFd, fd_set *fdSet, int *maxFd) +{ + int newfd; + struct sockaddr_in client_addr; + socklen_t sin_size = sizeof(client_addr); + if (FD_ISSET(sockFd, fdSet) == 0) { + return; + } + + newfd = accept(sockFd, (struct sockaddr *)&client_addr, &sin_size); + LOG_D("accept:: sock_fd = %d, newfd = %d\n", sockFd, newfd); + if (newfd < 0) { + LOG_E("accept:\n"); + return; + } + + g_netServer.connAmount++; + + if (g_netServer.connAmount < MAX_CONNECT) { + for (int i = 1; i < MAX_CONNECT; i++) { + if (g_netServer.sockfd[i] == -1) { + g_netServer.sockfd[i] = newfd; + break; + } + } + + if (newfd > *maxFd) { + *maxFd = newfd; + } + } else { + LOG_E("max connections arrive, exit\n"); + close(newfd); + } +} + +static void SocketListen(int sock_fd) +{ + fd_set fdset; + int maxsock; + maxsock = sock_fd; + + while (g_netServer.serRun) { + int ret; + struct timeval tv = {2, 0}; + FD_ZERO(&fdset); + FD_SET(sock_fd, &fdset); + for (int i = 0; i < MAX_CONNECT; i++) { + if (g_netServer.sockfd[i] != -1) { + FD_SET(g_netServer.sockfd[i], &fdset); + } + } + ret = select(maxsock + 1, &fdset, NULL, NULL, &tv); + if (ret <= 0) { + continue; + } + for (int i = 0; i < MAX_CONNECT; i++) { + if (g_netServer.sockfd[i] != -1 && FD_ISSET(g_netServer.sockfd[i], &fdset)) { + LOG_D("g_netServer.sockfd[%d] = %d\n", i, g_netServer.sockfd[i]); + ReadHandle(&g_netServer.sockfd[i], &fdset); + continue; + } + } + + CheckNewSocket(sock_fd, &fdset, &maxsock); + } + for (int i = 0; i < MAX_CONNECT; i++) { + if (g_netServer.sockfd[i] != -1) { + close(g_netServer.sockfd[i]); + g_netServer.sockfd[i] = -1; + } + } +} + +static void StartServer(void) +{ + struct sockaddr_in serv_addr; + int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (sockfd < 0) { + LOG_E("socket failed! \n"); + g_netServer.serRun = false; + return; + } + + if (memset_s(&serv_addr, sizeof(serv_addr), 0, sizeof(serv_addr)) < 0) { + LOG_E("memset_s faield! \n"); + close(sockfd); + g_netServer.serRun = false; + return; + } + + serv_addr.sin_family = AF_INET; // 使用IPv4地址 + serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); + serv_addr.sin_port = htons(SERVER_PORT); // 端口 + if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { + LOG_E("bind failed! errno = %d \n", errno); + g_netServer.serRun = false; + close(sockfd); + return; + } + + if (listen(sockfd, MAX_CONNECT) < 0) { + LOG_E("listen failed! errno = %d \n", errno); + g_netServer.serRun = false; + close(sockfd); + return; + } + + SocketListen(sockfd); + + LOG_D("SOCKET SERVER QUIT! \n"); + + close(sockfd); +} + +static void *NetServerTask(void *param) +{ + while (g_netServer.isActive) { + if (g_netServer.serRun == false) { + usleep(USLEEP_100MS); + continue; + } + + StartServer(); + } + + return NULL; +} + +int NetServerInit(NetManagerEventCallback nEventCallback) +{ + osThreadAttr_t attr; + attr.name = "NetServerTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = NETSERVER_TASK_STACK_SIZE; + attr.priority = NETSERVER_TASK_PRIO; + + if (memset_s(&g_netServer, sizeof(g_netServer), 0x00, sizeof(g_netServer)) < 0) { + LOG_E("memset_s failed! \n"); + return -1; + } + for (int i = 0; i < MAX_CONNECT; i++) { + g_netServer.sockfd[i] = -1; + } + g_netServer.isActive = true; + g_netServer.g_call = nEventCallback; + if (osThreadNew((osThreadFunc_t)NetServerTask, NULL, &attr) == NULL) { + LOG_E("Falied to create NetServerTask!\n"); + g_netServer.isActive = false; + return -1; + } + + return 0; +} + +void NetServerDeinit(void) +{ + g_netServer.serRun = false; + for (int i = 0; i < MAX_CONNECT; i++) { + if (g_netServer.sockfd[i] != -1) { + shutdown(g_netServer.sockfd[i], SHUT_RDWR); + g_netServer.sockfd[i] = -1; + } + } + + osDelay(DELAY_200MS); + g_netServer.isActive = false; +} + +void NetServerStart(void) +{ + g_netServer.serRun = true; +} + +void NetServerStop(void) +{ + g_netServer.serRun = false; + osDelay(DELAY_200MS); +} + +bool NetServerIsRun(void) +{ + return g_netServer.serRun; +} + +int NetServerSendMsg(const char *msg) +{ + if (g_netServer.serRun == false || g_netServer.sockfd[0] == -1) { + LOG_E("net server is not run! \n"); + return -1; + } + + return NetServerSend(g_netServer.sockfd[0], msg); +} diff --git a/CompleteApps/SmartFanDevice/common/netcfg/src/softap.c b/CompleteApps/SmartFanDevice/common/netcfg/src/softap.c new file mode 100644 index 0000000000000000000000000000000000000000..02b935d0fdf717020a97a0acbc2d59ec0064f81b --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/src/softap.c @@ -0,0 +1,82 @@ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "lwip/ip_addr.h" +#include "lwip/netifapi.h" +#include "wifi_hotspot.h" +#include "wifi_hotspot_config.h" +#include "softap.h" +#include "defines.h" + +static void ResetAddr(struct netif *pst_lwip_netif) +{ + ip4_addr_t st_gw; + ip4_addr_t st_ipaddr; + ip4_addr_t st_netmask; + + IP4_ADDR(&st_ipaddr, 0, 0, 0, 0); + IP4_ADDR(&st_gw, 0, 0, 0, 0); + IP4_ADDR(&st_netmask, 0, 0, 0, 0); + + netifapi_netif_set_addr(pst_lwip_netif, &st_ipaddr, &st_netmask, &st_gw); +} + +int SoftApStart(const char *ap_name) +{ + HotspotConfig config = {0}; + ip4_addr_t st_gw; + ip4_addr_t st_ipaddr; + ip4_addr_t st_netmask; + char *apName = ap_name; + char ifname[BUF_SHORT_SIZE] = {0}; + int retval; + + if (IsHotspotActive() == WIFI_HOTSPOT_ACTIVE) { + LOG_E("WIFI_HOTSPOT_ACTIVE \n"); + return -1; + } + if (apName == NULL) { + apName = AP_NAME; + } + if (strcpy_s(config.ssid, sizeof(config.ssid), apName) != 0) { + printf("[sample] strcpy ssid fail.\n"); + return -1; + } + config.securityType = WIFI_SEC_TYPE_OPEN; + retval = SetHotspotConfig((const HotspotConfig *)(&config)); + if (retval != WIFI_SUCCESS) { + LOG_E("SetHotspotConfig \n"); + return -1; + } + + retval = EnableHotspot(); + if (retval != WIFI_SUCCESS) { + LOG_E("EnableHotspot failed! \n"); + return -1; + } + + return 0; +} + +void SoftApStop(void) +{ + if (IsHotspotActive() == WIFI_HOTSPOT_NOT_ACTIVE) { + LOG_E("WIFI_HOTSPOT_NOT_ACTIVE \n"); + return; + } + + DisableHotspot(); +} diff --git a/CompleteApps/SmartFanDevice/common/netcfg/src/wifi_sta.c b/CompleteApps/SmartFanDevice/common/netcfg/src/wifi_sta.c new file mode 100644 index 0000000000000000000000000000000000000000..683a5d841146eb447072a511d1a3d96b1f543e37 --- /dev/null +++ b/CompleteApps/SmartFanDevice/common/netcfg/src/wifi_sta.c @@ -0,0 +1,128 @@ + +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "lwip/ip_addr.h" +#include "lwip/netifapi.h" +#include "wifi_sta.h" +#include "defines.h" + +#define TEST_CONNECT_RETRY_COUNT 5 + +static WifiEvent g_staEventHandler = {0}; +static WifiChangeEvent g_wifiChange = NULL; +static int g_connectRetryCount = 0; + +static void WifiConnectionChangedHandler(int state, WifiLinkedInfo *info) +{ + if (state == WIFI_STATE_AVALIABLE) { + LOG_I("WiFi: Connected.\n"); + g_connectRetryCount = 0; + } else if (state == WIFI_STATE_NOT_AVALIABLE) { + LOG_I("WiFi: Disconnected retry = %d, reason = %d\n", g_connectRetryCount, info->disconnectedReason); + if (g_connectRetryCount < TEST_CONNECT_RETRY_COUNT) { + g_connectRetryCount++; + return; + } + } + if (g_wifiChange) { + g_wifiChange(state); + } +} + +int WifiStaStart(WifiChangeEvent WifiChange) +{ + WifiErrorCode error; + + g_wifiChange = WifiChange; + + if (IsWifiActive() == WIFI_STA_ACTIVE) { + LOG_E("the wifi has been enabled! \n"); + return 1; + } + + error = EnableWifi(); + if (error != WIFI_SUCCESS) { + LOG_E("EnableWifi failed! \n"); + return -1; + } + + g_staEventHandler.OnWifiConnectionChanged = WifiConnectionChangedHandler; + error = RegisterWifiEvent(&g_staEventHandler); + if (error != WIFI_SUCCESS) { + LOG_E("RegisterWifiEvent fail, error = %d\n", error); + return -1; + } + + if (IsWifiActive() == WIFI_STA_NOT_ACTIVE) { + LOG_E("Wifi station is not actived.\n"); + return -1; + } + + return 0; +} + +int WifiStaConnect(const char *ssid, const char *pwd) +{ + WifiDeviceConfig config = {0}; + int netId = 0; + WifiErrorCode error; + + if (ssid == NULL) { + LOG_E("NULL POINT! \n"); + return -1; + } + if (strcpy_s(config.ssid, sizeof(config.ssid), ssid) < 0) { + LOG_E("strcpy_s! \n"); + return -1; + } + + config.ipType = DHCP; + if (pwd == NULL || strlen(pwd) == 0) { + config.securityType = WIFI_SEC_TYPE_OPEN; + } else { + config.securityType = WIFI_SEC_TYPE_PSK; + if (strcpy_s(config.preSharedKey, sizeof(config.preSharedKey), pwd) < 0) { + LOG_E("strcpy_s! \n"); + return -1; + } + } + + error = AddDeviceConfig(&config, &netId); + if (error != WIFI_SUCCESS) { + LOG_E("AddDeviceConfig! \n"); + return -1; + } + + error = ConnectTo(netId); + if (error != WIFI_SUCCESS) { + LOG_E("ConnectTo! \n"); + return -1; + } + + return 0; +} + +void WifiStaStop(void) +{ + if (IsWifiActive() == WIFI_STA_NOT_ACTIVE) { + LOG_E("Wifi station is not actived.\n"); + return; + } + + DisableWifi(); + UnRegisterWifiEvent(&g_staEventHandler); +} + diff --git a/CompleteApps/SmartFanDevice/screenshoot/device/fan_control.png b/CompleteApps/SmartFanDevice/screenshoot/device/fan_control.png new file mode 100644 index 0000000000000000000000000000000000000000..d39c61cf6cd81509a1b65331496473b5e4493255 Binary files /dev/null and b/CompleteApps/SmartFanDevice/screenshoot/device/fan_control.png differ diff --git a/CompleteApps/SmartFanDevice/smartfan/BUILD.gn b/CompleteApps/SmartFanDevice/smartfan/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a212eab4f7f9ce40e358ba17f81e1130757a4a19 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2020 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +static_library("smartfan") { + sources = [ + "src/sensor.c", + "src/oled.c", + "src/pwm.c", + "src/keypad.c", + "src/common.c", + "src/fan.c" + ] + + include_dirs = [ + "include", + "//applications/sample/wifi-iot/app/common/include", + "//base/iot_hardware/peripheral/interfaces/kits", + "//foundation/communication/wifi_lite/interfaces/wifiservice", + "//kernel/liteos_m/kal/cmsis", + "//kernel/liteos_m/cmsis", + "//third_party/mbedtls/include/mbedtls", + "//utils/native/lite/include", + "//device/hisilicon/hispark_pegasus/sdk_liteos/third_party/lwip_sack/include", + "//device/hisilicon/hispark_pegasus/sdk_liteos/platform/os/Huawei_LiteOS/components/lib/libsec/include", + "//base/security/deviceauth/frameworks/deviceauth_lite/source", + ] +} diff --git a/CompleteApps/SmartFanDevice/smartfan/include/code_tab.h b/CompleteApps/SmartFanDevice/smartfan/include/code_tab.h new file mode 100644 index 0000000000000000000000000000000000000000..07fcc91ec11ca9908cddb52adabc6e54530ea72e --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/code_tab.h @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CODE_TAB_H__ +#define _CODE_TAB_H__ + +/* **************************16*16******** */ +const unsigned char F16X16[] = { + 0x10, 0x60, 0x02, 0x8C, 0x00, 0x00, 0xFE, 0x92, 0x92, 0x92, 0x92, 0x92, 0xFE, 0x00, 0x00, 0x00, + 0x04, 0x04, 0x7E, 0x01, 0x40, 0x7E, 0x42, 0x42, 0x7E, 0x42, 0x7E, 0x42, 0x42, 0x7E, 0x40, 0x00, /* "温", 0 */ + 0x10, 0x60, 0x02, 0x8C, 0x00, 0xFE, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0xFE, 0x00, 0x00, 0x00, + 0x04, 0x04, 0x7E, 0x01, 0x44, 0x48, 0x50, 0x7F, 0x40, 0x40, 0x7F, 0x50, 0x48, 0x44, 0x40, 0x00, /* "湿", 1 */ + 0x00, 0x00, 0xFC, 0x24, 0x24, 0x24, 0xFC, 0x25, 0x26, 0x24, 0xFC, 0x24, 0x24, 0x24, 0x04, 0x00, + 0x40, 0x30, 0x8F, 0x80, 0x84, 0x4C, 0x55, 0x25, 0x25, 0x25, 0x55, 0x4C, 0x80, 0x80, 0x80, 0x00, /* "度", 2 */ +}; + +const unsigned char HZ_F16X16[][2][16] = { + { + {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} + }, /* " ", 0 */ + { + {0x80, 0x82, 0x82, 0x82, 0xFE, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFE, 0x82, 0x82, 0x82, 0x80, 0x00}, + {0x00, 0x80, 0x40, 0x30, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00} + }, /* "开", 1 */ + { + {0x00, 0x20, 0x20, 0x20, 0xA0, 0x60, 0x00, 0xFF, 0x60, 0x80, 0x40, 0x20, 0x18, 0x00, 0x00, 0x00}, + {0x20, 0x10, 0x08, 0x06, 0x01, 0x40, 0x80, 0x7F, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00} + }, /* "水", 2 */ + { + {0x04, 0x04, 0x04, 0x04, 0x9F, 0x44, 0x24, 0x94, 0x24, 0x44, 0x9F, 0x04, 0x04, 0x04, 0x04, 0x00}, + {0x02, 0x02, 0x21, 0x13, 0x0A, 0x42, 0x82, 0x7F, 0x02, 0x02, 0x0A, 0x13, 0x21, 0x02, 0x02, 0x00} + }, /* "茶", 3 */ + { + {0x40, 0x30, 0x0F, 0x88, 0x28, 0x18, 0x08, 0x40, 0x30, 0x0F, 0xC8, 0x08, 0x28, 0x18, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x7F, 0x20, 0x10, 0x88, 0x40, 0x30, 0x0E, 0x01, 0x0E, 0x30, 0x40, 0x80, 0x00} + }, /* "饮", 4 */ + { + {0x00, 0x02, 0x0C, 0xC0, 0x00, 0xF0, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00}, + {0x02, 0x02, 0x7F, 0x00, 0x00, 0x0F, 0x04, 0x04, 0x04, 0xFF, 0x04, 0x04, 0x04, 0x0F, 0x00, 0x00} + }, /* "冲", 5 */ + { + {0x10, 0x10, 0xF0, 0x1F, 0x10, 0xF0, 0x04, 0x04, 0xFC, 0x04, 0xC4, 0xB4, 0x8C, 0x80, 0x00, 0x00}, + {0x40, 0x22, 0x15, 0x08, 0x16, 0xA1, 0x60, 0x1C, 0x03, 0x00, 0x40, 0x80, 0x40, 0x3F, 0x00, 0x00} + }, /* "奶", 6 */ + { + {0x00, 0x04, 0x04, 0xF4, 0x94, 0x94, 0x94, 0x9F, 0x94, 0x94, 0x94, 0xF4, 0x04, 0x04, 0x00, 0x00}, + {0x40, 0x40, 0x40, 0x7F, 0x4A, 0x4A, 0x4A, 0x4A, 0x4A, 0x4A, 0x4A, 0x7F, 0x40, 0x40, 0x40, 0x00} + }, /* "直", 7 */ + { + {0x40, 0x30, 0x0F, 0x88, 0x28, 0x18, 0x08, 0x40, 0x30, 0x0F, 0xC8, 0x08, 0x28, 0x18, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x7F, 0x20, 0x10, 0x88, 0x40, 0x30, 0x0E, 0x01, 0x0E, 0x30, 0x40, 0x80, 0x00} + }, /* "饮", 8 */ +}; + +const unsigned char HZ_F16X16_1[][2][16] = { + { + {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} + }, /* " ", 0 */ + { + {0xFC, 0x04, 0x04, 0xFC, 0x10, 0xFF, 0x10, 0x10, 0xF0, 0x00, 0xF8, 0x08, 0x08, 0xF8, 0x00, 0x00}, + {0x0F, 0x04, 0x84, 0x4F, 0x30, 0x0F, 0x40, 0x80, 0x7F, 0x00, 0x7F, 0x20, 0x20, 0x7F, 0x00, 0x00} + }, /* "咖", 1 */ + { + {0xFC, 0x04, 0x04, 0xFC, 0x00, 0x08, 0x88, 0x88, 0xFF, 0x00, 0x00, 0xFF, 0x88, 0x88, 0x08, 0x00}, + {0x0F, 0x04, 0x04, 0x0F, 0x00, 0x08, 0x08, 0x08, 0xFF, 0x00, 0x00, 0xFF, 0x08, 0x08, 0x08, 0x00} + }, /* "啡", 2 */ + { + {0x04, 0x04, 0x04, 0x84, 0x6F, 0x04, 0x04, 0x04, 0xE4, 0x04, 0x8F, 0x44, 0x24, 0x04, 0x04, 0x00}, + {0x04, 0x02, 0x01, 0xFF, 0x00, 0x10, 0x08, 0x04, 0x3F, 0x41, 0x40, 0x40, 0x40, 0x40, 0x78, 0x00} + }, /* "花", 3 */ + { + {0x40, 0x44, 0x54, 0x54, 0x55, 0x56, 0xD4, 0x7C, 0x54, 0x56, 0x55, 0x54, 0x54, 0x44, 0x40, 0x00}, + {0x02, 0x82, 0x82, 0x9A, 0x56, 0x53, 0x22, 0x22, 0x22, 0x52, 0x4E, 0x42, 0x82, 0x02, 0x02, 0x00} + }, /* "姜", 4 */ + { + {0x04, 0x04, 0x04, 0x04, 0x9F, 0x44, 0x24, 0x94, 0x24, 0x44, 0x9F, 0x04, 0x04, 0x04, 0x04, 0x00}, + {0x02, 0x02, 0x21, 0x13, 0x0A, 0x42, 0x82, 0x7F, 0x02, 0x02, 0x0A, 0x13, 0x21, 0x02, 0x02, 0x00} + }, /* "茶", 5 */ +}; + +/* ***********************************6*8*********************************** */ +const unsigned char F6X8[][6] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // sp + {0x00, 0x00, 0x00, 0x2f, 0x00, 0x00}, // ! + {0x00, 0x00, 0x07, 0x00, 0x07, 0x00}, // " + {0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14}, // # + {0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12}, // $ + {0x00, 0x62, 0x64, 0x08, 0x13, 0x23}, // % + {0x00, 0x36, 0x49, 0x55, 0x22, 0x50}, // & + {0x00, 0x00, 0x05, 0x03, 0x00, 0x00}, // ' + {0x00, 0x00, 0x1c, 0x22, 0x41, 0x00}, // ( + {0x00, 0x00, 0x41, 0x22, 0x1c, 0x00}, // ) + {0x00, 0x14, 0x08, 0x3E, 0x08, 0x14}, // * + {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08}, // + + {0x00, 0x00, 0x00, 0xA0, 0x60, 0x00}, // ,1 + {0x00, 0x08, 0x08, 0x08, 0x08, 0x08}, // - + {0x00, 0x00, 0x60, 0x60, 0x00, 0x00}, // . + {0x00, 0x20, 0x10, 0x08, 0x04, 0x02}, // / + {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E}, // 0 + {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00}, // 1 + {0x00, 0x42, 0x61, 0x51, 0x49, 0x46}, // 2 + {0x00, 0x21, 0x41, 0x45, 0x4B, 0x31}, // 3 + {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10}, // 4 + {0x00, 0x27, 0x45, 0x45, 0x45, 0x39}, // 5 + {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30}, // 6 + {0x00, 0x01, 0x71, 0x09, 0x05, 0x03}, // 7 + {0x00, 0x36, 0x49, 0x49, 0x49, 0x36}, // 8 + {0x00, 0x06, 0x49, 0x49, 0x29, 0x1E}, // 9 + {0x00, 0x00, 0x36, 0x36, 0x00, 0x00}, // : + {0x00, 0x00, 0x56, 0x36, 0x00, 0x00}, // ; + {0x00, 0x08, 0x14, 0x22, 0x41, 0x00}, // < + {0x00, 0x14, 0x14, 0x14, 0x14, 0x14}, // = + {0x00, 0x00, 0x41, 0x22, 0x14, 0x08}, // > + {0x00, 0x02, 0x01, 0x51, 0x09, 0x06}, // ? + {0x00, 0x32, 0x49, 0x59, 0x51, 0x3E}, // @ + {0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C}, // A + {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36}, // B + {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22}, // C + {0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C}, // D + {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41}, // E + {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01}, // F + {0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A}, // G + {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F}, // H + {0x00, 0x00, 0x41, 0x7F, 0x41, 0x00}, // I + {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01}, // J + {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41}, // K + {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40}, // L + {0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F}, // M + {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F}, // N + {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E}, // O + {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06}, // P + {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E}, // Q + {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46}, // R + {0x00, 0x46, 0x49, 0x49, 0x49, 0x31}, // S + {0x00, 0x01, 0x01, 0x7F, 0x01, 0x01}, // T + {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F}, // U + {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F}, // V + {0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F}, // W + {0x00, 0x63, 0x14, 0x08, 0x14, 0x63}, // X + {0x00, 0x07, 0x08, 0x70, 0x08, 0x07}, // Y + {0x00, 0x61, 0x51, 0x49, 0x45, 0x43}, // Z + {0x00, 0x00, 0x7F, 0x41, 0x41, 0x00}, // [ + {0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55}, // 55 + {0x00, 0x00, 0x41, 0x41, 0x7F, 0x00}, // ] + {0x00, 0x04, 0x02, 0x01, 0x02, 0x04}, // ^ + {0x00, 0x40, 0x40, 0x40, 0x40, 0x40}, // _ + {0x00, 0x00, 0x01, 0x02, 0x04, 0x00}, // ' + {0x00, 0x20, 0x54, 0x54, 0x54, 0x78}, // a + {0x00, 0x7F, 0x48, 0x44, 0x44, 0x38}, // b + {0x00, 0x38, 0x44, 0x44, 0x44, 0x20}, // c + {0x00, 0x38, 0x44, 0x44, 0x48, 0x7F}, // d + {0x00, 0x38, 0x54, 0x54, 0x54, 0x18}, // e + {0x00, 0x08, 0x7E, 0x09, 0x01, 0x02}, // f + {0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C}, // g + {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78}, // h + {0x00, 0x00, 0x44, 0x7D, 0x40, 0x00}, // i + {0x00, 0x40, 0x80, 0x84, 0x7D, 0x00}, // j + {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00}, // k + {0x00, 0x00, 0x41, 0x7F, 0x40, 0x00}, // l + {0x00, 0x7C, 0x04, 0x18, 0x04, 0x78}, // m + {0x00, 0x7C, 0x08, 0x04, 0x04, 0x78}, // n + {0x00, 0x38, 0x44, 0x44, 0x44, 0x38}, // o + {0x00, 0xFC, 0x24, 0x24, 0x24, 0x18}, // p + {0x00, 0x18, 0x24, 0x24, 0x18, 0xFC}, // q + {0x00, 0x7C, 0x08, 0x04, 0x04, 0x08}, // r + {0x00, 0x48, 0x54, 0x54, 0x54, 0x20}, // s + {0x00, 0x04, 0x3F, 0x44, 0x40, 0x20}, // t + {0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C}, // u + {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C}, // v + {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C}, // w + {0x00, 0x44, 0x28, 0x10, 0x28, 0x44}, // x + {0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C}, // y + {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44}, // z + {0x14, 0x14, 0x14, 0x14, 0x14, 0x14}, // horiz lines +}; + +/* ***************************************8*16*********************************** */ +const unsigned char F8X16[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 + 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x30, 0x00, 0x00, 0x00, // !1 + 0x00, 0x10, 0x0C, 0x06, 0x10, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // "2 + 0x40, 0xC0, 0x78, 0x40, 0xC0, 0x78, 0x40, 0x00, 0x04, 0x3F, 0x04, 0x04, 0x3F, 0x04, 0x04, 0x00, // #3 + 0x00, 0x70, 0x88, 0xFC, 0x08, 0x30, 0x00, 0x00, 0x00, 0x18, 0x20, 0xFF, 0x21, 0x1E, 0x00, 0x00, // $4 + 0xF0, 0x08, 0xF0, 0x00, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x21, 0x1C, 0x03, 0x1E, 0x21, 0x1E, 0x00, // %5 + 0x00, 0xF0, 0x08, 0x88, 0x70, 0x00, 0x00, 0x00, 0x1E, 0x21, 0x23, 0x24, 0x19, 0x27, 0x21, 0x10, // &6 + 0x10, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // '7 + 0x00, 0x00, 0x00, 0xE0, 0x18, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x20, 0x40, 0x00, // (8 + 0x00, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x18, 0x07, 0x00, 0x00, 0x00, // )9 + 0x40, 0x40, 0x80, 0xF0, 0x80, 0x40, 0x40, 0x00, 0x02, 0x02, 0x01, 0x0F, 0x01, 0x02, 0x02, 0x00, // *10 + 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x1F, 0x01, 0x01, 0x01, 0x00, // +11 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xB0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, // ,12 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // -13 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, // .14 + 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x04, 0x00, 0x60, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, // 15 + 0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x10, 0x0F, 0x00, // 0 16 + 0x00, 0x10, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // 1 17 + 0x00, 0x70, 0x08, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x30, 0x28, 0x24, 0x22, 0x21, 0x30, 0x00, // 2 18 + 0x00, 0x30, 0x08, 0x88, 0x88, 0x48, 0x30, 0x00, 0x00, 0x18, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // 3 19 + 0x00, 0x00, 0xC0, 0x20, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x07, 0x04, 0x24, 0x24, 0x3F, 0x24, 0x00, // 4 20 + 0x00, 0xF8, 0x08, 0x88, 0x88, 0x08, 0x08, 0x00, 0x00, 0x19, 0x21, 0x20, 0x20, 0x11, 0x0E, 0x00, // 5 21 + 0x00, 0xE0, 0x10, 0x88, 0x88, 0x18, 0x00, 0x00, 0x00, 0x0F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // 6 22 + 0x00, 0x38, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, // 7 23 + 0x00, 0x70, 0x88, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x1C, 0x22, 0x21, 0x21, 0x22, 0x1C, 0x00, // 8 24 + 0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x00, 0x31, 0x22, 0x22, 0x11, 0x0F, 0x00, // 9 25 + 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, // : 26 + 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00, // ; 27 + 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, // < 28 + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, // = 29 + 0x00, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, // > 30 + 0x00, 0x70, 0x48, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x36, 0x01, 0x00, 0x00, // ? 31 + 0xC0, 0x30, 0xC8, 0x28, 0xE8, 0x10, 0xE0, 0x00, 0x07, 0x18, 0x27, 0x24, 0x23, 0x14, 0x0B, 0x00, // @ 32 + 0x00, 0x00, 0xC0, 0x38, 0xE0, 0x00, 0x00, 0x00, 0x20, 0x3C, 0x23, 0x02, 0x02, 0x27, 0x38, 0x20, // A 33 + 0x08, 0xF8, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // B 34 + 0xC0, 0x30, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x07, 0x18, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, // C 35 + 0x08, 0xF8, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // D 36 + 0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x23, 0x20, 0x18, 0x00, // E 37 + 0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, // F 38 + 0xC0, 0x30, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x07, 0x18, 0x20, 0x20, 0x22, 0x1E, 0x02, 0x00, // G 39 + 0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x21, 0x3F, 0x20, // H 40 + 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // I 41 + 0x00, 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, 0x00, // J 42 + 0x08, 0xF8, 0x88, 0xC0, 0x28, 0x18, 0x08, 0x00, 0x20, 0x3F, 0x20, 0x01, 0x26, 0x38, 0x20, 0x00, // K 43 + 0x08, 0xF8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00, // L 44 + 0x08, 0xF8, 0xF8, 0x00, 0xF8, 0xF8, 0x08, 0x00, 0x20, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x20, 0x00, // M 45 + 0x08, 0xF8, 0x30, 0xC0, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x20, 0x00, 0x07, 0x18, 0x3F, 0x00, // N 46 + 0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // O 47 + 0x08, 0xF8, 0x08, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x01, 0x00, 0x00, // P 48 + 0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x18, 0x24, 0x24, 0x38, 0x50, 0x4F, 0x00, // Q 49 + 0x08, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x0C, 0x30, 0x20, // R 50 + 0x00, 0x70, 0x88, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x38, 0x20, 0x21, 0x21, 0x22, 0x1C, 0x00, // S 51 + 0x18, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x18, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // T 52 + 0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // U 53 + 0x08, 0x78, 0x88, 0x00, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x07, 0x38, 0x0E, 0x01, 0x00, 0x00, // V 54 + 0xF8, 0x08, 0x00, 0xF8, 0x00, 0x08, 0xF8, 0x00, 0x03, 0x3C, 0x07, 0x00, 0x07, 0x3C, 0x03, 0x00, // W 55 + 0x08, 0x18, 0x68, 0x80, 0x80, 0x68, 0x18, 0x08, 0x20, 0x30, 0x2C, 0x03, 0x03, 0x2C, 0x30, 0x20, // X 56 + 0x08, 0x38, 0xC8, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // Y 57 + 0x10, 0x08, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x20, 0x38, 0x26, 0x21, 0x20, 0x20, 0x18, 0x00, // Z 58 + 0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x00, // [ 59 + 0x00, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x38, 0xC0, 0x00, // \ 60 + 0x00, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7F, 0x00, 0x00, 0x00, // ] 61 + 0x00, 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ^ 62 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // _ 63 + 0x00, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ` 64 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x19, 0x24, 0x22, 0x22, 0x22, 0x3F, 0x20, // a 65 + 0x08, 0xF8, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // b 66 + 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x20, 0x11, 0x00, // c 67 + 0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0xF8, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x10, 0x3F, 0x20, // d 68 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x22, 0x22, 0x22, 0x22, 0x13, 0x00, // e 69 + 0x00, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x18, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // f 70 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x6B, 0x94, 0x94, 0x94, 0x93, 0x60, 0x00, // g 71 + 0x08, 0xF8, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // h 72 + 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // i 73 + 0x00, 0x00, 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, // j 74 + 0x08, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x24, 0x02, 0x2D, 0x30, 0x20, 0x00, // k 75 + 0x00, 0x08, 0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // l 76 + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x3F, 0x20, 0x00, 0x3F, // m 77 + 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // n 78 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // o 79 + 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xA1, 0x20, 0x20, 0x11, 0x0E, 0x00, // p 80 + 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0xA0, 0xFF, 0x80, // q 81 + 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x20, 0x3F, 0x21, 0x20, 0x00, 0x01, 0x00, // r 82 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x33, 0x24, 0x24, 0x24, 0x24, 0x19, 0x00, // s 83 + 0x00, 0x80, 0x80, 0xE0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x00, 0x00, // t 84 + 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x10, 0x3F, 0x20, // u 85 + 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0E, 0x30, 0x08, 0x06, 0x01, 0x00, // v 86 + 0x80, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80, 0x80, 0x0F, 0x30, 0x0C, 0x03, 0x0C, 0x30, 0x0F, 0x00, // w 87 + 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x31, 0x2E, 0x0E, 0x31, 0x20, 0x00, // x 88 + 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x81, 0x8E, 0x70, 0x18, 0x06, 0x01, 0x00, // y 89 + 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x21, 0x30, 0x2C, 0x22, 0x21, 0x30, 0x00, // z 90 + 0x00, 0x00, 0x00, 0x00, 0x80, 0x7C, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x40, // { 91 + 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, // | 92 + 0x00, 0x02, 0x02, 0x7C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x00, 0x00, // } 93 + 0x00, 0x06, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ~ 94 +}; + +const unsigned char BMP1[] = { + 0x00, 0x03, 0x05, 0x09, 0x11, 0xFF, 0x11, 0x89, 0x05, 0xC3, 0x00, 0xE0, 0x00, 0xF0, 0x00, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x28, 0xFF, 0x11, 0xAA, 0x44, 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, 0x00, 0x00, 0x00, 0x00, 0x83, 0x01, 0x38, 0x44, 0x82, 0x92, + 0x92, 0x74, 0x01, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x44, 0xC7, 0x01, 0x7D, + 0x7D, 0x7D, 0x7D, 0x01, 0x7D, 0x7D, 0x7D, 0x7D, 0x01, 0x7D, 0x7D, 0x7D, 0x7D, 0x01, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, + 0x6D, 0x6D, 0x6D, 0x6D, 0x6D, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x40, 0x40, + 0x40, 0x40, 0x40, 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, 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, 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0x00, 0x00, + 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0x00, 0x00, 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0x00, 0x00, 0xDB, 0xDB, + 0xDB, 0xDB, 0xDB, 0x00, 0x00, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0x00, 0x00, 0xD8, 0xD8, 0xD8, 0xD8, + 0xD8, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, + 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x80, + 0x80, 0x80, 0x80, 0x80, 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, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x00, 0x00, 0x06, 0x06, 0x06, 0xE6, 0x66, 0x20, 0x00, 0x06, 0x06, 0x86, 0x06, + 0x06, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x86, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, + 0x00, 0x86, 0x86, 0x86, 0x86, 0x86, 0x80, 0x80, 0x86, 0x86, 0x06, 0x86, 0x86, 0xC0, 0xC0, 0x86, + 0x86, 0x86, 0x06, 0x06, 0xD0, 0x30, 0x76, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 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, 0x60, 0x1C, 0x00, 0xFE, 0x00, 0x01, + 0x02, 0x00, 0xC4, 0x18, 0x20, 0x02, 0x9E, 0x63, 0xB2, 0x0E, 0x00, 0xFF, 0x81, 0x81, 0xFF, 0x00, + 0x00, 0x80, 0x40, 0x30, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x23, 0xEA, 0xAA, 0xBF, 0xAA, + 0xEA, 0x03, 0x3F, 0x00, 0xFF, 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, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 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, 0x0E, 0x0C, 0x08, 0x00, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x81, 0x80, 0x80, 0x81, 0x80, + 0x81, 0x80, 0x80, 0x80, 0x80, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x01, 0x09, 0x0C, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, + 0x00, 0x1E, 0x21, 0x40, 0x40, 0x50, 0x21, 0x5E, 0x00, 0x1E, 0x21, 0x40, 0x40, 0x50, 0x21, 0x5E, + 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, 0xFF, 0xFF, 0xC1, 0xC1, 0xFF, + 0xFF, 0xC1, 0xC1, 0xFF, 0xFF, 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, 0xFF, 0xFF, 0x80, 0xFC, 0xF3, 0xEF, 0xF3, 0xFC, + 0x80, 0xFF, 0x80, 0xEE, 0xEE, 0xEE, 0xF5, 0xFB, 0xFF, 0x9C, 0xBE, 0xB6, 0xB6, 0x88, 0xFF, 0x00, + /* MP3_UI.bmp */ +}; +#endif // _CODE_TAB_H__ diff --git a/CompleteApps/SmartFanDevice/smartfan/include/common.h b/CompleteApps/SmartFanDevice/smartfan/include/common.h new file mode 100644 index 0000000000000000000000000000000000000000..850a4d15be4dab2c537c96150765732d18533855 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/common.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WINDER_COMMON_H__ +#define __WINDER_COMMON_H__ + + +/** + * @brief Init the common device + * + * @since 1.0 + * @version 1.0 + * + */ +void DeviceInit(void); + +#endif /* __WINDER_COMMON_H__ */ diff --git a/CompleteApps/SmartFanDevice/smartfan/include/defines.h b/CompleteApps/SmartFanDevice/smartfan/include/defines.h new file mode 100644 index 0000000000000000000000000000000000000000..02368c31e1fe5304b840b8aec25f7a3e3a31272b --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/defines.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __DEFINES_H__ +#define __DEFINES_H__ + +#include +#include + +#include + +#define LOG_E(fmt, arg...) printf("[ERROR][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define LOG_D(fmt, arg...) printf("[DEBUG][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define LOG_I(fmt, arg...) printf("[INFO ][%s|%d]" fmt, __func__, __LINE__, ##arg) + +#define FANDBG(fmt, args...) printf("[FAN_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) +#define FANERR(fmt, args...) printf("[FAN_ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) +#define FANPRN(fmt, args...) printf("[FAN_INFO ][%s|%d]" fmt, __func__, __LINE__, ##args) + +#define KEY_ERR(fmt, args...) printf("[KEY_ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) +#define KEY_DBG(fmt, args...) printf("[KEY_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) +#define KEY_PRT(fmt, args...) printf("[KEY_INFO ][%s|%d]" fmt, __func__, __LINE__, ##args) + +#define NET_ERR(fmt, args...) printf("[NETCFG_ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) +#define NET_DBG(fmt, args...) printf("[NETCFG_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) +#define NET_PRT(fmt, args...) printf("[NETCFG_INFO ][%s|%d]" fmt, __func__, __LINE__, ##args) + +#define OLED_ERR(fmt, arg...) printf("[OLED_ERROR][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define OLED_DBG(fmt, arg...) printf("[OLED_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define OLED_PRT(fmt, arg...) printf("[OLED_INFO ][%s|%d]" fmt, __func__, __LINE__, ##arg) + +#define PWM_ERR(fmt, arg...) printf("[PWM_ERROR][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define PWM_DBG(fmt, arg...) printf("[PWM_DEBUG][%s|%d]" fmt, __func__, __LINE__, ##arg) +#define PWM_PRT(fmt, arg...) printf("[PWM_INFO ][%s|%d]" fmt, __func__, __LINE__, ##arg) + + +#define REQUEST_OK 200 +#define REQUEST_ERR 401 + +#define BUF_SHORT_SIZE 256 + +#define DELAY_100MS 10 // for function osDelay(), unit 10ms +#define DELAY_200MS (DELAY_100MS * 2) +#define DELAY_500MS (DELAY_100MS * 5) +#define DELAY_1000MS (DELAY_100MS * 10) +#define DELAY_2000MS (DELAY_100MS * 20) +#define DELAY_5000MS (DELAY_100MS * 50) + +#define USLEEP_100MS 100000 // for function usleep(), unit 1us +#define USLEEP_200MS (USLEEP_100MS * 2) +#define USLEEP_500MS (USLEEP_100MS * 5) +#define USLEEP_1000MS (USLEEP_100MS * 10) +#define USLEEP_2000MS (USLEEP_100MS * 20) +#define USLEEP_2500MS (USLEEP_100MS * 25) +#define USLEEP_5000MS (USLEEP_100MS * 50) + +#define ARRAYSIZE(a) (sizeof((a)) / sizeof((a)[0])) + +#define HOT_AP_NAME "SmartFan_AP" + +#endif /* __DEFINES_H__ */ diff --git a/CompleteApps/SmartFanDevice/smartfan/include/fan.h b/CompleteApps/SmartFanDevice/smartfan/include/fan.h new file mode 100644 index 0000000000000000000000000000000000000000..67ff0527a0e41dd4ae69c04e15dd224e1ac31fdc --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/fan.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __FAN_H__ +#define __FAN_H__ + +#include + +#define FAN_TASK_STACK_SIZE (1024*4) +#define FAN_TASK_PRIO (25) + +#define FANUPD_TASK_STACK_SIZE (1024) +#define FANUPD_TASK_PRIO (33) + +#define FAN_LOOP_DELAY (500) +#define TIMER_HALF_HOUR 30 +#define TIMER_ONE_HOUR 60 +#define TIMER_MAX_HOURS 8 +#define TIMER_60_SECOND 60 + +#define FAN_MAX_SCOP 4 + + +#define ASCII_0 ('0') +#define ASCII_1 ('1') + +#define TICKS_NUMBER (100) // 1 ticks = 10ms +#define SPEED_INCREASE 0 +#define SPEED_REDUCTION 1 + +#define BUF_SIZE 128 + +#define POWER_XPOS 0 +#define POWER_YPOS 0 +#define NETSTA_XPOS 0 +#define NETSTA_YPOS 1 +#define MODE_XPOS 0 +#define MODE_YPOS 2 +#define SPEED_XPOS 0 +#define SPEED_YPOS 3 +#define SCOPE_XPOS 0 +#define SCOPE_YPOS 4 +#define TIMER_XPOS 0 +#define TIMER_YPOS 5 +#define TEMP_XPOS 0 +#define TEMP_YPOS 6 + +#define MESSAGE_LEN 256 // 6 +#define FAN_MAX_TEMP 4 +#define FAN_SCOPE_MAX 3 + +typedef enum { + MESSAGE_POWER_OFF = 1, + MESSAGE_SPEED_SET, + MESSAGE_SPEED_MODE, + MESSAGE_SCOP_SET, + MESSAGE_TIMER_ONOFF, + MESSAGE_TEMP_SET, + MESSAGE_TIMER_SET +}MESSAGE_TYPE; + +typedef enum { + FAN_MODE_SLEEP = 1, + FAN_MODE_NATURAL, + FAN_MODE_AUTO, + + FAN_MODE_NBR +}FAN_MODE; + +#endif /* __FAN_H__ */ diff --git a/CompleteApps/SmartFanDevice/smartfan/include/keypad.h b/CompleteApps/SmartFanDevice/smartfan/include/keypad.h new file mode 100644 index 0000000000000000000000000000000000000000..7bdf9875ce76a3fb94a27a388380369428ed5840 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/keypad.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __KEY_PAD_H__ +#define __KEY_PAD_H__ + +#define KEY_TASK_STACK_SIZE (1024*4) +#define KEY_TASK_PRIO (30) +#define KEY_DELAY_TIME (10) + +typedef enum { + KEY_CODE_0, // menu 确认键 + KEY_CODE_1, // speed++ 速度加 + KEY_CODE_2, // speed-- 速度减 + KEY_CODE_3, // mode 风速的模式(普通模式,睡眠模式) + KEY_CODE_4, // scope 转的角度 + + KEY_CODE_N +}KEY_CODE; + +#define KEY_DOWN 1 +#define KEY_UP 0 + +#define KEY_PAD_MENU KEY_CODE_3 +#define KEY_PAD_UP KEY_CODE_1 +#define KEY_PAD_DOWN KEY_CODE_2 +#define KEY_PAD_MODE KEY_CODE_0 +#define KEY_PAD_SCOP KEY_CODE_4 + +#define KEY_PAD_NONE 0xFF + +typedef struct { + KEY_CODE code; + int value; +}KeyEvent; + +/** + * @brief key event callback + * + * @param event -- key event. reference {@KeyEvent} + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +typedef int (*keypad_event_call)(KeyEvent *event); + +/** + * @brief register the key event + * + * @param gcall -- key event callback + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int KeyRegisterInit(keypad_event_call gcall); + +#endif /* __KEY_PAD_H__ */ diff --git a/CompleteApps/SmartFanDevice/smartfan/include/oled.h b/CompleteApps/SmartFanDevice/smartfan/include/oled.h new file mode 100644 index 0000000000000000000000000000000000000000..38ad3e8e9e4b99c891418d4c80007358f9f7bc04 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/oled.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __OLED_H__ +#define __OLED_H__ + +#include "ohos_types.h" + +#define WIFI_IOT_OLED_I2C_IDX_0 0 +#define WIFI_IOT_IO_FUNC_GPIO_13_I2C0_SDA 6 +#define WIFI_IOT_IO_FUNC_GPIO_14_I2C0_SCL 6 + +#define I2C_REG_ARRAY_LEN (64) +#define BH_SEND_BUFF (1) +#define OLED_SEND_BUFF_LEN (28) +#define OLED_SEND_BUFF_LEN2 (25) +#define OLED_SEND_BUFF_LEN3 (27) +#define OLED_SEND_BUFF_LEN4 (29) +#define Max_Column (128) +#define OLED_DEMO_TASK_STAK_SIZE (4096) +#define OLED_DEMO_TASK_PRIORITY (25) + +#define OLED_ADDRESS 0x78 +#define OLED_ADDRESS_WRITE_CMD 0x00 +#define OLED_ADDRESS_WRITE_DATA 0x40 + +#define OLED_CLEAN_SCREEN ((uint8)0x00) + +#define SLEEP_20_MS 20000 +#define SLEEP_100_MS 100000 + +#define DELAY_10_MS 1 +#define DELAY_100_MS 10 +#define DELAY_200_MS 20 +#define DELAY_250_MS 25 +#define DELAY_500_MS 50 +/* ssd1306 register cmd */ +#define DISPLAY_OFF 0xAE +#define SET_LOW_COLUMN_ADDRESS 0x00 +#define SET_HIGH_COLUMN_ADDRESS 0x10 +#define SET_START_LINE_ADDRESS 0x40 +#define SET_PAGE_ADDRESS 0xB0 +#define CONTRACT_CONTROL 0x81 +#define FULL_SCREEN 0xFF +#define SET_SEGMENT_REMAP 0xA1 +#define NORMAL 0xA6 +#define SET_MULTIPLEX 0xA8 +#define DUTY 0x3F +#define SCAN_DIRECTION 0xC8 +#define DISPLAY_OFFSET 0xD3 +#define DISPLAY_TYPE 0x00 +#define OSC_DIVISION 0xD5 +#define DIVISION 0x80 +#define COLOR_MODE_OFF 0xD8 +#define COLOR 0x05 +#define PRE_CHARGE_PERIOD 0xD9 +#define PERIOD 0xF1 +#define PIN_CONFIGUARTION 0xDA +#define CONFIGUARTION 0x12 +#define SET_VCOMH 0xDB +#define VCOMH 0x30 +#define SET_CHARGE_PUMP_ENABLE 0x8D +#define PUMP_ENABLE 0x14 +#define TURN_ON_OLED_PANEL 0xAF +#define CMD_LENGTH 27 + +#define OLED_I2C_WRITE_CMD_SEND_LEN 2 + +#define HORIZONTAL_COORDINATE_OF_SLOGANS 2 +#define VERTICAL_COORDINATE_OF_SLOGANS 3 +#define CHAR_SIZE_OF_LANTTICE_8_16 16 +#define HORI_PIXEL_OF_LANTTICE_8_16 8 + +#define CHAR_SIZE_OF_LANTTICE_HZ_16_16 32 +#define HORI_PIXEL_OF_LANTTICE_HZ_16_16 16 + +#define CHAR_SIZE_OF_LANTTICE_HZ_16_16_1 48 +#define HORI_PIXEL_OF_LANTTICE_HZ_16_16_1 16 +#define HORI_PIXEL_OF_LANTTICE_6_8 6 + +#define LIMIT_HORI_PIXEL 120 +#define MAX_LINE_OF_LANTTICE 8 +#define SET_POSITION_OFFSET 4 +#define MAX_OLED_INIT_CYCLE_TIMES 5 + + +/** + * @brief Oled Init Operations + * + * @since 1.0 + * @version 1.0 + */ +int OledInit(void); + +/** + * @brief Oled set oled ON or OFF + * @param value 0 set oled OFF, others set the oled ON + * + * @since 1.0 + * @version 1.0 + */ +void OledSetOnOff(int value); + +/** + * @brief Oled clear + * + * @since 1.0 + * @version 1.0 + */ +void OledClear(void); + + +/** + * @brief Oled Show str + * + * @param + * str The str that you want show + * length The length of the str that you want show + * x The offset of X axis + * y The offset of Y axis + * charSize The CharSize (eg: 8*6) + * @since 1.0 + * @version 1.0 + */ +void OledShowStr(const char *str, int length, uint8 x, uint8 y, uint8 charSize); + +#endif /* __OLED_H__ */ diff --git a/CompleteApps/SmartFanDevice/smartfan/include/pwm.h b/CompleteApps/SmartFanDevice/smartfan/include/pwm.h new file mode 100644 index 0000000000000000000000000000000000000000..dd9858fe4323bed851ff7d39723b4979f07e0fba --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/pwm.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __PWM_H__ +#define __PWM_H__ + +#include "ohos_types.h" + +#define WIFI_IOT_GPIO_IDX_2 2 +#define IOT_IO_FUNC_GPIO 0 +#define GPIO_PIN_HIGH 1 +#define GPIO_PIN_LOW 0 +#define PWM_DELAY_TIME 100 + +#define PWM_TASK_PRIO 30 +#define PWM_TASK_STACK_SIZE 512 + +typedef enum { + PWM_LEVEL_0 = 0, // 0为关闭PWM,其他对应PWM等级 + PWM_LEVEL_1, + PWM_LEVEL_2, + PWM_LEVEL_3, + PWM_LEVEL_4, + + PWM_LEVEL_NBR +} PWM_LEVEL; + +/** + * @brief pwm init + * + * @since 1.0 + * @version 1.0 + * + * @return 0 success, -1 failed + */ +int PwmInit(void); + +/** + * @brief set pwm level + * @param level -- pwm level, reference {@PWM_LEVEL} + * + * @since 1.0 + * @version 1.0 + * + */ +void PwmSetLevel(PWM_LEVEL level); + +/** + * @brief get pwm level + * + * @since 1.0 + * @version 1.0 + * + * @return the current pwm level + */ +int PwmGetLevel(void); + +#endif /* __PWM_H__ */ diff --git a/CompleteApps/SmartFanDevice/smartfan/include/sensor.h b/CompleteApps/SmartFanDevice/smartfan/include/sensor.h new file mode 100644 index 0000000000000000000000000000000000000000..83334fe431bbb9ff80c4f1b5fb1ffc831b652f40 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/include/sensor.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SENSOR_H__ +#define __SENSOR_H__ + +#define WIFI_IOT_SENSOR_I2C_IDX_0 (0) +#define AHT_SLEEP_20MS (20000) // 20ms +#define AHT_SLEEP_50MS (50000) // 50ms +#define AHT_SLEEP_1S (1000000) // 1s + +#define AHT_DELAY_10MS (1) // 10ms +#define AHT_DELAY_40MS (4) // 40ms +#define AHT_DELAY_100MS (10) // 100ms +#define AHT_DEVICE_ADDR (0x38) // device addr +#define AHT_DEVICE_READ_STATUS (0x71) // befor read tem&humi data need to send cmd to comfir the +#define AHT_DEVICE_INIT_CMD (0xBE) // aht init cmd +#define AHT_DEVICE_TEST_CMD (0xAC) // test cmd +#define AHT_DEVICE_PARAM_HIGH_BYTE (0x33) +#define AHT_DEVICE_PARAM_LOW_BYTE (0x00) +#define AHT_DEVICE_PARAM_INIT_HIGH (0x08) +#define AHT_DEVICE_CALIBRATION (0x80) +#define AHT_DEVICE_CALIBRATION_ERR (0x1C) +#define AHT_DEVICE_CALIBRATION_ERR_R (0x18) +#define AHT_TASK_SLEEP_TIME (20000) // thread sleep 20ms + +#define AHT_REG_ARRAY_LEN (6) +#define AHT_REG_TEMP_BITS_1 (3) +#define AHT_REG_TEMP_BITS_2 (4) +#define AHT_REG_TEMP_BITS_3 (5) +#define AHT_REG_TEMP_OFFSET (16) +#define AHT_REG_TEMP_OFFSET_1 (8) +#define AHT_OC_ARRAY_LEN (6) +#define AHT_SNED_CMD_LEN (3) +#define SENSOR_TASK_STAK_SIZE (1024*4) +#define SENSOR_TASK_PRIORITY (14) +#define AHT_REG_ARRAY_INIT_LEN (1) +#define AHT_CALCULATION (1048576) +#define DECIMAL 10 +#define NUMBER_OF_DECIMAL_POINTS 3 + +typedef enum { + AHT_TEMPERATURE = 1, // TEMP + AHT_HUMIDITY = 2, // HUMI +} aht_serson_type; + + +/** + * @brief The sensor init operation + * + * @return If success return WIFI_IOT_SUCCESS. else return WIFI_IOT_FAILURE. + * @since 1.0 + * @version 1.0 + */ +int SensorInit(void); + + +/** + * @brief Get the temp value of sensor. + * + * @return Return the temp value. + * @since 1.0 + * @version 1.0 + */ +int SensorGetValue(void); + +#endif /* __SENSOR_H__ */ diff --git a/CompleteApps/SmartFanDevice/smartfan/src/common.c b/CompleteApps/SmartFanDevice/smartfan/src/common.c new file mode 100644 index 0000000000000000000000000000000000000000..22caf2af0cc1a72c1da785d2e32b1c7ba6cb033a --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/src/common.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "lwip/if_api.h" +#include "lwip/netifapi.h" +#include "iot_gpio.h" +#include "iot_errno.h" +#include "peripheral_hal.h" +#include "netinet/in.h" +#include "sys/ioctl.h" + +#include "common.h" +#include "defines.h" + +#define I2C_IDX_BAUDRATE (400000) + +#define WIFI_IOT_IO_FUNC_GPIO_13_I2C0_SDA 6 +#define WIFI_IOT_IO_FUNC_GPIO_14_I2C0_SCL 6 +#define WIFI_IOT_I2C_IDX_0 0 + +static void I2cBusInit(void) +{ + IoTGpioInit(HAL_WIFI_IOT_IO_NAME_GPIO_13); + // Set up the gpio funcion as i2c bus 0 + HalIoSetFunc(HAL_WIFI_IOT_IO_NAME_GPIO_13, WIFI_IOT_IO_FUNC_GPIO_13_I2C0_SDA); + + IoTGpioInit(HAL_WIFI_IOT_IO_NAME_GPIO_14); + HalIoSetFunc(HAL_WIFI_IOT_IO_NAME_GPIO_14, WIFI_IOT_IO_FUNC_GPIO_14_I2C0_SCL); + IoTI2cInit(WIFI_IOT_I2C_IDX_0, I2C_IDX_BAUDRATE); // Rate: 400kbps +} + +void DeviceInit(void) +{ + // disable the watchdog + HalSetWatchDogEnable(0); + I2cBusInit(); +} diff --git a/CompleteApps/SmartFanDevice/smartfan/src/fan.c b/CompleteApps/SmartFanDevice/smartfan/src/fan.c new file mode 100644 index 0000000000000000000000000000000000000000..70b6c9acbcf57608cf1dbd377b0ed74cfbca14b5 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/src/fan.c @@ -0,0 +1,711 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include + +#include "json/jsonutil.h" +#include "ohos_init.h" +#include "securec.h" +#include "ohos_types.h" +#include "cmsis_os2.h" +#include "common.h" +#include "keypad.h" +#include "oled.h" +#include "pwm.h" +#include "sensor.h" +#include "defines.h" +#include "fan.h" + +#include "network_manager_service.h" + +#define CMD_KEY "cmd" +#define PAR_KEY "param" +#define VAL_KEY "value" +#define TYP_KEY "type" +#define TIM_KEY "time" +#define DUR_KEY "total" +#define ID__KEY "id" +#define TEMP_MIN "tempMin" +#define TEMP_MAX "tempMax" +#define SPEED_KEY "speed" +#define SHARK_KEY "shark" + +#define FAN_TEMP_NBR 2 + +typedef struct { + uint8 value[FAN_TEMP_NBR]; + uint8 speed; + uint8 scope; + + bool enable; +}TempInfo; + + +typedef struct { + uint8 id; + uint32 times; + uint32 duration; + + bool enable; + uint8 speed; + uint8 scope; + uint8 flag; +}TimerInfo; + +typedef struct { + uint8 power_off; + uint8 speed_level; + uint8 speed_mode; + uint8 shake_scope; + + bool timer_flag; + uint32 timer_count; + + TimerInfo gTimer; + + TempInfo temp_info[FAN_MAX_TEMP]; + + osTimerId_t timerID; +}FanInfo; + +static FanInfo g_fan; +static bool g_netstatus = false; +static const char *g_mode_str[] = {"sleep", "natural", "auto"}; +static const char *g_scop_str[] = {"forbid", "60", "120"}; + +static void ShowPowerStatus(void) +{ + char power_sta[BUF_SIZE] = {0}; + if (sprintf_s(power_sta, BUF_SIZE, "power %s", g_fan.power_off == 1 ? "OFF" : "ON") < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + OledShowStr(" ", strlen(" "), POWER_XPOS, POWER_YPOS, 1); + OledShowStr(power_sta, strlen(power_sta), POWER_XPOS, POWER_YPOS, 1); +} + +static void ShowNetStatus(void) +{ + char netsta_buf[BUF_SIZE] = {0}; + if (sprintf_s(netsta_buf, BUF_SIZE, "net %s", g_netstatus ? "online" : "offline") < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + OledShowStr(" ", strlen(" "), NETSTA_XPOS, NETSTA_YPOS, 1); + OledShowStr(netsta_buf, strlen(netsta_buf), NETSTA_XPOS, NETSTA_YPOS, 1); +} + +static void ShowSpeedMode(void) +{ + char mode_buf[BUF_SIZE] = {0}; + if (sprintf_s(mode_buf, BUF_SIZE, "mode %s", g_mode_str[g_fan.speed_mode - 1]) < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + OledShowStr(" ", strlen(" "), MODE_XPOS, MODE_YPOS, 1); + OledShowStr(mode_buf, strlen(mode_buf), MODE_XPOS, MODE_YPOS, 1); +} + +static void ShowSpeedLevel(int speed_level) +{ + char speed_buf[BUF_SIZE] = {0}; + if (sprintf_s(speed_buf, BUF_SIZE, "wind %d", speed_level) < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + OledShowStr(" ", strlen(" "), SPEED_XPOS, SPEED_YPOS, 1); + OledShowStr(speed_buf, strlen(speed_buf), SPEED_XPOS, SPEED_YPOS, 1); +} + +static void ShowShakeScope(int shake_scope) +{ + char scope_buf[BUF_SIZE] = {0}; + if (shake_scope < 0 || shake_scope >= FAN_SCOPE_MAX) { + FANERR("OOR!\n"); + return; + } + if (sprintf_s(scope_buf, BUF_SIZE, "shake %s", g_scop_str[shake_scope]) < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + OledShowStr(" ", strlen(" "), SCOPE_XPOS, SCOPE_YPOS, 1); + OledShowStr(scope_buf, strlen(scope_buf), SCOPE_XPOS, SCOPE_YPOS, 1); +} + +static void ShowPowerOffTimer(void) +{ + char timer_buf[BUF_SIZE] = {0}; + if (g_fan.timer_flag) { + if (g_fan.gTimer.flag == 0) { + if (sprintf_s(timer_buf, BUF_SIZE, "Timer on %d", g_fan.gTimer.times) < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + } else { + if (sprintf_s(timer_buf, BUF_SIZE, "Timer off %d", g_fan.gTimer.duration) < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + } + } else { + if (sprintf_s(timer_buf, BUF_SIZE, "Timer OFF") < 0) { + FANERR("sprintf_s failed! \n"); + return; + } + } + OledShowStr(" ", strlen(" "), TIMER_XPOS, TIMER_YPOS, 1); + OledShowStr(timer_buf, strlen(timer_buf), TIMER_XPOS, TIMER_YPOS, 1); +} + +static void ShowTemperature(int temp) +{ + char temp_buf[BUF_SIZE] = {}; + static int gTemp = -1; + if (temp == gTemp) { + return; + } + gTemp = temp; + if (gTemp > 0) { + if (sprintf_s(temp_buf, BUF_SIZE, "Temp %d", gTemp) < 0) { + FANERR("get temperature string failed! \n"); + return; + } + } else { + if (sprintf_s(temp_buf, BUF_SIZE, "Temp NONE") < 0) { + return; + } + } + OledShowStr(" ", strlen(" "), TEMP_XPOS, TEMP_YPOS, 1); + OledShowStr(temp_buf, strlen(temp_buf), TEMP_XPOS, TEMP_YPOS, 1); +} + +static void FanShowInfo(void) +{ + ShowPowerStatus(); + ShowNetStatus(); + ShowSpeedMode(); + ShowSpeedLevel(g_fan.speed_level); + ShowShakeScope(g_fan.shake_scope); + ShowPowerOffTimer(); + ShowTemperature(0); +} + +static void UpdateSpeedLevel(void) +{ + ShowSpeedLevel(g_fan.speed_level); +} + +static void UpdateSpeedMode(void) +{ + ShowSpeedMode(); +} + +static int FanDealTempSet(const json_pobject json) +{ + int value, speed, scope, t1, t2; + if (json == NULL) { + FANERR("FanDealPoweroff failed! \n"); + return -1; + } + + value = get_json_int(json, VAL_KEY); + t1 = get_json_int(json, TEMP_MIN); + t2 = get_json_int(json, TEMP_MAX); + speed = get_json_int(json, SPEED_KEY); + scope = get_json_int(json, SHARK_KEY); + + if (speed <= 0 || speed > PWM_LEVEL_4) { + FANERR("SPEED LEVEL OOR! \n"); + return -1; + } + + if (!g_fan.temp_info[speed - 1].enable && !value) { + return; + } + + g_fan.temp_info[speed - 1].enable = value == 1 ? true : false; + g_fan.temp_info[speed - 1].value[0] = t1; + g_fan.temp_info[speed - 1].value[1] = t2; + g_fan.temp_info[speed - 1].speed = speed; + g_fan.temp_info[speed - 1].scope = scope; + + g_fan.speed_mode = FAN_MODE_AUTO; + + UpdateSpeedMode(); + + return 0; +} + +static int FanDealTimerSet(const json_pobject json) +{ + int tm, tt, id, value, speed, scope; + if (json == NULL) { + FANERR("FanDealPoweroff failed! \n"); + return -1; + } + FANDBG("%s \n", json_to_string(json)); + id = get_json_int(json, ID__KEY); + value = get_json_int(json, VAL_KEY); + tm = get_json_int(json, TIM_KEY); + tt = get_json_int(json, DUR_KEY); + speed = get_json_int(json, SPEED_KEY); + scope = get_json_int(json, SHARK_KEY); + if (scope > FAN_SCOPE_MAX) { + scope = FAN_SCOPE_MAX; + } + if (g_fan.gTimer.id == 0 || g_fan.gTimer.enable == false) { + g_fan.gTimer.id = id; + g_fan.gTimer.enable = value == 1 ? true : false; + g_fan.gTimer.times = tm * TIMER_60_SECOND; + g_fan.gTimer.duration = tt * TIMER_60_SECOND; + g_fan.gTimer.speed = speed; + g_fan.gTimer.scope = scope; + if (g_fan.power_off == 0 || g_fan.gTimer.times == 0) { + g_fan.gTimer.flag = 1; + PwmSetLevel(g_fan.gTimer.speed); + ShowSpeedLevel(g_fan.gTimer.speed); + ShowShakeScope(g_fan.gTimer.scope); + } else { + g_fan.gTimer.flag = 0; + } + if (g_fan.gTimer.enable) { + g_fan.timer_flag = 1; + } else { + g_fan.timer_flag = 0; + } + ShowPowerOffTimer(); + } + + return 0; +} + +static int FanDealScope(const json_pobject json) +{ + int value; + if (json == NULL) { + FANERR("FanDealPoweroff failed! \n"); + return -1; + } + value = get_json_int(json, VAL_KEY); + if (g_fan.shake_scope != value && value <= FAN_SCOPE_MAX) { + g_fan.shake_scope = value; + ShowShakeScope(g_fan.shake_scope); + } + + return 0; +} + +static int FanDealMode(const json_pobject json) +{ + int value; + bool updateSpeed = false; + if (json == NULL) { + FANERR("FanDealPoweroff failed! \n"); + return -1; + } + value = get_json_int(json, VAL_KEY); + FANDBG("g_fan.speed_mode : %d, value : %d \n", g_fan.speed_mode, value); + if (g_fan.speed_mode != value) { + g_fan.speed_mode = value; + if (g_fan.speed_mode == FAN_MODE_SLEEP && g_fan.speed_level > PWM_LEVEL_2) { + g_fan.speed_level = PWM_LEVEL_1; + updateSpeed = true; + } else if (g_fan.speed_mode == FAN_MODE_NATURAL && g_fan.speed_level < PWM_LEVEL_3) { + g_fan.speed_level = PWM_LEVEL_3; + updateSpeed = true; + } + PwmSetLevel(g_fan.speed_level); + ShowSpeedMode(); + if (updateSpeed) { + UpdateSpeedLevel(); + } + } +} + +static int FanDealSpeed(const json_pobject json) +{ + int value; + bool updateMode = false; + if (json == NULL) { + FANERR("FanDealPoweroff failed! \n"); + return -1; + } + value = get_json_int(json, VAL_KEY); + FANDBG("g_fan.speed_level = %d, value=%d \n", g_fan.speed_level, value); + if (g_fan.speed_level != value) { + g_fan.speed_level = value; + PwmSetLevel(g_fan.speed_level); + if (g_fan.speed_level < PWM_LEVEL_3 && g_fan.speed_mode != FAN_MODE_SLEEP) { + g_fan.speed_mode = FAN_MODE_SLEEP; + updateMode = true; + } else if (g_fan.speed_level >= PWM_LEVEL_3 && g_fan.speed_mode != FAN_MODE_NATURAL) { + g_fan.speed_mode = FAN_MODE_NATURAL; + updateMode = true; + } + + ShowSpeedLevel(g_fan.speed_level); + if (updateMode) { + UpdateSpeedMode(); + } + } + + return 0; +} + +static int FanDealPoweroff(const json_pobject json) +{ + int value; + if (json == NULL) { + FANERR("FanDealPoweroff failed! \n"); + return -1; + } + value = get_json_int(json, VAL_KEY); + if (value == 0) { + g_fan.power_off = 1; + PwmSetLevel(PWM_LEVEL_0); + } else { + g_fan.power_off = 0; + PwmSetLevel(g_fan.speed_level); + } + ShowPowerStatus(); + + return 0; +} + +typedef struct { + int cmd; + int (*ProcessFunc)(const json_pobject json); +} MsgProcess; + +static MsgProcess g_msgProcess[] = { + {MESSAGE_POWER_OFF, FanDealPoweroff}, + {MESSAGE_SPEED_SET, FanDealSpeed}, + {MESSAGE_SPEED_MODE, FanDealMode}, + {MESSAGE_SCOP_SET, FanDealScope}, + {MESSAGE_TIMER_SET, FanDealTimerSet}, + {MESSAGE_TEMP_SET, FanDealTempSet} +}; + +static void FanProcessAppMessage(const char *data, int data_len) +{ + int cmd; + json_handle json; + json_pobject sub; + FANDBG("data : %s \n", data); + json = parse_json(data); + if (json == NULL) { + FANERR("parse_json\n"); + return -1; + } + + cmd = get_json_int(json, CMD_KEY); + sub = get_json_obj(json, PAR_KEY); + if (sub == NULL) { + FANERR("get param obj failed! \n"); + free_json(json); + return -1; + } + + FANDBG("cmd=%d \n", cmd); + for (uint8 i = 0; i < ARRAYSIZE(g_msgProcess); i++) { + if (g_msgProcess[i].cmd == cmd) { + if (g_msgProcess[i].ProcessFunc(sub) < 0) { + FANERR("do process func failed! \n"); + } + break; + } + } +} + +static int GenerateJsonData(char *buff, int length, int cmd, int value) +{ + int retval = 0; + json_pobject json = create_json_object(); + json_pobject obj = add_number_to_object(json, CMD_KEY, cmd); + json_pobject obj1 = add_object_to_object(json, PAR_KEY); + json_pobject obj2 = add_number_to_object(obj1, VAL_KEY, value); + + char *msg = json_to_string(json); + if (strncpy_s(buff, length, msg, strlen(msg)) < 0) { + retval = -1; + } + FANDBG("retval=%d, msg:%s, buff:%s \n", retval, msg, buff); + delete_json_object(json); + + return retval; +} + +static int FanSpeedChange(int position, char *message_buf, int length) +{ + uint8 value; + if (message_buf == NULL || length < MESSAGE_LEN) { + FANERR("NULL POINT!\n"); + return -1; + } + + if (position == SPEED_INCREASE) { + if (g_fan.speed_level == PWM_LEVEL_4) + return 1; + value = g_fan.speed_level + 1; + } else { + if (g_fan.speed_level == PWM_LEVEL_1) + return 1; + value = g_fan.speed_level - 1; + } + + return GenerateJsonData(message_buf, length, MESSAGE_SPEED_SET, value); +} + +static int FanPowerOff(char *message_buf, int length) +{ + uint8 value; + if (message_buf == NULL || length < MESSAGE_LEN) { + FANERR("NULL POINT!\n"); + return -1; + } + g_fan.power_off = !g_fan.power_off; + value = g_fan.power_off; + + return GenerateJsonData(message_buf, length, MESSAGE_POWER_OFF, value); +} + +static int FanSpeedIncrease(char *buff, int length) +{ + return FanSpeedChange(SPEED_INCREASE, buff, length); +} + +static int FanSpeedReduction(char *buff, int length) +{ + return FanSpeedChange(SPEED_REDUCTION, buff, length); +} + +typedef struct { + int keycode; + int (*KeyFunc)(char *buff, int length); +}KeyProcess; + +static KeyProcess g_keyProcess[] = { + {KEY_PAD_UP, FanSpeedIncrease}, + {KEY_PAD_DOWN, FanSpeedReduction}, + {KEY_PAD_MODE, FanPowerOff} +}; + +static int FanKeyEventHandle(KeyEvent *event) +{ + char message_buf[MESSAGE_LEN + 1] = {0}; + bool message_ready = false; + + FANDBG("keycode = %d \n", event->code); + for (uint8 i = 0; i < ARRAYSIZE(g_keyProcess); i++) { + if (event->code == g_keyProcess[i].keycode) { + if (g_keyProcess[i].KeyFunc(message_buf, sizeof(message_buf)) == 0) { + message_ready = true; + break; + } + } + } + + if (message_ready) { // effective button + FanProcessAppMessage((const char *)message_buf, strlen(message_buf)); // message function + FANDBG("message_buf : %s \n\n", message_buf); + NetManagerSendMsg((char *)message_buf); // send message to FA + } + + return 0; +} + +static int FanNetEventHandler(NET_EVENT_TYPE event, const void *data) +{ + FANDBG("event = %d \n", event); + switch (event) { + case NET_EVENT_CONNECTTED: + g_netstatus = true; + ShowNetStatus(); + break; + case NET_EVENT_RECV_DATA: + FanProcessAppMessage((const char *)data, strlen(data)); + break; + default: + break; + } + return 0; +} + +typedef struct { + int w_speed; + int w_scope; +}UpdateInfo; + +static void *FanUpdateTask(void *args) +{ + UpdateInfo *info = (UpdateInfo *)args; + PwmSetLevel(info->w_speed); + ShowSpeedLevel(info->w_speed); + ShowShakeScope(info->w_scope); + // notify FA the status changed + + return NULL; +} + +static void FanUpdate(int speed, int scope) +{ + UpdateInfo info; + osThreadAttr_t attr; + attr.name = "updateTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = FANUPD_TASK_STACK_SIZE; + attr.priority = FANUPD_TASK_PRIO; + info.w_speed = speed; + info.w_scope = scope; + + if (osThreadNew((osThreadFunc_t)FanUpdateTask, &info, &attr) == NULL) { + FANERR("Falied to create FanUpdateTask!\n"); + } +} + +static void FanTimerHandler(void *arg) +{ + (void)arg; + + if (g_fan.timer_flag) { + if (g_fan.gTimer.flag == 0) { + if (--g_fan.gTimer.times <= 0) { + g_fan.gTimer.times = 0; + g_fan.gTimer.flag = 1; + g_fan.power_off = 0; + FanUpdate(g_fan.gTimer.speed, g_fan.gTimer.scope); + } + } else { + if (--g_fan.gTimer.duration <= 0) { + g_fan.timer_flag = 0; + g_fan.gTimer.duration = 0; + g_fan.gTimer.flag = 0; + g_fan.gTimer.enable = false; + FanUpdate(g_fan.speed_level, g_fan.shake_scope); + } + } + } +} + +static void FanStartTimer(void) +{ + g_fan.timerID = osTimerNew(&FanTimerHandler, osTimerPeriodic, NULL, NULL); + osTimerStart(g_fan.timerID, TICKS_NUMBER); +} + +static int FanGetTempLevel(int temp) +{ + for (int i = 0; i < FAN_MAX_TEMP; i++) { + if (g_fan.temp_info[i].enable && + temp >= g_fan.temp_info[i].value[0] && + temp < g_fan.temp_info[i].value[1]) { + g_fan.shake_scope = g_fan.temp_info[i].scope; + + return g_fan.temp_info[i].speed; + } + } + + return 0; +} + +static void FanInit(void) +{ + DeviceInit(); + PwmInit(); + SensorInit(); + + if (OledInit() != 0) { + FANERR("OledInit failed! \n"); + while (1) { + } + } +} + +static void FanLoop(void) +{ + while (1) { + if (g_fan.power_off) { + if (PwmGetLevel() != PWM_LEVEL_0) { + PwmSetLevel(PWM_LEVEL_0); + ShowSpeedLevel(g_fan.speed_level); // display the speedlevel + ShowPowerStatus(); + } + osDelay(FAN_LOOP_DELAY); + continue; + } + if (g_fan.speed_mode == FAN_MODE_AUTO) { + int speed; + int temp = SensorGetValue(); + speed = FanGetTempLevel(temp); + if (speed != 0 && speed != g_fan.speed_level) { + FANDBG("speed = %d \n", speed); + g_fan.speed_level = speed; + PwmSetLevel(g_fan.speed_level); + ShowSpeedLevel(g_fan.speed_level); + ShowShakeScope(g_fan.shake_scope); + // notify FA the status changed + } + ShowTemperature(temp); + } + osDelay(FAN_LOOP_DELAY); + } +} + +static void *FanTask(const char *arg) +{ + (void)arg; + FANDBG("FanTask Enter! \n"); + FanInit(); + (void)memset_s(&g_fan, sizeof(g_fan), 0x00, sizeof(g_fan)); + g_fan.speed_mode = FAN_MODE_SLEEP; + g_fan.speed_level = PWM_LEVEL_1; + + if (KeyRegisterInit(FanKeyEventHandle) != 0) { // register button callback + FANERR("KeyRegisterInit failed!!! \n"); + } + + FanStartTimer(); // timer start + + NetManagerRegister(HOT_AP_NAME, FanNetEventHandler); + FanShowInfo(); + + FanLoop(); +} + +void FanDemoEntry(void) +{ + osThreadAttr_t attr; + attr.name = "FanTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = FAN_TASK_STACK_SIZE; + attr.priority = FAN_TASK_PRIO; + + if (osThreadNew((osThreadFunc_t)FanTask, NULL, &attr) == NULL) { + FANERR("Falied to create FanTask!\n"); + } +} + +SYS_RUN(FanDemoEntry); diff --git a/CompleteApps/SmartFanDevice/smartfan/src/keypad.c b/CompleteApps/SmartFanDevice/smartfan/src/keypad.c new file mode 100644 index 0000000000000000000000000000000000000000..a1c4d3c96a531955774357f9225119d041256c21 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/src/keypad.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "iot_gpio.h" +#include "iot_errno.h" + +#include "peripheral_hal.h" +#include "keypad.h" +#include "defines.h" + +#include "ohos_types.h" + +#define ADC_TIME_COUNT 20 + +enum { + ADC_S0_MIN = 5, + ADC_S0_MAX = 228, + ADC_S1_MIN, + ADC_S1_MAX = 512, + ADC_S2_MIN, + ADC_S2_MAX = 854 +}; + +static KEY_CODE KeyPadGetKey(void) +{ + unsigned short data = 0; + if (HalAdcRead(HAL_WIFI_IOT_ADC_CHANNEL_2, &data, HAL_WIFI_IOT_ADC_EQU_MODEL_4, + HAL_WIFI_IOT_ADC_CUR_BAIS_DEFAULT, ADC_TIME_COUNT) == 0) { + if ((ADC_S0_MIN <= data) && (data <= ADC_S0_MAX)) return KEY_PAD_MODE; + if ((ADC_S1_MIN <= data) && (data <= ADC_S1_MAX)) return KEY_PAD_UP; + if ((ADC_S2_MIN <= data) && (data <= ADC_S2_MAX)) return KEY_PAD_DOWN; + } + + return KEY_PAD_NONE; +} + +static void *KeyEventTask(const char *args) +{ + uint8 keycode = KEY_PAD_NONE; + keypad_event_call g_event_call = (keypad_event_call)args; + if (g_event_call == NULL) { + KEY_ERR("no key event call! \n"); + } + while (1) { + KEY_CODE key = KeyPadGetKey(); + if (keycode == key) { + osDelay(KEY_DELAY_TIME); + continue; + } + keycode = key; + if (keycode == KEY_PAD_NONE) { + osDelay(KEY_DELAY_TIME); + continue; + } + + if (g_event_call != NULL) { + KeyEvent e; + e.code = keycode; + e.value = 1; + g_event_call(&e); + } + } + + return NULL; +} + +int KeyRegisterInit(keypad_event_call gcall) +{ + osThreadAttr_t attr; + attr.name = "KeyEventTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = KEY_TASK_STACK_SIZE; + attr.priority = KEY_TASK_PRIO; + + if (osThreadNew((osThreadFunc_t)KeyEventTask, gcall, &attr) == NULL) { + KEY_ERR("Falied to create KeyEventTask! \n"); + } + + return 0; +} diff --git a/CompleteApps/SmartFanDevice/smartfan/src/oled.c b/CompleteApps/SmartFanDevice/smartfan/src/oled.c new file mode 100644 index 0000000000000000000000000000000000000000..a10243dc067dc332396ed52242050a6d2e77c14a --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/src/oled.c @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "kal.h" +#include "iot_errno.h" +#include "iot_i2c.h" + +#include "oled.h" +#include "code_tab.h" + +#include "defines.h" + + +static uint8 OledInitCmd[CMD_LENGTH] = { + DISPLAY_OFF, // Display off + SET_LOW_COLUMN_ADDRESS, // ---set low column address + SET_HIGH_COLUMN_ADDRESS, // ---set high column address + SET_START_LINE_ADDRESS, // --set start line address + SET_PAGE_ADDRESS, // --set page address + CONTRACT_CONTROL, // contract control + FULL_SCREEN, // --128 + SET_SEGMENT_REMAP, // set segment remap + NORMAL, + SET_MULTIPLEX, // --set multiplex ratio(1 to 64) + DUTY, // --1/32 duty + SCAN_DIRECTION, // Com scan direction + DISPLAY_OFFSET, // -set display offset + DISPLAY_TYPE, + OSC_DIVISION, // set osc division + DIVISION, + COLOR_MODE_OFF, // set area color mode off + COLOR, + PRE_CHARGE_PERIOD, // set Pre-Charge Period + PERIOD, + PIN_CONFIGUARTION, // set com pin configuartion + CONFIGUARTION, + SET_VCOMH, // set Vcomh + VCOMH, + SET_CHARGE_PUMP_ENABLE, // set charge pump enable + PUMP_ENABLE, + TURN_ON_OLED_PANEL // --turn on oled panel +}; + + +/* I2C write Byte */ +static uint32 I2cWriteByte(uint8 regAddr, uint8 i2cData) +{ + uint32 status; + uint8 sendBuf[2]; + sendBuf[0] = regAddr; + sendBuf[1] = i2cData; + + status = IoTI2cWrite(WIFI_IOT_OLED_I2C_IDX_0, OLED_ADDRESS, sendBuf, sizeof(sendBuf)); + if (status != IOT_SUCCESS) { + OLED_ERR("===== Error: SSD1306 OLED Screen I2C write status = 0x%x! =====\r\n", status); + } + + return status; +} + +static uint32 WriteCmd(uint8 cmd) +{ + return I2cWriteByte(OLED_ADDRESS_WRITE_CMD, cmd); +} + +static uint32 WriteData(uint8 data) +{ + return I2cWriteByte(OLED_ADDRESS_WRITE_DATA, data); +} + +static void OledSetPosition(uint8 x, uint8 y) +{ + if (IOT_SUCCESS != WriteCmd(0xb0 + y)) { + OLED_ERR("WriteCmd Error \n"); + return; + } + + if (IOT_SUCCESS != WriteCmd(((x&0xf0)>>SET_POSITION_OFFSET) | 0x10)) { + OLED_ERR("WriteCmd Error \n"); + return; + } + + if (IOT_SUCCESS != WriteCmd(x & 0x0f)) { + OLED_ERR("WriteCmd Error \n"); + return; + } +} + +static void OledFillScreen(uint8 fii_data) +{ + for (uint8 m = 0; m < MAX_LINE_OF_LANTTICE; m++) { + if (IOT_SUCCESS != WriteCmd(0xb0 + m)) { + OLED_ERR("WriteCmd Error \n"); + return; + } + + if (IOT_SUCCESS != WriteCmd(0x00)) { + OLED_ERR("WriteCmd Error \n"); + return; + } + + if (IOT_SUCCESS != WriteCmd(0x10)) { + OLED_ERR("WriteCmd Error \n"); + return; + } + + for (uint8 n = 0; n < Max_Column; n++) { + if (IOT_SUCCESS != WriteData(fii_data)) { + OLED_ERR("WriteData Error \n"); + return; + } + } + } +} + +static void OledShowChar(uint8 x, uint8 y, uint8 chr, uint8 charSize) +{ + uint8 i; + uint8 c = chr - ' '; // calc the offset + + if (charSize == CHAR_SIZE_OF_LANTTICE_8_16) { + OledSetPosition(x, y); + for (i = 0; i < HORI_PIXEL_OF_LANTTICE_8_16; i++) { + WriteData(F8X16[c*CHAR_SIZE_OF_LANTTICE_8_16 + i ]); + } + OledSetPosition(x, y + 1); + for (i = 0; i < HORI_PIXEL_OF_LANTTICE_8_16; i++) { + WriteData(F8X16[c*CHAR_SIZE_OF_LANTTICE_8_16 + i + HORI_PIXEL_OF_LANTTICE_8_16]); + } + } else if (charSize == CHAR_SIZE_OF_LANTTICE_HZ_16_16) { + c = chr - '0'; + OledSetPosition(x, y); + for (i = 0; i < HORI_PIXEL_OF_LANTTICE_HZ_16_16; i++) { + WriteData(HZ_F16X16[c][0][i]); + } + + OledSetPosition(x, y + 1); + for (i = 0; i < HORI_PIXEL_OF_LANTTICE_HZ_16_16; i++) { + WriteData(HZ_F16X16[c][1][i]); + } + } else if (charSize == CHAR_SIZE_OF_LANTTICE_HZ_16_16_1) { + c = chr - '0'; + OledSetPosition(x, y); + for (i = 0; i < HORI_PIXEL_OF_LANTTICE_HZ_16_16_1; i++) { + WriteData(HZ_F16X16_1[c][0][i]); + } + OledSetPosition(x, y + 1); + for (i = 0; i < HORI_PIXEL_OF_LANTTICE_HZ_16_16_1; i++) { + WriteData(HZ_F16X16_1[c][1][i]); + } + } else { + OledSetPosition(x, y); + for (i = 0; i < HORI_PIXEL_OF_LANTTICE_6_8; i++) { + WriteData(F6X8[c][i]); + } + } +} + +// oled init +int OledInit(void) +{ + uint32 status; + osDelay(DELAY_100_MS); // 100ms Keep the power supply stable. + + for (int i = 0; i < CMD_LENGTH; i++) { + status = WriteCmd(OledInitCmd[i]); + if (status != IOT_SUCCESS) { + OLED_ERR("Failed to write OledInitCmd: 0x%x \n", OledInitCmd[i]); + return IOT_FAILURE; + } + } + + OledFillScreen(0x00); // The screen off + + osDelay(DELAY_10_MS); // 10ms + OledShowStr("OpenHarmony OS", strlen("OpenHarmony OS"), HORIZONTAL_COORDINATE_OF_SLOGANS, + VERTICAL_COORDINATE_OF_SLOGANS, 1); + osDelay(DELAY_500_MS); // The time of keep display + OledShowStr(" ", strlen(" "), HORIZONTAL_COORDINATE_OF_SLOGANS, + VERTICAL_COORDINATE_OF_SLOGANS, 1); + + OLED_PRT("OledInit succuss\n"); + + return IOT_SUCCESS; +} + +void OledSetOnOff(int value) +{ + (void)value; +} + +void OledClear(void) +{ + OledFillScreen(0x00); // The screen off +} + +void OledShowStr(const char *str, int length, uint8 x, uint8 y, uint8 charSize) +{ + uint8 i; + if (str == NULL || length <= 0) { + OLED_ERR("no str to show! \n"); + return; + } + + if (x >= LIMIT_HORI_PIXEL) { + OLED_ERR("please input the correct x coord! \n"); + return; + } + + for (i = 0; i < length; i++) { + OledShowChar(x, y, str[i], charSize); + if (charSize == CHAR_SIZE_OF_LANTTICE_HZ_16_16 || charSize == CHAR_SIZE_OF_LANTTICE_HZ_16_16_1) { + x += HORI_PIXEL_OF_LANTTICE_HZ_16_16; + } else { + x += HORI_PIXEL_OF_LANTTICE_8_16; + } + } +} \ No newline at end of file diff --git a/CompleteApps/SmartFanDevice/smartfan/src/pwm.c b/CompleteApps/SmartFanDevice/smartfan/src/pwm.c new file mode 100644 index 0000000000000000000000000000000000000000..a15bb10a482cc6b553fddffddba042802009f30c --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/src/pwm.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "iot_gpio.h" +#include "iot_errno.h" +#include "cmsis_os2.h" +#include "base64.h" +#include "ohos_types.h" + +#include "peripheral_hal.h" +#include "pwm.h" +#include "defines.h" + +static uint8 g_level = PWM_LEVEL_1; + + +static void *PwmProcess(const char *arg) +{ + (void)arg; + int delayTimes = 0; + + IoTGpioInit(WIFI_IOT_GPIO_IDX_2); + HalIoSetFunc(HAL_WIFI_IOT_IO_NAME_GPIO_2, IOT_IO_FUNC_GPIO); + IoTGpioSetDir(WIFI_IOT_GPIO_IDX_2, IOT_GPIO_DIR_OUT); + + while (1) { + if (g_level == PWM_LEVEL_0) { // when the PWM is set close + IoTGpioSetOutputVal(WIFI_IOT_GPIO_IDX_2, GPIO_PIN_LOW); + osDelay(PWM_DELAY_TIME); + continue; + } + + if (g_level >= PWM_LEVEL_NBR) + g_level = PWM_LEVEL_1; + + IoTGpioSetOutputVal(WIFI_IOT_GPIO_IDX_2, GPIO_PIN_HIGH); + delayTimes = PWM_DELAY_TIME / (PWM_LEVEL_NBR - g_level); + osDelay(delayTimes); + + IoTGpioSetOutputVal(WIFI_IOT_GPIO_IDX_2, GPIO_PIN_LOW); + delayTimes = PWM_DELAY_TIME / g_level; + osDelay(delayTimes); + } +} + + +int PwmInit(void) +{ + osThreadAttr_t attr; + attr.name = "PwmProcess"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = PWM_TASK_STACK_SIZE; + attr.priority = PWM_TASK_PRIO; + + if (osThreadNew((osThreadFunc_t)PwmProcess, NULL, &attr) == NULL) { + PWM_ERR("Falied to create NanCfgNetTask!\n"); + return -1; + } + + return 0; +} + +void PwmSetLevel(PWM_LEVEL level) +{ + if (level >= 0 && level < PWM_LEVEL_NBR) + g_level = level; +} + +int PwmGetLevel(void) +{ + return g_level; +} diff --git a/CompleteApps/SmartFanDevice/smartfan/src/sensor.c b/CompleteApps/SmartFanDevice/smartfan/src/sensor.c new file mode 100644 index 0000000000000000000000000000000000000000..ea7b05dd64fa2f713920150f43145e62469470d6 --- /dev/null +++ b/CompleteApps/SmartFanDevice/smartfan/src/sensor.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include + +#include "ohos_types.h" +#include "iot_errno.h" +#include "kal.h" +#include "sensor.h" +#include "defines.h" + +static uint32 SensorWrite(uint8 triggerCmd, uint8 highByteCmd, uint8 lowByteCmd) +{ + uint8 _send_user_cmd[AHT_SNED_CMD_LEN] = {triggerCmd, highByteCmd, lowByteCmd}; + + return IoTI2cWrite(WIFI_IOT_SENSOR_I2C_IDX_0, (AHT_DEVICE_ADDR<<1) | 0x00, _send_user_cmd, AHT_SNED_CMD_LEN); +} + +static uint32 SensorRead(uint8 type) +{ + uint8 recvData[AHT_REG_ARRAY_LEN] = {0}; + float temper = 0; + uint32 temper_t = 0; + + memset_s(&recvData, sizeof(recvData), 0x0, sizeof(recvData)); + + IoTI2cRead(WIFI_IOT_SENSOR_I2C_IDX_0, (AHT_DEVICE_ADDR<<1) | 0x01, recvData, AHT_REG_ARRAY_LEN); + if (type == AHT_TEMPERATURE) { + temper = (float)((recvData[AHT_REG_TEMP_BITS_1] &0x0f)<