|
|
@@ -8,6 +8,7 @@ import BLE from 'util/util-js/BLE.js';
|
|
|
//快速打击部分
|
|
|
import o0 from "@/util/util-js/o0.js"
|
|
|
import o0Project from "@/util/util-js/o0Project.js"
|
|
|
+import o0ProjectRelease from "@/util/util-js/o0ProjectRelease0.1.js"
|
|
|
|
|
|
import deviceData from "@/util/util-js/devices.js"
|
|
|
|
|
|
@@ -152,7 +153,20 @@ const store = new Vuex.Store({
|
|
|
|
|
|
|
|
|
//绑定的设备
|
|
|
- DeviceBindingList: [],
|
|
|
+ DeviceBindingList: [{
|
|
|
+ id: 0,
|
|
|
+ cname: "开启手机数据",
|
|
|
+ ename: "bindMobilePhoneBandage",
|
|
|
+ icon: "/static/devicesIcon/bandage.png",
|
|
|
+ mIcon: "/static/devicesIcon/bandage.png",
|
|
|
+ bRatio: false,
|
|
|
+ usageMode: 'bindPhone',
|
|
|
+ describe: '手机情景下使用',
|
|
|
+ limitType: 'rebound', //限制回弹版本
|
|
|
+ deviceType: 'mySelf', //指的是使用手机本身加速计计算
|
|
|
+ deviceName: 'PHONE', //连接硬件名称
|
|
|
+
|
|
|
+ }],
|
|
|
ConnectBindingDevice: null,
|
|
|
|
|
|
cIndex: -1,
|
|
|
@@ -214,6 +228,22 @@ const store = new Vuex.Store({
|
|
|
|
|
|
globalAcc: null,
|
|
|
globalOri: null,
|
|
|
+ globalAccData: {
|
|
|
+ ax: 0,
|
|
|
+ ay: 0,
|
|
|
+ az: 0
|
|
|
+ },
|
|
|
+ globalGyroData: {
|
|
|
+ gx: 0,
|
|
|
+ gy: 0,
|
|
|
+ gz: 0
|
|
|
+ },
|
|
|
+ globalLastGyroData: {
|
|
|
+ gx: 0,
|
|
|
+ gy: 0,
|
|
|
+ gz: 0
|
|
|
+ },
|
|
|
+ globalMyAttitude: null,
|
|
|
|
|
|
//当前显示的模式下标
|
|
|
currentModeIndex: 0,
|
|
|
@@ -258,6 +288,10 @@ const store = new Vuex.Store({
|
|
|
filter: null,
|
|
|
deviceMs: 1,
|
|
|
|
|
|
+ //改进版的沙袋打击对象
|
|
|
+ sandbagAlgorithm: null,
|
|
|
+ sandbagAlgorithmLastTime: new Date().getTime(),
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 蓝牙参数对象
|
|
|
@@ -274,6 +308,7 @@ const store = new Vuex.Store({
|
|
|
bListenerUpdate: false,
|
|
|
bListenerJson: false,
|
|
|
bListenerMac: false,
|
|
|
+ bListenerAccArray: false,
|
|
|
|
|
|
/**
|
|
|
* 发送16进制时候,返回的刷新数据
|
|
|
@@ -1391,6 +1426,8 @@ const store = new Vuex.Store({
|
|
|
state.bListenerJson = false;
|
|
|
|
|
|
state.bListenerMac = false;
|
|
|
+
|
|
|
+ state.bListenerAccArray = false;
|
|
|
//更新二进制的
|
|
|
state.bListenerHexUpdate = false;
|
|
|
|
|
|
@@ -1772,6 +1809,107 @@ const store = new Vuex.Store({
|
|
|
|
|
|
state.filter.Update(new o0.Vector3(ax, ay, az), msGap, new o0.Vector3(gx, gy, gz), callback); //我自己的更新acc的函数
|
|
|
},
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建一个沙袋打击对象
|
|
|
+ * @param {Object} state
|
|
|
+ */
|
|
|
+ gCreateSandbagAlgorithm(state) {
|
|
|
+ state.sandbagAlgorithm = null;
|
|
|
+ state.sandbagAlgorithmLastTime = new Date().getTime();
|
|
|
+ state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm();
|
|
|
+ console.log("gCreateSandbagAlgorithm");
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 更新 沙袋打击对象 数据
|
|
|
+ * @param {Object} state
|
|
|
+ * @param {Object} context
|
|
|
+ */
|
|
|
+ gUpdateSandbagAlgorithm(state, context) {
|
|
|
+
|
|
|
+ let {
|
|
|
+ data,
|
|
|
+ callback = null
|
|
|
+ } = context;
|
|
|
+
|
|
|
+ let {
|
|
|
+ ax,
|
|
|
+ ay,
|
|
|
+ az
|
|
|
+ } = data.acc;
|
|
|
+
|
|
|
+ let {
|
|
|
+ gx,
|
|
|
+ gy,
|
|
|
+ gz
|
|
|
+ } = data.gyro;
|
|
|
+ let [hit, dir] = state.sandbagAlgorithm.Update(ax / 10, az / 10, gz, -gx, data.ms);
|
|
|
+ if (dir != undefined) {
|
|
|
+ let temp = state.sandbagAlgorithm.getTempValue(dir);
|
|
|
+ if (callback) {
|
|
|
+ callback(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开启加速计,陀螺仪,并且模拟ble发送
|
|
|
+ * @param {Object} state
|
|
|
+ */
|
|
|
+ gStartSimulateBLEUpdate(state) {
|
|
|
+
|
|
|
+ //todo 区分平台,目前是android 模块
|
|
|
+
|
|
|
+ if (state.globalMyAttitude == null) {
|
|
|
+ state.globalMyAttitude = uni.requireNativePlugin("MyAttitude");
|
|
|
+
|
|
|
+ let globalEvent = uni.requireNativePlugin('globalEvent');
|
|
|
+ globalEvent.addEventListener('updateAccAndGyro', function(e) {
|
|
|
+ //updateAccAndGyro{"accelerometer":[-0.178375244140625,9.327804565429688,2.6168670654296875],"gyroscope":[0.0018310546875,-0.0019989013671875,0.0027923583984375]}
|
|
|
+ //console.log('updateAccAndGyro' + JSON.stringify(e));
|
|
|
+ let _accArray = e.accelerometer;
|
|
|
+ let _gyroArray = e.gyroscope;
|
|
|
+
|
|
|
+ state.globalAccData.ax = _accArray[0];
|
|
|
+ state.globalAccData.ay = _accArray[1];
|
|
|
+ state.globalAccData.az = _accArray[2];
|
|
|
+
|
|
|
+ state.globalGyroData.gx = _gyroArray[0];
|
|
|
+ state.globalGyroData.gy = _gyroArray[1];
|
|
|
+ state.globalGyroData.gz = _gyroArray[2];
|
|
|
+
|
|
|
+ let box = {};
|
|
|
+ box["acc"] = state.globalAccData;
|
|
|
+ box["gyro"] = state.globalGyroData;
|
|
|
+ box["ms"] = e.ms;
|
|
|
+ //更新数据给webview,在game-play-web||game-play-sub绑定
|
|
|
+ //后面更新数据都用此接口
|
|
|
+ uni.$emit('updateBLEDeviceData', box);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ var ret = state.globalMyAttitude.onStartAccAndGyro();
|
|
|
+ if (!ret.accelerometer || !ret.gyroscope) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '是否初始化,加速计:' + ret.accelerometer + ',陀螺仪:' + ret.gyroscope
|
|
|
+ })
|
|
|
+ }
|
|
|
+ console.log('gStartSimulateBLEUpdate:', ret);
|
|
|
+
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 停止加速计,陀螺仪
|
|
|
+ * @param {Object} state
|
|
|
+ */
|
|
|
+ gStopSimulateBLEUpdate(state) {
|
|
|
+ //todo 区分平台,目前是android 模块
|
|
|
+ let globalEvent = uni.requireNativePlugin('globalEvent');
|
|
|
+ globalEvent.removeEventListener('updateAccAndGyro');
|
|
|
+ var ret = state.globalMyAttitude.onStopAccAndGyro();
|
|
|
+ console.log('gStopSimulateBLEUpdate:', ret);
|
|
|
+ state.globalMyAttitude = null;
|
|
|
+ },
|
|
|
/**
|
|
|
* 限制开始游戏
|
|
|
*/
|
|
|
@@ -2187,6 +2325,96 @@ const store = new Vuex.Store({
|
|
|
box["Json"] = resValueStr;
|
|
|
uni.$emit('updateBLEDeviceJson', box);
|
|
|
}
|
|
|
+
|
|
|
+ //解析4组加速计数据
|
|
|
+ if (state.bListenerAccArray) {
|
|
|
+ let ms1 = BLE.hex2int(resValue.substr(2, 4));
|
|
|
+ let min1 = BLE.hex2int(resValue.substr(6, 2));
|
|
|
+ let s1 = BLE.hex2int(resValue.substr(8, 2));
|
|
|
+ let ax1Str = resValue.substr(10, 4);
|
|
|
+ let ay1Str = resValue.substr(14, 4);
|
|
|
+ let az1Str = resValue.substr(18, 4);
|
|
|
+ let ax1 = BLE.hexToSignedInt(ax1Str) / 32768 * 16;
|
|
|
+ let ay1 = BLE.hexToSignedInt(ay1Str) / 32768 * 16;
|
|
|
+ let az1 = BLE.hexToSignedInt(az1Str) / 32768 * 16;
|
|
|
+
|
|
|
+ let ms2 = BLE.hex2int(resValue.substr(22, 4));
|
|
|
+ let min2 = BLE.hex2int(resValue.substr(26, 2));
|
|
|
+ let s2 = BLE.hex2int(resValue.substr(28, 2));
|
|
|
+ let ax2Str = resValue.substr(30, 4);
|
|
|
+ let ay2Str = resValue.substr(34, 4);
|
|
|
+ let az2Str = resValue.substr(38, 4);
|
|
|
+ let ax2 = BLE.hexToSignedInt(ax2Str) / 32768 * 16;
|
|
|
+ let ay2 = BLE.hexToSignedInt(ay2Str) / 32768 * 16;
|
|
|
+ let az2 = BLE.hexToSignedInt(az2Str) / 32768 * 16;
|
|
|
+
|
|
|
+ let ms3 = BLE.hex2int(resValue.substr(42, 4));
|
|
|
+ let min3 = BLE.hex2int(resValue.substr(46, 2));
|
|
|
+ let s3 = BLE.hex2int(resValue.substr(48, 2));
|
|
|
+ let ax3Str = resValue.substr(50, 4);
|
|
|
+ let ay3Str = resValue.substr(54, 4);
|
|
|
+ let az3Str = resValue.substr(58, 4);
|
|
|
+ let ax3 = BLE.hexToSignedInt(ax3Str) / 32768 * 16;
|
|
|
+ let ay3 = BLE.hexToSignedInt(ay3Str) / 32768 * 16;
|
|
|
+ let az3 = BLE.hexToSignedInt(az3Str) / 32768 * 16;
|
|
|
+
|
|
|
+ let ms4 = BLE.hex2int(resValue.substr(62, 4));
|
|
|
+ let min4 = BLE.hex2int(resValue.substr(66, 2));
|
|
|
+ let s4 = BLE.hex2int(resValue.substr(68, 2));
|
|
|
+ let ax4Str = resValue.substr(70, 4);
|
|
|
+ let ay4Str = resValue.substr(74, 4);
|
|
|
+ let az4Str = resValue.substr(78, 4);
|
|
|
+ let ax4 = BLE.hexToSignedInt(ax4Str) / 32768 * 16;
|
|
|
+ let ay4 = BLE.hexToSignedInt(ay4Str) / 32768 * 16;
|
|
|
+ let az4 = BLE.hexToSignedInt(az4Str) / 32768 * 16;
|
|
|
+
|
|
|
+ let accArray= [{
|
|
|
+ ax: ax1,
|
|
|
+ ay: ay1,
|
|
|
+ az: az1,
|
|
|
+ ms: ms1,
|
|
|
+ min: min1,
|
|
|
+ s: s1
|
|
|
+ }, {
|
|
|
+ ax: ax2,
|
|
|
+ ay: ay2,
|
|
|
+ az: az2,
|
|
|
+ ms: ms2,
|
|
|
+ min: min2,
|
|
|
+ s: s2
|
|
|
+ }, {
|
|
|
+ ax: ax3,
|
|
|
+ ay: ay3,
|
|
|
+ az: az3,
|
|
|
+ ms: ms3,
|
|
|
+ min: min3,
|
|
|
+ s: s3
|
|
|
+ }, {
|
|
|
+ ax: ax4,
|
|
|
+ ay: ay4,
|
|
|
+ az: az4,
|
|
|
+ ms: ms4,
|
|
|
+ min: min4,
|
|
|
+ s: s4
|
|
|
+ }]
|
|
|
+
|
|
|
+ for(let i=0 ;i<accArray.length;i++){
|
|
|
+ let _temp = accArray[i];
|
|
|
+ box["acc"] = {
|
|
|
+ ax:_temp.ax,
|
|
|
+ ay:_temp.ay,
|
|
|
+ az:_temp.az,
|
|
|
+ };
|
|
|
+ box["min"] = _temp.min;
|
|
|
+ box["s"] = _temp.s;
|
|
|
+ box["ms"] = _temp.ms;
|
|
|
+
|
|
|
+ uni.$emit('updateBLEDeviceData', box);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//原始数据解析
|
|
|
if (state.bListenerUpdate) {
|
|
|
//R/L 左手还是右手
|
|
|
@@ -2261,7 +2489,7 @@ const store = new Vuex.Store({
|
|
|
if (byteArray[0] == '00') {
|
|
|
|
|
|
state.bRopeKeyOne = 1;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
//'01'
|
|
|
state.bRopeKeyTwo = 1;
|
|
|
|
|
|
@@ -2318,10 +2546,10 @@ const store = new Vuex.Store({
|
|
|
}
|
|
|
let _sendData;
|
|
|
if (bSendHex) {
|
|
|
-
|
|
|
+
|
|
|
state.bRopeKeyTwo = 0;
|
|
|
state.bRopeKeyOne = 0;
|
|
|
-
|
|
|
+
|
|
|
//如果是发送16进制
|
|
|
state.bListenerHexUpdate = true;
|
|
|
|
|
|
@@ -2358,16 +2586,24 @@ const store = new Vuex.Store({
|
|
|
}
|
|
|
|
|
|
if (value == "6") {
|
|
|
- state.bListenerJson = false;
|
|
|
+ // state.bListenerJson = false;
|
|
|
+ state.bListenerAccArray = false;
|
|
|
}
|
|
|
if (value == "5") {
|
|
|
- if (state.bListenerJson) {
|
|
|
+ // if (state.bListenerJson) {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: "步数数据已开启"
|
|
|
+ // })
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // state.bListenerJson = true;
|
|
|
+ if (state.bListenerAccArray) {
|
|
|
uni.showToast({
|
|
|
- title: "步数数据已开启"
|
|
|
+ title: "加速计组数据已开启"
|
|
|
})
|
|
|
return;
|
|
|
}
|
|
|
- state.bListenerJson = true;
|
|
|
+ state.bListenerAccArray = true;
|
|
|
}
|
|
|
|
|
|
_sendData = BLE.str2ab(value);
|