Commit 2d1ce2edbad1d08f4620bf6d0baf4b582fe69ea2
1 parent
599101a5
documents update ,save mesh update
Showing
6 changed files
with
92 additions
and
55 deletions
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | # 1.智能模块 |
| 8 | 8 | |
| 9 | 9 | ## 1.1 门锁蓝牙控制模块 |
| 10 | -门锁使用的desman的方案,基于蓝牙4.0,官方app是小滴管家。通过其提供的android sdk(`greenbluetoothlelib.jar`),可以实现开关的控制。sdk中通过蓝牙模块的mac(蓝牙名以`IDLOCK_`开头) 地址区分不同的门锁. | |
| 10 | +门锁使用的desman的方案,基于蓝牙4.0,官方app是小滴管家。通过其提供的android sdk(`greenbluetoothlelib.jar`),可以实现开关的控制。sdk中通过蓝牙模块的mac(蓝牙名以`IDLOCK_`开头) 地址区分不同的门锁.在启动`GREENBluetoothLeService`时,其'onCreate'代码中有重启ble相关操作`GREENBluetoothLeService.restartBleDevice()`,故会导致蓝牙遥控器短暂失效。 | |
| 11 | 11 | 主要使用流程概述如下 |
| 12 | 12 | > * 注册启动相关服务 |
| 13 | 13 | ```java |
| ... | ... | @@ -46,7 +46,8 @@ bleBroadcastReceiver.setResponseObj(new GREENCITYBLEProtocolFactory.GREENCITYBle |
| 46 | 46 | ``` |
| 47 | 47 | |
| 48 | 48 | ## 1.2 智能灯光 |
| 49 | -智能灯光使用的是大豆的方案,基于蓝牙4.0,官方app是dadouLight。使用时需要`add mess`,基出厂的默认配置均为`mesh name:telink_zz,pwd:123`,配置成功后,调用相关方法可以通过mesh name寻找当前范围内是否有相关智能灯存在,若存在会登录,成功后即可控制。 | |
| 49 | +智能灯光使用的是大豆的方案,基于蓝牙4.0,官方app是dadouLight。使用时需要`add mess`,基出厂的默认配置均为`mesh name:telink_zz,pwd:123`,配置成功后,调用相关方法可以通过mesh name寻找当前范围内是否有相关智能灯存在,若存在会登录,成功后即可控制。 | |
| 50 | +**注意:在重设置`mesh name`时,在设置mesh页面将`mesh name` 填入`factory name`,保存后,一定要等所连灯消失后再去点`network scanning`,否则很大的可能会设置失败,失败后需要将,`mesh name `改回去再改一次** | |
| 50 | 51 | 主要使用流程概述如下 |
| 51 | 52 | > * 注册application主要用于初始化`Mesh`启动灯光相关服务 |
| 52 | 53 | ```java | ... | ... |
| ... | ... | @@ -26,7 +26,6 @@ import android.widget.Button; |
| 26 | 26 | import android.widget.EditText; |
| 27 | 27 | import android.widget.ImageView; |
| 28 | 28 | import android.widget.Toast; |
| 29 | - | |
| 30 | 29 | import com.qnbar.smc.service.TelinkLightService; |
| 31 | 30 | import com.telink.bluetooth.light.model.Mesh; |
| 32 | 31 | import com.xgimi.gimicinema.R; |
| ... | ... | @@ -130,6 +129,29 @@ public final class AddMeshActivity extends Activity { |
| 130 | 129 | if (mesh.saveOrUpdate()) { |
| 131 | 130 | this.mApplication.setMesh(mesh); |
| 132 | 131 | Toast.makeText(AddMeshActivity.this, "保存mesh成功", Toast.LENGTH_SHORT).show(); |
| 132 | + | |
| 133 | +// int connectMeshAddress = mesh.getDeviceAddress(); | |
| 134 | +// | |
| 135 | +// if (connectMeshAddress == -1) { | |
| 136 | +//// show("哎呦,网络里的灯泡太多了!目前可以有256灯"); | |
| 137 | +// this.finish(); | |
| 138 | +// return; | |
| 139 | +// } | |
| 140 | +// | |
| 141 | +// //更新参数 | |
| 142 | +// LeUpdateParameters params = Parameters.createUpdateParameters(); | |
| 143 | +// params.setOldMeshName(mesh.factoryName); | |
| 144 | +// params.setOldPassword(mesh.factoryPassword); | |
| 145 | +// params.setNewMeshName(mesh.name); | |
| 146 | +// params.setNewPassword(mesh.password); | |
| 147 | +// | |
| 148 | +//// DeviceInfo deviceInfo = event.getArgs(); | |
| 149 | +//// deviceInfo.meshAddress = connectMeshAddress; | |
| 150 | +//// params.setUpdateDeviceList(deviceInfo); | |
| 151 | +// //params.set(Parameters.PARAM_DEVICE_LIST, deviceInfo); | |
| 152 | +// TelinkLightService.Instance().idleMode(true); | |
| 153 | +// //加灯 | |
| 154 | +// TelinkLightService.Instance().updateMesh(params); | |
| 133 | 155 | } |
| 134 | 156 | } |
| 135 | 157 | } | ... | ... |
| ... | ... | @@ -25,7 +25,6 @@ import android.view.View; |
| 25 | 25 | import android.view.ViewGroup; |
| 26 | 26 | import android.widget.ImageView; |
| 27 | 27 | import android.widget.TextView; |
| 28 | - | |
| 29 | 28 | import com.qnbar.smc.model.Light; |
| 30 | 29 | import com.qnbar.smc.model.Lights; |
| 31 | 30 | import com.xgimi.gimicinema.R; |
| ... | ... | @@ -105,7 +104,9 @@ public class DeviceListAdapter extends RecyclerView.Adapter<DeviceListAdapter.De |
| 105 | 104 | public void onClick(View v) { |
| 106 | 105 | if (listener != null) { |
| 107 | 106 | Integer tag = (Integer) v.getTag(); |
| 108 | - listener.onItemClick(Lights.getInstance().get(tag), tag); | |
| 107 | + if (Lights.getInstance() != null && Lights.getInstance().get(tag) != null) { | |
| 108 | + listener.onItemClick(Lights.getInstance().get(tag), tag); | |
| 109 | + } | |
| 109 | 110 | } |
| 110 | 111 | } |
| 111 | 112 | |
| ... | ... | @@ -141,6 +142,6 @@ public class DeviceListAdapter extends RecyclerView.Adapter<DeviceListAdapter.De |
| 141 | 142 | |
| 142 | 143 | void onLongClick(Light light, int position); |
| 143 | 144 | |
| 144 | - void onMenuClick(View v,int position); | |
| 145 | + void onMenuClick(View v, int position); | |
| 145 | 146 | } |
| 146 | 147 | } | ... | ... |
| ... | ... | @@ -17,9 +17,11 @@ |
| 17 | 17 | package com.telink.bluetooth.light.model; |
| 18 | 18 | |
| 19 | 19 | |
| 20 | -import com.qnbar.smc.utils.FileSystem; | |
| 20 | +import com.gimi.common.cinema.utils.Utils; | |
| 21 | +import com.google.gson.Gson; | |
| 21 | 22 | import com.telink.bluetooth.light.DeviceInfo; |
| 22 | 23 | import com.telink.util.MeshUtils; |
| 24 | +import com.xgimi.gimicinema.application.FangTangApplication; | |
| 23 | 25 | |
| 24 | 26 | import java.io.Serializable; |
| 25 | 27 | import java.util.ArrayList; |
| ... | ... | @@ -29,7 +31,7 @@ public class Mesh implements Serializable { |
| 29 | 31 | |
| 30 | 32 | private static final long serialVersionUID = 1L; |
| 31 | 33 | public static final String MESH_FILE_NAME = "telink.meshs"; |
| 32 | -// public static final String MESH_FILE_NAME = "telink-qn.meshs"; | |
| 34 | + // public static final String MESH_FILE_NAME = "telink-qn.meshs"; | |
| 33 | 35 | public String name; |
| 34 | 36 | public String password; |
| 35 | 37 | public String factoryName; |
| ... | ... | @@ -64,6 +66,14 @@ public class Mesh implements Serializable { |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | public boolean saveOrUpdate() { |
| 67 | - return FileSystem.writeAsObject(MESH_FILE_NAME, this); | |
| 69 | + boolean ret = false; | |
| 70 | + try { | |
| 71 | + Utils.saveString(FangTangApplication.getInstance().getApplicationContext(), "mesh-config", new Gson().toJson(this)); | |
| 72 | + ret = true; | |
| 73 | + } catch (Exception e) { | |
| 74 | + e.printStackTrace(); | |
| 75 | + } | |
| 76 | +// return FileSystem.writeAsObject(MESH_FILE_NAME, this); | |
| 77 | + return ret; | |
| 68 | 78 | } |
| 69 | 79 | } | ... | ... |
| 1 | 1 | package com.xgimi.gimicinema.application; |
| 2 | 2 | |
| 3 | 3 | import android.util.Log; |
| 4 | - | |
| 4 | +import android.widget.Toast; | |
| 5 | +import com.gimi.common.cinema.utils.Utils; | |
| 6 | +import com.google.gson.Gson; | |
| 5 | 7 | import com.qnbar.smc.application.MySampleAdvanceStrategy; |
| 6 | 8 | import com.qnbar.smc.service.TelinkLightService; |
| 7 | 9 | import com.qnbar.smc.utils.FileSystem; |
| ... | ... | @@ -35,8 +37,15 @@ public class FangTangApplication extends TelinkApplication { |
| 35 | 37 | */ |
| 36 | 38 | //TODO save by json string |
| 37 | 39 | if (FileSystem.exists(Mesh.MESH_FILE_NAME)) { |
| 38 | - this.mesh = (Mesh) FileSystem.readAsObject(Mesh.MESH_FILE_NAME); | |
| 40 | + String string = Utils.getString(this, "mesh-config"); | |
| 41 | + this.mesh = new Gson().fromJson(string, Mesh.class); | |
| 42 | + } | |
| 43 | + | |
| 44 | + if (mesh == null) { | |
| 45 | + Toast.makeText(this, "没有配置智能灯光,请配置", Toast.LENGTH_SHORT).show(); | |
| 46 | +// return; | |
| 39 | 47 | } |
| 48 | + | |
| 40 | 49 | Log.d("SMCService", "doInit"); |
| 41 | 50 | //启动LightService |
| 42 | 51 | this.startLightService(TelinkLightService.class); | ... | ... |
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | - xmlns:tools="http://schemas.android.com/tools" | |
| 4 | - android:id="@+id/activity_main" | |
| 5 | - android:layout_width="match_parent" | |
| 6 | - android:layout_height="match_parent" | |
| 7 | - android:paddingBottom="@dimen/activity_vertical_margin" | |
| 8 | - android:paddingLeft="@dimen/activity_horizontal_margin" | |
| 9 | - android:paddingRight="@dimen/activity_horizontal_margin" | |
| 10 | - android:paddingTop="@dimen/activity_vertical_margin" | |
| 11 | - tools:context="com.qnbar.smc.MainActivity"> | |
| 12 | - | |
| 13 | - <TextView | |
| 14 | - android:id="@+id/textView" | |
| 15 | - android:layout_width="wrap_content" | |
| 16 | - android:layout_height="wrap_content" | |
| 17 | - android:text="Hello World!" /> | |
| 3 | + xmlns:tools="http://schemas.android.com/tools" | |
| 4 | + android:id="@+id/activity_main" | |
| 5 | + android:layout_width="match_parent" | |
| 6 | + android:layout_height="match_parent" | |
| 7 | + android:paddingBottom="@dimen/activity_vertical_margin" | |
| 8 | + android:paddingLeft="@dimen/activity_horizontal_margin" | |
| 9 | + android:paddingRight="@dimen/activity_horizontal_margin" | |
| 10 | + android:paddingTop="@dimen/activity_vertical_margin" | |
| 11 | + tools:context="com.qnbar.smc.MainActivity"> | |
| 18 | 12 | |
| 19 | 13 | <Button |
| 20 | - android:id="@+id/button" | |
| 21 | - android:layout_width="wrap_content" | |
| 22 | - android:layout_height="wrap_content" | |
| 23 | - android:layout_alignParentStart="true" | |
| 24 | - android:layout_below="@+id/textView" | |
| 25 | - android:layout_marginTop="12dp" | |
| 26 | - android:onClick="setMesh" | |
| 27 | - android:text="设置mesh" /> | |
| 14 | + android:id="@+id/button" | |
| 15 | + android:layout_width="wrap_content" | |
| 16 | + android:layout_height="wrap_content" | |
| 17 | + android:layout_alignParentStart="true" | |
| 18 | + android:layout_below="@+id/textView" | |
| 19 | + android:layout_marginTop="12dp" | |
| 20 | + android:onClick="setMesh" | |
| 21 | + android:text="设置mesh"/> | |
| 28 | 22 | |
| 29 | 23 | <Button |
| 30 | - android:layout_width="wrap_content" | |
| 31 | - android:layout_height="wrap_content" | |
| 32 | - android:layout_alignParentStart="true" | |
| 33 | - android:layout_below="@+id/button" | |
| 34 | - android:layout_marginTop="12dp" | |
| 35 | - android:onClick="openLight" | |
| 36 | - android:text="open all" /> | |
| 24 | + android:layout_width="wrap_content" | |
| 25 | + android:layout_height="wrap_content" | |
| 26 | + android:layout_alignParentStart="true" | |
| 27 | + android:layout_below="@+id/button" | |
| 28 | + android:layout_marginTop="12dp" | |
| 29 | + android:onClick="openLight" | |
| 30 | + android:text="open all"/> | |
| 37 | 31 | |
| 38 | 32 | <Button |
| 39 | - android:layout_width="wrap_content" | |
| 40 | - android:layout_height="wrap_content" | |
| 41 | - android:layout_alignEnd="@+id/textView" | |
| 42 | - android:layout_alignParentStart="true" | |
| 43 | - android:layout_below="@+id/button" | |
| 44 | - android:layout_marginTop="64dp" | |
| 45 | - android:onClick="closeLight" | |
| 46 | - android:text="close all" /> | |
| 33 | + android:layout_width="wrap_content" | |
| 34 | + android:layout_height="wrap_content" | |
| 35 | + android:layout_alignEnd="@+id/textView" | |
| 36 | + android:layout_alignParentStart="true" | |
| 37 | + android:layout_below="@+id/button" | |
| 38 | + android:layout_marginTop="64dp" | |
| 39 | + android:onClick="closeLight" | |
| 40 | + android:text="close all"/> | |
| 47 | 41 | |
| 48 | 42 | <android.support.v7.widget.RecyclerView |
| 49 | - android:id="@+id/light_rv" | |
| 50 | - android:layout_width="match_parent" | |
| 51 | - android:layout_height="wrap_content" | |
| 52 | - android:layout_alignParentStart="true" | |
| 53 | - android:layout_below="@+id/button" | |
| 54 | - android:layout_marginTop="124dp" /> | |
| 43 | + android:id="@+id/light_rv" | |
| 44 | + android:layout_width="match_parent" | |
| 45 | + android:layout_height="wrap_content" | |
| 46 | + android:layout_alignParentStart="true" | |
| 47 | + android:layout_below="@+id/button" | |
| 48 | + android:layout_marginTop="124dp"/> | |
| 55 | 49 | <Button |
| 56 | 50 | android:text="network scanning" |
| 57 | 51 | android:onClick="networkScan" | ... | ... |
Please
register
or
login
to post a comment