diff --git a/src/components/PullDownScrollView/index.jsx b/src/components/PullDownScrollView/index.jsx
new file mode 100644
index 0000000..c61ad00
--- /dev/null
+++ b/src/components/PullDownScrollView/index.jsx
@@ -0,0 +1,34 @@
+import { memo, useRef, useState } from 'react';
+import { ScrollView } from '@tarojs/components';
+import Taro from '@tarojs/taro';
+
+const Index = (props) => {
+ const { children, refreshFetcher } = props;
+ const scrollTop = useRef(0);
+ const [refreshStatus, setStatus] = useState(false);
+ return (
+ {
+ setStatus(() => true);
+ refreshFetcher && refreshFetcher()
+ setTimeout(() => {
+ setStatus(() => false)
+ }, 1000)
+ }}
+ onTouchMove={(e) => {
+ if (scrollTop.current !== 0) {
+ e.stopPropagation();
+ }
+ }}
+ onScroll={(e) => {
+ scrollTop.current = e.detail.scrollTop;
+ }}
+ >
+ {children}
+
+ );
+};
+export default memo(Index);
diff --git a/src/pages/device/index.jsx b/src/pages/device/index.jsx
index 82c1556..cc2754f 100644
--- a/src/pages/device/index.jsx
+++ b/src/pages/device/index.jsx
@@ -1,25 +1,28 @@
-import { View, Image, Text } from '@tarojs/components'
-import './index.less'
+import { View, Image } from '@tarojs/components'
import connectble from "@/assets/connectble.png";
import addDev from "@/assets/addDev.png";
import router from '@/baseRouter/index'
import BLESDK from '@/utils/ble'
-import { useEffect, useState } from 'react';
+import { useState } from 'react';
import Taro, { useDidShow } from '@tarojs/taro';
+import './index.less'
export default function Index() {
const [isLink, setIsLink] = useState(BLESDK.deviceInfo.state)
+ const [deviceInfo, setDeviceInfo] = useState(BLESDK.deviceInfo)
const addDevice = () => {
router.navigate('/pages/deviceList/index')
}
const deviceCallBack = () => {
console.log(BLESDK.deviceInfo, '解绑2');
+ setDeviceInfo({ ...BLESDK.deviceInfo })
setIsLink(BLESDK.deviceInfo.state)
}
useDidShow(() => {
BLESDK.deviceCallBack(deviceCallBack)
setIsLink(BLESDK.deviceInfo.state)
+ setDeviceInfo({ ...BLESDK.deviceInfo })
})
const unbind = () => {
@@ -28,7 +31,6 @@ export default function Index() {
content: '确认解绑当前设备?',
success: (res) => {
if (res.confirm) {
- setIsLink(false)
BLESDK.closeBluetoothAdapter()
Taro.showToast({ title: '设备解绑成功', icon: 'success' })
}
@@ -37,21 +39,21 @@ export default function Index() {
}
return (
-
- {BLESDK.deviceInfo?.name ? <>
-
+
+ {deviceInfo?.name ? <>
+
-
- 连接状态
- {isLink ? '已连接' : '未连接'}
+
+ 连接状态
+ {isLink ? '已连接' : '未连接'}
-
- 设备名称
- {BLESDK.deviceInfo.name}
+
+ 设备名称
+ {deviceInfo.name}
-
- MAC 地址
- {BLESDK.deviceInfo.mac}
+
+ MAC 地址
+ {deviceInfo.mac}
解绑设备
diff --git a/src/pages/game/index.jsx b/src/pages/game/index.jsx
index c0d5952..cf218c3 100644
--- a/src/pages/game/index.jsx
+++ b/src/pages/game/index.jsx
@@ -1,12 +1,12 @@
import { View, Image } from '@tarojs/components'
-import './index.less'
import ColorPicker from "@/components/color-picker";
-import { useEffect, useState } from 'react';
-import history from "../../assets/history.png";
+import { useState } from 'react';
import Taro from '@tarojs/taro';
import { hex, strInsert } from '@/utils/sendOrder';
import BLESDK from '@/utils/ble'
import router from '@/baseRouter/index'
+import './index.less'
+import history from "../../assets/history.png";
export default function Index() {
const [list, setList] = useState(["255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255"])
@@ -39,7 +39,6 @@ export default function Index() {
str += hex(item[0])
str += hex(item[1])
str += hex(item[2])
- str += hex(1)
}
BLESDK.writeBleValue(new Uint8Array(strInsert(str)).buffer)
setTimeout(() => {
@@ -67,13 +66,13 @@ export default function Index() {
})
return (
-
+
像素跳动
模板列表
-
- {list.map((item, index) => addColor(index)}>)}
+
+ {list.map((item, index) => addColor(index)}>)}
diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx
index 6cb42be..15ec0cc 100644
--- a/src/pages/index/index.jsx
+++ b/src/pages/index/index.jsx
@@ -1,19 +1,20 @@
import { View, Image, Text } from '@tarojs/components'
-import './index.less'
import { Switch, Slider } from "@taroify/core"
import ble from "@/assets/ble.png";
-import soundCard from "@/assets/soundCard.png";
+// import soundCard from "@/assets/soundCard.png";
import game from "@/assets/game.png";
import ai from "@/assets/ai.png";
-import Taro, { useDidShow } from '@tarojs/taro';
+import Taro, { useDidHide, useDidShow } from '@tarojs/taro';
import { useCallback, useState } from 'react';
-import { hex, strInsert } from '@/utils/sendOrder';
+import { hex, strInsert, getInitData } from '@/utils/sendOrder';
import { debounce } from '@/utils/index'
import BLESDK from '@/utils/ble'
+import PullDownScrollView from "@/components/PullDownScrollView";
+import './index.less'
export default function Index() {
- const sourceList = ['Line', 'OPT', 'ARC', 'USB']
- const [ruleForm, setRuleForm] = useState({
+ const sourceList = ['Line', 'OPT', 'USB']
+ let [ruleForm, setRuleForm] = useState({
volume: 0, //话筒音量
music: 0, //音乐音量
source: 0, //音源设置
@@ -28,14 +29,26 @@ export default function Index() {
AI: 0, //AI
playPause: 0, //播放暂停
})
+ let timeout = null
const musicModeEnum = ['标准', '动感', '轻柔', '安静']
+
const toPage = () => {
Taro.navigateTo({ url: '/pages/game/index' })
}
const sendCode = useCallback(debounce((e) => {
BLESDK.writeBleValue(new Uint8Array(strInsert(e)).buffer)
}), [])
+ const refresh = () => {
+ clearTimeout(timeout)
+ if (BLESDK.deviceInfo.state) {
+ getInitData()
+ timeout = setTimeout(() => {
+ refresh()
+ }, 3000)
+ }
+ }
+
const handleChange = (e, key) => {
if (key !== 'nextAndPre') {
setRuleForm({
@@ -99,75 +112,103 @@ export default function Index() {
handleChange(num, 'musicMode')
}
- const control = (type) => {
- let num = ruleForm.girth
- if (type == "+" && ruleForm.girth < 3) {
- num++
- } else if (type == "-" && ruleForm.girth > 0) {
- num--
- }
- if (num == ruleForm.girth) return
- handleChange(num, 'girth')
- }
+ // const control = (type) => {
+ // let num = ruleForm.girth
+ // if (type == "+" && ruleForm.girth < 3) {
+ // num++
+ // } else if (type == "-" && ruleForm.girth > 0) {
+ // num--
+ // }
+ // if (num == ruleForm.girth) return
+ // handleChange(num, 'girth')
+ // }
const BleCallBack = (bytes) => {
if (bytes[0] == 0x7D && bytes[4] == 0xB0) {
Taro.showToast({ title: bytes[5] == 0x00 ? '操作失败' : '操作成功', icon: 'none' })
}
+
+ if (bytes[4] == 0xB3) {
+ let nameEnum = {
+ 5: 'volume',
+ 6: 'music',
+ 7: 'source',
+ 8: 'bleSwitch',
+ 10: 'musicMode',
+ 11: 'playPause',
+ 13: 'reverb',
+ 14: 'microphoneReverberation',
+ }
+ ruleForm[nameEnum[bytes[3]]] = bytes[5]
+ setRuleForm({ ...ruleForm })
+ }
}
+
useDidShow(() => {
BLESDK.onBLECharacteristicValueChange(BleCallBack)
+ refresh()
+ })
+ useDidHide(() => {
+ clearTimeout(timeout)
})
return (
-
-
-
- 音乐信号(音源)
-
- {
- sourceList.map((item, index) => {
- return handleChange(index, 'source')}>
-
-
- {item}
-
- })
- }
+
+
+
+
+ 音乐信号(音源)
+
+ {
+ sourceList.map((item, index) => {
+ return handleChange(index, 'source')}>
+
+
+ {item}
+
+ })
+ }
+
-
-
- 开关状态
-
-
- 蓝牙
- handleChange(e, 'bleSwitch')} checked={ruleForm.bleSwitch} />
-
-
+
+ 开关状态
+
+
+ 蓝牙
+ handleChange(e, 'bleSwitch')} checked={ruleForm.bleSwitch} />
+
+ {/*
声卡
- handleChange(e, 'soundCadSwitch')} checked={ruleForm.soundCadSwitch} />
+ handleChange(e, 'soundCadSwitch')} checked={ruleForm.soundCadSwitch} />
+ */}
-
-
- handleChange(3, 'nextAndPre')}>
- {
- handleChange(!ruleForm.playPause, 'playPause')
- }}>
- handleChange(4, 'nextAndPre')}>
-
-
-
- 音乐模式
-
- handelMusicMode("-")}>
- {musicModeEnum[ruleForm.musicMode]}
- handelMusicMode("+")}>
+
+ handleChange(3, 'nextAndPre')}>
+ {
+ handleChange(!ruleForm.playPause, 'playPause')
+ }}
+ >
+ handleChange(4, 'nextAndPre')}>
+
+
+
+ 音乐模式
+
+ handelMusicMode("-")}>
+ {musicModeEnum[ruleForm.musicMode]}
+ handelMusicMode("+")}>
+
-
-
+ {/*
超低音强度
@@ -176,65 +217,68 @@ export default function Index() {
control("+")}>
-
-
-
- 音乐音量
-
- {ruleForm.volume}%
- handleChange(e, 'volume')} value={ruleForm.volume} >
-
-
-
-
+ */}
+
+
+ 音乐音量
+
+ {ruleForm.volume}%
+ handleChange(e, 'volume')} value={ruleForm.volume} >
+
+
+
+
+
-
-
-
- 话筒音量
-
- {ruleForm.music}%
- handleChange(e, 'music')} value={ruleForm.music} >
-
-
-
-
+
+
+ 话筒音量
+
+ {ruleForm.music}%
+ handleChange(e, 'music')} value={ruleForm.music} >
+
+
+
+
+
-
-
+ {/*
话筒混响音量
{ruleForm.microphoneReverberation}%
- handleChange(e, 'microphoneReverberation')} value={ruleForm.microphoneReverberation} >
+ handleChange(e, 'microphoneReverberation')} value={ruleForm.microphoneReverberation} >
-
+
+ */}
+
+ 话筒混响模式
+
+ {[1, 2, 3, 4, 5, 6].map(item => {
+ return {
+ if (item == ruleForm.reverb) return
+ handleChange(item, 'reverb')
+ }}
+ >{item}
+ })}
+
+
-
- 话筒混响模式
-
- {[1, 2, 3, 4, 5, 6].map(item => {
- return {
- if (item == ruleForm.reverb) return
- handleChange(item, 'reverb')
- }}>{item}
- })}
+
+
+
+ GAME
+
+
+
+ AI
-
-
-
- GAME
-
-
-
- AI
-
-
-
+
+
)
}
diff --git a/src/pages/index/index.less b/src/pages/index/index.less
index acf2ee1..fc065e5 100644
--- a/src/pages/index/index.less
+++ b/src/pages/index/index.less
@@ -1,7 +1,17 @@
+.PullDownScrollView {
+ position: absolute;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ top: 0;
+ background: #F7F7F7;
+}
+
.index {
padding: 24rpx 40rpx 60rpx;
background: #F7F7F7;
overflow: auto;
+ box-sizing: border-box;
scrollbar-width: none;
-ms-overflow-style: none;
diff --git a/src/utils/ble.js b/src/utils/ble.js
index 8b0fcfc..28f6598 100644
--- a/src/utils/ble.js
+++ b/src/utils/ble.js
@@ -162,7 +162,7 @@ class Bluetooth {
// 蓝牙连接
createBleConnection() {
- if (!this.available || this.linkFlag) return;
+ if (!this.available || this.linkFlag || !this.deviceInfo.deviceId) return;
this.linkFlag = true;
Taro.setStorageSync("deviceInfo", this.deviceInfo);
console.log("正在连接设备");
@@ -274,7 +274,7 @@ class Bluetooth {
this.timeout = setTimeout(() => {
this.timeout && this.clearTimeoutFn("timeout");
this.createBleConnection();
- }, 1000);
+ }, 3000);
}
});
}
@@ -288,7 +288,7 @@ class Bluetooth {
closeBluetoothAdapter() {
this.linkFlag = false;
this.deviceInfo = { state: false };
- wx.removeStorageSync("deviceInfo");
+ Taro.removeStorageSync("deviceInfo");
Taro.closeBluetoothAdapter({
success: (res) => {
console.log(this.deviceInfo, '解绑1');
@@ -311,7 +311,7 @@ class Bluetooth {
}
// unBindDevice() {
// this.deviceInfo = {}
- // wx.removeStorageSync('deviceInfo')
+ // Taro.removeStorageSync('deviceInfo')
// this.closeBluetoothAdapter()
// }
/**
diff --git a/src/utils/sendOrder.js b/src/utils/sendOrder.js
index 40d4001..138e942 100644
--- a/src/utils/sendOrder.js
+++ b/src/utils/sendOrder.js
@@ -1,4 +1,3 @@
-import BLESDK from './ble'
import TASK from './taskQueue'
import { aes128Encrypt } from '@/utils/index'
@@ -88,6 +87,9 @@ export function getInitData() {
// 话筒混响模式
TASK.addTask(strInsert(`7B05EA0DB100`));
+ // 音乐控制
+ TASK.addTask(strInsert(`7B05EA0BB100`));
+
}
diff --git a/src/utils/taskQueue.js b/src/utils/taskQueue.js
index 25bbd79..16a3993 100644
--- a/src/utils/taskQueue.js
+++ b/src/utils/taskQueue.js
@@ -27,7 +27,7 @@ class taskQueue {
this.overtime = setTimeout(() => {
this.stopOverTime()
this.executeTask()
- }, 800)
+ }, 300)
}
stopOverTime() {
clearTimeout(this.overtime)