Skip to content

Commit

Permalink
Latest Release RM0305-2339-0.99.1-992f2cf on PATREON - JS APP
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueMaster committed Mar 7, 2024
1 parent 861f14b commit 41bb094
Show file tree
Hide file tree
Showing 8 changed files with 979 additions and 0 deletions.
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This software is for experimental purposes only and is not meant for any illegal
- OFW: PR: [Fix Troika 4K parser keys #3499 (By Astrrra)](https://github.com/flipperdevices/flipperzero-firmware/pull/3499)
- Added: [Pi Terminal v1.0 (By dagnazty & InfoSecREDD)](https://github.com/InfoSecREDD/Flip-pi)
- [Air Arkanoid & Air Labyrinth: Use PYTHON3 var (By Willy-JL)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/7eb47a5993e49a95903faad8b01bae63e872603c)
- Updated: [JS Runner v1.0 (By nminaylov & DrZlo13)-OFW](https://github.com/flipperdevices/flipperzero-firmware/pull/3286) [Added ble beacon, math and keyboard to JavaScript API (By Spooks4576)]()

<a name="release">

Expand Down
26 changes: 26 additions & 0 deletions applications/system/js_app/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,29 @@ App(
requires=["js_app"],
sources=["modules/js_submenu.c"],
)

App(
appid="js_blebeacon",
apptype=FlipperAppType.PLUGIN,
entry_point="js_blebeacon_ep",
requires=["js_app"],
sources=["modules/js_blebeacon.c"],
)

App(
appid="js_math",
apptype=FlipperAppType.PLUGIN,
entry_point="js_math_ep",
requires=["js_app"],
sources=["modules/js_math.c"],
)

App(
appid="js_keyboard",
apptype=FlipperAppType.PLUGIN,
entry_point="js_keyboard_ep",
requires=["js_app"],
sources=["modules/js_keyboard.c"],
)


87 changes: 87 additions & 0 deletions applications/system/js_app/examples/apps/Scripts/blebeacon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
let bleBeacon = require("blebeacon");

let currentIndex = 0;
let currentByteValue = 0;
let watchValues = [
0x1A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0xE4, 0xE5, 0x1B, 0x1C, 0x1D, 0x1E,
0x20, 0xEC, 0xEF
];

function byteToHex(byte) {
let hexChars = '0123456789abcdef';
let hex = '';
if (byte >= 0 && byte <= 255) {
hex = hexChars[(byte >> 4) & 0x0F] + hexChars[byte & 0x0F];
}
return hex;
}

function getNextByteValue() {
let value = currentByteValue;
currentByteValue = (currentByteValue + 1) % 256;
return value;
}

function generateRandomMac() {
let mac = '';
for (let i = 0; i < 6; i++) {
if (mac.length) mac += ':';
let byte = getNextByteValue();
mac += byteToHex(byte);
}
return mac;
}

function bytesToHexString(bytes) {
if (!bytes) {
print("Invalid input for bytesToHexString");
return '';
}

let hexString = '';
for (let i = 0; i < bytes.length; i++) {
hexString += byteToHex(bytes[i]);
}
return hexString;
}

function sendRandomModelAdvertisement() {
if (!watchValues || watchValues.length === 0) {
print("watchValues array is empty or undefined.");
return;
}

let model = watchValues[currentIndex];

let packet = [
14, 0xFF, 0x75, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x43,
model
];

let packetString = bytesToHexString(packet);
if (!packetString) {
print("Failed to generate packet string.");
return;
}

bleBeacon.setMac(generateRandomMac());
bleBeacon.setData(packetString);
bleBeacon.send();

print("Sent data for model ID " + to_string(model));

currentIndex = (currentIndex + 1) % watchValues.length;

delay(500);

bleBeacon.stop();

bleBeacon
}

while (true)
{
sendRandomModelAdvertisement();
}
5 changes: 5 additions & 0 deletions applications/system/js_app/examples/apps/Scripts/keyboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let keyboard = require("keyboard");

let text = keyboard.text(100, "Please Input Shit", 1);

print(text);
47 changes: 47 additions & 0 deletions applications/system/js_app/examples/apps/Scripts/math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let math = require("math");

let absResult = math.abs(-5);
let acosResult = math.acos(0.5);
let acoshResult = math.acosh(2);
let asinResult = math.asin(0.5);
let asinhResult = math.asinh(2);
let atanResult = math.atan(1);
let atan2Result = math.atan2(1, 1);
let atanhResult = math.atanh(0.5);
let cbrtResult = math.cbrt(27);
let ceilResult = math.ceil(5.3);
let clz32Result = math.clz32(1);
let cosResult = math.cos(math.PI);
let expResult = math.exp(1);
let floorResult = math.floor(5.7);
let maxResult = math.max(3, 5);
let minResult = math.min(3, 5);
let powResult = math.pow(2, 3);
let randomResult = math.random();
let signResult = math.sign(-5);
let sinResult = math.sin(math.PI / 2);
let sqrtResult = math.sqrt(25);
let truncResult = math.trunc(5.7);

print("math.abs(-5):", absResult);
print("math.acos(0.5):", acosResult);
print("math.acosh(2):", acoshResult);
print("math.asin(0.5):", asinResult);
print("math.asinh(2):", asinhResult);
print("math.atan(1):", atanResult);
print("math.atan2(1, 1):", atan2Result);
print("math.atanh(0.5):", atanhResult);
print("math.cbrt(27):", cbrtResult);
print("math.ceil(5.3):", ceilResult);
print("math.clz32(1):", clz32Result);
print("math.cos(math.PI):", cosResult);
print("math.exp(1):", expResult);
print("math.floor(5.7):", floorResult);
print("math.max(3, 5):", maxResult);
print("math.min(3, 5):", minResult);
print("math.pow(2, 3):", powResult);
print("math.random():", randomResult);
print("math.sign(-5):", signResult);
print("math.sin(math.PI/2):", sinResult);
print("math.sqrt(25):", sqrtResult);
print("math.trunc(5.7):", truncResult);
Loading

0 comments on commit 41bb094

Please sign in to comment.