mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-07 19:01:54 -07:00
Update and clean apps
This commit is contained in:
@@ -8,4 +8,5 @@ App(
|
||||
fap_category="Misc",
|
||||
fap_icon="images/barcode_10.png",
|
||||
fap_icon_assets="images",
|
||||
fap_icon_assets_symbol="barcode_app",
|
||||
)
|
||||
|
||||
+9
-3
@@ -13,7 +13,7 @@
|
||||
static bool select_file(const char* folder, FuriString* file_path) {
|
||||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(&browser_options, BARCODE_EXTENSION, &I_barcode_10);
|
||||
dialog_file_browser_set_basic_options(&browser_options, "", &I_barcode_10);
|
||||
browser_options.base_path = DEFAULT_USER_BARCODES;
|
||||
furi_string_set(file_path, folder);
|
||||
|
||||
@@ -65,7 +65,7 @@ bool get_file_name_from_path(FuriString* file_path, FuriString* file_name, bool
|
||||
if(file_path == NULL || file_name == NULL) {
|
||||
return false;
|
||||
}
|
||||
uint slash_index = furi_string_search_rchar(file_path, '/', 0);
|
||||
uint32_t slash_index = furi_string_search_rchar(file_path, '/', 0);
|
||||
if(slash_index == FURI_STRING_FAILURE || slash_index >= (furi_string_size(file_path) - 1)) {
|
||||
return false;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ bool get_file_name_from_path(FuriString* file_path, FuriString* file_name, bool
|
||||
furi_string_set(file_name, file_path);
|
||||
furi_string_right(file_name, slash_index + 1);
|
||||
if(remove_extension) {
|
||||
uint ext_index = furi_string_search_rchar(file_name, '.', 0);
|
||||
uint32_t ext_index = furi_string_search_rchar(file_name, '.', 0);
|
||||
if(ext_index != FURI_STRING_FAILURE && ext_index < (furi_string_size(file_path))) {
|
||||
furi_string_left(file_name, ext_index);
|
||||
}
|
||||
@@ -239,6 +239,11 @@ void submenu_callback(void* context, uint32_t index) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t create_view_callback(void* context) {
|
||||
UNUSED(context);
|
||||
return CreateBarcodeView;
|
||||
}
|
||||
|
||||
uint32_t main_menu_callback(void* context) {
|
||||
UNUSED(context);
|
||||
return MainMenuView;
|
||||
@@ -305,6 +310,7 @@ int32_t barcode_main(void* p) {
|
||||
* Creating Text Input View
|
||||
******************************/
|
||||
app->text_input = text_input_alloc();
|
||||
view_set_previous_callback(text_input_get_view(app->text_input), create_view_callback);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, TextInputView, text_input_get_view(app->text_input));
|
||||
|
||||
|
||||
+8
-7
@@ -15,7 +15,7 @@
|
||||
#include "barcode_utils.h"
|
||||
|
||||
#define TAG "BARCODE"
|
||||
#define VERSION "1.0"
|
||||
#define VERSION "1.1"
|
||||
#define FILE_VERSION "1"
|
||||
|
||||
#define TEXT_BUFFER_SIZE 128
|
||||
@@ -23,10 +23,11 @@
|
||||
#define BARCODE_HEIGHT 50
|
||||
#define BARCODE_Y_START 3
|
||||
|
||||
#define APPS_DATA EXT_PATH("apps_data")
|
||||
|
||||
//the folder where the encodings are located
|
||||
#define BARCODE_DATA_FILE_DIR_PATH APPS_DATA "/barcode_data"
|
||||
#define BARCODE_DATA_FILE_DIR_PATH EXT_PATH("apps_data/barcode_data")
|
||||
|
||||
//the folder where the codabar encoding table is located
|
||||
#define CODABAR_DICT_FILE_PATH BARCODE_DATA_FILE_DIR_PATH "/codabar_encodings.txt"
|
||||
|
||||
//the folder where the code 39 encoding table is located
|
||||
#define CODE39_DICT_FILE_PATH BARCODE_DATA_FILE_DIR_PATH "/code39_encodings.txt"
|
||||
@@ -35,11 +36,11 @@
|
||||
#define CODE128_DICT_FILE_PATH BARCODE_DATA_FILE_DIR_PATH "/code128_encodings.txt"
|
||||
|
||||
//the folder where the user stores their barcodes
|
||||
#define DEFAULT_USER_BARCODES EXT_PATH("barcodes")
|
||||
#define DEFAULT_USER_BARCODES EXT_PATH("apps_data/barcodes")
|
||||
|
||||
//The extension barcode files use
|
||||
#define BARCODE_EXTENSION ".barcode"
|
||||
#define BARCODE_EXTENSION_LENGTH 8
|
||||
#define BARCODE_EXTENSION ".txt"
|
||||
#define BARCODE_EXTENSION_LENGTH 4
|
||||
|
||||
#include "views/barcode_view.h"
|
||||
#include "views/create_view.h"
|
||||
|
||||
+13
-2
@@ -43,6 +43,14 @@ void init_types() {
|
||||
code_128->start_pos = 0;
|
||||
barcode_type_objs[CODE128] = code_128;
|
||||
|
||||
BarcodeTypeObj* codabar = malloc(sizeof(BarcodeTypeObj));
|
||||
codabar->name = "Codabar";
|
||||
codabar->type = CODABAR;
|
||||
codabar->min_digits = 1;
|
||||
codabar->max_digits = -1;
|
||||
codabar->start_pos = 0;
|
||||
barcode_type_objs[CODABAR] = codabar;
|
||||
|
||||
BarcodeTypeObj* unknown = malloc(sizeof(BarcodeTypeObj));
|
||||
unknown->name = "Unknown";
|
||||
unknown->type = UNKNOWN;
|
||||
@@ -74,6 +82,9 @@ BarcodeTypeObj* get_type(FuriString* type_string) {
|
||||
if(furi_string_cmp_str(type_string, "CODE-128") == 0) {
|
||||
return barcode_type_objs[CODE128];
|
||||
}
|
||||
if(furi_string_cmp_str(type_string, "Codabar") == 0) {
|
||||
return barcode_type_objs[CODABAR];
|
||||
}
|
||||
|
||||
return barcode_type_objs[UNKNOWN];
|
||||
}
|
||||
@@ -98,7 +109,7 @@ const char* get_error_code_name(ErrorCode error_code) {
|
||||
return "OK";
|
||||
default:
|
||||
return "Unknown Code";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const char* get_error_code_message(ErrorCode error_code) {
|
||||
@@ -121,5 +132,5 @@ const char* get_error_code_message(ErrorCode error_code) {
|
||||
return "OK";
|
||||
default:
|
||||
return "Could not read barcode data";
|
||||
}
|
||||
};
|
||||
}
|
||||
+2
-1
@@ -3,7 +3,7 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define NUMBER_OF_BARCODE_TYPES 6
|
||||
#define NUMBER_OF_BARCODE_TYPES 7
|
||||
|
||||
typedef enum {
|
||||
WrongNumberOfDigits, //There is too many or too few digits in the barcode
|
||||
@@ -22,6 +22,7 @@ typedef enum {
|
||||
EAN13,
|
||||
CODE39,
|
||||
CODE128,
|
||||
CODABAR,
|
||||
|
||||
UNKNOWN
|
||||
} BarcodeType;
|
||||
|
||||
+61
-2
@@ -13,6 +13,9 @@ void barcode_loader(BarcodeData* barcode_data) {
|
||||
case CODE128:
|
||||
code_128_loader(barcode_data);
|
||||
break;
|
||||
case CODABAR:
|
||||
codabar_loader(barcode_data);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
barcode_data->reason = UnsupportedType;
|
||||
barcode_data->valid = false;
|
||||
@@ -36,6 +39,7 @@ int calculate_check_digit(BarcodeData* barcode_data) {
|
||||
break;
|
||||
case CODE39:
|
||||
case CODE128:
|
||||
case CODABAR:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
@@ -130,7 +134,6 @@ void code_39_loader(BarcodeData* barcode_data) {
|
||||
int barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
// int max_digit = barcode_data->type_obj->max_digits;
|
||||
|
||||
//check the length of the barcode, must contain atleast a character,
|
||||
//this can have as many characters as it wants, it might not fit on the screen
|
||||
@@ -215,7 +218,6 @@ void code_128_loader(BarcodeData* barcode_data) {
|
||||
const char* stop_code_bits = "1100011101011";
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
// int max_digit = barcode_data->type_obj->max_digits;
|
||||
|
||||
/**
|
||||
* A sum of all of the characters values
|
||||
@@ -342,3 +344,60 @@ void code_128_loader(BarcodeData* barcode_data) {
|
||||
furi_string_cat(barcode_data->correct_data, barcode_bits);
|
||||
furi_string_free(barcode_bits);
|
||||
}
|
||||
|
||||
void codabar_loader(BarcodeData* barcode_data) {
|
||||
int barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
|
||||
//check the length of the barcode, must contain atleast a character,
|
||||
//this can have as many characters as it wants, it might not fit on the screen
|
||||
if(barcode_length < min_digits) {
|
||||
barcode_data->reason = WrongNumberOfDigits;
|
||||
barcode_data->valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
FuriString* barcode_bits = furi_string_alloc();
|
||||
|
||||
barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
//Open Storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
|
||||
if(!flipper_format_file_open_existing(ff, CODABAR_DICT_FILE_PATH)) {
|
||||
FURI_LOG_E(TAG, "Could not open file %s", CODABAR_DICT_FILE_PATH);
|
||||
barcode_data->reason = MissingEncodingTable;
|
||||
barcode_data->valid = false;
|
||||
} else {
|
||||
FuriString* char_bits = furi_string_alloc();
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char barcode_char = toupper(furi_string_get_char(barcode_data->raw_data, i));
|
||||
|
||||
//convert a char into a string so it used in flipper_format_read_string
|
||||
char current_character[2];
|
||||
snprintf(current_character, 2, "%c", barcode_char);
|
||||
|
||||
if(!flipper_format_read_string(ff, current_character, char_bits)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"%c\" string", barcode_char);
|
||||
barcode_data->reason = InvalidCharacters;
|
||||
barcode_data->valid = false;
|
||||
break;
|
||||
} else {
|
||||
FURI_LOG_I(
|
||||
TAG, "\"%c\" string: %s", barcode_char, furi_string_get_cstr(char_bits));
|
||||
furi_string_cat(barcode_bits, char_bits);
|
||||
}
|
||||
flipper_format_rewind(ff);
|
||||
}
|
||||
furi_string_free(char_bits);
|
||||
}
|
||||
|
||||
//Close Storage
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_cat(barcode_data->correct_data, barcode_bits);
|
||||
furi_string_free(barcode_bits);
|
||||
}
|
||||
@@ -10,4 +10,5 @@ void ean_8_loader(BarcodeData* barcode_data);
|
||||
void ean_13_loader(BarcodeData* barcode_data);
|
||||
void code_39_loader(BarcodeData* barcode_data);
|
||||
void code_128_loader(BarcodeData* barcode_data);
|
||||
void codabar_loader(BarcodeData* barcode_data);
|
||||
void barcode_loader(BarcodeData* barcode_data);
|
||||
@@ -322,6 +322,68 @@ static void draw_code_128(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
canvas, 62, y + height + 8, AlignCenter, AlignBottom, furi_string_get_cstr(raw_data));
|
||||
}
|
||||
|
||||
static void draw_codabar(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
FuriString* raw_data = barcode_data->raw_data;
|
||||
FuriString* barcode_digits = barcode_data->correct_data;
|
||||
//BarcodeTypeObj* type_obj = barcode_data->type_obj;
|
||||
|
||||
int barcode_length = furi_string_size(barcode_digits);
|
||||
int total_pixels = 0;
|
||||
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
//1 for wide, 0 for narrow
|
||||
char wide_or_narrow = furi_string_get_char(barcode_digits, i);
|
||||
int wn_digit = wide_or_narrow - '0'; //wide(1) or narrow(0) digit
|
||||
|
||||
if(wn_digit == 1) {
|
||||
total_pixels += 3;
|
||||
} else {
|
||||
total_pixels += 1;
|
||||
}
|
||||
if((i + 1) % 7 == 0) {
|
||||
total_pixels += 1;
|
||||
}
|
||||
}
|
||||
|
||||
int x = (128 - total_pixels) / 2;
|
||||
int y = BARCODE_Y_START;
|
||||
int width = 1;
|
||||
int height = BARCODE_HEIGHT;
|
||||
bool filled_in = true;
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
// canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignCenter, error);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 62, y + height + 8, AlignCenter, AlignBottom, furi_string_get_cstr(raw_data));
|
||||
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
//1 for wide, 0 for narrow
|
||||
char wide_or_narrow = furi_string_get_char(barcode_digits, i);
|
||||
int wn_digit = wide_or_narrow - '0'; //wide(1) or narrow(0) digit
|
||||
|
||||
if(filled_in) {
|
||||
if(wn_digit == 1) {
|
||||
x = draw_bits(canvas, "111", x, y, width, height);
|
||||
} else {
|
||||
x = draw_bits(canvas, "1", x, y, width, height);
|
||||
}
|
||||
filled_in = false;
|
||||
} else {
|
||||
if(wn_digit == 1) {
|
||||
x = draw_bits(canvas, "000", x, y, width, height);
|
||||
} else {
|
||||
x = draw_bits(canvas, "0", x, y, width, height);
|
||||
}
|
||||
filled_in = true;
|
||||
}
|
||||
if((i + 1) % 7 == 0) {
|
||||
x = draw_bits(canvas, "0", x, y, width, height);
|
||||
filled_in = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void barcode_draw_callback(Canvas* canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
BarcodeModel* barcode_model = ctx;
|
||||
@@ -346,6 +408,9 @@ static void barcode_draw_callback(Canvas* canvas, void* ctx) {
|
||||
case CODE128:
|
||||
draw_code_128(canvas, data);
|
||||
break;
|
||||
case CODABAR:
|
||||
draw_codabar(canvas, data);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
|
||||
+2
-1
@@ -448,7 +448,8 @@ void save_barcode(CreateView* create_view_object) {
|
||||
|
||||
flipper_format_write_string_cstr(ff, "Version", FILE_VERSION);
|
||||
|
||||
flipper_format_write_comment_cstr(ff, "Types - UPC-A, EAN-8, EAN-13, CODE-39, CODE-128");
|
||||
flipper_format_write_comment_cstr(
|
||||
ff, "Types - UPC-A, EAN-8, EAN-13, CODE-39, CODE-128, Codabar");
|
||||
|
||||
flipper_format_write_string_cstr(ff, "Type", barcode_type->name);
|
||||
|
||||
|
||||
+1
-7
@@ -53,15 +53,9 @@ MessageView* message_view_allocate(BarcodeApp* barcode_app) {
|
||||
return message_view_object;
|
||||
}
|
||||
|
||||
void message_view_free_model(MessageView* message_view_object) {
|
||||
with_view_model(
|
||||
message_view_object->view, MessageViewModel * model, { UNUSED(model); }, true);
|
||||
}
|
||||
|
||||
void message_view_free(MessageView* message_view_object) {
|
||||
furi_assert(message_view_object);
|
||||
|
||||
message_view_free_model(message_view_object);
|
||||
view_free(message_view_object->view);
|
||||
free(message_view_object);
|
||||
}
|
||||
@@ -69,4 +63,4 @@ void message_view_free(MessageView* message_view_object) {
|
||||
View* message_get_view(MessageView* message_view_object) {
|
||||
furi_assert(message_view_object);
|
||||
return message_view_object->view;
|
||||
}
|
||||
}
|
||||
+32
-42
@@ -39,53 +39,33 @@ typedef struct {
|
||||
static void draw_callback(Canvas* canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
|
||||
mutexStruct* mutexVal = ctx;
|
||||
mutexStruct mutexDraw;
|
||||
furi_mutex_acquire(mutexVal->mutex, FuriWaitForever);
|
||||
memcpy(&mutexDraw, mutexVal, sizeof(mutexStruct));
|
||||
furi_mutex_release(mutexVal->mutex);
|
||||
mutexStruct displayStruct;
|
||||
mutexStruct* geigerMutex = ctx;
|
||||
furi_mutex_acquire(geigerMutex->mutex, FuriWaitForever);
|
||||
memcpy(&displayStruct, geigerMutex, sizeof(mutexStruct));
|
||||
furi_mutex_release(geigerMutex->mutex);
|
||||
|
||||
char buffer[32];
|
||||
if(mutexDraw.data == 0)
|
||||
snprintf(buffer, sizeof(buffer), "%ld cps - %ld cpm", mutexDraw.cps, mutexDraw.cpm);
|
||||
else if(mutexDraw.data == 1)
|
||||
if(displayStruct.data == 0)
|
||||
snprintf(
|
||||
buffer, sizeof(buffer), "%ld cps - %ld cpm", displayStruct.cps, displayStruct.cpm);
|
||||
else if(displayStruct.data == 1)
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%ld cps - %.2f uSv/h",
|
||||
mutexDraw.cps,
|
||||
((double)mutexDraw.cpm * (double)CONVERSION_FACTOR));
|
||||
else if(mutexDraw.data == 2)
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%ld cps - %.2f mSv/y",
|
||||
mutexDraw.cps,
|
||||
(((double)mutexDraw.cpm * (double)CONVERSION_FACTOR)) * (double)8.76);
|
||||
else if(mutexDraw.data == 3)
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%ld cps - %.4f Rad/h",
|
||||
mutexDraw.cps,
|
||||
((double)mutexDraw.cpm * (double)CONVERSION_FACTOR) / (double)10000);
|
||||
else if(mutexDraw.data == 4)
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%ld cps - %.2f mR/h",
|
||||
mutexDraw.cps,
|
||||
((double)mutexDraw.cpm * (double)CONVERSION_FACTOR) / (double)10);
|
||||
displayStruct.cps,
|
||||
((double)displayStruct.cpm * (double)CONVERSION_FACTOR));
|
||||
else
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%ld cps - %.2f uR/h",
|
||||
mutexDraw.cps,
|
||||
((double)mutexDraw.cpm * (double)CONVERSION_FACTOR) * (double)100);
|
||||
"%ld cps - %.2f mSv/y",
|
||||
displayStruct.cps,
|
||||
(((double)displayStruct.cpm * (double)CONVERSION_FACTOR)) * (double)8.76);
|
||||
|
||||
for(int i = 0; i < SCREEN_SIZE_X; i += 2) {
|
||||
float Y = SCREEN_SIZE_Y - (mutexDraw.line[i / 2] * mutexDraw.coef);
|
||||
float Y = SCREEN_SIZE_Y - (displayStruct.line[i / 2] * displayStruct.coef);
|
||||
|
||||
canvas_draw_line(canvas, i, Y, i, SCREEN_SIZE_Y);
|
||||
canvas_draw_line(canvas, i + 1, Y, i + 1, SCREEN_SIZE_Y);
|
||||
@@ -109,7 +89,7 @@ static void clock_tick(void* ctx) {
|
||||
randomNumber &= 0xFFF;
|
||||
if(randomNumber == 0) randomNumber = 1;
|
||||
|
||||
furi_hal_pwm_start(FuriHalPwmOutputIdLptim2PA4, randomNumber, 50);
|
||||
furi_hal_pwm_set_params(FuriHalPwmOutputIdLptim2PA4, randomNumber, 50);
|
||||
|
||||
FuriMessageQueue* queue = ctx;
|
||||
EventApp event = {.type = ClockEventTypeTick};
|
||||
@@ -123,7 +103,8 @@ static void gpiocallback(void* ctx) {
|
||||
furi_message_queue_put(queue, &event, 0);
|
||||
}
|
||||
|
||||
int32_t flipper_geiger_app() {
|
||||
int32_t flipper_geiger_app(void* p) {
|
||||
UNUSED(p);
|
||||
EventApp event;
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(EventApp));
|
||||
|
||||
@@ -146,7 +127,7 @@ int32_t flipper_geiger_app() {
|
||||
}
|
||||
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, draw_callback, &mutexVal.mutex);
|
||||
view_port_draw_callback_set(view_port, draw_callback, &mutexVal);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
|
||||
furi_hal_gpio_add_int_callback(&gpio_ext_pa7, gpiocallback, event_queue);
|
||||
@@ -158,7 +139,13 @@ int32_t flipper_geiger_app() {
|
||||
furi_timer_start(timer, 1000);
|
||||
|
||||
// ENABLE 5V pin
|
||||
furi_hal_power_enable_otg();
|
||||
|
||||
// Enable 5v power, multiple attempts to avoid issues with power chip protection false triggering
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
|
||||
while(1) {
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, FuriWaitForever);
|
||||
@@ -186,7 +173,7 @@ int32_t flipper_geiger_app() {
|
||||
if(mutexVal.data != 0)
|
||||
mutexVal.data--;
|
||||
else
|
||||
mutexVal.data = 5;
|
||||
mutexVal.data = 2;
|
||||
|
||||
screenRefresh = 1;
|
||||
furi_mutex_release(mutexVal.mutex);
|
||||
@@ -194,7 +181,7 @@ int32_t flipper_geiger_app() {
|
||||
event.input.type == InputTypeShort)) {
|
||||
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
||||
|
||||
if(mutexVal.data != 5)
|
||||
if(mutexVal.data != 2)
|
||||
mutexVal.data++;
|
||||
else
|
||||
mutexVal.data = 0;
|
||||
@@ -235,7 +222,10 @@ int32_t flipper_geiger_app() {
|
||||
if(screenRefresh == 1) view_port_update(view_port);
|
||||
}
|
||||
|
||||
furi_hal_power_disable_otg();
|
||||
// Disable 5v power
|
||||
if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
furi_hal_gpio_disable_int_callback(&gpio_ext_pa7);
|
||||
furi_hal_gpio_remove_int_callback(&gpio_ext_pa7);
|
||||
|
||||
+71
-101
@@ -1,6 +1,8 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <infrared_worker.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
@@ -13,8 +15,7 @@
|
||||
#include "infrared_signal.h"
|
||||
#include "infrared_remote.h"
|
||||
#include "infrared_remote_button.h"
|
||||
#define TAG "IR_Remote"
|
||||
#define MENU_BTN_TXT_X 36
|
||||
#define TAG "ir_remote"
|
||||
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
@@ -32,6 +33,7 @@ typedef struct {
|
||||
FuriString* left_hold_button;
|
||||
FuriString* right_hold_button;
|
||||
FuriString* ok_hold_button;
|
||||
InfraredWorker* infrared_worker;
|
||||
} IRApp;
|
||||
|
||||
// Screen is 128x64 px
|
||||
@@ -61,47 +63,17 @@ static void app_draw_callback(Canvas* canvas, void* ctx) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
8,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->up_button));
|
||||
canvas, 32, 8, AlignCenter, AlignCenter, furi_string_get_cstr(app->up_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
18,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->down_button));
|
||||
canvas, 32, 18, AlignCenter, AlignCenter, furi_string_get_cstr(app->down_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
28,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->left_button));
|
||||
canvas, 32, 28, AlignCenter, AlignCenter, furi_string_get_cstr(app->left_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
38,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->right_button));
|
||||
canvas, 32, 38, AlignCenter, AlignCenter, furi_string_get_cstr(app->right_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
48,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->ok_button));
|
||||
canvas, 32, 48, AlignCenter, AlignCenter, furi_string_get_cstr(app->ok_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
58,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->back_button));
|
||||
canvas, 32, 58, AlignCenter, AlignCenter, furi_string_get_cstr(app->back_button));
|
||||
|
||||
canvas_draw_line(canvas, 0, 65, 64, 65);
|
||||
|
||||
@@ -113,41 +85,21 @@ static void app_draw_callback(Canvas* canvas, void* ctx) {
|
||||
canvas_draw_icon(canvas, 0, 118, &I_back_10px);
|
||||
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
73,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->up_hold_button));
|
||||
canvas, 32, 73, AlignCenter, AlignCenter, furi_string_get_cstr(app->up_hold_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 32, 83, AlignCenter, AlignCenter, furi_string_get_cstr(app->down_hold_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 32, 93, AlignCenter, AlignCenter, furi_string_get_cstr(app->left_hold_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
83,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->down_hold_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
93,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->left_hold_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
32,
|
||||
103,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->right_hold_button));
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
MENU_BTN_TXT_X,
|
||||
113,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
furi_string_get_cstr(app->ok_hold_button));
|
||||
canvas_draw_str_aligned(canvas, MENU_BTN_TXT_X, 123, AlignCenter, AlignCenter, "Exit App");
|
||||
canvas, 32, 113, AlignCenter, AlignCenter, furi_string_get_cstr(app->ok_hold_button));
|
||||
canvas_draw_str_aligned(canvas, 32, 123, AlignCenter, AlignCenter, "Exit App");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +129,7 @@ int32_t infrared_remote_app(void* p) {
|
||||
app->right_hold_button = furi_string_alloc();
|
||||
app->ok_hold_button = furi_string_alloc();
|
||||
app->view_port = view_port_alloc();
|
||||
app->infrared_worker = infrared_worker_alloc();
|
||||
|
||||
// Configure view port
|
||||
view_port_draw_callback_set(app->view_port, app_draw_callback, app);
|
||||
@@ -247,6 +200,9 @@ int32_t infrared_remote_app(void* p) {
|
||||
InfraredSignal* right_hold_signal = infrared_signal_alloc();
|
||||
InfraredSignal* ok_hold_signal = infrared_signal_alloc();
|
||||
|
||||
InfraredSignal* active_signal = NULL;
|
||||
bool is_transmitting = false;
|
||||
|
||||
bool up_enabled = false;
|
||||
bool down_enabled = false;
|
||||
bool left_enabled = false;
|
||||
@@ -281,8 +237,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
//set missing filenames to N/A
|
||||
//assign button signals
|
||||
size_t index = 0;
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "UP", app->up_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read UP string");
|
||||
furi_string_set(app->up_button, "N/A");
|
||||
@@ -297,7 +251,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "DOWN", app->down_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read DOWN string");
|
||||
furi_string_set(app->down_button, "N/A");
|
||||
@@ -312,7 +265,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "LEFT", app->left_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read LEFT string");
|
||||
furi_string_set(app->left_button, "N/A");
|
||||
@@ -327,7 +279,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "RIGHT", app->right_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read RIGHT string");
|
||||
furi_string_set(app->right_button, "N/A");
|
||||
@@ -342,7 +293,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "OK", app->ok_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read OK string");
|
||||
furi_string_set(app->ok_button, "N/A");
|
||||
@@ -357,7 +307,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "BACK", app->back_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read BACK string");
|
||||
furi_string_set(app->back_button, "N/A");
|
||||
@@ -372,7 +321,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "UPHOLD", app->up_hold_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read UPHOLD string");
|
||||
furi_string_set(app->up_hold_button, "N/A");
|
||||
@@ -387,7 +335,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "DOWNHOLD", app->down_hold_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read DOWNHOLD string");
|
||||
furi_string_set(app->down_hold_button, "N/A");
|
||||
@@ -402,7 +349,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "LEFTHOLD", app->left_hold_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read LEFTHOLD string");
|
||||
furi_string_set(app->left_hold_button, "N/A");
|
||||
@@ -417,7 +363,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "RIGHTHOLD", app->right_hold_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read RIGHTHOLD string");
|
||||
furi_string_set(app->right_hold_button, "N/A");
|
||||
@@ -432,7 +377,6 @@ int32_t infrared_remote_app(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_rewind(ff);
|
||||
if(!flipper_format_read_string(ff, "OKHOLD", app->ok_hold_button)) {
|
||||
FURI_LOG_W(TAG, "Could not read OKHOLD string");
|
||||
furi_string_set(app->ok_hold_button, "N/A");
|
||||
@@ -480,43 +424,37 @@ int32_t infrared_remote_app(void* p) {
|
||||
switch(event.key) {
|
||||
case InputKeyUp:
|
||||
if(up_enabled) {
|
||||
infrared_signal_transmit(up_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = up_signal;
|
||||
FURI_LOG_I(TAG, "up");
|
||||
}
|
||||
break;
|
||||
case InputKeyDown:
|
||||
if(down_enabled) {
|
||||
infrared_signal_transmit(down_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = down_signal;
|
||||
FURI_LOG_I(TAG, "down");
|
||||
}
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(right_enabled) {
|
||||
infrared_signal_transmit(right_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = right_signal;
|
||||
FURI_LOG_I(TAG, "right");
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(left_enabled) {
|
||||
infrared_signal_transmit(left_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = left_signal;
|
||||
FURI_LOG_I(TAG, "left");
|
||||
}
|
||||
break;
|
||||
case InputKeyOk:
|
||||
if(ok_enabled) {
|
||||
infrared_signal_transmit(ok_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = ok_signal;
|
||||
FURI_LOG_I(TAG, "ok");
|
||||
}
|
||||
break;
|
||||
case InputKeyBack:
|
||||
if(back_enabled) {
|
||||
infrared_signal_transmit(back_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = back_signal;
|
||||
FURI_LOG_I(TAG, "back");
|
||||
}
|
||||
break;
|
||||
@@ -529,36 +467,31 @@ int32_t infrared_remote_app(void* p) {
|
||||
switch(event.key) {
|
||||
case InputKeyUp:
|
||||
if(up_hold_enabled) {
|
||||
infrared_signal_transmit(up_hold_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = up_hold_signal;
|
||||
FURI_LOG_I(TAG, "up!");
|
||||
}
|
||||
break;
|
||||
case InputKeyDown:
|
||||
if(down_hold_enabled) {
|
||||
infrared_signal_transmit(down_hold_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = down_hold_signal;
|
||||
FURI_LOG_I(TAG, "down!");
|
||||
}
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(right_hold_enabled) {
|
||||
infrared_signal_transmit(right_hold_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = right_hold_signal;
|
||||
FURI_LOG_I(TAG, "right!");
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(left_hold_enabled) {
|
||||
infrared_signal_transmit(left_hold_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = left_hold_signal;
|
||||
FURI_LOG_I(TAG, "left!");
|
||||
}
|
||||
break;
|
||||
case InputKeyOk:
|
||||
if(ok_hold_enabled) {
|
||||
infrared_signal_transmit(ok_hold_signal);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
active_signal = ok_hold_signal;
|
||||
FURI_LOG_I(TAG, "ok!");
|
||||
}
|
||||
break;
|
||||
@@ -566,8 +499,39 @@ int32_t infrared_remote_app(void* p) {
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
} else if(event.type == InputTypeRelease) {
|
||||
} else if(event.type == InputTypeRelease && is_transmitting) {
|
||||
notification_message(notification, &sequence_blink_stop);
|
||||
infrared_worker_tx_stop(app->infrared_worker);
|
||||
is_transmitting = false;
|
||||
active_signal = NULL;
|
||||
}
|
||||
|
||||
if(active_signal != NULL &&
|
||||
(event.type == InputTypeShort || event.type == InputTypeLong)) {
|
||||
if(is_transmitting) {
|
||||
infrared_worker_tx_stop(app->infrared_worker);
|
||||
}
|
||||
|
||||
if(infrared_signal_is_raw(active_signal)) {
|
||||
InfraredRawSignal* raw_signal =
|
||||
infrared_signal_get_raw_signal(active_signal);
|
||||
infrared_worker_set_raw_signal(
|
||||
app->infrared_worker,
|
||||
raw_signal->timings,
|
||||
raw_signal->timings_size,
|
||||
raw_signal->frequency,
|
||||
raw_signal->duty_cycle);
|
||||
} else {
|
||||
InfraredMessage* message = infrared_signal_get_message(active_signal);
|
||||
infrared_worker_set_decoded_signal(app->infrared_worker, message);
|
||||
}
|
||||
|
||||
infrared_worker_tx_set_get_signal_callback(
|
||||
app->infrared_worker, infrared_worker_tx_get_signal_steady_callback, app);
|
||||
|
||||
infrared_worker_tx_start(app->infrared_worker);
|
||||
notification_message(notification, &sequence_blink_start_magenta);
|
||||
is_transmitting = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -586,6 +550,12 @@ int32_t infrared_remote_app(void* p) {
|
||||
furi_string_free(app->right_hold_button);
|
||||
furi_string_free(app->ok_hold_button);
|
||||
|
||||
if(is_transmitting) {
|
||||
infrared_worker_tx_stop(app->infrared_worker);
|
||||
notification_message(notification, &sequence_blink_stop);
|
||||
}
|
||||
infrared_worker_free(app->infrared_worker);
|
||||
|
||||
infrared_remote_free(remote);
|
||||
view_port_enabled_set(app->view_port, false);
|
||||
gui_remove_view_port(gui, app->view_port);
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
Rate: 1
|
||||
Ch: 2
|
||||
ESB: 1
|
||||
DPL: 0
|
||||
CRC: 2
|
||||
Payload: 4
|
||||
P0: C8C8C0
|
||||
P1: C8C8C1
|
||||
P2: C2
|
||||
P3: C3
|
||||
P4: E5
|
||||
@@ -1,5 +0,0 @@
|
||||
SNIFF
|
||||
ESB: 1
|
||||
CRC: 2
|
||||
P0: 00AA
|
||||
P1: 0055
|
||||
+20
-10
@@ -15,7 +15,8 @@
|
||||
|
||||
#define PAD_SIZE_X 3
|
||||
#define PAD_SIZE_Y 8
|
||||
#define PLAYER1_PAD_SPEED 2
|
||||
#define PLAYER1_PAD_SPEED 4
|
||||
|
||||
#define PLAYER2_PAD_SPEED 2
|
||||
#define BALL_SIZE 4
|
||||
|
||||
@@ -38,22 +39,29 @@ typedef struct Players {
|
||||
|
||||
static void draw_callback(Canvas* canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
Players* players = ctx;
|
||||
furi_mutex_acquire(players->mutex, FuriWaitForever);
|
||||
Players* playersMutex = ctx;
|
||||
furi_mutex_acquire(playersMutex->mutex, FuriWaitForever);
|
||||
|
||||
canvas_draw_frame(canvas, 0, 0, 128, 64);
|
||||
canvas_draw_box(canvas, players->player1_X, players->player1_Y, PAD_SIZE_X, PAD_SIZE_Y);
|
||||
canvas_draw_box(canvas, players->player2_X, players->player2_Y, PAD_SIZE_X, PAD_SIZE_Y);
|
||||
canvas_draw_box(canvas, players->ball_X, players->ball_Y, BALL_SIZE, BALL_SIZE);
|
||||
canvas_draw_box(
|
||||
canvas, playersMutex->player1_X, playersMutex->player1_Y, PAD_SIZE_X, PAD_SIZE_Y);
|
||||
canvas_draw_box(
|
||||
canvas, playersMutex->player2_X, playersMutex->player2_Y, PAD_SIZE_X, PAD_SIZE_Y);
|
||||
canvas_draw_box(canvas, playersMutex->ball_X, playersMutex->ball_Y, BALL_SIZE, BALL_SIZE);
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_set_font_direction(canvas, CanvasDirectionBottomToTop);
|
||||
char buffer[16];
|
||||
snprintf(buffer, sizeof(buffer), "%u - %u", players->player1_score, players->player2_score);
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%u - %u",
|
||||
playersMutex->player1_score,
|
||||
playersMutex->player2_score);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SCREEN_SIZE_X / 2 + 15, SCREEN_SIZE_Y / 2 + 2, AlignCenter, AlignTop, buffer);
|
||||
|
||||
furi_mutex_release(players->mutex);
|
||||
furi_mutex_release(playersMutex->mutex);
|
||||
}
|
||||
|
||||
static void input_callback(InputEvent* input_event, void* ctx) {
|
||||
@@ -93,7 +101,8 @@ uint8_t changeDirection() {
|
||||
return randomuint8[0];
|
||||
}
|
||||
|
||||
int32_t flipper_pong_app() {
|
||||
int32_t flipper_pong_app(void* p) {
|
||||
UNUSED(p);
|
||||
EventApp event;
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(EventApp));
|
||||
|
||||
@@ -120,7 +129,7 @@ int32_t flipper_pong_app() {
|
||||
}
|
||||
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, draw_callback, &players.mutex);
|
||||
view_port_draw_callback_set(view_port, draw_callback, &players);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
@@ -143,6 +152,7 @@ int32_t flipper_pong_app() {
|
||||
if(event.type == EventTypeInput) {
|
||||
if(event.input.key == InputKeyBack) {
|
||||
furi_mutex_release(players.mutex);
|
||||
notification_message(notification, &sequence_set_only_green_255);
|
||||
break;
|
||||
} else if(event.input.key == InputKeyUp) {
|
||||
if(players.player1_Y >= 1 + PLAYER1_PAD_SPEED)
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
1. Prepare the image
|
||||
a. Open your *black and white* image in GIMP
|
||||
b. File -> Export As
|
||||
filename: EXAMPLE.c
|
||||
Type : "C source code"
|
||||
[Export]
|
||||
prefixed name: gimp_image
|
||||
Comment : <any>
|
||||
[x] Use GLib types
|
||||
[ ] <<all other options>>
|
||||
Opacity : 100%
|
||||
[Export]
|
||||
|
||||
2. Prepare conversion tool [stored in (eg.) /path/]
|
||||
a. cp _convert*.* /path/
|
||||
b. cp EXAMPLE.c /path/
|
||||
|
||||
3. Run the conversion tool
|
||||
a. cd /path/
|
||||
b. ./_convert.sh EXAMPLE.c
|
||||
|
||||
4. All being well, you will see an ascii version of your image.
|
||||
If not, then you're gonna have to submit a bug report <shrug>
|
||||
|
||||
5. You should now have a directory called img_/
|
||||
In that directory should be
|
||||
img_EXAMPLE.c - The data for your new image
|
||||
img_*.c - The data for other images
|
||||
images.h - A header for ALL images that have been created in this directory
|
||||
images.c - A sample FlipperZero show() function [not optimised]
|
||||
@@ -1,79 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -z $1 ] && {
|
||||
echo "Specify an image"
|
||||
echo "gimp -> export -> c source file -> [x] gunit names"
|
||||
exit 2
|
||||
}
|
||||
|
||||
echo $*
|
||||
|
||||
for N in $* ; do
|
||||
|
||||
[ ! -f $N ] && {
|
||||
echo "!! File missing $N"
|
||||
continue
|
||||
}
|
||||
|
||||
# filename (sans extension)
|
||||
FN=$(basename -- "$N")
|
||||
EXT="${FN##*.}"
|
||||
NAME="${FN%.*}"
|
||||
|
||||
OUTDIR=img_/
|
||||
mkdir -p ${OUTDIR}
|
||||
|
||||
HDR=${OUTDIR}/images.h
|
||||
SRC=${OUTDIR}/images.c
|
||||
|
||||
OUT=${OUTDIR}/img_${NAME}.c
|
||||
|
||||
echo -e "\n¦${N}¦ == ¦${NAME}¦ -> ¦${OUT}¦"
|
||||
|
||||
TESTX=test_${NAME}
|
||||
TESTC=test_${NAME}.c
|
||||
|
||||
# compile name
|
||||
CONV=${NAME}_
|
||||
|
||||
# clean up gimp output
|
||||
sed -e "s/gimp_image/img/g" \
|
||||
-e 's/guint8/unsigned char/g' \
|
||||
-e 's/width/w/g' \
|
||||
-e 's/height/h/g' \
|
||||
-e 's/bytes_per_pixel/bpp/g' \
|
||||
-e 's/pixel_data/b/g' \
|
||||
-e 's/guint/unsigned int/g' \
|
||||
$N \
|
||||
| grep -v ^/ \
|
||||
| grep -v ^$ \
|
||||
> ${CONV}.c
|
||||
|
||||
# append conversion code
|
||||
cat _convert.c >> ${CONV}.c
|
||||
|
||||
# compile & run converter
|
||||
rm -f ${CONV}
|
||||
gcc ${CONV}.c -DIMGTEST -o ${CONV}
|
||||
./${CONV} ${NAME} ${OUT}
|
||||
rm -f ${CONV} ${CONV}.c
|
||||
|
||||
# (create &) update header
|
||||
[[ ! -f ${HDR} ]] && cp _convert_images.h ${HDR}
|
||||
sed -i "/ img_${NAME};/d" ${HDR}
|
||||
sed -i "s#//\[TAG\]#//\[TAG\]\nextern const image_t img_${NAME};#" ${HDR}
|
||||
|
||||
# sample FZ code
|
||||
[[ ! -f images.c ]] && cp _convert_images.c ${SRC}
|
||||
|
||||
# test
|
||||
ROOT=${PWD}
|
||||
pushd ${OUTDIR} >/dev/null
|
||||
sed "s/zzz/${NAME}/" ${ROOT}/_convert_test.c > ${TESTC}
|
||||
rm -f ${TESTX}
|
||||
gcc ${TESTC} ${OUT##*/} -DIMGTEST -o ${TESTX}
|
||||
./${TESTX}
|
||||
rm -f ${TESTX} ${TESTC}
|
||||
popd >/dev/null
|
||||
|
||||
done
|
||||
@@ -1,137 +0,0 @@
|
||||
#include <gui/gui.h> // GUI (screen/keyboard) API
|
||||
|
||||
#include "images.h"
|
||||
|
||||
//----------------------------------------------------------------------------- ----------------------------------------
|
||||
static Canvas* _canvas;
|
||||
static uint8_t _tlx;
|
||||
static uint8_t _tly;
|
||||
|
||||
static uint8_t _x;
|
||||
static uint8_t _y;
|
||||
|
||||
static const image_t* _img;
|
||||
|
||||
static bool _blk;
|
||||
static Color _set;
|
||||
static Color _clr;
|
||||
|
||||
//+============================================================================
|
||||
static void _showByteSet(const uint8_t b) {
|
||||
for(uint8_t m = 0x80; m; m >>= 1) {
|
||||
if(b & m) // plot only SET bits
|
||||
canvas_draw_dot(_canvas, (_tlx + _x), (_tly + _y));
|
||||
if(((++_x) == _img->w) && !(_x = 0) && ((++_y) == _img->h)) break;
|
||||
}
|
||||
}
|
||||
|
||||
//+============================================================================
|
||||
static void _showByteClr(const uint8_t b) {
|
||||
for(uint8_t m = 0x80; m; m >>= 1) {
|
||||
if(!(b & m)) // plot only CLR bits
|
||||
canvas_draw_dot(_canvas, (_tlx + _x), (_tly + _y));
|
||||
if(((++_x) == _img->w) && !(_x = 0) && ((++_y) == _img->h)) break;
|
||||
}
|
||||
}
|
||||
|
||||
//+============================================================================
|
||||
static void _showByteAll(const uint8_t b) {
|
||||
for(uint8_t m = 0x80; m; m >>= 1) {
|
||||
if((!!(b & m)) ^ _blk) { // Change colour only when required
|
||||
canvas_set_color(_canvas, ((b & m) ? _set : _clr));
|
||||
_blk = !_blk;
|
||||
}
|
||||
canvas_draw_dot(_canvas, (_tlx + _x), (_tly + _y));
|
||||
if(((++_x) == _img->w) && !(_x = 0) && ((++_y) == _img->h)) break;
|
||||
}
|
||||
}
|
||||
|
||||
//+============================================================================
|
||||
// available modes are SHOW_SET_BLK - plot image pixels that are SET in BLACK
|
||||
// SHOW_XOR - same as SET_BLACK
|
||||
// SHOW_SET_WHT - plot image pixels that are SET in WHITE
|
||||
// SHOW_CLR_BLK - plot image pixels that are CLEAR in BLACK
|
||||
// SHOW_CLR_WHT - plot image pixels that are CLEAR in WHITE
|
||||
// SHOW_ALL - plot all images pixels as they are
|
||||
// SHOW_ALL_INV - plot all images pixels inverted
|
||||
//
|
||||
void show(
|
||||
Canvas* const canvas,
|
||||
const uint8_t tlx,
|
||||
const uint8_t tly,
|
||||
const image_t* img,
|
||||
const showMode_t mode) {
|
||||
void (*fnShow)(const uint8_t) = NULL;
|
||||
|
||||
const uint8_t* bp = img->data;
|
||||
|
||||
// code size optimisation
|
||||
switch(mode & SHOW_INV_) {
|
||||
case SHOW_NRM_:
|
||||
_set = ColorBlack;
|
||||
_clr = ColorWhite;
|
||||
break;
|
||||
|
||||
case SHOW_INV_:
|
||||
_set = ColorWhite;
|
||||
_clr = ColorBlack;
|
||||
break;
|
||||
|
||||
case SHOW_BLK_:
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
break;
|
||||
|
||||
case SHOW_WHT_:
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
break;
|
||||
}
|
||||
switch(mode & SHOW_INV_) {
|
||||
case SHOW_NRM_:
|
||||
case SHOW_INV_:
|
||||
fnShow = _showByteAll;
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
_blk = 0;
|
||||
break;
|
||||
|
||||
case SHOW_BLK_:
|
||||
case SHOW_WHT_:
|
||||
switch(mode & SHOW_ALL_) {
|
||||
case SHOW_SET_:
|
||||
fnShow = _showByteSet;
|
||||
break;
|
||||
case SHOW_CLR_:
|
||||
fnShow = _showByteClr;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
furi_check(fnShow);
|
||||
|
||||
// I want nested functions!
|
||||
_canvas = canvas;
|
||||
_img = img;
|
||||
_tlx = tlx;
|
||||
_tly = tly;
|
||||
_x = 0;
|
||||
_y = 0;
|
||||
|
||||
// Compressed
|
||||
if(img->c) {
|
||||
for(unsigned int i = 0; i < img->len; i++, bp++) {
|
||||
// Compressed data? {tag, length, value}
|
||||
if(*bp == img->tag) {
|
||||
for(uint16_t c = 0; c < bp[1]; c++) fnShow(bp[2]);
|
||||
bp += 3 - 1;
|
||||
i += 3 - 1;
|
||||
|
||||
// Uncompressed byte
|
||||
} else {
|
||||
fnShow(*bp);
|
||||
}
|
||||
}
|
||||
|
||||
// Not compressed
|
||||
} else {
|
||||
for(unsigned int i = 0; i < img->len; i++, bp++) fnShow(*bp);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#ifndef IMAGES_H_
|
||||
#define IMAGES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
//----------------------------------------------------------------------------- ----------------------------------------
|
||||
typedef enum showMode {
|
||||
// {INV:--:WHT:BLK::--:--:CLR:SET}
|
||||
SHOW_SET_ = 0x01,
|
||||
SHOW_CLR_ = 0x02,
|
||||
SHOW_ALL_ = SHOW_SET_ | SHOW_CLR_,
|
||||
|
||||
SHOW_BLK_ = 0x10,
|
||||
SHOW_WHT_ = 0x20,
|
||||
SHOW_NRM_ = 0x00,
|
||||
SHOW_INV_ = SHOW_BLK_ | SHOW_WHT_,
|
||||
|
||||
SHOW_SET_BLK = SHOW_SET_ | SHOW_BLK_,
|
||||
SHOW_SET_WHT = SHOW_SET_ | SHOW_WHT_,
|
||||
|
||||
SHOW_CLR_BLK = SHOW_CLR_ | SHOW_BLK_,
|
||||
SHOW_CLR_WHT = SHOW_CLR_ | SHOW_WHT_,
|
||||
|
||||
SHOW_ALL = SHOW_ALL_ | SHOW_NRM_,
|
||||
SHOW_ALL_INV = SHOW_ALL_ | SHOW_INV_,
|
||||
} showMode_t;
|
||||
|
||||
//----------------------------------------------------------------------------- ----------------------------------------
|
||||
typedef struct image {
|
||||
uint8_t w; // width
|
||||
uint8_t h; // height
|
||||
bool c; // compressed?
|
||||
uint16_t len; // image data length
|
||||
uint8_t tag; // rle tag
|
||||
uint8_t data[]; // image data
|
||||
} image_t;
|
||||
|
||||
//----------------------------------------------------------------------------- ----------------------------------------
|
||||
//[TAG]
|
||||
|
||||
//----------------------------------------------------------------------------- ----------------------------------------
|
||||
#ifndef IMGTEST
|
||||
#include <gui/gui.h>
|
||||
void show(
|
||||
Canvas* const canvas,
|
||||
const uint8_t tlx,
|
||||
const uint8_t tly,
|
||||
const image_t* img,
|
||||
const showMode_t mode);
|
||||
#endif
|
||||
|
||||
#endif //IMAGES_H_
|
||||
Vendored
-11
@@ -1,11 +0,0 @@
|
||||
echo "MARKED AS TODO"
|
||||
echo "=============="
|
||||
grep //! *.c *.h
|
||||
|
||||
echo -e "\nSUPPORTED CONTROLLERS"
|
||||
echo "====================="
|
||||
grep '\[PID_.*{ {' wii_ec.c | head -n -3 | sed 's/\s*\(.*\)/\1/'
|
||||
|
||||
echo -e "\nLOGGING"
|
||||
echo "======="
|
||||
grep LOG_LEVEL *.h | grep -v '#if '
|
||||
Reference in New Issue
Block a user