Forráskód Böngészése

1.添加彩灯操作

slambb 2 éve
szülő
commit
12d1f23aa6

+ 3 - 1
components/modal/action-hit/action-hit.vue

@@ -412,7 +412,7 @@
 			
 		},
 		methods: {
-			...mapMutations(['onWriteBLEConnectionValue', 'onConvertDeviceData']),
+			...mapMutations(['onHitOpenBLELight']),
 			//更新新手状态提示
 			onUpdateTipLevelValue(value) {
 				this.bTipLevel = value;
@@ -964,6 +964,8 @@
 							this.startJumpGame();
 						}, 2000)
 					}
+					
+					// this.onHitOpenBLELight();
 				} else {
 					//失误
 					this.setFaultCount(1);

+ 2 - 2
manifest.json

@@ -2,8 +2,8 @@
     "name" : "哔蹦",
     "appid" : "__UNI__2635DF5",
     "description" : "",
-    "versionName" : "2.5.43",
-    "versionCode" : 23050601,
+    "versionName" : "2.5.44",
+    "versionCode" : 23050901,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {

+ 8 - 2
pages/game-page/game-play-sub/subGame/subGame.nvue

@@ -3,7 +3,7 @@
 		<!-- :src="url" src = 'http://192.168.0.112:7456/build/index.html' :src="LocationGameUrl" -->
 		<!-- @receivedtitle="onReceivedTitle"   @pagefinish="onPageFinish" http://192.168.31.223:7456/-->
 		<view class="web-view">
-			<web-view class="web-view-child" :src="url" ref="webview" @pagestart="onPageStart"
+			<web-view class="web-view-child" src = 'http://192.168.0.109:7456/' ref="webview" @pagestart="onPageStart"
 				@onPostMessage="handlePostMessage" @error="onError"></web-view>
 		</view>
 
@@ -213,7 +213,7 @@
 			uni.$emit("game-unload");
 		},
 		methods: {
-			...mapMutations(['addlocalCalorie', 'syncRequestEvent', 'onWriteBLEConnectionValue',
+			...mapMutations(['addlocalCalorie', 'syncRequestEvent', 'onWriteBLEConnectionValue', 'B_WriteHexToBLECharacteristic',
 				'gCreateFilterObj', 'gUpdateFilter', 'B_OpenRopeSkipping', 'B_CloseRopeSkipping',
 				'gStopSimulateBLEUpdate', 'gStartSimulateBLEUpdate', 'gIntelligentUpdateSandbagAlgorithm', 'gUpdateSandbagAlgorithm',
 				'gCreateSandbagAlgorithm', 'onConvertDeviceData', 'addSandbagHitCount', 'uploadUserData_hitCount',
@@ -736,6 +736,12 @@
 					if (!this.BLEConnectDevice) return;
 					//蓝牙写入数据
 					this.onWriteBLEConnectionValue(gameData);
+				} else if(temp.funName == "writeHexToBLEDevice"){
+					if (!gameData.value || gameData.value == "") return;
+					
+					if (!this.BLEConnectDevice) return;
+					//蓝牙写入数据
+					this.B_WriteHexToBLECharacteristic(gameData);
 				} else if (temp.funName == "log") {
 					console.log(gameData);
 				} else if (temp.funName == "addDeviceUpdateListener") {

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

@@ -231,6 +231,15 @@
 				</button> -->
 			
 			<!-- </view> -->
+			
+			<button type="primary" @click="onHitOpenBLELight">
+				onHitOpenBLELight
+			</button>
+			<!-- <button type="primary" @click="B_OpenRopeSkipping">
+				B_OpenRopeSkipping
+			</button> -->
+			
+			
 			<view style="height: 50rpx;"></view>
 		</scroll-view>
 
@@ -1088,6 +1097,9 @@
 				'jumpIdenModule_onTestUpdate',
 				'jumpIdenModule_onTestJump6AxisDataUpdate',
 				//算法相关END
+				
+				//灯光
+				'onHitOpenBLELight'
 			]),
 			BasicsSteps() {
 				this.basics = this.basics == this.basicsList.length - 1 ? 0 : this.basics + 1

+ 154 - 43
util/util-js/store.js

@@ -437,15 +437,21 @@ const store = new Vuex.Store({
 		 */
 		signInList: [],
 		isSignIn: false,
-		
+
 		//读取文件的名称
-		readDataName:"",
+		readDataName: "",
 		filesList: [],
+
+		//灯带灯光闪烁
+		lightInterval: null,
+		showLight: '',
+		showLightArray: [],
+		lightCount: 0,
 	},
 	mutations: {
-		
-		
-		
+
+
+
 		/**
 		 * 蓝牙解析后的数据,转化成对应的坐标系方向
 		 * @param {Object} context
@@ -1987,7 +1993,7 @@ const store = new Vuex.Store({
 		},
 		onWriteBLEConnectionValue(state, context) {
 			//#ifdef H5
-			console.warn("h5不支持蓝牙:", 'onWriteBLEConnectionValue');
+			console.warn("h5不支持蓝牙:");
 			return;
 			//#endif
 			let {
@@ -2117,6 +2123,8 @@ const store = new Vuex.Store({
 			state.sandbagAlgorithmLastTime = new Date().getTime();
 			state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm();
 			console.log("gCreateSandbagAlgorithm");
+			
+			this.commit("onUpdateShowLightArray");
 		},
 		/**
 		 * 更新 沙袋打击对象 数据
@@ -2211,9 +2219,68 @@ const store = new Vuex.Store({
 				}
 
 				// let hitCount = temp.hitCount;
+				// 打击灯带时候播放一段闪烁
+				// if (temp.type == 'hit') {
+				// 	console.log("onHitOpenBLELight");
+				// 	this.commit("onHitOpenBLELight");
+				// }
 			}
 		},
 
+		onHitOpenBLELight(state) {
+			// this.commit('B_WriteHexToBLECharacteristic', {
+			// 	value: "5B06015200470042005D"
+			// });
+			if (state.lightInterval != null) {
+				clearInterval(state.lightInterval);
+				state.lightInterval == null;
+			};
+			state.lightCount = 0;
+			let timerCount = 0;
+			state.lightInterval = setInterval(() => {
+				state.showLight = state.showLightArray[state.lightCount];
+				// console.log(state.showLight);
+				this.commit('B_WriteHexToBLECharacteristic', {
+					value: state.showLight
+				});
+				if (state.lightCount >= state.showLightArray.length - 1) {
+					state.lightCount = 0;
+				} else {
+					state.lightCount += 1;
+				}
+
+				timerCount++;
+				if (timerCount > 5) {
+					if (state.lightInterval != null) {
+						clearInterval(state.lightInterval);
+						state.lightInterval == null;
+					};
+					state.lightCount = 0;
+					//关闭红绿蓝
+					this.commit('B_WriteHexToBLECharacteristic', {
+						value: "5B06015202470242025D"
+					});
+				}
+			}, 100)
+		},
+		//更新一个灯光数组
+		onUpdateShowLightArray(state) {
+			state.showLightArray = [];
+
+			let openRed = "5B06015201470042005D";
+			let shutRed = "5B06015202470042005D";
+			// state.showLightArray.push(openRed);
+			// state.showLightArray.push(shutRed);
+			let openGreen = "5B06015200470142005D";
+			let shutGreen = "5B06015200470242005D";
+			state.showLightArray.push(openGreen);
+			state.showLightArray.push(shutGreen);
+			let openBlue = "5B06015200470042015D";
+			let shutBlue = "5B06015200470042025D";
+			state.showLightArray.push(openBlue);
+			state.showLightArray.push(shutBlue);
+		},
+
 		/**
 		 * 开启加速计,陀螺仪,并且模拟ble发送
 		 * @param {Object} state
@@ -2935,14 +3002,14 @@ const store = new Vuex.Store({
 			let _sendData;
 			if (bSendHex) {
 
-				state.bRopeKeyTwo = 0;
-				state.bRopeKeyOne = 0;
+				// state.bRopeKeyTwo = 0;
+				// state.bRopeKeyOne = 0;
 
-				//如果是发送16进制
-				state.bListenerHexUpdate = true;
+				//不用解析跳绳模式
+				state.bListenerHexUpdate = false;
 
-				//重置原 update
-				state.bListenerUpdate = false;
+				//不用关闭原始数据更新
+				state.bListenerUpdate = true;
 
 				let typedArray = new Uint8Array(value.match(/[\da-f]{2}/gi).map(function(h) {
 					return parseInt(h, 16)
@@ -2965,27 +3032,15 @@ const store = new Vuex.Store({
 				}
 				if (value == "3") {
 					if (state.bListenerUpdate) {
-						// uni.showToast({
-						// 	title: "原始数据已开启"
-						// })
 						console.warn("原始数据已开启");
-						// return;
 					}
 					state.bListenerUpdate = true;
 				}
 
 				if (value == "6") {
-					// state.bListenerJson = false;
 					state.bListenerAccArray = false;
 				}
 				if (value == "5") {
-					// if (state.bListenerJson) {
-					// 	uni.showToast({
-					// 		title: "步数数据已开启"
-					// 	})
-					// 	return;
-					// }
-					// state.bListenerJson = true;
 					if (state.bListenerAccArray) {
 						uni.showToast({
 							title: "加速计组数据已开启"
@@ -3039,6 +3094,58 @@ const store = new Vuex.Store({
 			})
 
 		},
+		
+		B_WriteHexToBLECharacteristic(state, context) {
+			let {
+				value,
+				retryCount = 5,
+				success = null,
+				getFail = null,
+			} = context;
+			if (!value && value === '') {
+				uni.showToast({
+					title: "指令为空"
+				})
+				return;
+			}
+			let typedArray = new Uint8Array(value.match(/[\da-f]{2}/gi).map(function(h) {
+				return parseInt(h, 16)
+			}))
+			uni.writeBLECharacteristicValue({
+				deviceId: state.deviceId,
+				serviceId: state.serviceId,
+				characteristicId: state.writeCharacteristicId,
+				value: typedArray.buffer,
+				success: (res) => {
+					console.log('B_WriteHexToBLECharacteristicSuccess', res.errMsg, value,
+						retryCount);
+					if (success) {
+						success(res);
+					}
+				},
+				fail: (fail) => {
+					console.log(fail)
+					//重新写入
+					if (retryCount > 0) {
+						console.log("B_WriteHexToBLECharacteristicRewrite =======>" +
+							value + " == " + retryCount);
+						retryCount--;
+						setTimeout(() => {
+							this.commit("B_WriteHexToBLECharacteristic", {
+								value,
+								retryCount,
+								success,
+								getFail
+							});
+						}, 300);
+					}
+					if (getFail) {
+						getFail(fail);
+					}
+				}
+			})
+		
+		},
 
 		/**
 		 * 断开蓝牙连接
@@ -3839,8 +3946,8 @@ const store = new Vuex.Store({
 			// 	data: JSON.stringify(msg)
 			// });
 		},
-		
-		
+
+
 		//jumpIdenModule 算法插件  start
 		jumpIdenModule_SearchData(state, context) {
 			if (uni.getSystemInfoSync().platform == "ios") {
@@ -3856,15 +3963,15 @@ const store = new Vuex.Store({
 				name: state.readDataName
 			}
 			console.log('requestData search ===== url:' + url);
-			reqUtil.requestData(url, _temp,'POST').then(res => {
-				
+			reqUtil.requestData(url, _temp, 'POST').then(res => {
+
 					let strArray = res.split('\n');
-						console.log(strArray);
-					for (let i = 0; i < strArray.length-1; i++) {
+					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,
+							cname: _name,
 							bRatio: false
 						});
 						state.filesList.push(item);
@@ -3886,7 +3993,7 @@ const store = new Vuex.Store({
 					})
 				});
 		},
-		jumpIdenModule_DownloadReadData(state,context) {
+		jumpIdenModule_DownloadReadData(state, context) {
 			if (uni.getSystemInfoSync().platform == "ios") {
 				return;
 			}
@@ -3896,16 +4003,18 @@ const store = new Vuex.Store({
 			} = 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 => {
+			reqUtil.requestData(downloadUrl, {
+				name: data.cname
+			}, 'POST').then(res => {
 					//console.log(res);
 					uni.setStorageSync('readData', res);
-					if(callback)
+					if (callback)
 						callback(res);
 					//读取的数据传入android端
 					let _temp = jumpIdenModule.onJumpInitInputData({
 						data: res
 					})
-					
+
 					uni.showToast({
 						title: '' + _temp.msg,
 						icon: 'none',
@@ -3929,19 +4038,19 @@ const store = new Vuex.Store({
 			}
 			let res = jumpIdenModule.onJumpInit();
 			uni.showToast({
-				title: ''+ res.code,
+				title: '' + res.code,
 				icon: 'none',
 				duration: 1000,
 				mask: true
 			})
 		},
-		jumpIdenModule_onJumpInitLocalData(){
+		jumpIdenModule_onJumpInitLocalData() {
 			if (uni.getSystemInfoSync().platform == "ios") {
 				return;
 			}
 			let res = jumpIdenModule.onJumpInitLocalData();
 			uni.showToast({
-				title: ''+ res.code,
+				title: '' + res.code,
 				icon: 'none',
 				duration: 1000,
 				mask: true
@@ -3965,17 +4074,19 @@ const store = new Vuex.Store({
 		jumpIdenModule_onTestUpdate() {
 			jumpIdenModule.onTestUpdate();
 		},
-		jumpIdenModule_onJump6AxisDataUpdate(state,context){
+		jumpIdenModule_onJump6AxisDataUpdate(state, context) {
 			let {
 				data,
 				callback = null
 			} = context;
-			let res = jumpIdenModule.onJump6AxisDataUpdate({hex:data.hex});
-			if(callback)
+			let res = jumpIdenModule.onJump6AxisDataUpdate({
+				hex: data.hex
+			});
+			if (callback)
 				callback(res);
 		},
-		
-		onGetReadDataName(state){
+
+		onGetReadDataName(state) {
 			state.readDataName = uni.getStorageSync('readDataName');
 		},
 		onSetReadDataName(state, value) {