mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-23 13:21:44 +03:00
merge examples fixes [ci skip]
by Willy-JL p2
This commit is contained in:
parent
63d1890156
commit
f37799e0f4
@ -1,42 +0,0 @@
|
||||
// This is an example of how to use the analog pins (ADC) on the Flipper Zero.
|
||||
// The example uses a reference voltage of 2048mV (2.048V), but you can also use 2500mV (2.5V).
|
||||
// The example reads the values of the analog pins A7, A6, and A4 and prints them to the console.
|
||||
// The example also checks if the value of A7 is twice the value of A6 and breaks the loop if it is.
|
||||
// The example uses the analog pins A7, A6, and A4, but you can also use PC3, PC1, and PC0.
|
||||
|
||||
let gpio = require("gpio");
|
||||
|
||||
// initialize pins A7, A6, A4 as analog (you can also use PC3, PC1, PC0)
|
||||
gpio.init("PA7", "analog", "no"); // pin, mode, pull
|
||||
gpio.init("PA6", "analog", "no"); // pin, mode, pull
|
||||
gpio.init("PA4", "analog", "no"); // pin, mode, pull
|
||||
|
||||
gpio.startAnalog(2048); // vRef = 2.048V (you can also use 2500 for a 2.5V reference voltage)
|
||||
|
||||
while (true) {
|
||||
let pa7_value = gpio.readAnalog("PA7");
|
||||
let pa6_value = gpio.readAnalog("PA6");
|
||||
let pa4_value = gpio.readAnalog("PA4");
|
||||
print("A7: " + to_string(pa7_value) + " A6: " + to_string(pa6_value) + " A4: " + to_string(pa4_value));
|
||||
delay(100);
|
||||
if (pa7_value === pa6_value * 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
print("A7 is twice A6!");
|
||||
|
||||
gpio.stopAnalog();
|
||||
|
||||
// possible analog pins https://docs.flipper.net/gpio-and-modules#miFsS
|
||||
// "PA7" aka 2
|
||||
// "PA6" aka 3
|
||||
// "PA4" aka 4
|
||||
// "PC3" aka 7
|
||||
// "PC1" aka 15
|
||||
// "PC0" aka 16
|
||||
|
||||
// possible modes
|
||||
// "analog"
|
||||
|
||||
// possible pull
|
||||
// "no"
|
@ -1,18 +1,10 @@
|
||||
let badusb = require("badusb");
|
||||
let notify = require("notification");
|
||||
let flipper = require("flipper");
|
||||
let eventLoop = require("event_loop");
|
||||
let gui = require("gui");
|
||||
let dialog = require("gui/dialog");
|
||||
|
||||
|
||||
// TODO: Add event loop from ofw
|
||||
badusb.setup({
|
||||
vid: 0xAAAA,
|
||||
pid: 0xBBBB,
|
||||
mfrName: "Flipper",
|
||||
prodName: "Zero",
|
||||
layout_path: "/ext/badusb/assets/layouts/en-US.kl"
|
||||
});
|
||||
let views = {
|
||||
dialog: dialog.makeWith({
|
||||
header: "BadUSB demo",
|
||||
@ -21,37 +13,61 @@ let views = {
|
||||
}),
|
||||
};
|
||||
|
||||
if (badusb.isConnected()) {
|
||||
notify.blink("green", "short");
|
||||
print("USB is connected");
|
||||
badusb.setup({
|
||||
vid: 0xAAAA,
|
||||
pid: 0xBBBB,
|
||||
mfrName: "Flipper",
|
||||
prodName: "Zero",
|
||||
layoutPath: "/ext/badusb/assets/layouts/en-US.kl"
|
||||
});
|
||||
|
||||
badusb.println("Hello, world!");
|
||||
eventLoop.subscribe(views.dialog.input, function (_sub, button, eventLoop, gui) {
|
||||
if (button !== "center")
|
||||
return;
|
||||
|
||||
badusb.press("CTRL", "a");
|
||||
badusb.press("CTRL", "c");
|
||||
badusb.press("DOWN");
|
||||
delay(1000);
|
||||
badusb.press("CTRL", "v");
|
||||
delay(1000);
|
||||
badusb.press("CTRL", "v");
|
||||
gui.viewDispatcher.sendTo("back");
|
||||
|
||||
badusb.println("1234", 200);
|
||||
if (badusb.isConnected()) {
|
||||
notify.blink("green", "short");
|
||||
print("USB is connected");
|
||||
|
||||
badusb.println("Flipper Model: " + flipper.getModel());
|
||||
badusb.println("Flipper Name: " + flipper.getName());
|
||||
badusb.println("Battery level: " + toString(flipper.getBatteryCharge()) + "%");
|
||||
badusb.println("Hello, world!");
|
||||
|
||||
// Alt+Numpad method works only on Windows!!!
|
||||
badusb.altPrintln("This was printed with Alt+Numpad method!");
|
||||
badusb.press("CTRL", "a");
|
||||
badusb.press("CTRL", "c");
|
||||
badusb.press("DOWN");
|
||||
delay(1000);
|
||||
badusb.press("CTRL", "v");
|
||||
delay(1000);
|
||||
badusb.press("CTRL", "v");
|
||||
|
||||
// There's also badusb.print() and badusb.altPrint()
|
||||
// which don't add the return at the end
|
||||
badusb.println("1234", 200);
|
||||
|
||||
notify.success();
|
||||
} else {
|
||||
print("USB not connected");
|
||||
notify.error();
|
||||
}
|
||||
badusb.println("Flipper Model: " + flipper.getModel());
|
||||
badusb.println("Flipper Name: " + flipper.getName());
|
||||
badusb.println("Battery level: " + toString(flipper.getBatteryCharge()) + "%");
|
||||
|
||||
// Optional, but allows to interchange with usbdisk
|
||||
badusb.quit();
|
||||
// Alt+Numpad method works only on Windows!!!
|
||||
badusb.altPrintln("This was printed with Alt+Numpad method!");
|
||||
|
||||
// There's also badusb.print() and badusb.altPrint()
|
||||
// which don't add the return at the end
|
||||
|
||||
notify.success();
|
||||
} else {
|
||||
print("USB not connected");
|
||||
notify.error();
|
||||
}
|
||||
|
||||
// Optional, but allows to interchange with usbdisk
|
||||
badusb.quit();
|
||||
|
||||
eventLoop.stop();
|
||||
}, eventLoop, gui);
|
||||
|
||||
eventLoop.subscribe(gui.viewDispatcher.navigation, function (_sub, _item, eventLoop) {
|
||||
eventLoop.stop();
|
||||
}, eventLoop);
|
||||
|
||||
gui.viewDispatcher.switchTo(views.dialog);
|
||||
eventLoop.run();
|
||||
|
@ -45,7 +45,7 @@ function sendRandomModelAdvertisement() {
|
||||
|
||||
blebeacon.start();
|
||||
|
||||
print("Sent data for model ID " + to_string(model));
|
||||
print("Sent data for model ID " + toString(model));
|
||||
|
||||
currentIndex = (currentIndex + 1) % watchValues.length;
|
||||
|
||||
|
@ -5,6 +5,7 @@ let loadingView = require("gui/loading");
|
||||
let submenuView = require("gui/submenu");
|
||||
let emptyView = require("gui/empty_screen");
|
||||
let textInputView = require("gui/text_input");
|
||||
let byteInputView = require("gui/byte_input");
|
||||
let textBoxView = require("gui/text_box");
|
||||
let dialogView = require("gui/dialog");
|
||||
|
||||
@ -20,6 +21,11 @@ let views = {
|
||||
helloDialog: dialogView.makeWith({
|
||||
center: "Hi Flipper! :)",
|
||||
}),
|
||||
bytekb: byteInputView.makeWith({
|
||||
header: "Look ma, I'm a header text!",
|
||||
length: 8,
|
||||
defaultData: Uint8Array([0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88]),
|
||||
}),
|
||||
longText: textBoxView.makeWith({
|
||||
text: "This is a very long string that demonstrates the TextBox view. Use the D-Pad to scroll backwards and forwards.\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rhoncus est malesuada quam egestas ultrices. Maecenas non eros a nulla eleifend vulputate et ut risus. Quisque in mauris mattis, venenatis risus eget, aliquam diam. Fusce pretium feugiat mauris, ut faucibus ex volutpat in. Phasellus volutpat ex sed gravida consectetur. Aliquam sed lectus feugiat, tristique lectus et, bibendum lacus. Ut sit amet augue eu sapien elementum aliquam quis vitae tortor. Vestibulum quis commodo odio. In elementum fermentum massa, eu pellentesque nibh cursus at. Integer eleifend lacus nec purus elementum sodales. Nulla elementum neque urna, non vulputate massa semper sed. Fusce ut nisi vitae dui blandit congue pretium vitae turpis.",
|
||||
}),
|
||||
@ -29,6 +35,7 @@ let views = {
|
||||
"Hourglass screen",
|
||||
"Empty screen",
|
||||
"Text input & Dialog",
|
||||
"Byte input",
|
||||
"Text box",
|
||||
"Exit app",
|
||||
],
|
||||
@ -49,8 +56,10 @@ eventLoop.subscribe(views.demos.chosen, function (_sub, index, gui, eventLoop, v
|
||||
} else if (index === 2) {
|
||||
gui.viewDispatcher.switchTo(views.keyboard);
|
||||
} else if (index === 3) {
|
||||
gui.viewDispatcher.switchTo(views.longText);
|
||||
gui.viewDispatcher.switchTo(views.bytekb);
|
||||
} else if (index === 4) {
|
||||
gui.viewDispatcher.switchTo(views.longText);
|
||||
} else if (index === 5) {
|
||||
eventLoop.stop();
|
||||
}
|
||||
}, gui, eventLoop, views);
|
||||
@ -67,6 +76,17 @@ eventLoop.subscribe(views.helloDialog.input, function (_sub, button, gui, views)
|
||||
gui.viewDispatcher.switchTo(views.demos);
|
||||
}, gui, views);
|
||||
|
||||
// show data after byte input
|
||||
eventLoop.subscribe(views.bytekb.input, function (_sub, data, gui, views) {
|
||||
let data_view = Uint8Array(data);
|
||||
let text = "0x";
|
||||
for (let i = 0; i < data_view.length; i++) {
|
||||
text += toString(data_view[i], 16);
|
||||
}
|
||||
views.helloDialog.set("text", "You typed " + text + "! :)");
|
||||
gui.viewDispatcher.switchTo(views.helloDialog);
|
||||
}, gui, views);
|
||||
|
||||
// go to the demo chooser screen when the back key is pressed
|
||||
eventLoop.subscribe(gui.viewDispatcher.navigation, function (_sub, _, gui, views) {
|
||||
gui.viewDispatcher.switchTo(views.demos);
|
||||
|
@ -1,23 +0,0 @@
|
||||
let keyboard = require("keyboard");
|
||||
|
||||
keyboard.setHeader("Example Text Input");
|
||||
|
||||
// Default text is optional
|
||||
let text = keyboard.text(100, "Default text", true);
|
||||
// Returns undefined when pressing back
|
||||
print("Got text:", text);
|
||||
|
||||
keyboard.setHeader("Example Byte Input");
|
||||
|
||||
// Default data is optional
|
||||
let result = keyboard.byte(6, Uint8Array([1, 2, 3, 4, 5, 6]));
|
||||
// Returns undefined when pressing back
|
||||
if (result !== undefined) {
|
||||
let data = Uint8Array(result);
|
||||
result = "0x";
|
||||
for (let i = 0; i < data.byteLength; i++) {
|
||||
if (data[i] < 0x10) result += "0";
|
||||
result += to_hex_string(data[i]);
|
||||
}
|
||||
}
|
||||
print("Got data:", result);
|
@ -1,6 +1,6 @@
|
||||
let sampleText = "Hello, World!";
|
||||
|
||||
let lengthOfText = "Length of text: " + to_string(sampleText.length);
|
||||
let lengthOfText = "Length of text: " + toString(sampleText.length);
|
||||
print(lengthOfText);
|
||||
|
||||
let start = 7;
|
||||
@ -9,11 +9,11 @@ let substringResult = sampleText.slice(start, end);
|
||||
print(substringResult);
|
||||
|
||||
let searchStr = "World";
|
||||
let result2 = to_string(sampleText.indexOf(searchStr));
|
||||
let result2 = toString(sampleText.indexOf(searchStr));
|
||||
print(result2);
|
||||
|
||||
let upperCaseText = "Text in upper case: " + to_upper_case(sampleText);
|
||||
let upperCaseText = "Text in upper case: " + toUpperCase(sampleText);
|
||||
print(upperCaseText);
|
||||
|
||||
let lowerCaseText = "Text in lower case: " + to_lower_case(sampleText);
|
||||
let lowerCaseText = "Text in lower case: " + toLowerCase(sampleText);
|
||||
print(lowerCaseText);
|
||||
|
Loading…
Reference in New Issue
Block a user