mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-03 22:23:35 -07:00
Merge branch 'UNLEASHED' into 420
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <furi/furi.h>
|
||||
|
||||
/*
|
||||
Testing 10000 api calls
|
||||
|
||||
No lock
|
||||
Time diff: 445269.218750 us
|
||||
Time per call: 44.526920 us
|
||||
|
||||
furi_thread_flags
|
||||
Time diff: 430279.875000 us // lol wtf? smaller than no lock?
|
||||
Time per call: 43.027988 us // I tested it many times, it's always smaller
|
||||
|
||||
FuriEventFlag
|
||||
Time diff: 831523.625000 us
|
||||
Time per call: 83.152359 us
|
||||
|
||||
FuriSemaphore
|
||||
Time diff: 999807.125000 us
|
||||
Time per call: 99.980713 us
|
||||
|
||||
FuriMutex
|
||||
Time diff: 1071417.500000 us
|
||||
Time per call: 107.141747 us
|
||||
*/
|
||||
|
||||
typedef FuriEventFlag* FuriApiLock;
|
||||
|
||||
#define API_LOCK_EVENT (1U << 0)
|
||||
|
||||
#define api_lock_alloc_locked() furi_event_flag_alloc()
|
||||
|
||||
#define api_lock_wait_unlock(_lock) \
|
||||
furi_event_flag_wait(_lock, API_LOCK_EVENT, FuriFlagWaitAny, FuriWaitForever)
|
||||
|
||||
#define api_lock_free(_lock) furi_event_flag_free(_lock)
|
||||
|
||||
#define api_lock_unlock(_lock) furi_event_flag_set(_lock, API_LOCK_EVENT)
|
||||
|
||||
#define api_lock_wait_unlock_and_free(_lock) \
|
||||
api_lock_wait_unlock(_lock); \
|
||||
api_lock_free(_lock);
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "property.h"
|
||||
|
||||
#include <core/check.h>
|
||||
|
||||
void property_value_out(PropertyValueContext* ctx, const char* fmt, unsigned int nparts, ...) {
|
||||
furi_assert(ctx);
|
||||
furi_string_reset(ctx->key);
|
||||
|
||||
va_list args;
|
||||
va_start(args, nparts);
|
||||
|
||||
for(size_t i = 0; i < nparts; ++i) {
|
||||
const char* keypart = va_arg(args, const char*);
|
||||
furi_string_cat(ctx->key, keypart);
|
||||
if(i < nparts - 1) {
|
||||
furi_string_push_back(ctx->key, ctx->sep);
|
||||
}
|
||||
}
|
||||
|
||||
const char* value_str;
|
||||
|
||||
if(fmt) {
|
||||
furi_string_vprintf(ctx->value, fmt, args);
|
||||
value_str = furi_string_get_cstr(ctx->value);
|
||||
} else {
|
||||
// C string passthrough (no formatting)
|
||||
value_str = va_arg(args, const char*);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
ctx->out(furi_string_get_cstr(ctx->key), value_str, ctx->last, ctx->context);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <core/string.h>
|
||||
|
||||
/** Callback type called every time another key-value pair of device information is ready
|
||||
*
|
||||
* @param key[in] device information type identifier
|
||||
* @param value[in] device information value
|
||||
* @param last[in] whether the passed key-value pair is the last one
|
||||
* @param context[in] to pass to callback
|
||||
*/
|
||||
typedef void (*PropertyValueCallback)(const char* key, const char* value, bool last, void* context);
|
||||
|
||||
typedef struct {
|
||||
FuriString* key; /**< key string buffer, must be initialised before use */
|
||||
FuriString* value; /**< value string buffer, must be initialised before use */
|
||||
PropertyValueCallback out; /**< output callback function */
|
||||
char sep; /**< separator character between key parts */
|
||||
bool last; /**< flag to indicate last element */
|
||||
void* context; /**< user-defined context, passed through to out callback */
|
||||
} PropertyValueContext;
|
||||
|
||||
/** Builds key and value strings and outputs them via a callback function
|
||||
*
|
||||
* @param ctx[in] local property context
|
||||
* @param fmt[in] value format, set to NULL to bypass formatting
|
||||
* @param nparts[in] number of key parts (separated by character)
|
||||
* @param ...[in] list of key parts followed by value
|
||||
*/
|
||||
void property_value_out(PropertyValueContext* ctx, const char* fmt, unsigned int nparts, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user