Quellcode durchsuchen

1.调整灯光拳击模块部分参数和代码

slambb vor 2 Jahren
Ursprung
Commit
2e16855795

+ 7 - 3
pages/game-page/game-play-sub/subGame/subGame.nvue

@@ -216,7 +216,7 @@
 			...mapMutations(['addlocalCalorie', 'syncRequestEvent', 'onWriteBLEConnectionValue', 'B_WriteHexToBLECharacteristic',
 				'gCreateFilterObj', 'gUpdateFilter', 'B_OpenRopeSkipping', 'B_CloseRopeSkipping',
 				'gStopSimulateBLEUpdate', 'gStartSimulateBLEUpdate', 'gIntelligentUpdateSandbagAlgorithm', 'gUpdateSandbagAlgorithm',
-				'gCreateSandbagAlgorithm', 'onConvertDeviceData', 'addSandbagHitCount', 'uploadUserData_hitCount',
+				'gCreateSandbagAlgorithm','gIntelligentCreateSandbagAlgorithm', 'onConvertDeviceData', 'addSandbagHitCount', 'uploadUserData_hitCount',
 				'jumpIdenModule_onJump6AxisDataUpdate'
 			]),
 			navBack() {
@@ -652,8 +652,12 @@
 							this._createEquipmentBasedOnBoxingPostHit();
 						} else if (this.BLEConnectDevice.usageMode == "hotman") {
 							//hotman 沙袋情景  
-							// this.gCreateFilterObj();
-							this.gCreateSandbagAlgorithm();
+							// this.gCreateSandbagAlgorithm();
+							if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
+								this.gIntelligentCreateSandbagAlgorithm();
+							} else {
+								this.gCreateSandbagAlgorithm();
+							}
 						}
 					} else if (this.BLEConnectDevice.deviceType == "mySelf") {
 						//处理手机本身情况下

+ 30 - 22
pages/personal-page/devices-hardware/devices-hardware.vue

@@ -35,12 +35,12 @@
 					mode="aspectFit" @tap="_onRadio(item,$event)"></image>
 			</view>
 		</view>
-		
+
 		<!-- <view style="display: flex;justify-content: space-between;" class="margin-top margin-bottom">
 			<button @click="switchList(1)">jumpList</button>
 			<button @click="switchList(2)">hitList</button>
 		</view> -->
-	
+
 
 
 		<view v-if="currentIndex<5" class="position-absolute-center" style="z-index: 1; width: 750rpx;display: flex;">
@@ -160,7 +160,7 @@
 	export default {
 		computed: mapState(['bOpenBluetooth', 'bOpenSuccess', 'bListenAdapterStateChange', 'bListenDeviceFound',
 			'BLEConnectDevice', 'BLEGetServices', 'cIndex', 'bConnection', 'bVerifiedConnection', 'BLEInfoList',
-			'BLEDeviceShowList', 'finallyUseDevice', 'systemInfo', 'guideUnlockState','currentModeIndex'
+			'BLEDeviceShowList', 'finallyUseDevice', 'systemInfo', 'guideUnlockState', 'currentModeIndex'
 		]),
 		data() {
 			return {
@@ -198,23 +198,25 @@
 			}
 		},
 		onLoad(op) {
-			this.BLEInfoList.forEach((item, index, selfarr) => {
-				// ios 暂时去除跳,因为算法还没转化Xcode
-				if (uni.getSystemInfoSync().platform == "ios") {
-					if (((item.deviceType == 'BLEHandle' || item.deviceType == 'BLEIntelligent')  && item.usageMode == 'hotman') ) {
-						let item = Object.assign({}, selfarr[index], {
-							bOldDevice: false
-						});
-						this.devicesList.push(item);
-					}
-				}else{
-					if (((item.deviceType == 'BLEHandle' || item.deviceType == 'BLEIntelligent') && item.usageMode == 'hotman') || item.deviceType ==
-						'BLERope') {
-						let item = Object.assign({}, selfarr[index], {
-							bOldDevice: false
-						});
-						this.devicesList.push(item);
-					}
+			this.BLEInfoList.forEach((item, index, selfarr) => {
+				// ios 暂时去除跳,因为算法还没转化Xcode
+				if (uni.getSystemInfoSync().platform == "ios") {
+					if (((item.deviceType == 'BLEHandle' || item.deviceType == 'BLEIntelligent') && item
+							.usageMode == 'hotman')) {
+						let item = Object.assign({}, selfarr[index], {
+							bOldDevice: false
+						});
+						this.devicesList.push(item);
+					}
+				} else {
+					if (((item.deviceType == 'BLEHandle' || item.deviceType == 'BLEIntelligent') && item
+							.usageMode == 'hotman') || item.deviceType ==
+						'BLERope') {
+						let item = Object.assign({}, selfarr[index], {
+							bOldDevice: false
+						});
+						this.devicesList.push(item);
+					}
 				}
 			})
 			uni.$on('retryConnectBLESuccess', this.onRetryConnectBLESuccess);
@@ -462,9 +464,15 @@
 						(eq.ename.indexOf("rope") > -1 && this.BLEConnectDevice.id == 3) ||
 						(eq.ename.indexOf("intelligent") > -1 && this.BLEConnectDevice.id == 4)) {
 
-						if (eq.ename.indexOf("hotman") > -1 || eq.ename.indexOf("intelligent") > -1) {
-							//拳击
+
+						if (eq.ename.indexOf("intelligent") > -1) {
+							//灯带 拳击
+							this.switchList(2);
+							this.$store.state.bIgnore = true;
+						} else if (eq.ename.indexOf("hotman") > -1) {
+							//手柄 拳击
 							this.switchList(2);
+							this.$store.state.bIgnore = false;
 						} else if (eq.ename.indexOf("rope") > -1) {
 							//跳绳
 							this.switchList(1);

+ 89 - 12
pages/personal-page/personal/personal.vue

@@ -231,7 +231,34 @@
 				</button> -->
 
 			<!-- </view> -->
-			<view class="cu-list menu card-menu">
+			<view v-if="false" class="cu-list menu card-menu">
+				<view class="cu-item">
+					<view class="content">
+						<text class="cuIcon-title text-green"></text>
+						<text class="text-grey">输入测试参数</text>
+					</view>
+				</view>
+				<checkbox-group class="block" @change="CheckboxChange">
+					<view class="cu-form-group">
+						<view class="title">是否拦截偶数帧数据({{bIgnore}})({{showMs}} ms)</view>
+						<checkbox :class="bIgnore?'checked':''" :checked="bIgnore?true:false" value="A"></checkbox>
+					</view>
+				</checkbox-group>
+				<view class="cu-item">
+					<view class="title">frameHitCapacity</view>
+					<input type="number" inputmode="numeric" class="uni-input"
+						style=" border: 1rpx solid #000;"
+						:value="hotmanIntelligentData.frameHitCapacity" @input="onFrameHitCapacityInput"
+						placeholder="输入frameHitCapacity" />
+				</view>
+				
+				<view class="cu-item">
+					<view class="title">slopeArr</view>
+					<input  class="uni-input"
+						style=" border: 1rpx solid #000;" :value="hotmanIntelligentData.slopeArr"
+						@input="onSlopeArrInput" placeholder="输入slopeArr" />
+				</view>
+				
 				<view class="cu-item">
 
 					<view class="content">
@@ -264,8 +291,8 @@
 						name="input"></input>
 					<button class='cu-btn round bg-green shadow' @click="onSendBLELightValue(readBLELight)">发送</button>
 				</view>
-				
-				
+
+
 				<view class="cu-item">
 					<view class="content">
 						<text class="cuIcon-btn text-green"></text>
@@ -276,7 +303,7 @@
 					</view>
 				</view>
 			</view>
-			<view class="cu-list menu card-menu">
+			<view v-if="false" class="cu-list menu card-menu">
 				<view class="cu-item">
 
 					<view class="content">
@@ -661,7 +688,11 @@
 			'sandbagHitCount',
 			'readDataName',
 			'filesList',
-			'readBLELight'
+			'readBLELight',
+
+			'hotmanData',
+			'hotmanIntelligentData',
+			'bIgnore'
 		]),
 		components: {
 			// uniNavBar,
@@ -861,8 +892,14 @@
 				/**
 				 * 记录一个旧的index
 				 */
-				oldModeIndex: 1
-
+				oldModeIndex: 1,
+				
+				checkbox: [{
+					value: 'A',
+					checked: true
+				}],
+				showMs:0,
+				oldMs:0,
 			};
 		},
 		onLoad() {
@@ -1000,7 +1037,8 @@
 
 			//
 			this.onGetReadBLELight();
-
+			
+			this.onGetHotmanIntelligentData();
 		},
 		onShow() {
 			_self.bHide = false;
@@ -1135,7 +1173,8 @@
 				'gOnAddClientInfo', 'onWriteBLEConnectionValue',
 				'gCreateFilterObj', 'gUpdateFilter', 'B_GetBondedDevices', 'B_OpenBLESetting', 'B_OpenRopeSkipping',
 				'B_CloseRopeSkipping',
-				'gCreateSandbagAlgorithm', 'gUpdateSandbagAlgorithm', 'gIntelligentUpdateSandbagAlgorithm',
+				'gCreateSandbagAlgorithm', 'gUpdateSandbagAlgorithm', 'gIntelligentCreateSandbagAlgorithm',
+				'gIntelligentUpdateSandbagAlgorithm',
 				'gStartSimulateBLEUpdate',
 				'gStopSimulateBLEUpdate',
 				'getActionJumpTask',
@@ -1168,7 +1207,9 @@
 				'onHitOpenBLELightNew',
 				'onGetReadBLELight',
 				'onSetReadBLELight',
-				'B_WriteHexToBLECharacteristic'
+				'B_WriteHexToBLECharacteristic',
+				'onGetHotmanIntelligentData',
+				'onSaveHotmanIntelligentData'
 			]),
 			BasicsSteps() {
 				this.basics = this.basics == this.basicsList.length - 1 ? 0 : this.basics + 1
@@ -1532,6 +1573,8 @@
 
 				if (this.BLEConnectDevice.usageMode == "hotman") {
 					if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
+						this.showMs = data.ms - this.oldMs;
+						this.oldMs = data.ms;
 						this.gIntelligentUpdateSandbagAlgorithm({
 							data: data,
 							callback: (res) => {
@@ -1827,8 +1870,14 @@
 									//倒计时结束后开始游戏
 									//初始化一个沙袋打击对象
 									if (this.BLEConnectDevice.usageMode == "hotman") {
-										this.gCreateSandbagAlgorithm();
+
+										if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
+											this.gIntelligentCreateSandbagAlgorithm();
+										} else {
+											this.gCreateSandbagAlgorithm();
+										}
 									}
+
 									if (this.BLEConnectDevice.usageMode == "ropeSkipping" ||
 										this.BLEConnectDevice.usageMode == "hotman") {
 										//打开跳绳模式
@@ -3467,8 +3516,36 @@
 					value: value
 				});
 				this.onSetReadBLELight(value);
-			}
+			},
 
+			onFrameHitCapacityInput: function(event) {
+				this.$store.state.hotmanIntelligentData.frameHitCapacity = event.target.value;
+				// console.log( this.hotmanIntelligentData);
+				this.onSaveHotmanIntelligentData();
+			},
+			onSlopeArrInput: function(event) {
+				this.$store.state.hotmanIntelligentData.slopeArr = event.target.value.split(',').map(Number);
+				// console.log( this.hotmanIntelligentData);
+				this.onSaveHotmanIntelligentData();
+			},
+
+			CheckboxChange(e) {
+				var items = this.checkbox,
+					values = e.detail.value;
+				let bCheck = false;
+				for (var i = 0, lenI = items.length; i < lenI; ++i) {
+					items[i].checked = false;
+					for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
+						if (items[i].value == values[j]) {
+							items[i].checked = true;
+							bCheck = true;
+							break
+						}
+					}
+				}
+				
+				this.$store.state.bIgnore = bCheck;
+			},
 		}
 	};
 </script>

+ 4 - 4
util/util-js/BLE_RGB.js

@@ -1,7 +1,7 @@
 //随机获取7种颜色中的一种颜色,常亮显示
 const getRandomRGB = () => {
 	let index = Math.floor(Math.random() * 7);
-	console.log("index:" + index);
+	// console.log("index:" + index);
 	let head = '5B0E02';
 	let tail = '5D';
 
@@ -15,7 +15,7 @@ const getRandomRGB = () => {
 		head = head.concat('00');
 	}
 	head = head.concat(tail);
-	console.log(head);
+	// console.log(head);
 	return head;
 }
 
@@ -33,7 +33,7 @@ const getRandomThreeRGB = () => {
 		out.push(arr.splice(temp, 1));
 	}
 
-	console.log("out:" + out);
+	// console.log("out:" + out);
 	let head = '5B0E02';
 	let tail = '5D';
 
@@ -56,7 +56,7 @@ const getRandomThreeRGB = () => {
 		head = head.concat(timeStr);
 	}
 	head = head.concat(tail);
-	console.log(head);
+	// console.log(head);
 	return head;
 }
 

+ 23 - 13
util/util-js/effect/firework.js

@@ -93,19 +93,29 @@ var Firework = function Firework(image, typeImage, direction, tx, ty, cw, ch, of
 	this.hiddenMidImage = hiddenMidImage || false;
 
 
-	const innerAudioContext = uni.createInnerAudioContext();
-	innerAudioContext.autoplay = true;
-	innerAudioContext.src = '/static/elect/hit.mp3';
-	innerAudioContext.onPlay(() => {
-		// console.log('开始播放');
-	});
-	innerAudioContext.onError((res) => {
-		console.log(res.errMsg);
-		console.log(res.errCode);
-	});
-	setTimeout(() => {
-		innerAudioContext.destroy();
-	}, 800)
+	// const innerAudioContext = uni.createInnerAudioContext();
+	// innerAudioContext.autoplay = true;
+	// innerAudioContext.src = '/static/elect/hit.mp3';
+	// innerAudioContext.onPlay(() => {
+	// 	// console.log('开始播放');
+	// });
+	// innerAudioContext.onError((res) => {
+	// 	console.log(res.errMsg);
+	// 	console.log(res.errCode);
+	// });
+	// setTimeout(() => {
+	// 	innerAudioContext.destroy();
+	// }, 800)
+	
+	// let p = plus.audio.createPlayer("/static/elect/hit.mp3");
+	// p.play(function() {
+	// 	alert("Audio play success!");
+	// }, function(e) {
+	// 	alert("Audio play error: " + e.message);
+	// });
+	// setTimeout(() => {
+	// 	p.close();
+	// }, 800)
 }
 
 Firework.prototype.addEventListener = function(type, listener) {

+ 16 - 8
util/util-js/o0ProjectRelease0.1.js

@@ -2,8 +2,11 @@ import o0 from "./o0.js"
 
 module.exports = {
 	SandbagAlgorithm: class {
-		constructor() {
-
+		constructor(option) {
+			let {
+				frameHitCapacity,
+				slopeArr
+			} = option;
 			this.stableAcc = new o0.Vector2(0, 0);
 			this.stableGyr = new o0.Vector2(0, 0);
 			this.stableCount = 0;
@@ -14,7 +17,11 @@ module.exports = {
 			this.frameLength = 5;
 			this.frameOffset = 0;
 
-			this.frameHitCapacity = 11;
+			// this.frameHitCapacity = 11;
+			this.frameHitCapacity = frameHitCapacity;
+			this.slopeArr = slopeArr;
+			console.log("init frameHitCapacity:" + this.frameHitCapacity + ",slopeArr:" + this
+				.slopeArr);
 			this.frameHit = []; //打击后的n帧
 
 			for (var i = 0; i < this.frameCapacity; ++i) {
@@ -130,14 +137,15 @@ module.exports = {
 			var direction = undefined;
 
 			//15 20 20 40 , 13 17 17 35
-			let slopeArr = [15, 20, 20, 40];
+			// let slopeArr = [15, 20, 20, 40];
+			// let slopeArr = this.slopeArr;// [13, 17, 17, 35];
 			if (lastFrame.hit == 0 &&
 				last2Frame.hit == 0 &&
 				last3Frame.hit == 0 &&
 				last4Frame.hit == 0 &&
 				last5Frame.hit == 0 &&
-				(newFrame.accSlope >= slopeArr[0] || lastFrame.accSlope >= slopeArr[1]) &&
-				(newFrame.shakeSlope >= slopeArr[2] || lastFrame.shakeSlope >= slopeArr[3])) {
+				(newFrame.accSlope >= this.slopeArr[0] || lastFrame.accSlope >= this.slopeArr[1]) &&
+				(newFrame.shakeSlope >= this.slopeArr[2] || lastFrame.shakeSlope >= this.slopeArr[3])) {
 				newFrame.hit = 1;
 				if (this.frameHit.length < this.frameHitCapacity && this.frameHit.length !=
 					0) { //判断到第二次hit,但还未输出第一次hit的方向,强制输出方向
@@ -188,8 +196,8 @@ module.exports = {
 			let directionPunch = "all",
 				name = "击中",
 				ename = "hit";
-			let positiveMidSlope = [70,110];//min max
-			let negativeMidSlope = [250,290];//min max
+			let positiveMidSlope = [70, 110]; //min max
+			let negativeMidSlope = [250, 290]; //min max
 			if (curAngle < positiveMidSlope[1] && curAngle >= positiveMidSlope[0]) {
 				directionPunch = "straightPunch";
 				name = "正向的直拳";

+ 55 - 10
util/util-js/store.js

@@ -449,7 +449,19 @@ const store = new Vuex.Store({
 		showLight: '',
 		showLightArray: [],
 		lightCount: 0,
-		readBLELight: '5B0E02141E141E141E00000000000000005D'
+		readBLELight: '5B0E02141E141E141E00000000000000005D',
+		//区分两个设备的参数
+		hotmanData: {
+			frameHitCapacity: 11,
+			slopeArr: [15, 20, 20, 40]
+		},
+		hotmanIntelligentData: {
+			frameHitCapacity: 11,
+			// slopeArr: [9, 13, 13, 25],
+			slopeArr: [7, 11, 11, 22]
+		},
+		bIgnore: true,
+		LastMS: 0
 	},
 	mutations: {
 
@@ -2124,7 +2136,7 @@ const store = new Vuex.Store({
 		gCreateSandbagAlgorithm(state) {
 			state.sandbagAlgorithm = null;
 			state.sandbagAlgorithmLastTime = new Date().getTime();
-			state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm();
+			state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm(state.hotmanData);
 			console.log("gCreateSandbagAlgorithm");
 
 		},
@@ -2187,6 +2199,17 @@ const store = new Vuex.Store({
 			}
 		},
 		//灯带
+		/**
+		 * 创建一个沙袋打击对象
+		 * @param {Object} state
+		 */
+		gIntelligentCreateSandbagAlgorithm(state) {
+			state.sandbagAlgorithm = null;
+			state.sandbagAlgorithmLastTime = new Date().getTime();
+			state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm(state.hotmanIntelligentData);
+			console.log("gCreateSandbagAlgorithm");
+
+		},
 		gIntelligentUpdateSandbagAlgorithm(state, context) {
 
 			let {
@@ -2239,7 +2262,7 @@ const store = new Vuex.Store({
 				state.lightTimeout == null;
 			};
 			this.commit('B_WriteHexToBLECharacteristic', {
-				value:  BLERGB.getRandomThreeRGB()
+				value: BLERGB.getRandomThreeRGB()
 			});
 			state.lightTimeout = setTimeout(() => {
 				//关闭红绿蓝
@@ -2946,7 +2969,20 @@ const store = new Vuex.Store({
 					box["hex"] = resValue;
 					//更新数据给webview,在game-play-web||game-play-sub绑定
 					//后面更新数据都用此接口
-					uni.$emit('updateBLEDeviceData', box);
+					// uni.$emit('updateBLEDeviceData', box);
+					//忽略偶数帧
+					if (state.bIgnore) {
+						state.LastMS++;
+						if (state.LastMS % 2 != 0){
+							uni.$emit('updateBLEDeviceData', box);
+						}
+						if (state.LastMS >= 1000){
+							state.LastMS = 0;
+						}
+					} else {
+						uni.$emit('updateBLEDeviceData', box);
+					}
+					
 				}
 
 				//todo 解析跳绳模式
@@ -3103,8 +3139,8 @@ const store = new Vuex.Store({
 				// 这里的value是ArrayBuffer类型
 				value: _sendData,
 				success: (res) => {
-					console.log('writeBLECharacteristicValue success', res.errMsg, value,
-						retryCount);
+					// console.log('writeBLECharacteristicValue success', res.errMsg, value,
+					// 	retryCount);
 					if (success) {
 						success(res);
 					}
@@ -3113,8 +3149,8 @@ const store = new Vuex.Store({
 					console.log(fail)
 					//重新写入
 					if (retryCount > 0) {
-						console.log("writeBLECharacteristicValue Rewrite ===================>" +
-							value + " == " + retryCount);
+						// console.log("writeBLECharacteristicValue Rewrite ===================>" +
+						// 	value + " == " + retryCount);
 						retryCount--;
 						setTimeout(() => {
 							this.commit("B_WriteBLECharacteristicValue", {
@@ -3155,8 +3191,8 @@ const store = new Vuex.Store({
 				characteristicId: state.writeCharacteristicId,
 				value: typedArray.buffer,
 				success: (res) => {
-					console.log('B_WriteHexToBLECharacteristicSuccess', res.errMsg, value,
-						retryCount);
+					// console.log('B_WriteHexToBLECharacteristicSuccess', res.errMsg, value,
+					// 	retryCount);
 					if (success) {
 						success(res);
 					}
@@ -4144,6 +4180,15 @@ const store = new Vuex.Store({
 			uni.setStorageSync('readBLELight', value);
 			state.readBLELight = value;
 		},
+		onGetHotmanIntelligentData(state) {
+			let _hotmanIntelligentData = uni.getStorageSync('hotmanIntelligentData');
+			if (_hotmanIntelligentData) {
+				state.hotmanIntelligentData = _hotmanIntelligentData;
+			}
+		},
+		onSaveHotmanIntelligentData(state) {
+			uni.setStorageSync('hotmanIntelligentData', state.hotmanIntelligentData);
+		},
 	}
 })