Ver Fonte

1.整合跳识别部分代码。需要适配不同方向轴测试问题

slambb há 4 anos atrás
pai
commit
b4cb9a378d

+ 261 - 15
components/modal/action-jump/action-jump.vue

@@ -120,6 +120,9 @@
 	import boxingCountDown from '@/components/uni-count-down/uni-count-down.vue'
 
 
+	import ActionJump from "@/util/util-js/action/jump.js"
+
+
 	export default {
 		components: {
 			boxingCountDown
@@ -177,13 +180,13 @@
 					jumpName: 'LEFT_ROTATE',
 					jumpCode: 3,
 					icon: 'rotateJump',
-					scaleX: 1,
+					scaleX: -1,
 					bTrigger: false,
 				}, {
 					jumpName: 'RIGHT_ROTATE',
 					jumpCode: 4,
 					icon: 'rotateJump',
-					scaleX: -1,
+					scaleX: 1,
 					bTrigger: false,
 				}],
 				spawnArray: [],
@@ -225,7 +228,15 @@
 
 				bJumpPlay: false,
 				jumpCalorie: 1000,
-				jumpSpeed: 1000
+				jumpSpeed: 1000,
+
+				//硬件设备处理
+				BLEAccIndex: 0,
+				bJump: false,
+				xA: 0,
+				yA: 0,
+				zA: 0,
+				actionJumpObj: null
 			}
 		},
 
@@ -241,6 +252,41 @@
 			this.canvasW = this.SystemInfo.windowWidth; // 画布宽度
 			this.canvasH = 114;
 
+			// this.xA = 0;
+			// this.yA = 0;
+			// this.zA = 0;
+			// this.bJump = false;
+
+			_self.actionJumpObj = new ActionJump();
+
+			_self.actionJumpObj.addEventListener('resultant', (e) => {
+				if (e.type == 'jump') {
+					// this.jumpCount++;
+					this.bJump = true;
+				} else if (e.type == 'peakOfWave') {} else if (e.type == 'valleyOfWave') {} else if (e.type ==
+					'curAngle') {
+					// if (e.value > 0) {
+					//     this.rotate.rotation = 180;
+					//     this.playerControScript.leftJump();
+					// } else {
+					//     this.rotate.rotation = 0;
+					//     this.playerControScript.rightJump();
+					// }
+				} else if (e.type == 'rotate') {
+
+				} else if (e.type == 'stateDataOfJump') {
+					//发送给game,在game里面处理判断
+					this.listenStateDataOfJump(e);
+				} else if (e.type == 'bUpdateDraw') {
+
+				} else if (e.type == 'stop') {
+
+					this.onClearData();
+					console.log('stop');
+				}
+
+
+			})
 		},
 		methods: {
 			//load 相关图片
@@ -352,7 +398,7 @@
 					if (_ranType >= 1) ran2 += 2;
 
 					_newArray = _newArray.concat(_spawnList2[ran2]);
-					console.log(_newArray);
+					// console.log(_newArray);
 					for (let i = 0; i < _newArray.length; i++) {
 						this.spawnJumpPrefabsFromType(i, _newArray[i]);
 					}
@@ -395,17 +441,17 @@
 
 				this.onDraw();
 			},
-			spawnJumpPrefabsFromType(index,_jumpType) {
+			spawnJumpPrefabsFromType(index, _jumpType) {
 
 				//todo 生成的节点,后面再处理节奏问题。比如生成顺序
-				for(let i=0;i<this.jumpTypeArray.length;i++){
-					if(this.jumpTypeArray[i].jumpCode == _jumpType){
+				for (let i = 0; i < this.jumpTypeArray.length; i++) {
+					if (this.jumpTypeArray[i].jumpCode == _jumpType) {
 						let _jumpPrefab = Object.assign({}, this.jumpTypeArray[i]);
 						this.spawnArray.push(_jumpPrefab);
 						break;
 					}
 				}
-			
+
 
 			},
 			spawnJumpPrefabs(index) {
@@ -590,22 +636,25 @@
 			// update (dt) {}
 
 			eliminateJumpPrefab(_jumpType) {
-				//如果消除完,需要重新生成
-				if (this.index >= this.spawnArray.length) return;
 				let _temp = this.spawnArray[this.index];
-				_temp.bTrigger = true;
-				this.index++;
-				//绘制新触发状态
-				this.onDraw();
 				//如果当前的跳类型和预制目标一样
 				if (_jumpType == _temp.jumpCode) {
+					_temp.bTrigger = true;
+					this.index++;
+					if (this.index >= this.spawnArray.length) {
+						clearInterval(this.countdownInterval);
+						this.countdownInterval = null;
+						this.startJumpGame();
+					} else {
+						//绘制新触发状态
+						this.onDraw();
+					}
 					//成功
 					this.setEliminationCount(1);
 				} else {
 					//失误
 					this.setFaultCount(1);
 				}
-
 			},
 
 			//设置倒计时
@@ -628,12 +677,209 @@
 			},
 			//控制播放
 			onControllerPlay() {
+				this.$emit("onControllerPlay");
 				this.bJumpPlay = !this.bJumpPlay;
 				if (this.bJumpPlay) {
 					this.startJumpGame();
 				} else {
 					this.onClear();
 				}
+			},
+
+			getCurrentJumpType() {
+				let _temp = this.spawnArray[this.index];;
+				return _temp.jumpCode;
+			},
+
+			//监听跳的状态数据
+			listenStateDataOfJump(data) {
+				let _jumpType = this.getCurrentJumpType();
+				//初始全部默认状态
+				let _tempState = [{
+						jumpName: 'NORMAL',
+						jumpCode: 0,
+						bTrigger: true,
+						describe: '正常跳'
+					},
+					{
+						jumpName: 'LEFT',
+						jumpCode: 1,
+						bTrigger: false,
+						describe: '左直跳'
+					},
+					{
+						jumpName: 'RIGHT',
+						jumpCode: 2,
+						bTrigger: false,
+						describe: '右直跳'
+					},
+					{
+						jumpName: 'LEFT_ROTATE',
+						jumpCode: 3,
+						bTrigger: false,
+						describe: '左旋转跳'
+					},
+					{
+						jumpName: 'RIGHT_ROTATE',
+						jumpCode: 4,
+						bTrigger: false,
+						describe: '右旋转跳'
+					}
+				];
+
+
+				let {
+					currentMaxValue,
+					oGyroValue
+				} = data
+				console.log('====', data);
+				if (currentMaxValue == 0) {
+					//JumpType.NORMAL = 0
+					if (_jumpType == 0) {
+						console.log('1====', data);
+						this.eliminateJumpPrefabFormTemp(_tempState);
+					}
+					//JumpType.RIGHT_ROTATE = 4
+					else if (_jumpType == 4 && oGyroValue < 0) {
+						console.log('right1:', oGyroValue);
+						_tempState[4].bTrigger = true;
+						this.eliminateJumpPrefabFormTemp(_tempState);
+					}
+					//JumpType.LEFT_ROTATE = 3
+					else if (_jumpType == 3 && oGyroValue > 0) {
+						console.log('left1:', oGyroValue);
+						_tempState[3].bTrigger = true;
+						this.eliminateJumpPrefabFormTemp(_tempState);
+					}
+
+				} else {
+					console.log('2====', data);
+					if (currentMaxValue > 5) {
+						_tempState[1].bTrigger = true;
+					} else if (currentMaxValue < -5) {
+						_tempState[2].bTrigger = true;
+					}
+
+					//如果是检测到旋转跳
+					if (oGyroValue < -5) {
+						console.log('right:', oGyroValue);
+						_tempState[4].bTrigger = true;
+					} else if (oGyroValue > 5) {
+						console.log('left:', oGyroValue);
+						_tempState[3].bTrigger = true;
+					}
+
+					this.eliminateJumpPrefabFormTemp(_tempState);
+				}
+			},
+			eliminateJumpPrefabFormTemp(_tempState) {
+				//如果消除完,需要重新生成
+				let _temp = this.spawnArray[this.index];
+				let bSuccess = false;
+				console.log(_tempState);
+				for (let i = 0; i < _tempState.length; i++) {
+					let _state = _tempState[i];
+					//如果当前的跳类型和预制目标一样
+					if (_state.jumpCode == _temp.jumpCode && _state.bTrigger) {
+						//成功
+						bSuccess = true;
+						break;
+					}
+				}
+				//如果存在其中一个为true
+				if (bSuccess) {
+					console.log("bSuccess:", bSuccess);
+					_temp.bTrigger = true;
+					this.index++;
+					if (this.index >= this.spawnArray.length) {
+						clearInterval(this.countdownInterval);
+						this.countdownInterval = null;
+						this.startJumpGame();
+					} else {
+						//绘制新触发状态
+						this.onDraw();
+					}
+					//成功
+					this.setEliminationCount(1);
+				} else {
+					//失误
+					this.setFaultCount(1);
+				}
+
+
+			},
+
+
+			/**
+			 * @param {Object} gameData
+			 * 识别跳部分数据处理
+			 */
+			onBLERopeUpdate(gameData) {
+				//********陀螺仪角速度********
+				let {
+					gx,
+					gy,
+					gz
+				} = gameData.gyro;
+				let {
+					min,
+					s,
+					ms
+				} = gameData;
+
+				let _ax = -gameData.acc.ax * 10;
+				let _ay = gameData.acc.ay * 10;
+				let _az = gameData.acc.az * 10;
+				//低通滤波分离重力
+				let alpha = 0.8;
+				this.xA = alpha * this.xA + (1 - alpha) * _ax;
+				this.yA = alpha * this.yA + (1 - alpha) * _ay;
+				this.zA = alpha * this.zA + (1 - alpha) * _az;
+
+				//高通滤波获取线性速度
+				let linear_acceleration_x = _ax - this.xA;
+				let linear_acceleration_y = _az - this.zA;
+				let linear_acceleration_z = _ay - this.yA;
+
+				let _temp = {
+					linearAcc: {
+						lAccX: linear_acceleration_x,
+						lAccY: linear_acceleration_y,
+						lAccZ: linear_acceleration_z
+					}, //gameData.acc,
+					oriAcc: {
+						oAccX: _ax,
+						oAccY: _ay,
+						oAccZ: _az
+					},
+					gravityAcc: {
+						gravityX: this.xA,
+						gravityY: this.yA,
+						gravityZ: this.zA
+					},
+					bLimitRebound: false,
+					resultant: Math.sqrt(_ax * _ax +
+						_ay * _ay + _az * _az),
+					runIndex: this.BLEAccIndex,
+					//陀螺仪
+					oriGyro: {
+						oGyroX: gx,
+						oGyroY: gy,
+						oGyroZ: gz
+					}
+				};
+				this.actionJumpObj.updateJump(_temp);
+
+
+				if (this.BLEAccIndex > 150) {
+					this.onClearData();
+					this.bJump = false;
+				}
+				this.BLEAccIndex++;
+				this.oldxA = this.xA;
+			},
+			onClearData() {
+				this.BLEAccIndex = 0;
 			}
 		}
 	}

+ 32 - 20
pages/personal-page/personal/personal.vue

@@ -43,7 +43,8 @@
 										<HitEffect ref="aiHitEffectRef"></HitEffect>
 									</view>
 									<view style="margin-top: 20rpx; width: 165rpx;" class="text-cut text-white">
-										{{userName}}</view>
+										{{userName}}
+									</view>
 								</view>
 
 								<view>
@@ -57,7 +58,8 @@
 										<HitEffect ref="hitEffectRef"></HitEffect>
 									</view>
 									<view style="margin-top: 20rpx; width: 165rpx;" class="text-cut text-white">
-										{{aiObj.name}}</view>
+										{{aiObj.name}}
+									</view>
 								</view>
 
 								<view
@@ -81,10 +83,11 @@
 								<!-- <view class="personal-fruit-container">
 									<fruit ref="personalFruitRef" :calorie="planData.allCalorie"></fruit>
 								</view> -->
-								
+
 								<!-- 计划运动时间提示 -->
 								<view class="personal-fruit-container">
-									<LEDFont style="margin-top: 50px;" :showValue = '99' :size="66" color='#FFFFFF'></LEDFont>
+									<LEDFont style="margin-top: 50px;" :showValue='99' :size="66" color='#FFFFFF'>
+									</LEDFont>
 									<!-- <view style="margin-top: 130px;font-size:12px;color: #FFFFFF;">计划时间{{planData.sportTime}}分钟</view> -->
 								</view>
 								<!-- 计划按钮 -->
@@ -133,7 +136,7 @@
 							</view>
 
 							<view id='actionJumpID' v-if="true" class="charts-pring-bottom">
-								<action-jump ref="actionJumpRef"></action-jump>
+								<action-jump ref="actionJumpRef" @onControllerPlay="onPersonalCheck"></action-jump>
 							</view>
 							<!-- <button @tap="onTestAddLocalCalorie">11</button> -->
 						</view>
@@ -212,7 +215,8 @@
 											style="text-align: start; line-height: 24px; font-weight: 400;">累计消耗</text>
 										<view class="text-11px "
 											style="text-align: start;font-weight: 400; line-height: 28px;">
-											{{ planData.cumulativeCalorie }}/ka</view>
+											{{ planData.cumulativeCalorie }}/ka
+										</view>
 										<view class="text-gray" style="font-size: 10px;">始于{{ planData.startTime }}
 										</view>
 									</view>
@@ -229,7 +233,8 @@
 										<text style="text-align: start; line-height: 24px;font-weight: 400;">剩余天数</text>
 										<view class="text-11px "
 											style="text-align: start;font-weight: 400;line-height: 28px;">
-											{{ remainingDays }}/day</view>
+											{{ remainingDays }}/day
+										</view>
 										<view class="text-gray" style="font-size: 10px;">计划天数{{ days }}</view>
 									</view>
 								</view>
@@ -497,7 +502,8 @@
 						<view style="width: 80rpx;height: 2rpx;border-radius: 2px;background-color: #cbcdcf;"></view>
 					</view>
 					<view class="text-16px" style="align-self: center; max-width: 200px; word-break: break-all;">
-						{{planTip[planTipIndex]}}</view>
+						{{planTip[planTipIndex]}}
+					</view>
 
 					<view class="flex justify-around align-center"
 						style=" border-top: 1rpx solid #EEEEEE; margin-bottom: 2px;">
@@ -1364,13 +1370,13 @@
 						}
 					} else if (eq.ename.indexOf("rope") > -1 && this.BLEConnectDevice.id == 3) {
 						//todo 暂时设置兼容跑步模式
-						if (this.$refs.boxingPostRef) {
-							this.$refs.boxingPostRef.onSetMode('ropeMode');
-						} else {
-							setTimeout(() => {
-								this.$refs.boxingPostRef.onSetMode('ropeMode');
-							}, 500)
-						}
+						// if (this.$refs.boxingPostRef) {
+						// 	this.$refs.boxingPostRef.onSetMode('ropeMode');
+						// } else {
+						// 	setTimeout(() => {
+						// 		this.$refs.boxingPostRef.onSetMode('ropeMode');
+						// 	}, 500)
+						// }
 					}
 				}
 			},
@@ -1451,10 +1457,7 @@
 					this.$refs.boxingPostRef.onBLEHandleUpdate(data);
 				} else if (this.BLEConnectDevice.usageMode == "ropeSkipping") {
 					//跳绳蓝牙反馈
-					let _data = {
-						jump: 1
-					}
-					this.$refs.boxingPostRef.onBLERopeUpdate(_data);
+					this.$refs.actionJumpRef.onBLERopeUpdate(data);
 
 				}
 
@@ -1563,7 +1566,7 @@
 							} else if (eq.ename.indexOf("BLEHandle") > -1 && this.BLEConnectDevice.id == 2) {
 								this.$refs.boxingPostRef.onSetMode('calorieMode');
 							} else if (eq.ename.indexOf("rope") > -1 && this.BLEConnectDevice.id == 3) {
-								this.$refs.boxingPostRef.onSetMode('ropeMode');
+								// this.$refs.boxingPostRef.onSetMode('ropeMode');
 							}
 						}
 					}
@@ -1849,6 +1852,15 @@
 						this.onBoxingGuideFinish();
 					}
 
+				} else if (1 == this.currentModeIndex) {
+					console.log();
+					if (this.BLEConnectDevice.usageMode == "ropeSkipping") {
+						//打开跳绳模式
+						this.B_OpenRopeSkipping();
+					}
+					//监听蓝牙回调
+					uni.$on('updateBLEDeviceData', this.callbackUpdateBLEData);
+					
 				}
 			},
 			onShowBoxingHitTip() {

+ 13 - 6
util/util-js/store.js

@@ -2517,20 +2517,27 @@ const store = new Vuex.Store({
 		 * 开启跳绳模式
 		 */
 		B_OpenRopeSkipping() {
+			// this.commit('onWriteBLEConnectionValue', {
+			// 	value: "5B310101FE5D",
+			// 	bSendHex: true,
+			// 	bOpen: true
+			// });
+			console.log('B_OpenRopeSkipping',3);
 			this.commit('onWriteBLEConnectionValue', {
-				value: "5B310101FE5D",
-				bSendHex: true,
-				bOpen: true
+				value: "3"
 			});
 		},
 		/**
 		 * 关闭跳绳模式
 		 */
 		B_CloseRopeSkipping() {
+			// this.commit('onWriteBLEConnectionValue', {
+			// 	value: "5B210100FF5D",
+			// 	bSendHex: true,
+			// 	bOpen: false
+			// });
 			this.commit('onWriteBLEConnectionValue', {
-				value: "5B210100FF5D",
-				bSendHex: true,
-				bOpen: false
+				value: "4"
 			});
 		},
 		//向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持 write 才可以成功调用。