mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-28 07:20:29 +00:00
274c12fc56
* Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
130 lines
3.9 KiB
C
Executable file
130 lines
3.9 KiB
C
Executable file
#include "gpio_test.h"
|
|
#include "../gpio_item.h"
|
|
|
|
#include <gui/elements.h>
|
|
|
|
struct GpioTest {
|
|
View* view;
|
|
GpioTestOkCallback callback;
|
|
void* context;
|
|
};
|
|
|
|
typedef struct {
|
|
uint8_t pin_idx;
|
|
} GpioTestModel;
|
|
|
|
static bool gpio_test_process_left(GpioTest* gpio_test);
|
|
static bool gpio_test_process_right(GpioTest* gpio_test);
|
|
static bool gpio_test_process_ok(GpioTest* gpio_test, InputEvent* event);
|
|
|
|
static void gpio_test_draw_callback(Canvas* canvas, void* _model) {
|
|
GpioTestModel* model = _model;
|
|
canvas_set_font(canvas, FontPrimary);
|
|
elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Gpio Output mode test");
|
|
canvas_set_font(canvas, FontSecondary);
|
|
elements_multiline_text_aligned(
|
|
canvas, 64, 16, AlignCenter, AlignTop, "Press < or > to change pin");
|
|
elements_multiline_text_aligned(
|
|
canvas, 64, 32, AlignCenter, AlignTop, gpio_item_get_pin_name(model->pin_idx));
|
|
}
|
|
|
|
static bool gpio_test_input_callback(InputEvent* event, void* context) {
|
|
furi_assert(context);
|
|
GpioTest* gpio_test = context;
|
|
bool consumed = false;
|
|
|
|
if(event->type == InputTypeShort) {
|
|
if(event->key == InputKeyRight) {
|
|
consumed = gpio_test_process_right(gpio_test);
|
|
} else if(event->key == InputKeyLeft) {
|
|
consumed = gpio_test_process_left(gpio_test);
|
|
}
|
|
} else if(event->key == InputKeyOk) {
|
|
consumed = gpio_test_process_ok(gpio_test, event);
|
|
}
|
|
|
|
return consumed;
|
|
}
|
|
|
|
static bool gpio_test_process_left(GpioTest* gpio_test) {
|
|
with_view_model(
|
|
gpio_test->view, (GpioTestModel * model) {
|
|
if(model->pin_idx) {
|
|
model->pin_idx--;
|
|
}
|
|
return true;
|
|
});
|
|
return true;
|
|
}
|
|
|
|
static bool gpio_test_process_right(GpioTest* gpio_test) {
|
|
with_view_model(
|
|
gpio_test->view, (GpioTestModel * model) {
|
|
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
|
model->pin_idx++;
|
|
}
|
|
return true;
|
|
});
|
|
return true;
|
|
}
|
|
|
|
static bool gpio_test_process_ok(GpioTest* gpio_test, InputEvent* event) {
|
|
bool consumed = false;
|
|
|
|
with_view_model(
|
|
gpio_test->view, (GpioTestModel * model) {
|
|
if(event->type == InputTypePress) {
|
|
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
|
gpio_item_set_pin(model->pin_idx, true);
|
|
} else {
|
|
gpio_item_set_all_pins(true);
|
|
}
|
|
consumed = true;
|
|
} else if(event->type == InputTypeRelease) {
|
|
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
|
gpio_item_set_pin(model->pin_idx, false);
|
|
} else {
|
|
gpio_item_set_all_pins(false);
|
|
}
|
|
consumed = true;
|
|
}
|
|
gpio_test->callback(event->type, gpio_test->context);
|
|
return true;
|
|
});
|
|
|
|
return consumed;
|
|
}
|
|
|
|
GpioTest* gpio_test_alloc() {
|
|
GpioTest* gpio_test = malloc(sizeof(GpioTest));
|
|
|
|
gpio_test->view = view_alloc();
|
|
view_allocate_model(gpio_test->view, ViewModelTypeLocking, sizeof(GpioTestModel));
|
|
view_set_context(gpio_test->view, gpio_test);
|
|
view_set_draw_callback(gpio_test->view, gpio_test_draw_callback);
|
|
view_set_input_callback(gpio_test->view, gpio_test_input_callback);
|
|
|
|
return gpio_test;
|
|
}
|
|
|
|
void gpio_test_free(GpioTest* gpio_test) {
|
|
furi_assert(gpio_test);
|
|
view_free(gpio_test->view);
|
|
free(gpio_test);
|
|
}
|
|
|
|
View* gpio_test_get_view(GpioTest* gpio_test) {
|
|
furi_assert(gpio_test);
|
|
return gpio_test->view;
|
|
}
|
|
|
|
void gpio_test_set_ok_callback(GpioTest* gpio_test, GpioTestOkCallback callback, void* context) {
|
|
furi_assert(gpio_test);
|
|
furi_assert(callback);
|
|
with_view_model(
|
|
gpio_test->view, (GpioTestModel * model) {
|
|
gpio_test->callback = callback;
|
|
gpio_test->context = context;
|
|
return false;
|
|
});
|
|
}
|