瀏覽代碼

1.替换跳,使用c算法

slambb 2 年之前
父節點
當前提交
7ff7e090d6
共有 4 個文件被更改,包括 446 次插入85 次删除
  1. 3 3
      common/config.js
  2. 192 71
      components/modal/action-jump/action-jump.vue
  3. 104 8
      pages/personal-page/personal/personal.vue
  4. 147 3
      util/util-js/store.js

+ 3 - 3
common/config.js

@@ -7,11 +7,11 @@ const refreshRate = "a";
 //*******当前活动环境,需要和根据地址设置!!环境 dev,prd
 const active = "dev";
 //线上地址,腾讯云服务器
-// const host="https://www.9527fun.cn/api_prd"
+//const host="https://www.9527fun.cn/api_prd"
 //测试地址,阿里云服务器
-// const host = "https://www.9527fun.cn/api_dev"
+const host = "https://www.9527fun.cn/api_dev"
 //本地测试地址
-const host = "http://192.168.0.108:9090/api_dev"
+// const host = "http://192.168.0.108:9090/api_dev"
 
 const URL = {
 	//验证token,获取服务器返回的信息

+ 192 - 71
components/modal/action-jump/action-jump.vue

@@ -432,7 +432,9 @@
 		},
 		beforeDestroy() {},
 		methods: {
-			...mapMutations(['onWriteBLEConnectionValue', 'onConvertDeviceData', "onSendSocketMessage"]),
+			...mapMutations(['onWriteBLEConnectionValue', 'onConvertDeviceData', "onSendSocketMessage",
+				'jumpIdenModule_onJump6AxisDataUpdate'
+			]),
 			//更新新手状态提示
 			onUpdateTipLevelValue(value) {
 				this.bTipLevel = value;
@@ -440,44 +442,44 @@
 			onListenActionJump() {
 				let _self = this;
 				console.log("*****************onListenActionHit*****************************");
-				_self.actionJumpObj = new ActionJump();
-				_self.actionJumpObj.addEventListener('resultant', (e) => {
-					if (e.type == 'stateDataOfJump') {
-						//发送给game,在game里面处理判断
-						this.listenStateDataOfJump(e);
-					} else if (e.type == 'stop') {
-						console.log("stop");
-						this.onClearData();
-						if (this.canOnDraw) {
-							this.canOnDraw = false;
-							// //这里更新特效
-							// this.onDrawEffect(this.canSpawnTemp);
-							this.onDraw("tipHit", true);
-						}
-						if (this.canGoNext) {
-							this.canGoNext = false;
-							// //这里更新特效
-							// this.onDrawEffect(this.canSpawnTemp);
-							//绘制新触发状态
-							this.onDraw("normal", false);
-							setTimeout(() => {
-								this.startJumpGame();
-							}, 500)
-						}
-						// console.log('stop');
-						//这里处理生成下一个
-					} else if (e.type == 'log') {
-						if (e.logType == 'normal') {
-							console.log(e.data);
-						} else if (e.logType == 'error') {
-							console.error(e.data);
-						} else if (e.logType == 'warn') {
-							console.warn(e.data);
-						} else if (e.logType == 'socket') {
-							this.onSendSocketMessage(e.data);
-						}
-					}
-				})
+				// _self.actionJumpObj = new ActionJump();
+				// _self.actionJumpObj.addEventListener('resultant', (e) => {
+				// 	if (e.type == 'stateDataOfJump') {
+				// 		//发送给game,在game里面处理判断
+				// 		this.listenStateDataOfJump(e);
+				// 	} else if (e.type == 'stop') {
+				// 		console.log("stop");
+				// 		this.onClearData();
+				// 		if (this.canOnDraw) {
+				// 			this.canOnDraw = false;
+				// 			// //这里更新特效
+				// 			// this.onDrawEffect(this.canSpawnTemp);
+				// 			this.onDraw("tipHit", true);
+				// 		}
+				// 		if (this.canGoNext) {
+				// 			this.canGoNext = false;
+				// 			// //这里更新特效
+				// 			// this.onDrawEffect(this.canSpawnTemp);
+				// 			//绘制新触发状态
+				// 			this.onDraw("normal", false);
+				// 			setTimeout(() => {
+				// 				this.startJumpGame();
+				// 			}, 500)
+				// 		}
+				// 		// console.log('stop');
+				// 		//这里处理生成下一个
+				// 	} else if (e.type == 'log') {
+				// 		if (e.logType == 'normal') {
+				// 			console.log(e.data);
+				// 		} else if (e.logType == 'error') {
+				// 			console.error(e.data);
+				// 		} else if (e.logType == 'warn') {
+				// 			console.warn(e.data);
+				// 		} else if (e.logType == 'socket') {
+				// 			this.onSendSocketMessage(e.data);
+				// 		}
+				// 	}
+				// })
 			},
 			//load 相关图片
 			onLoadImage() {
@@ -1361,6 +1363,89 @@
 				// 	this.eliminateJumpPrefabFormTemp(_tempState);
 				// }
 			},
+
+			//监听跳的状态数据
+			jumpIdenModule_listenStateDataOfJump(data) {
+
+				console.log(JSON.stringify(data));
+				if (this.spawnArray.length < 3) return;
+				let _jumpType = this.getCurrentJumpType();
+				//初始全部默认状态
+				let _tempState = [{
+						jumpName: 'NORMAL',
+						jumpCode: 0,
+						bTrigger: false,
+						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 _rotateLimit = 4;
+				let _jumpLimit = 0;
+
+				switch (_jumpType) {
+					case 0:
+						//JumpType.NORMAL = 0
+						if (data.tag === 0) {
+							_tempState[0].bTrigger = true;
+						}
+						this.eliminateJumpPrefabFormTemp(_tempState);
+						break;
+					case 1:
+						if (data.tag === 2) {
+							//left jump
+							_tempState[1].bTrigger = true;
+						}
+						this.eliminateJumpPrefabFormTemp(_tempState);
+						break;
+					case 2:
+						if (data.tag === 1) {
+							//right jump
+							_tempState[2].bTrigger = true;
+						}
+						this.eliminateJumpPrefabFormTemp(_tempState);
+						break;
+					case 4:
+						if (data.tag === 3) {
+							_tempState[4].bTrigger = true;
+						}
+						this.eliminateJumpPrefabFormTemp(_tempState);
+						break;
+					case 3:
+						if (data.tag === 4) {
+							_tempState[3].bTrigger = true;
+						}
+						this.eliminateJumpPrefabFormTemp(_tempState);
+						break;
+					default:
+						console.log('没有对应的_jumpType', _jumpType);
+						break;
+				}
+			},
+
 			eliminateJumpPrefabFormTemp(_tempState) {
 				//只触发第三个
 				if (this.spawnArray.length < 3) {
@@ -1397,16 +1482,32 @@
 					}
 					//成功
 					this.setEliminationCount(1);
+
+					//去除原本算法后添加 start
+					console.log("stop");
+					this.onClearData();
+					//去除原本算法后添加 end
 					//替换数组
 					// console.log(this.index + " == " + this.spawnArray.length);
 					if (this.spawnArray.length < 3 && this.index > 3) {
 						clearInterval(this.countdownInterval);
 						this.countdownInterval = null;
 						//绘制新触发状态
-						this.canGoNext = true;
+						//this.canGoNext = true; //去除jumpAction注销
+
+						//去除原本算法后添加 start
+						this.onDraw("normal", false);
+						setTimeout(() => {
+							this.startJumpGame();
+						}, 500)
+						//去除原本算法后添加 end
 					} else {
 						//绘制新触发状态
-						this.canOnDraw = true;
+						// this.canOnDraw = true; //去除jumpAction注销
+
+						//去除原本算法后添加 start
+						this.onDraw("tipHit", true);
+						//去除原本算法后添加 end
 					}
 
 				} else {
@@ -1425,6 +1526,26 @@
 			onBLERopeUpdate(gameData) {
 				if (!this.bJumpPlay || this.isGameOver || this.spawnAnimation != null) return;
 
+
+				//调用识别算法
+				this.jumpIdenModule_onJump6AxisDataUpdate({
+					data: {
+						hex: gameData.hex
+					},
+					callback: (res) => {
+						if (res.code == 0) {
+							if (res.tag != -1) {
+								this.jumpIdenModule_listenStateDataOfJump(res);
+								uni.showToast({
+									title: res.tag + ',' + res.msg,
+									icon: 'none',
+									duration: 1000,
+									mask: true
+								})
+							}
+						}
+					}
+				});
 				//********陀螺仪角速度********
 				let {
 					gx,
@@ -1454,36 +1575,36 @@
 				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
-					},
-					//输入当前轴,旧设备使用Y轴,即为true
-					bYAxis: this.bOldDeviceType ? true : false,
-				};
-				this.actionJumpObj.updateJump(_temp);
+				// 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
+				// 	},
+				// 	//输入当前轴,旧设备使用Y轴,即为true
+				// 	bYAxis: this.bOldDeviceType ? true : false,
+				// };
+				//this.actionJumpObj.updateJump(_temp);
 				this.BLEAccIndex++;
 			},
 			onClearData() {

+ 104 - 8
pages/personal-page/personal/personal.vue

@@ -191,7 +191,46 @@
 												hiddenType: 'firstInstallation'
 											})">计划</button>
 			</view> -->
-
+			<view class="flex align-center margin text-white">
+				<view class="title" style="width: 150rpx;">轨迹名称:</view>
+				<input class="uni-input" style="width: 250rpx; border: 1rpx solid #FFFFFF;" :value="readDataName" @input="onReadDataNameInput"
+					placeholder="输入轨迹名称" />
+				<button type="primary" style="width: 250rpx; height: 50rpx; font-size: 14px; line-height: 50rpx;" @click="jumpIdenModule_SearchData">
+					获取列表
+				</button>
+			</view>
+			<scroll-view scroll-y="true" style="height: 280rpx; background-color: #c6c6c6;">
+				<view class="card-view padding-top-sm padding-bottom-sm" v-for="(item,index) in filesList" :key="index"
+					:id="'task_'+index" :class="item.bRatio?'hardware-border':''">
+					<view class="flex justify-between align-center">
+						<view class="flex justify-start align-center">
+							<view style="margin-left: 10rpx;">
+								<view style="margin: 5rpx; font-weight: bold; font-size: 18px; color: #565656;">
+									{{item.cname}}
+								</view>
+							</view>
+						</view>
+						<image style="margin-right: 60rpx; width: 60rpx;height: 60rpx;"
+							:src="item.bRatio?'/static/devicesOther/radio-b.png':'/static/devicesOther/radio-g.png'"
+							mode="aspectFit" @tap="_jumpIdenModule_DownloadReadData(item)"></image>
+					</view>
+				</view>
+			</scroll-view>
+			
+			<!-- <view class="margin-sm "> -->
+				<!-- <button type="primary" @click="jumpIdenModule_onJumpInit">
+					使用本地默认轨迹
+				</button>
+				<button type="primary" class=" margin-top-sm"  @click="jumpIdenModule_onJumpInitLocalData">
+					使用so默认轨迹
+				</button> -->
+			
+				<!-- onTestUpdate -->
+				<!-- <button type="primary" class="margin-top-sm" @click="jumpIdenModule_onTestUpdate">
+					模拟跳数据输入
+				</button> -->
+			
+			<!-- </view> -->
 			<view style="height: 50rpx;"></view>
 		</scroll-view>
 
@@ -550,7 +589,9 @@
 			'finallySelectFriendInfo',
 			'currentJumpTask', 'singlePersonList', 'multiPersonList',
 			'guideUnlockState',
-			'sandbagHitCount'
+			'sandbagHitCount',
+			'readDataName',
+			'filesList'
 		]),
 		components: {
 			// uniNavBar,
@@ -879,6 +920,14 @@
 
 			//获取对应的用户数据,并且设置记录的打击数据
 			this.getUserData_hitCount();
+
+
+			//获取记录的数据
+			this.onGetReadDataName();
+			plus.globalEvent.addEventListener("onTestModuleUpdate", this.onTestModuleUpdateCallback);
+			//初始化一个android数据
+			this.jumpIdenModule_onJumpInit();
+
 		},
 		onShow() {
 			_self.bHide = false;
@@ -968,7 +1017,7 @@
 			}
 
 			// #endif
-			
+
 			this.onConnectSocket();
 		},
 		onUnload() {
@@ -1026,8 +1075,19 @@
 				'resetActionJumpTask',
 				'getUserData_hitCount',
 				'uploadUserData_hitCount', 'getUserData_hitCount',
-				'addSandbagHitCount',
-				,'onConnectSocket','onCloseSocket','onSendSocketMessage'
+				'addSandbagHitCount', , 'onConnectSocket', 'onCloseSocket', 'onSendSocketMessage',
+
+				//算法相关START
+				'onGetReadDataName',
+				'onSetReadDataName',
+				'jumpIdenModule_SearchData',
+				'jumpIdenModule_DownloadReadData',
+				'jumpIdenModule_onJumpInit',
+				'jumpIdenModule_onJumpInitLocalData',
+				'jumpIdenModule_onJump6AxisDataUpdate',
+				'jumpIdenModule_onTestUpdate',
+				'jumpIdenModule_onTestJump6AxisDataUpdate',
+				//算法相关END
 			]),
 			BasicsSteps() {
 				this.basics = this.basics == this.basicsList.length - 1 ? 0 : this.basics + 1
@@ -1422,7 +1482,7 @@
 					//这个是普通打击模式
 					this.$refs.boxingPostRef.onBLEHandleUpdate(data);
 				} else if (this.BLEConnectDevice.usageMode == "ropeSkipping") {
-					
+
 					this.$refs.actionJumpRef.onBLERopeUpdate(data);
 					// this.onConvertDeviceData({
 					// 	data: data,
@@ -3201,8 +3261,8 @@
 			onReset() {
 				this.$store.state.sandbagHitCount = 0;
 			},
-			
-			onSendMsg(){
+
+			onSendMsg() {
 				let msg = [{
 					"maxValue": 19.267578125,
 					"gyroValue": -1172.607421875,
@@ -3400,6 +3460,42 @@
 					}
 				}];
 				this.onSendSocketMessage(msg);
+			},
+
+
+			onReadDataNameInput: function(event) {
+				this.onSetReadDataName(event.target.value);
+			},
+
+			onTestModuleUpdateCallback(res) {
+				console.log(JSON.stringify(res));
+				if (res.code == 0) {
+					if (res.tag == -1) {
+						// this.normalText = "测试 msg:" + res.msg + ",return int:" + res.tag + "\n";
+					} else {
+						//识别到跳
+						uni.showToast({
+							title: res.tag + ',' + res.msg,
+							icon: 'none',
+							duration: 1000,
+							mask: true
+						})
+					}
+				}
+
+			},
+
+			_jumpIdenModule_DownloadReadData(item) {
+				if (this.currentJumpItem)
+					this.currentJumpItem.bRatio = false;
+
+				this.currentJumpItem = item;
+				this.jumpIdenModule_DownloadReadData({
+					data: item,
+					callback: (res) => {
+						item.bRatio = true;
+					}
+				});
 			}
 		}
 	};

+ 147 - 3
util/util-js/store.js

@@ -12,6 +12,10 @@ import o0ProjectRelease from "@/util/util-js/o0ProjectRelease0.1.js"
 
 import deviceData from "@/util/util-js/devices.js"
 
+// 加载算法插件 JumpIdentificationModule
+var jumpIdenModule = uni.requireNativePlugin("JumpIdentificationModule")
+
+
 Vue.use(Vuex)
 
 const store = new Vuex.Store({
@@ -433,9 +437,15 @@ const store = new Vuex.Store({
 		 */
 		signInList: [],
 		isSignIn: false,
-
+		
+		//读取文件的名称
+		readDataName:"",
+		filesList: [],
 	},
 	mutations: {
+		
+		
+		
 		/**
 		 * 蓝牙解析后的数据,转化成对应的坐标系方向
 		 * @param {Object} context
@@ -2790,7 +2800,8 @@ const store = new Vuex.Store({
 					box["min"] = min;
 					box["s"] = s;
 					box["ms"] = ms;
-
+					//16进制参数
+					box["hex"] = resValue;
 					//更新数据给webview,在game-play-web||game-play-sub绑定
 					//后面更新数据都用此接口
 					uni.$emit('updateBLEDeviceData', box);
@@ -3790,7 +3801,140 @@ const store = new Vuex.Store({
 			uni.sendSocketMessage({
 				data: JSON.stringify(msg)
 			});
-		}
+		},
+		
+		
+		//jumpIdenModule 算法插件  start
+		jumpIdenModule_SearchData(state, context) {
+			state.filesList = [];
+			let {
+				data,
+				callback = null
+			} = context;
+			let url = "http://42.192.165.168:2022/search";
+			let _temp = {
+				name: state.readDataName
+			}
+			console.log('requestData search ===== url:' + url);
+			reqUtil.requestData(url, _temp,'POST').then(res => {
+				
+					let strArray = res.split('\n');
+						console.log(strArray);
+					for (let i = 0; i < strArray.length-1; i++) {
+						let _name = strArray[i].split('.')[0];
+						if (_name.Length <= 0) continue;
+						let item = Object.assign({}, {
+							cname:_name,
+							bRatio: false
+						});
+						state.filesList.push(item);
+					}
+					uni.showToast({
+						title: '获取列表成功!',
+						icon: 'none',
+						duration: 1000,
+						mask: true
+					})
+				},
+				e => {
+					console.log(e)
+					uni.showToast({
+						title: '请求失败!',
+						icon: 'none',
+						duration: 1000,
+						mask: true
+					})
+				});
+		},
+		jumpIdenModule_DownloadReadData(state,context) {
+			let {
+				data,
+				callback = null
+			} = context;
+			let downloadUrl = "http://42.192.165.168:2022/download";
+			console.log('requestData downloadUrl ===== url:' + downloadUrl);
+			reqUtil.requestData(downloadUrl, {name:data.cname},'POST').then(res => {
+					//console.log(res);
+					uni.setStorageSync('readData', res);
+					if(callback)
+						callback(res);
+					//读取的数据传入android端
+					let _temp = jumpIdenModule.onJumpInitInputData({
+						data: res
+					})
+					
+					uni.showToast({
+						title: '' + _temp.msg,
+						icon: 'none',
+						duration: 1000,
+						mask: true
+					})
+				},
+				e => {
+					console.log(e)
+					uni.showToast({
+						title: '请求失败!',
+						icon: 'none',
+						duration: 1000,
+						mask: true
+					})
+				});
+		},
+		jumpIdenModule_onJumpInit() {
+			let res = jumpIdenModule.onJumpInit();
+			uni.showToast({
+				title: ''+ res.code,
+				icon: 'none',
+				duration: 1000,
+				mask: true
+			})
+		},
+		jumpIdenModule_onJumpInitLocalData(){
+			let res = jumpIdenModule.onJumpInitLocalData();
+			uni.showToast({
+				title: ''+ res.code,
+				icon: 'none',
+				duration: 1000,
+				mask: true
+			})
+		},
+		jumpIdenModule_onTestJump6AxisDataUpdate() {
+			let box = {};
+			box["acc"] = {
+				ax: 11,
+				ay: 22,
+				az: 33,
+			};
+			box["gyro"] = {
+				gx: 111,
+				gy: 222,
+				gz: 333,
+			};
+			box["ms"] = 33;
+			jumpIdenModule.onJump6AxisDataUpdate(box)
+		},
+		jumpIdenModule_onTestUpdate() {
+			jumpIdenModule.onTestUpdate();
+		},
+		jumpIdenModule_onJump6AxisDataUpdate(state,context){
+			let {
+				data,
+				callback = null
+			} = context;
+			let res = jumpIdenModule.onJump6AxisDataUpdate({hex:data.hex});
+			if(callback)
+				callback(res);
+		},
+		
+		onGetReadDataName(state){
+			console.log(1)
+			state.readDataName = uni.getStorageSync('readDataName');
+		},
+		onSetReadDataName(state, value) {
+			uni.setStorageSync('readDataName', value);
+			state.readDataName = value;
+		},
+		//jumpIdenModule 算法插件 end
 
 	}
 })