//pages/ble_ui/ble_ui.js
var util=require('../../utils/util.js')
const app = getApp()
var power_flag = ""
var joke = ""
var bt_change_f=0
var BuleAVD_dataBuffer=''
var jsondeviceId=""
var BuffinputValue=""
var BuffinputValue1=""
var saveinputuuid_f=0;
const innerAudioContext = wx.createInnerAudioContext();
Page({
data: {
server: {},
ble_adv_sta: false,
timer_id_adv: 0,
Rx_datadsplay:"0000000000000000",
Tx_datadsplay:"0000000000000000",
focus: false,
inputValue: '',
check:false,
option: [
/* {
id: 'car',
icon: 'bluetooth',
name: 'Bluetooth Car',
open: false,
},*/
{
id: 'index',
icon: 'bluetooth',
name: 'Nebulizer',
open: false,
},
{
id: 'ble_radio',
icon: 'bluetooth',
name: 'BLE_radio',
open: false,
}
],
},
///++++++++++++++++++++++
switch1Change: function (e) {
// console.log('switch1 发生 change 事件,携带值为', e.detail.value);
if(e.detail.value) {
// this.openBluetoothAdapter();
var that = this;
this.startPerphiAdv();
console.log('打开广播');
wx.showToast({
title: '打开广播',
icon: 'none',
duration: 2000
})
} else {
this.stopAdvertising();
console.log('关闭广播');
wx.showToast({
title: '关闭广播',
icon: 'none',
duration: 2000
})
}
},
///=====
switch2Change: function (e) {
// console.log('switch1 发生 change 事件,携带值为', e.detail.value);
if (e.detail.value) {
// this.openBluetoothAdapter();
var that = this;
wx.openBluetoothAdapter({
mode:'peripheral',
success: function (res) {
console.log('初始化蓝牙适配器成功')
//页面日志显示
// that.setData({
// info: '初始化蓝牙适配器成功'
// })
power_flag = true;
wx.showToast({
title: '初始化蓝牙适配器成功',
icon: 'none',
duration: 2000
})
},
fail: function (res) {
console.log('请打开手机蓝牙和定位功能')
// that.setData({
// info: '请打开蓝牙和定位功能'
// })
wx.showToast({
title: '蓝牙开启失败,请打开手机蓝牙功能',
icon: 'none',
duration: 2000
})
}
})
}else {
this.closeConnect();
wx.showToast({
title: '蓝牙已断开',
icon: 'none',
duration: 2000
})
power_flag = false;
}
},
//__________________________
bindKeyInput: function(e) {
// this.setData({
// inputValue: e.detail.value
// })
BuffinputValue= e.detail.value;
console.log("输入的uuid是:",BuffinputValue)
},
bindKeyInput_confirm:function(e){
saveinputuuid_f=1;
BuffinputValue1= BuffinputValue;
console.log("确认的uuid是:",BuffinputValue)
},
radiocon:function(e){
this.setData({
check: !this.data.check
})
console.log("用户打勾的是 ",this.data.check)
if(this.data.check==true)
{
saveinputuuid_f=1;
BuffinputValue1= BuffinputValue;
}else{
saveinputuuid_f=0;
}
},
//__________________________
//++++++++++++++++++++++
kindToggle: function (e) {
var id = e.currentTarget.id
wx.navigateTo({
url: '../' + id + '/' + id
})
/*
var id = e.currentTarget.id, list = this.data.option;
for (var i = 0, len = list.length; i < len; ++i) {
if (list[i].id == id) {
list[i].open = !list[i].open
} else {
list[i].open = false
}
}
this.setData({
option: list
});
*/
},
//=================
query:function(){
if(!!wx.getStorageSync('userInfo')){
let _this=this;
setTimeout(()=> {
_this.query();
},500);
return;
}
},
//-------=======
Bt01: function (e){
var that = this;
bt_change_f=1;
that.Bt_gg();
},
Bt02: function (e){
var that = this;
bt_change_f=2;
that.Bt_gg();
},
Bt03: function (e){
var that = this;
bt_change_f=3;
that.Bt_gg();
},
Bt04: function (e){
var that = this;
bt_change_f=4;
that.Bt_gg();
},
Bt05: function (e){
var that = this;
bt_change_f=5;
that.Bt_gg();
},
Bt06: function (e){
var that = this;
bt_change_f=6;
that.Bt_gg();
},
Bt_gg: function (){
var that = this;
// power_flag = true;
if(power_flag==true)
{
that.starAdvertise_loop();
//-----------------------------
wx.playVoice({
filePath: '/utils/di.mp3',
complete: function (res) {
console.log('playVoice res')
console.log(res)
}
})
//---------------------------------
}else{
wx.showToast({
title: '请打开蓝牙开关',
icon: 'none',
duration: 2000
})
}
},
//=====
addClickAudio:function(){
wx.stopVoice();
innerAudioContext.autoplay = true // 是否自动开始播放,默认为 false
innerAudioContext.loop = false // 是否循环播放,默认为 false
wx.setInnerAudioOption({ // ios在静音状态下能够正常播放音效
obeyMuteSwitch: false, // 是否遵循系统静音开关,默认为 true。当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音。
success: function (e) {},
fail: function (e) {}
})
innerAudioContext.src = '/utils/di.mp3'; // this.globalData.Audiopath; // 音频资源的地址
//innerAudioContext.onPlay()
console.log("播放了di")
},
keyplay: function () {
// innerAudioContext .onStop();
innerAudioContext .play();
console.log("播放了di")
},
//点击 停止
keystop: function () {
innerAudioContext .pause();
},
//================================================send
starAdvertise_loop: function (){
if(power_flag==true)
{
this. stopAdvertising();
if (JSON.stringify(this.data.server) == "{}") {
this.createBLEPeripheralServer();
} else {
console.log("准备广播,已有服务无需再建,serverId:", this.data.server.serverId)
console.log("开始广播")
this.startAdvertising_0();
}
}else{
wx.showToast({
title: '蓝牙初始化失败,请打开BuleTooth',
icon: 'none',
duration: 2000
})
}
/*
setInterval (function() {
//循环执行代码
//------------------------------------------
this.data.server.startAdvertising();
//------------------------------------------
console.log('1秒');
}, 1000) //循环时间 这里是1秒
*/
},
///==============
///=====================================
res_search:function() {
var that = this;
that.startBluetoothDevicesDiscovery();
},
//==================================
//-----
startAdvertising_0() {
var that=this;
let m_id = "013A";
//let m_spdata1 = new Uint8Array(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]);
let m_uuid = '00001111-5555-6666-7777-FFFFFFFF8888';
let m_spdata1 = 'buu1';
let m_spdata2=""
switch (bt_change_f)
{
case 1: m_uuid='00001111-5555-6666-7777-FFFFFFFF8888'; break;
case 2: m_uuid='00002222-5555-6666-7777-FFFFFFFF8888'; break;
case 3: m_uuid='00003333-5555-6666-7777-FFFFFFFF8888'; break;
case 4: m_uuid='00004444-5555-6666-7777-FFFFFFFF8888'; break;
case 5: m_uuid='00005555-5555-6666-7777-FFFFFFFF8888'; break;
case 6: m_uuid='00006666-5555-6666-7777-FFFFFFFF8888'; break;
}
if(saveinputuuid_f)
{
m_uuid=BuffinputValue1;
console.log('测试这里为发送Buffinputuuid',BuffinputValue1);
console.log('测试这里为发送m_uuid',m_uuid);
}
// m_uuid = '00001111-77-FFFFFFFF8888';
that.setData({
Tx_datadsplay: m_uuid, //更新
});
this.data.serv
没有合适的资源?快使用搜索试试~ 我知道了~
定位小程序的源码应用-代码包
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共4个文件
wxss:1个
json:1个
wxml:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 15 浏览量
2023-06-02
13:51:35
上传
评论
收藏 8KB RAR 举报
温馨提示
这个程序代码,有需要的可以用来学习
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 4 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/9a3590e75389400eb50e03f30cce7261_qq_24219911.jpg!1)
IT_beiji
- 粉丝: 1
- 资源: 17
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 电脑配件管理系统数据库文件
- 基于预处理的小麦品种的分类和聚类源码+高分项目源码.7z
- BCI项目成果梳理,涵盖最新成果、算法创新、工程搭建、BCI大赛等
- S7-1500PLC工艺对象 105报文安装S7-1500PLC工艺对象 105报文安装S7-1500PLC工艺对象 105报文
- VID_20240626_120702_HSR_240.mp4
- 答题小程序-毕业设计资源
- code-gen-SQL资源
- Graduation Design Backend-毕业设计资源
- 一个简化的 Python 脚本示例,用于从连接到树莓派 GPIO 引脚的 DS18B20 温度传感器读取温度值 这个脚本假设你已
- 留学生网(www.lxs.net).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)