Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed old file. Added items to folder to sync. #3716

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions apps/BLEConnect/BLEConnect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
let menu = {
"": { "title": "BLECONNECT" },
"RE-SCAN": () => scan()
};

function showMainMenu() {
menu["< Back"] = () => load();
Bangle.drawWidgets();
return E.showMenu(menu);
}

function showDeviceInfo(device){
const deviceMenu = {
"": { "title": "Device Info" },
"name": {
value: device.name
},
"Signal-Str(dBm)": {
value: device.rssi
// Very strong connection -30 to -60
//strong -60 to -70
//Moderate -70 to -80
},
"manufacturer": {
value: device.manufacturer===undefined ? "-" : device.manufacturer
},
"CONNECT": () => connectDevice(device), // connect to a BLE device //

"< Back": () => showMainMenu() // show a back button if wrong BLE selected //
};

return E.showMenu(deviceMenu);
}

function connectDevice(device) {
E.showMessage("Connecting...");

NRF.connect(device.id)
.then(() => {
E.showMessage("Connected!");
// Handle the connected device, for example, interact with its services
})
.catch(err => {
E.showMessage("Failed to connect");
console.log("Connection error: ", err);
});
}

function scan() {
menu = {
"": { "title": "BLE Detector" },
"RE-SCAN": () => scan()
};

waitMessage();

NRF.findDevices(devices => {
devices.forEach(device => {
let deviceName = device.id.substring(0,17);

if (device.name) {
deviceName = device.name;
}

// Add a menu entry for each device
menu[deviceName] = () => showDeviceInfo(device);
});
showMainMenu();
}, { active: true });
}

function waitMessage() {
E.showMenu();
E.showMessage("scanning");
}

Bangle.loadWidgets();
scan();
waitMessage();

// check error code status

/*Please change your own errors for BLE machines */

function checkForErrorCode(status) {
if (status === "Auto Run") return;
if (status === "E-Stp") showErrorMessage("Emergency stop detected. Please check the machine.");
if (status === "Blocked") showErrorMessage("Machine blocked. Please inspect for obstructions.");
if (status === "Other") return;
// (other) showErrorMessage("Unknown error. Please investigate the issue.");
}

// Show error message and allow Button 1 to confirm resolution
function showErrorMessage(status) {
Bangle.buzz();
E.showMessage("Error Code: " + status + "\nDevice down! Please check");

// Wait for 3 seconds, then show the confirmation message
setTimeout(() => {
E.showMessage("Press Button 1 to confirm issue fixed");
// Listen for Button 1 press to confirm issue fixed
setButtonWatch();
}, 3000);
}

// Wait for Button 1 press to confirm issue fixed
function setButtonWatch() {
// Button 1 is typically on the top-left of the Bangle.js (button 1 is the topmost button)
setWatch(() => {
confirmIssueFixed(); // Call the function to confirm issue has been fixed
}, BTN1, {repeat: false, edge: "falling"});
}

Binary file added apps/BLEConnect/BTApp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/BLEConnect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# BLE-Connect

custom app to scan and connect to ble devices.
2 changes: 2 additions & 0 deletions apps/BLEConnect/app-icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions apps/BLEConnect/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ "id": "BLE_Connect",
"name": "BLE_Connect",
"shortName":"BLE_Conn",
"icon": "BTApp.png",
"version":"0.02",

"description": "BT Scanner & Connect",

"tags": "Connect",
"type": "Bluetooth"

"supports": ["BANGLEJS"],
"readme": "README.md",

"storage": [
{"name":"BLE_Connect.app.js","url":"app.js"},
{"name":"BTConnect_App.img","url":"app-icon.js","evaluate":true}
]
}
113 changes: 113 additions & 0 deletions apps/BLE_Connect
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
let menu = {
"": { "title": "BLE SCAN CONN" },
"RE-SCAN": () => scan()
};

function showMainMenu() {
menu["< Back"] = () => load();
Bangle.drawWidgets();
return E.showMenu(menu);
}

function showDeviceInfo(device){
const deviceMenu = {
"": { "title": "Device Info" },
"name": {
value: device.name
},
"Signal-Str(dBm)": {
value: device.rssi
// Very strong connection -30 to -60
//strong -60 to -70
//Moderate -70 to -80
},
"manufacturer": {
value: device.manufacturer===undefined ? "-" : device.manufacturer
},
"CONNECT": () => connectDevice(device), // connect to a BLE device //

"< Back": () => showMainMenu() // show a back button if wrong BLE selected //
};

return E.showMenu(deviceMenu);
}

function connectDevice(device) {
E.showMessage("Connecting...");

NRF.connect(device.id)
.then(() => {
E.showMessage("Connected!");
// Handle the connected device, for example, interact with its services
})
.catch(err => {
E.showMessage("Failed to connect");
console.log("Connection error: ", err);
});
}

function scan() {
menu = {
"": { "title": "BLE Detector" },
"RE-SCAN": () => scan()
};

waitMessage();

NRF.findDevices(devices => {
devices.forEach(device => {
let deviceName = device.id.substring(0,17);

if (device.name) {
deviceName = device.name;
}

// Add a menu entry for each device
menu[deviceName] = () => showDeviceInfo(device);
});
showMainMenu();
}, { active: true });
}

function waitMessage() {
E.showMenu();
E.showMessage("scanning");
}

Bangle.loadWidgets();
scan();
waitMessage();

// check error code status

/*Please change your own errors for BLE machines */

function checkForErrorCode(status) {
if (status === "Auto Run") return;
if (status === "E-Stp") showErrorMessage("Emergency stop detected. Please check the machine.");
if (status === "Blocked") showErrorMessage("Machine blocked. Please inspect for obstructions.");
if (status === "Other") return;
// (other) showErrorMessage("Unknown error. Please investigate the issue.");
}

// Show error message and allow Button 1 to confirm resolution
function showErrorMessage(status) {
Bangle.buzz();
E.showMessage("Error Code: " + status + "\nDevice down! Please check");

// Wait for 3 seconds, then show the confirmation message
setTimeout(() => {
E.showMessage("Press Button 1 to confirm issue fixed");
// Listen for Button 1 press to confirm issue fixed
setButtonWatch();
}, 3000);
}

// Wait for Button 1 press to confirm issue fixed
function setButtonWatch() {
// Button 1 is typically on the top-left of the Bangle.js (button 1 is the topmost button)
setWatch(() => {
confirmIssueFixed(); // Call the function to confirm issue has been fixed
}, BTN1, {repeat: false, edge: "falling"});
}