|
@@ -3,11 +3,12 @@
|
|
|
const getBle = require("../../utils/ble");
|
|
|
const handle = require("../../utils/handle");
|
|
|
const sleep = require("../../utils/sleep");
|
|
|
+const TimeClock = require('../../utils/timer');
|
|
|
const app = getApp();
|
|
|
const ble = getBle();
|
|
|
|
|
|
let services = [];
|
|
|
-
|
|
|
+const timeClock = new TimeClock();
|
|
|
const connectStateMap = {
|
|
|
0: {text:'未连接',color:"red"},
|
|
|
1: {text:'扫描中',color:"greenYellow"},
|
|
@@ -90,12 +91,28 @@ Page({
|
|
|
motto: 'Hello World',
|
|
|
userInfo: {},
|
|
|
hasUserInfo: false,
|
|
|
+ shutterBtnY1: 0,
|
|
|
+ isHolder: false,
|
|
|
+ time_minute: 0,// 分
|
|
|
+ time_second: 0,// 秒
|
|
|
+ time_ms: 0,// 毫秒
|
|
|
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
|
|
canIUseGetUserProfile: false,
|
|
|
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
|
|
|
},
|
|
|
async onShow(){
|
|
|
+ timeClock.setHook((msNum)=>{
|
|
|
+ console.log(msNum);
|
|
|
+ let res = timeClock.parse(msNum)
|
|
|
+ console.log(res);
|
|
|
+ this.setData({
|
|
|
+ time_minute:res.minute,
|
|
|
+ time_second:res.second,
|
|
|
+ time_ms:res.ms,
|
|
|
+ })
|
|
|
+ });
|
|
|
// 初始化蓝牙
|
|
|
+
|
|
|
try {
|
|
|
console.log("init ble");
|
|
|
await ble.initBle();
|
|
@@ -124,7 +141,8 @@ Page({
|
|
|
async holdFoucus(){
|
|
|
console.log("发送对焦命令");
|
|
|
},
|
|
|
- async shutterHandle(){
|
|
|
+
|
|
|
+ async devControlShutter(isDown = true){
|
|
|
let cmds,waitTime=10;
|
|
|
let code = bleServerMap.remote.code.hold;
|
|
|
let dev = this.data.bleDevs.find(dev=>this.data.remoteDev.devId===dev.deviceId);
|
|
@@ -132,7 +150,7 @@ Page({
|
|
|
if(!server){console.log('无法找到远程控制服务')}
|
|
|
let characteristic = server.characteristics.find(c=>c.uuid.startsWith(code.firstUuid));
|
|
|
if(!characteristic){return console.log('无法匹配到特征')}
|
|
|
- if(this.data.remoteDev.shutter){
|
|
|
+ if(isDown){
|
|
|
console.log('快门抬起')
|
|
|
// 发送抬起快门
|
|
|
cmds =[
|
|
@@ -144,11 +162,6 @@ Page({
|
|
|
console.log('快门按下')
|
|
|
cmds = [code.command.shutterDown]
|
|
|
}
|
|
|
- this.setData({
|
|
|
- remoteDev:{...this.data.remoteDev,shutter:!this.data.remoteDev.shutter}
|
|
|
- });
|
|
|
- // 获取对应的服务
|
|
|
- // let server =
|
|
|
for (let index = 0; index < cmds.length; index++) {
|
|
|
const cmd = cmds[index];
|
|
|
let [_err,_res] = await handle(ble.sendData(
|
|
@@ -158,13 +171,69 @@ Page({
|
|
|
cmd.replace(/\s/g,'')
|
|
|
));
|
|
|
if(_err){
|
|
|
- console.log('发送命令失败');
|
|
|
+ // console.log('发送命令失败');
|
|
|
console.error(_err);
|
|
|
}
|
|
|
- console.log('发送命令成功');
|
|
|
+ // console.log('发送命令成功');
|
|
|
await sleep(waitTime);
|
|
|
}
|
|
|
+ },
|
|
|
+ async touchStartHandle(e){
|
|
|
+ // console.log("按钮按下");
|
|
|
+ // console.log(e);
|
|
|
+ // todo 获取当前的y信息
|
|
|
+ let touche = e.touches[0];
|
|
|
+ let y1 = 0;
|
|
|
+ if(touche){
|
|
|
+ y1 = touche.clientY;
|
|
|
+ }
|
|
|
+ this.data.shutterBtnY1 = y1;
|
|
|
+ if(this.data.isHolder){
|
|
|
+ // 已经按下,视作已经发送按下快门的操作
|
|
|
+ return false;
|
|
|
+ }else{
|
|
|
+ // todo 未按下,发送按下快门的操作
|
|
|
+ this.devControlShutter(false);
|
|
|
+ timeClock.start();
|
|
|
+ }
|
|
|
+ // 记录当前时间. 等抬起时再次获取
|
|
|
+ },
|
|
|
+ async touchEndHandle(e){
|
|
|
+ console.log("按钮抬起");
|
|
|
|
|
|
+ if(this.data.isHolder){
|
|
|
+ // 按住,not do sth
|
|
|
+ }else{
|
|
|
+ // 抬起按钮
|
|
|
+ timeClock.stop();
|
|
|
+ this.devControlShutter(true);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async touchMoveHandle(e){
|
|
|
+ // console.log("按钮移动");
|
|
|
+ let touche = e.touches[0];
|
|
|
+ let y1 = this.data.shutterBtnY1;
|
|
|
+ let y2 = 0;
|
|
|
+ if(touche){
|
|
|
+ y2 = touche.clientY;
|
|
|
+ }
|
|
|
+ let endY = y2 - y1;
|
|
|
+ if(Math.abs(endY)<15){
|
|
|
+ // console.log("移动范围太小")
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ this.data.shutterBtnY1 = y2;
|
|
|
+ if(endY < 0){
|
|
|
+ console.log('+');
|
|
|
+ this.setData({
|
|
|
+ isHolder:true
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ console.log('-');
|
|
|
+ this.setData({
|
|
|
+ isHolder:false
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
async connectDev(e){
|
|
|
let devId = e.currentTarget.dataset.dev;
|