diff --git a/src/app.config.js b/src/app.config.js index 805dc0e..e120a16 100644 --- a/src/app.config.js +++ b/src/app.config.js @@ -5,6 +5,7 @@ export default defineAppConfig({ "pages/deviceList/index", "pages/game/index", "pages/history/index", + "pages/lampEffect/index", ], window: { diff --git a/src/assets/lamp.png b/src/assets/lamp.png new file mode 100644 index 0000000..7542a37 Binary files /dev/null and b/src/assets/lamp.png differ diff --git a/src/assets/nextpiece_def.png b/src/assets/nextpiece_def.png new file mode 100644 index 0000000..64b15f3 Binary files /dev/null and b/src/assets/nextpiece_def.png differ diff --git a/src/assets/picture_01.png b/src/assets/picture_01.png new file mode 100644 index 0000000..0dd776f Binary files /dev/null and b/src/assets/picture_01.png differ diff --git a/src/assets/picture_02.png b/src/assets/picture_02.png new file mode 100644 index 0000000..8511536 Binary files /dev/null and b/src/assets/picture_02.png differ diff --git a/src/assets/picture_03.png b/src/assets/picture_03.png new file mode 100644 index 0000000..c4a0225 Binary files /dev/null and b/src/assets/picture_03.png differ diff --git a/src/assets/picture_04.png b/src/assets/picture_04.png new file mode 100644 index 0000000..e9077ef Binary files /dev/null and b/src/assets/picture_04.png differ diff --git a/src/assets/picture_05.png b/src/assets/picture_05.png new file mode 100644 index 0000000..e4718b4 Binary files /dev/null and b/src/assets/picture_05.png differ diff --git a/src/assets/picture_06.png b/src/assets/picture_06.png new file mode 100644 index 0000000..c50eff4 Binary files /dev/null and b/src/assets/picture_06.png differ diff --git a/src/assets/prepiece_def.png b/src/assets/prepiece_def.png new file mode 100644 index 0000000..df83ad6 Binary files /dev/null and b/src/assets/prepiece_def.png differ diff --git a/src/pages/device/index.jsx b/src/pages/device/index.jsx index cc2754f..61e6ceb 100644 --- a/src/pages/device/index.jsx +++ b/src/pages/device/index.jsx @@ -10,12 +10,10 @@ 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) } diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index 90d326c..2abe107 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -3,7 +3,7 @@ import { Switch, Slider } from "@taroify/core" import ble from "@/assets/ble.png"; // import soundCard from "@/assets/soundCard.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 { useCallback, useState } from 'react'; import { hex, strInsert, getInitData } from '@/utils/sendOrder'; @@ -31,11 +31,14 @@ export default function Index() { }) // let timeout = null const musicModeEnum = ['标准', '动感', '轻柔', '安静'] + const reverbEnum = ['KTV', '实力唱将', '朗诵主持', '萌萌卡通', '魔鬼猫', '原声'] - - const toPage = () => { + const toGame = () => { Taro.navigateTo({ url: '/pages/game/index' }) } + const toLampEffect = () => { + Taro.navigateTo({ url: '/pages/lampEffect/index' }) + } const sendCode = useCallback(debounce((e) => { BLESDK.writeBleValue(new Uint8Array(strInsert(e)).buffer) }), []) @@ -95,13 +98,14 @@ export default function Index() { str = `7B05EA0AB2${hex(e)}` break; case 'nextAndPre': + if (ruleForm.source == 0) return str = `7B05EA0BB2${hex(e)}` break; } sendCode(str) } - const handelMusicMode = (type) => { + const handleMusicMode = (type) => { let num = ruleForm.musicMode if (type == "+" && ruleForm.musicMode < 3) { num++ @@ -112,6 +116,19 @@ export default function Index() { 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) => { // let num = ruleForm.girth // if (type == "+" && ruleForm.girth < 3) { @@ -128,18 +145,31 @@ export default function Index() { } 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 }) + // 音乐音量(1B)+话筒音量(1B)+音源设置(1B)+蓝牙开关(1B) + // +声卡开关(1B)+音乐模式(1B)+音乐控制(1B)+超低音强度(1B)+混响模式(1B)+话筒混响(1B) + setRuleForm(state => { + //音乐音量 + state.music = bytes[5] + //话筒音量 + state.volume = bytes[6] + //音源设置 + state.source = bytes[7] + //蓝牙开关 + state.bleSwitch = bytes[8] + //声卡开关 + 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(() => { // clearTimeout(timeout) }) - return ( - handleChange(3, 'nextAndPre')}> + handleChange(3, 'nextAndPre')}> { handleChange(!ruleForm.playPause, 'playPause') }} > - handleChange(4, 'nextAndPre')}> + handleChange(4, 'nextAndPre')}> 音乐模式 - handelMusicMode("-")}> + handleMusicMode("-")}> {musicModeEnum[ruleForm.musicMode]} - handelMusicMode("+")}> + handleMusicMode("+")}> @@ -256,7 +285,12 @@ export default function Index() { */} 话筒混响模式 - + + handleReverb("-")}> + {reverbEnum[ruleForm.reverb - 1]} + handleReverb("+")}> + + {/* {[1, 2, 3, 4, 5, 6].map(item => { return { if (item == ruleForm.reverb) return @@ -264,17 +298,17 @@ export default function Index() { }} >{item} })} - + */} - + GAME - - - AI + + + 灯效 diff --git a/src/pages/index/index.less b/src/pages/index/index.less index fc065e5..4926af6 100644 --- a/src/pages/index/index.less +++ b/src/pages/index/index.less @@ -138,19 +138,33 @@ .play-icon { width: 46rpx; height: 39rpx; + } + + .pre { + background: url('../../assets/prepiece.png') no-repeat; + background-size: 46rpx 39rpx; &:active { transform: scale(1.2); } } - .pre { - background: url('../../assets/prepiece.png') no-repeat; + .next { + 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; } - .next { - background: url('../../assets/nextpiece.png') no-repeat; + .next_def { + background: url('../../assets/nextpiece_def.png') no-repeat; background-size: 46rpx 39rpx; } @@ -337,4 +351,4 @@ height: 60rpx; background: url('../../assets/sliding.png') no-repeat; background-size: 60rpx 60rpx; -} +} \ No newline at end of file diff --git a/src/pages/lampEffect/index.config.js b/src/pages/lampEffect/index.config.js new file mode 100644 index 0000000..4732e51 --- /dev/null +++ b/src/pages/lampEffect/index.config.js @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: "灯效", + navigationBarBackgroundColor: "#F7F7F7", +}); diff --git a/src/pages/lampEffect/index.jsx b/src/pages/lampEffect/index.jsx new file mode 100644 index 0000000..8e3792a --- /dev/null +++ b/src/pages/lampEffect/index.jsx @@ -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 ( + + + {images.map((item, index) => setLampEffect(index)} />)} + + + ); +} diff --git a/src/pages/lampEffect/index.less b/src/pages/lampEffect/index.less new file mode 100644 index 0000000..89b8808 --- /dev/null +++ b/src/pages/lampEffect/index.less @@ -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; + } + } + +} \ No newline at end of file diff --git a/src/utils/ble.js b/src/utils/ble.js index 365e517..2f74343 100644 --- a/src/utils/ble.js +++ b/src/utils/ble.js @@ -45,7 +45,7 @@ class Bluetooth { platform = Taro.getSystemInfoSync().platform; appAuthorize = Taro.getAppAuthorizeSetting(); - deviceInfo = {} + deviceInfo = Taro.getStorageSync('deviceInfo') || {} callBack = () => { }; searchBack = () => { }; @@ -91,7 +91,6 @@ class Bluetooth { success: () => { console.log("初始化蓝牙模块"); this.isInit = true; - this.deviceInfo = Taro.getStorageSync('deviceInfo') || {} if (this.deviceInfo.name) { this.createBleConnection() } diff --git a/src/utils/sendOrder.js b/src/utils/sendOrder.js index 138e942..775b296 100644 --- a/src/utils/sendOrder.js +++ b/src/utils/sendOrder.js @@ -25,6 +25,7 @@ export function handshake2() { TASK.addTask(list) } + // 同步时间 export function asyncDate() { const now = new Date(); @@ -58,38 +59,53 @@ export function asyncDate() { TASK.addTask(strInsert(aes128Encrypt(str))); } -// -----------------获取--------------------- + +// 获取设备状态 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`)); + let list = strInsert(`7B05EA12B100`) + TASK.addTask(list) +} +// 设置灯效 +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`)); +// } + +