2025年05月26日16:57:13

This commit is contained in:
luojiayi 2025-05-26 16:57:15 +08:00
parent 0c3f951c74
commit b91f4738f2
18 changed files with 182 additions and 66 deletions

View File

@ -5,6 +5,7 @@ export default defineAppConfig({
"pages/deviceList/index", "pages/deviceList/index",
"pages/game/index", "pages/game/index",
"pages/history/index", "pages/history/index",
"pages/lampEffect/index",
], ],
window: { window: {

BIN
src/assets/lamp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
src/assets/picture_01.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
src/assets/picture_02.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
src/assets/picture_03.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
src/assets/picture_04.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
src/assets/picture_05.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
src/assets/picture_06.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
src/assets/prepiece_def.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -10,12 +10,10 @@ import './index.less'
export default function Index() { export default function Index() {
const [isLink, setIsLink] = useState(BLESDK.deviceInfo.state) const [isLink, setIsLink] = useState(BLESDK.deviceInfo.state)
const [deviceInfo, setDeviceInfo] = useState(BLESDK.deviceInfo) const [deviceInfo, setDeviceInfo] = useState(BLESDK.deviceInfo)
const addDevice = () => { const addDevice = () => {
router.navigate('/pages/deviceList/index') router.navigate('/pages/deviceList/index')
} }
const deviceCallBack = () => { const deviceCallBack = () => {
console.log(BLESDK.deviceInfo, '解绑2');
setDeviceInfo({ ...BLESDK.deviceInfo }) setDeviceInfo({ ...BLESDK.deviceInfo })
setIsLink(BLESDK.deviceInfo.state) setIsLink(BLESDK.deviceInfo.state)
} }

View File

@ -3,7 +3,7 @@ import { Switch, Slider } from "@taroify/core"
import ble from "@/assets/ble.png"; 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 game from "@/assets/game.png";
import ai from "@/assets/ai.png"; import lamp from "@/assets/lamp.png";
import Taro, { useDidHide, useDidShow } from '@tarojs/taro'; import Taro, { useDidHide, useDidShow } from '@tarojs/taro';
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import { hex, strInsert, getInitData } from '@/utils/sendOrder'; import { hex, strInsert, getInitData } from '@/utils/sendOrder';
@ -31,11 +31,14 @@ export default function Index() {
}) })
// let timeout = null // let timeout = null
const musicModeEnum = ['标准', '动感', '轻柔', '安静'] const musicModeEnum = ['标准', '动感', '轻柔', '安静']
const reverbEnum = ['KTV', '实力唱将', '朗诵主持', '萌萌卡通', '魔鬼猫', '原声']
const toGame = () => {
const toPage = () => {
Taro.navigateTo({ url: '/pages/game/index' }) Taro.navigateTo({ url: '/pages/game/index' })
} }
const toLampEffect = () => {
Taro.navigateTo({ url: '/pages/lampEffect/index' })
}
const sendCode = useCallback(debounce((e) => { const sendCode = useCallback(debounce((e) => {
BLESDK.writeBleValue(new Uint8Array(strInsert(e)).buffer) BLESDK.writeBleValue(new Uint8Array(strInsert(e)).buffer)
}), []) }), [])
@ -95,13 +98,14 @@ export default function Index() {
str = `7B05EA0AB2${hex(e)}` str = `7B05EA0AB2${hex(e)}`
break; break;
case 'nextAndPre': case 'nextAndPre':
if (ruleForm.source == 0) return
str = `7B05EA0BB2${hex(e)}` str = `7B05EA0BB2${hex(e)}`
break; break;
} }
sendCode(str) sendCode(str)
} }
const handelMusicMode = (type) => { const handleMusicMode = (type) => {
let num = ruleForm.musicMode let num = ruleForm.musicMode
if (type == "+" && ruleForm.musicMode < 3) { if (type == "+" && ruleForm.musicMode < 3) {
num++ num++
@ -112,6 +116,19 @@ export default function Index() {
handleChange(num, 'musicMode') handleChange(num, 'musicMode')
} }
//
const handleReverb = (type) => {
let num = ruleForm.reverb
if (type == "+" && ruleForm.reverb < 6) {
num++
} else if (type == "-" && ruleForm.reverb > 1) {
num--
}
if (num == ruleForm.reverb) return
setRuleForm({ ...ruleForm, reverb: num })
handleChange(num, 'reverb')
}
// const control = (type) => { // const control = (type) => {
// let num = ruleForm.girth // let num = ruleForm.girth
// if (type == "+" && ruleForm.girth < 3) { // if (type == "+" && ruleForm.girth < 3) {
@ -128,18 +145,31 @@ export default function Index() {
} }
if (bytes[4] == 0xB3) { if (bytes[4] == 0xB3) {
let nameEnum = { // (1B)+(1B)+(1B)+(1B)
5: 'volume', // +(1B)+(1B)+(1B)+(1B)+(1B)+(1B)
6: 'music', setRuleForm(state => {
7: 'source', //
8: 'bleSwitch', state.music = bytes[5]
10: 'musicMode', //
11: 'playPause', state.volume = bytes[6]
13: 'reverb', //
14: 'microphoneReverberation', state.source = bytes[7]
} //
ruleForm[nameEnum[bytes[3]]] = bytes[5] state.bleSwitch = bytes[8]
setRuleForm({ ...ruleForm }) //
state.soundCadSwitch = bytes[9]
//
state.musicMode = bytes[10]
//
state.playPause = bytes[11]
//
state.girth = bytes[12]
//
state.reverb = bytes[13]
//
state.microphoneReverberation = bytes[14]
return { ...state }
})
} }
} }
@ -150,7 +180,6 @@ export default function Index() {
useDidHide(() => { useDidHide(() => {
// clearTimeout(timeout) // clearTimeout(timeout)
}) })
return ( return (
<PullDownScrollView <PullDownScrollView
className='PullDownScrollView' className='PullDownScrollView'
@ -191,20 +220,20 @@ export default function Index() {
</View> </View>
</View> </View>
<View className='play'> <View className='play'>
<View className='play-icon pre' onClick={() => handleChange(3, 'nextAndPre')}></View> <View className={`play-icon ${ruleForm.source == 0 ? 'pre_def' : 'pre'}`} onClick={() => handleChange(3, 'nextAndPre')}></View>
<View className={ruleForm.playPause ? 'play-pause' : 'play-play'} onClick={() => { <View className={ruleForm.playPause ? 'play-pause' : 'play-play'} onClick={() => {
handleChange(!ruleForm.playPause, 'playPause') handleChange(!ruleForm.playPause, 'playPause')
}} }}
></View> ></View>
<View className='play-icon next' onClick={() => handleChange(4, 'nextAndPre')}></View> <View className={`play-icon ${ruleForm.source == 0 ? 'next_def' : 'next'}`} onClick={() => handleChange(4, 'nextAndPre')}></View>
</View> </View>
<View className='card'> <View className='card'>
<View className='funitem'> <View className='funitem'>
<View className='funitem-text'>音乐模式</View> <View className='funitem-text'>音乐模式</View>
<View className='mode'> <View className='mode'>
<View className='icon l' onClick={() => handelMusicMode("-")}></View> <View className='icon l' onClick={() => handleMusicMode("-")}></View>
<View className='input'>{musicModeEnum[ruleForm.musicMode]}</View> <View className='input'>{musicModeEnum[ruleForm.musicMode]}</View>
<View className='icon r' onClick={() => handelMusicMode("+")}></View> <View className='icon r' onClick={() => handleMusicMode("+")}></View>
</View> </View>
</View> </View>
</View> </View>
@ -256,7 +285,12 @@ export default function Index() {
</View> */} </View> */}
<View className='funitem'> <View className='funitem'>
<View className='funitem-text'>话筒混响模式</View> <View className='funitem-text'>话筒混响模式</View>
<View className='numlist'> <View className='mode'>
<View className='icon l' onClick={() => handleReverb("-")}></View>
<View className='input'>{reverbEnum[ruleForm.reverb - 1]}</View>
<View className='icon r' onClick={() => handleReverb("+")}></View>
</View>
{/* <View className='numlist'>
{[1, 2, 3, 4, 5, 6].map(item => { {[1, 2, 3, 4, 5, 6].map(item => {
return <View className={`numlist-num ${ruleForm.reverb == item ? 'active' : ''} `} key={item} onClick={() => { return <View className={`numlist-num ${ruleForm.reverb == item ? 'active' : ''} `} key={item} onClick={() => {
if (item == ruleForm.reverb) return if (item == ruleForm.reverb) return
@ -264,17 +298,17 @@ export default function Index() {
}} }}
>{item}</View> >{item}</View>
})} })}
</View> </View> */}
</View> </View>
</View> </View>
<View className='btns'> <View className='btns'>
<View className='btn-item' onClick={toPage}> <View className='btn-item' onClick={toGame}>
<Image src={game} className='img' /> <Image src={game} className='img' />
GAME GAME
</View> </View>
<View className='btn-item'> <View className='btn-item' onClick={toLampEffect}>
<Image src={ai} className='img' /> <Image src={lamp} className='img' />
AI 灯效
</View> </View>
</View> </View>
</View> </View>

View File

@ -138,19 +138,33 @@
.play-icon { .play-icon {
width: 46rpx; width: 46rpx;
height: 39rpx; height: 39rpx;
}
.pre {
background: url('../../assets/prepiece.png') no-repeat;
background-size: 46rpx 39rpx;
&:active { &:active {
transform: scale(1.2); transform: scale(1.2);
} }
} }
.pre { .next {
background: url('../../assets/prepiece.png') no-repeat; background: url('../../assets/nextpiece.png') no-repeat;
background-size: 46rpx 39rpx;
&:active {
transform: scale(1.2);
}
}
.pre_def {
background: url('../../assets/prepiece_def.png') no-repeat;
background-size: 46rpx 39rpx; background-size: 46rpx 39rpx;
} }
.next { .next_def {
background: url('../../assets/nextpiece.png') no-repeat; background: url('../../assets/nextpiece_def.png') no-repeat;
background-size: 46rpx 39rpx; background-size: 46rpx 39rpx;
} }

View File

@ -0,0 +1,4 @@
export default definePageConfig({
navigationBarTitleText: "灯效",
navigationBarBackgroundColor: "#F7F7F7",
});

View File

@ -0,0 +1,31 @@
import { View, Image } from "@tarojs/components";
import picture_01 from "@/assets/picture_01.png";
import picture_02 from "@/assets/picture_02.png";
import picture_03 from "@/assets/picture_03.png";
import picture_04 from "@/assets/picture_04.png";
import picture_05 from "@/assets/picture_05.png";
import picture_06 from "@/assets/picture_06.png";
import { setLampEffect } from "@/utils/sendOrder";
import BLESDK from '@/utils/ble'
import Taro from "@tarojs/taro";
import "./index.less";
export default function Index() {
const images = [picture_01, picture_02, picture_03, picture_04, picture_05, picture_06]
BLESDK.onBLECharacteristicValueChange((bytes) => {
let str = '操作成功'
if (bytes[0] == 0x7A && bytes[4] == 0xB3 && bytes[5] != 0x00) {
str = '操作失败'
}
Taro.showToast({ title: str, icon: 'none' })
})
return (
<View className='lampEffect index'>
<View className='list'>
{images.map((item, index) => <Image src={item} className='img' key={index} onClick={() => setLampEffect(index)} />)}
</View>
</View>
);
}

View File

@ -0,0 +1,19 @@
.lampEffect {
padding: 32rpx;
box-sizing: border-box;
background: #F7F7F7;
.list {
flex: 1;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
.img {
width: 200rpx;
height: 200rpx;
margin-bottom: 32rpx;
}
}
}

View File

@ -45,7 +45,7 @@ class Bluetooth {
platform = Taro.getSystemInfoSync().platform; platform = Taro.getSystemInfoSync().platform;
appAuthorize = Taro.getAppAuthorizeSetting(); appAuthorize = Taro.getAppAuthorizeSetting();
deviceInfo = {} deviceInfo = Taro.getStorageSync('deviceInfo') || {}
callBack = () => { }; callBack = () => { };
searchBack = () => { }; searchBack = () => { };
@ -91,7 +91,6 @@ class Bluetooth {
success: () => { success: () => {
console.log("初始化蓝牙模块"); console.log("初始化蓝牙模块");
this.isInit = true; this.isInit = true;
this.deviceInfo = Taro.getStorageSync('deviceInfo') || {}
if (this.deviceInfo.name) { if (this.deviceInfo.name) {
this.createBleConnection() this.createBleConnection()
} }

View File

@ -25,6 +25,7 @@ export function handshake2() {
TASK.addTask(list) TASK.addTask(list)
} }
// 同步时间 // 同步时间
export function asyncDate() { export function asyncDate() {
const now = new Date(); const now = new Date();
@ -58,38 +59,53 @@ export function asyncDate() {
TASK.addTask(strInsert(aes128Encrypt(str))); TASK.addTask(strInsert(aes128Encrypt(str)));
} }
// -----------------获取---------------------
// 获取设备状态
export function getInitData() { export function getInitData() {
// 音源设置 let list = strInsert(`7B05EA12B100`)
TASK.addTask(strInsert(`7B05EA07B100`)); TASK.addTask(list)
}
// 蓝牙开关
TASK.addTask(strInsert(`7B05EA08B100`));
// 声卡开关
TASK.addTask(strInsert(`7B05EA09B100`));
// 播放模式 (音乐模式)
TASK.addTask(strInsert(`7B05EA0AB100`));
// 超低音强度
TASK.addTask(strInsert(`7B05EA0CB100`));
// 音乐音量
TASK.addTask(strInsert(`7B05EA06B100`));
// 话筒音量
TASK.addTask(strInsert(`7B05EA05B100`));
// 话筒混响音量
TASK.addTask(strInsert(`7B05EA0EB100`));
// 话筒混响模式
TASK.addTask(strInsert(`7B05EA0DB100`));
// 音乐控制
TASK.addTask(strInsert(`7B05EA0BB100`));
// 设置灯效
export function setLampEffect(num) {
let list = strInsert(`7B05EA13B2${hex(num)}`)
TASK.addTask(list)
} }
// export function getInitData() {
// // 音源设置
// TASK.addTask(strInsert(`7B05EA07B100`));
// // 蓝牙开关
// TASK.addTask(strInsert(`7B05EA08B100`));
// // 声卡开关
// TASK.addTask(strInsert(`7B05EA09B100`));
// // 播放模式 (音乐模式)
// TASK.addTask(strInsert(`7B05EA0AB100`));
// // 超低音强度
// TASK.addTask(strInsert(`7B05EA0CB100`));
// // 音乐音量
// TASK.addTask(strInsert(`7B05EA06B100`));
// // 话筒音量
// TASK.addTask(strInsert(`7B05EA05B100`));
// // 话筒混响音量
// TASK.addTask(strInsert(`7B05EA0EB100`));
// // 话筒混响模式
// TASK.addTask(strInsert(`7B05EA0DB100`));
// // 音乐控制
// TASK.addTask(strInsert(`7B05EA0BB100`));
// // // 获取设备状态
// // TASK.addTask(strInsert(`7B05EA12B100`));
// }