Pārlūkot izejas kodu

1.添加拳击设备灯光测试和打击效果

slambb 2 gadi atpakaļ
vecāks
revīzija
83f9e044ea

+ 2 - 2
components/modal/action-hit/action-hit.vue

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

+ 112 - 25
pages/personal-page/personal/personal.vue

@@ -1,6 +1,6 @@
 <!-- 新版本跳首页文件修改版本 -->
 
-<template> 
+<template>
 	<view class="bg-person " :class="bEFHitShake?' screen-jitter ':''">
 		<uni-nav-bar id="nav-bar" status-bar="true" backgroundColor="RGBA(30, 30, 85, 1)" @clickLeft="showClickEvent()"
 			color="#FFFFFF" fixed="true" :border="false">
@@ -216,31 +216,91 @@
 					</view>
 				</view>
 			</scroll-view> -->
-			
+
 			<!-- <view class="margin-sm "> -->
-				<!-- <button type="primary" @click="jumpIdenModule_onJumpInit">
+			<!-- <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">
+
+			<!-- onTestUpdate -->
+			<!-- <button type="primary" class="margin-top-sm" @click="jumpIdenModule_onTestUpdate">
 					模拟跳数据输入
 				</button> -->
-			
+
 			<!-- </view> -->
-			
-			<button type="primary" @click="onHitOpenBLELight">
-				onHitOpenBLELight
-			</button>
+			<view 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>
+				<view class="cu-item">
+					<view class="content">
+						<text class="cuIcon-btn text-green"></text>
+						<text class="text-grey">默认 (5B0E02141E141E141E0...05D)</text>
+					</view>
+					<view class="action">
+						<button class="cu-btn round bg-green shadow"
+							@click="onSendBLELightNoSet('5B0E02141E141E141E00000000000000005D')"> 发送</button>
+					</view>
+				</view>
+				<view class="cu-item">
+					<view class="content">
+						<text class="cuIcon-btn text-green"></text>
+						<text class="text-grey">退出(5B0E020...05D)</text>
+					</view>
+					<view class="action">
+						<button class="cu-btn round bg-green shadow"
+							@click="onSendBLELightNoSet('5B0E0200000000000000000000000000005D')"> 发送</button>
+					</view>
+				</view>
+				<view class="cu-form-group">
+					<input placeholder="输入自定义指令" :value="readBLELight" @input="onReadBLELightInput"
+						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>
+						<text class="text-grey">播放一段闪烁</text>
+					</view>
+					<view class="action">
+						<button class="cu-btn round bg-green shadow" @click="onHitOpenBLELightNew"> 确定</button>
+					</view>
+				</view>
+			</view>
+			<view 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>
+				<view class="cu-item">
+					<view class="content">
+						<text class="cuIcon-btn text-green"></text>
+						<text class="text-grey">播放一段闪烁</text>
+					</view>
+					<view class="action">
+						<button class="cu-btn round bg-green shadow" @click="onHitOpenBLELight"> 确定</button>
+					</view>
+				</view>
+
+			</view>
 			<!-- <button type="primary" @click="B_OpenRopeSkipping">
 				B_OpenRopeSkipping
 			</button> -->
-			
-			
-			<view style="height: 50rpx;"></view>
+
+
+			<view style="height: 250rpx;"></view>
 		</scroll-view>
 
 		<!-- 底部中间上滑按钮 -->
@@ -600,7 +660,8 @@
 			'guideUnlockState',
 			'sandbagHitCount',
 			'readDataName',
-			'filesList'
+			'filesList',
+			'readBLELight'
 		]),
 		components: {
 			// uniNavBar,
@@ -937,6 +998,9 @@
 			//初始化一个android数据
 			this.jumpIdenModule_onJumpInit();
 
+			//
+			this.onGetReadBLELight();
+
 		},
 		onShow() {
 			_self.bHide = false;
@@ -1071,7 +1135,8 @@
 				'gOnAddClientInfo', 'onWriteBLEConnectionValue',
 				'gCreateFilterObj', 'gUpdateFilter', 'B_GetBondedDevices', 'B_OpenBLESetting', 'B_OpenRopeSkipping',
 				'B_CloseRopeSkipping',
-				'gCreateSandbagAlgorithm', 'gUpdateSandbagAlgorithm','gIntelligentUpdateSandbagAlgorithm', 'gStartSimulateBLEUpdate',
+				'gCreateSandbagAlgorithm', 'gUpdateSandbagAlgorithm', 'gIntelligentUpdateSandbagAlgorithm',
+				'gStartSimulateBLEUpdate',
 				'gStopSimulateBLEUpdate',
 				'getActionJumpTask',
 				'setActionJumpTask', 'getLevelList',
@@ -1097,9 +1162,13 @@
 				'jumpIdenModule_onTestUpdate',
 				'jumpIdenModule_onTestJump6AxisDataUpdate',
 				//算法相关END
-				
+
 				//灯光
-				'onHitOpenBLELight'
+				'onHitOpenBLELight',
+				'onHitOpenBLELightNew',
+				'onGetReadBLELight',
+				'onSetReadBLELight',
+				'B_WriteHexToBLECharacteristic'
 			]),
 			BasicsSteps() {
 				this.basics = this.basics == this.basicsList.length - 1 ? 0 : this.basics + 1
@@ -1433,8 +1502,8 @@
 						// 		this.$refs.boxingPostRef.onSetMode('ropeMode');
 						// 	}, 500)
 						// }
-					} else if(eq.ename.indexOf("intelligent") > -1 && this.BLEConnectDevice.id == 4){
-						
+					} else if (eq.ename.indexOf("intelligent") > -1 && this.BLEConnectDevice.id == 4) {
+
 					}
 				}
 			},
@@ -1462,7 +1531,7 @@
 				if (!this.instructionState.bOpen) return;
 
 				if (this.BLEConnectDevice.usageMode == "hotman") {
-					if(this.BLEConnectDevice.deviceType == "BLEIntelligent"){
+					if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
 						this.gIntelligentUpdateSandbagAlgorithm({
 							data: data,
 							callback: (res) => {
@@ -1471,7 +1540,7 @@
 								}
 							}
 						});
-					}else{
+					} else {
 						this.gUpdateSandbagAlgorithm({
 							data: data,
 							callback: (res) => {
@@ -1481,7 +1550,7 @@
 							}
 						});
 					}
-					
+
 				} else if (this.BLEConnectDevice.usageMode == "general") {
 					//这个是普通打击模式
 					this.$refs.boxingPostRef.onBLEHandleUpdate(data);
@@ -2539,7 +2608,7 @@
 				let {
 					isOffEvent = false
 				} = data;
-				
+
 				//游戏结束,重置时间
 				this.arcbarCountDownTimeReset();
 				//todo 可能区分 levelJump 关卡类型
@@ -2579,7 +2648,7 @@
 								this.uploadUserData_hitCount();
 							}
 						}
-						
+
 						this.AJData.isFinish = true;
 						//奖励赢的人 PKLEVELREWARD
 						let _item = this.currentJumpTask.item;
@@ -3381,7 +3450,25 @@
 						item.bRatio = true;
 					}
 				});
+			},
+
+			onReadBLELightInput: function(event) {
+				this.onSetReadBLELight(event.target.value);
+			},
+			onSendBLELightNoSet(value) {
+				console.log(value);
+				this.B_WriteHexToBLECharacteristic({
+					value: value
+				});
+			},
+			onSendBLELightValue(value) {
+				console.log(value);
+				this.B_WriteHexToBLECharacteristic({
+					value: value
+				});
+				this.onSetReadBLELight(value);
 			}
+
 		}
 	};
 </script>

+ 66 - 0
util/util-js/BLE_RGB.js

@@ -0,0 +1,66 @@
+//随机获取7种颜色中的一种颜色,常亮显示
+const getRandomRGB = () => {
+	let index = Math.floor(Math.random() * 7);
+	console.log("index:" + index);
+	let head = '5B0E02';
+	let tail = '5D';
+
+	for (let i = 0; i < 7; i++) {
+		if (i == index) {
+			head = head.concat('FF')
+		} else {
+			head = head.concat('00')
+		}
+		//时间设置为0,常亮
+		head = head.concat('00');
+	}
+	head = head.concat(tail);
+	console.log(head);
+	return head;
+}
+
+
+//随机获取7种颜色中的三种颜色,随机显示
+const getRandomThreeRGB = () => {
+	//原数组
+	var arr = [0, 1, 2, 3, 4, 5, 6];
+	//输出数组    
+	var out = [];
+	//输出个数    
+	var num = 3;
+	while (out.length < num) {
+		var temp = (Math.random() * arr.length) >> 0;
+		out.push(arr.splice(temp, 1));
+	}
+
+	console.log("out:" + out);
+	let head = '5B0E02';
+	let tail = '5D';
+
+	for (let i = 0; i < 7; i++) {
+		let bHas = false;
+		for (let j = 0; j < out.length; j++) {
+			// console.log(i + '==' + out[j])
+			if (i == out[j]) {
+				bHas = true;
+			}
+			if (j == out.length - 1) {
+				//需要灭灯的时间
+				let addStr = bHas ? '08' : '00';
+				head = head.concat(addStr);
+				// console.log(addStr)
+			}
+		}
+		//时间设置为0,常亮, 对应灭灯时间 20ms
+		let timeStr = bHas ? '02' : '00';
+		head = head.concat(timeStr);
+	}
+	head = head.concat(tail);
+	console.log(head);
+	return head;
+}
+
+export default {
+	getRandomRGB,
+	getRandomThreeRGB
+}

+ 53 - 4
util/util-js/store.js

@@ -5,6 +5,7 @@ import reqUtil from 'util/util-js/requstUtil.js'
 import date from 'util/util-js/date.js'
 import cNumber from 'util/util-js/makeNumber.js'
 import BLE from 'util/util-js/BLE.js';
+import BLERGB from 'util/util-js/BLE_RGB.js'
 //快速打击部分
 import o0 from "@/util/util-js/o0.js"
 import o0Project from "@/util/util-js/o0Project.js"
@@ -444,9 +445,11 @@ const store = new Vuex.Store({
 
 		//灯带灯光闪烁
 		lightInterval: null,
+		lightTimeout: null,
 		showLight: '',
 		showLightArray: [],
 		lightCount: 0,
+		readBLELight: '5B0E02141E141E141E00000000000000005D'
 	},
 	mutations: {
 
@@ -2123,8 +2126,7 @@ const store = new Vuex.Store({
 			state.sandbagAlgorithmLastTime = new Date().getTime();
 			state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm();
 			console.log("gCreateSandbagAlgorithm");
-			
-			this.commit("onUpdateShowLightArray");
+
 		},
 		/**
 		 * 更新 沙袋打击对象 数据
@@ -2226,8 +2228,44 @@ const store = new Vuex.Store({
 				// }
 			}
 		},
+		onHitOpenBLELightNew(state) {
+
+			if (state.BLEConnectDevice.deviceType != "BLEIntelligent") {
+				return;
+			}
+
+			if (state.lightTimeout != null) {
+				clearTimeout(state.lightTimeout);
+				state.lightTimeout == null;
+			};
+			this.commit('B_WriteHexToBLECharacteristic', {
+				value:  BLERGB.getRandomThreeRGB()
+			});
+			state.lightTimeout = setTimeout(() => {
+				//关闭红绿蓝
+				this.commit('B_WriteHexToBLECharacteristic', {
+					// value: "5B0E0200000000000000000000000000005D"
+					value: BLERGB.getRandomRGB()
+				});
+				if (state.lightTimeout != null) {
+					clearInterval(state.lightTimeout);
+					state.lightTimeout == null;
+				};
+
+			}, 310)
+		},
 
 		onHitOpenBLELight(state) {
+			state.showLightArray = [];
+			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);
+
 			// this.commit('B_WriteHexToBLECharacteristic', {
 			// 	value: "5B06015200470042005D"
 			// });
@@ -3094,7 +3132,7 @@ const store = new Vuex.Store({
 			})
 
 		},
-		
+
 		B_WriteHexToBLECharacteristic(state, context) {
 			let {
 				value,
@@ -3144,7 +3182,7 @@ const store = new Vuex.Store({
 					}
 				}
 			})
-		
+
 		},
 
 		/**
@@ -4095,6 +4133,17 @@ const store = new Vuex.Store({
 		},
 		//jumpIdenModule 算法插件 end
 
+		//读取灯光存储的ble
+		onGetReadBLELight(state) {
+			let _readBLELight = uni.getStorageSync('readBLELight');
+			if (_readBLELight) {
+				state.readBLELight = _readBLELight;
+			}
+		},
+		onSetReadBLELight(state, value) {
+			uni.setStorageSync('readBLELight', value);
+			state.readBLELight = value;
+		},
 	}
 })