Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
fixes by Willy-JL
nfc parser by zacharyweiss
js widget and path globals by jamisonderek
  • Loading branch information
xMasterX committed Apr 4, 2024
1 parent 45e7913 commit ec4b8b8
Show file tree
Hide file tree
Showing 14 changed files with 2,137 additions and 8 deletions.
9 changes: 9 additions & 0 deletions applications/main/nfc/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ App(
sources=["plugins/supported_cards/metromoney.c"],
)

App(
appid="charliecard_parser",
apptype=FlipperAppType.PLUGIN,
entry_point="charliecard_plugin_ep",
targets=["f7"],
requires=["nfc"],
sources=["plugins/supported_cards/charliecard.c"],
)

App(
appid="kazan_parser",
apptype=FlipperAppType.PLUGIN,
Expand Down
1,059 changes: 1,059 additions & 0 deletions applications/main/nfc/plugins/supported_cards/charliecard.c

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions applications/services/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ static void desktop_loader_callback(const void* message, void* context) {
const LoaderEvent* event = message;

if(event->type == LoaderEventTypeApplicationStarted) {
desktop->animation_lock = api_lock_alloc_locked();
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalBeforeAppStarted);
furi_check(furi_semaphore_acquire(desktop->animation_semaphore, 3000) == FuriStatusOk);
api_lock_wait_unlock_and_free(desktop->animation_lock);
desktop->animation_lock = NULL;
} else if(event->type == LoaderEventTypeApplicationStopped) {
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAfterAppFinished);
}
Expand Down Expand Up @@ -126,7 +128,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
animation_manager_unload_and_stall_animation(desktop->animation_manager);
}
desktop_auto_lock_inhibit(desktop);
furi_semaphore_release(desktop->animation_semaphore);
api_lock_unlock(desktop->animation_lock);
return true;
case DesktopGlobalAfterAppFinished:
animation_manager_load_and_continue_animation(desktop->animation_manager);
Expand Down Expand Up @@ -276,7 +278,6 @@ void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled) {
Desktop* desktop_alloc(void) {
Desktop* desktop = malloc(sizeof(Desktop));

desktop->animation_semaphore = furi_semaphore_alloc(1, 0);
desktop->animation_manager = animation_manager_alloc();
desktop->gui = furi_record_open(RECORD_GUI);
desktop->scene_thread = furi_thread_alloc();
Expand Down
3 changes: 2 additions & 1 deletion applications/services/desktop/desktop_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <loader/loader.h>
#include <notification/notification_app.h>
#include <toolbox/api_lock.h>

#define STATUS_BAR_Y_SHIFT 13

Expand Down Expand Up @@ -81,7 +82,7 @@ struct Desktop {

bool in_transition : 1;

FuriSemaphore* animation_semaphore;
FuriApiLock animation_lock;
};

Desktop* desktop_alloc(void);
Expand Down
8 changes: 8 additions & 0 deletions applications/system/js_app/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ App(
requires=["js_app"],
sources=["modules/js_textbox.c"],
)

App(
appid="js_widget",
apptype=FlipperAppType.PLUGIN,
entry_point="js_widget_ep",
requires=["js_app"],
sources=["modules/js_widget.c"],
)
9 changes: 9 additions & 0 deletions applications/system/js_app/examples/apps/Scripts/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let storage = require("storage");

print("script has __dirpath of" + __dirpath);
print("script has __filepath of" + __filepath);
if (storage.exists(__dirpath + "/math.js")) {
print("math.js exist here.");
} else {
print("math.js does not exist here.");
}
Binary file not shown.
59 changes: 59 additions & 0 deletions applications/system/js_app/examples/apps/Scripts/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
let widget = require("widget");

let demo_seconds = 30;

print("Loading file", __filepath);
print("From directory", __dirpath);

// addText supports "Primary" and "Secondary" font sizes.
widget.addText(10, 10, "Primary", "Example JS widget");
widget.addText(10, 20, "Secondary", "Example widget from JS!");

// load a Xbm file from the same directory as this script.
widget.addText(0, 30, "Secondary", __filepath);
let logo = widget.loadImageXbm(__dirpath + "/widget-js.fxbm");

// add a line (x1, y1, x2, y2)
widget.addLine(10, 35, 120, 35);

// add a circle/disc (x, y, radius)
widget.addCircle(12, 52, 10);
widget.addDisc(12, 52, 5);

// add a frame/box (x, y, width, height)
widget.addFrame(30, 45, 10, 10);
widget.addBox(32, 47, 6, 6);

// add a rounded frame/box (x, y, width, height, radius)
widget.addRframe(50, 45, 15, 15, 3);
widget.addRbox(53, 48, 6, 6, 2);

// add a dot (x, y)
widget.addDot(100, 45);
widget.addDot(102, 44);
widget.addDot(104, 43);

// add a glyph (x, y, glyph)
widget.addGlyph(115, 50, "#".charCodeAt(0));

// Show the widget (drawing the layers in the orderer they were added)
widget.show();

let i = 1;
let bitmap = undefined;
while (widget.isOpen() && i <= demo_seconds) {
// Print statements will only show up once the widget is closed.
print("count is at", i++);

// You can call remove on any added item, it does not impact the other ids.
if (bitmap) { widget.remove(bitmap); bitmap = undefined; }
// All of the addXXX functions return an id that can be used to remove the item.
else { bitmap = widget.addXbm(77, 45, logo); }

delay(1000);
}

// If user did not press the back button, close the widget.
if (widget.isOpen()) {
widget.close();
}
19 changes: 19 additions & 0 deletions applications/system/js_app/js_thread.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <common/cs_dbg.h>
#include <toolbox/path.h>
#include <toolbox/stream/file_stream.h>
#include <loader/firmware_api/firmware_api.h>
#include <flipper_application/api_hashtable/api_hashtable.h>
Expand Down Expand Up @@ -319,6 +320,24 @@ static int32_t js_thread(void* arg) {
struct mjs* mjs = mjs_create(worker);
worker->modules = js_modules_create(mjs, worker->resolver);
mjs_val_t global = mjs_get_global(mjs);
if(worker->path) {
FuriString* dirpath = furi_string_alloc();
path_extract_dirname(furi_string_get_cstr(worker->path), dirpath);
mjs_set(
mjs,
global,
"__filepath",
~0,
mjs_mk_string(
mjs, furi_string_get_cstr(worker->path), furi_string_size(worker->path), true));
mjs_set(
mjs,
global,
"__dirpath",
~0,
mjs_mk_string(mjs, furi_string_get_cstr(dirpath), furi_string_size(dirpath), true));
furi_string_free(dirpath);
}
mjs_set(mjs, global, "print", ~0, MJS_MK_FN(js_print));
mjs_set(mjs, global, "delay", ~0, MJS_MK_FN(js_delay));
mjs_set(mjs, global, "to_string", ~0, MJS_MK_FN(js_global_to_string));
Expand Down
2 changes: 1 addition & 1 deletion applications/system/js_app/modules/js_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void js_math_random(struct mjs* mjs) {
mjs_return(mjs, MJS_UNDEFINED);
}
const uint32_t random_val = furi_hal_random_get();
double rnd = (double)random_val / RAND_MAX;
double rnd = (double)random_val / FURI_HAL_RANDOM_MAX;
mjs_return(mjs, mjs_mk_number(mjs, rnd));
}

Expand Down
Loading

0 comments on commit ec4b8b8

Please sign in to comment.