Outdated apps: add api-light-usage (#359)

This commit is contained in:
SG 2021-03-03 06:25:51 +10:00 committed by GitHub
parent cfa76f19d0
commit 3c088dcf7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 213 deletions

View File

@ -1,4 +1,5 @@
#include <furi.h>
#include <api-hal.h>
#include <input.h>
static void event_cb(const void* value, void* ctx) {
@ -21,20 +22,6 @@ void application_strobe(void* p) {
// WAT
osDelay(100);
// create pins
GpioPin red = {.pin = LED_RED_Pin, .port = LED_RED_GPIO_Port};
GpioPin green = {.pin = LED_GREEN_Pin, .port = LED_GREEN_GPIO_Port};
GpioPin blue = {.pin = LED_BLUE_Pin, .port = LED_BLUE_GPIO_Port};
GpioPin* red_record = &red;
GpioPin* green_record = &green;
GpioPin* blue_record = &blue;
// configure pins
gpio_init(red_record, GpioModeOutputOpenDrain);
gpio_init(green_record, GpioModeOutputOpenDrain);
gpio_init(blue_record, GpioModeOutputOpenDrain);
uint32_t delay_time_holder = 100;
ValueMutex delay_mutex;
init_mutex(&delay_mutex, &delay_time_holder, sizeof(delay_time_holder));
@ -46,13 +33,14 @@ void application_strobe(void* p) {
uint32_t delay_time = 100;
read_mutex_block(&delay_mutex, &delay_time, sizeof(delay_time));
gpio_write(red_record, false);
gpio_write(green_record, false);
gpio_write(blue_record, false);
api_hal_light_set(LightRed, 0x00);
api_hal_light_set(LightGreen, 0x00);
api_hal_light_set(LightBlue, 0x00);
osDelay(delay_time / 10);
gpio_write(red_record, true);
gpio_write(green_record, true);
gpio_write(blue_record, true);
api_hal_light_set(LightRed, 0xFF);
api_hal_light_set(LightGreen, 0xFF);
api_hal_light_set(LightBlue, 0xFF);
osDelay(delay_time);
}
}

View File

@ -1,168 +0,0 @@
#include "app-template.h"
extern "C" {
#include <rfal_analogConfig.h>
#include <rfal_rf.h>
#include <rfal_nfc.h>
#include <rfal_nfca.h>
#include <st25r3916.h>
#include <st25r3916_irq.h>
}
#include "fatfs/ff.h"
#include "stm32_adafruit_sd.h"
// event enumeration type
typedef uint8_t event_t;
// app state class
class AppSdNFCState {
public:
// state data
const char* name;
// state initializer
AppSdNFCState() {
name = "sd nfc test";
}
};
// app events class
class AppSdNFCEvent {
public:
// events enum
static const event_t EventTypeTick = 0;
static const event_t EventTypeKey = 1;
// payload
union {
InputEvent input;
} value;
// event type
event_t type;
};
// our app derived from base AppTemplate class
// with template variables <state, events>
class AppSdNFC : public AppTemplate<AppSdNFCState, AppSdNFCEvent> {
public:
GpioPin* red_led_record;
GpioPin* green_led_record;
void run();
void render(Canvas* canvas);
void set_error(const char* text);
void set_text(const char* text);
void light_red();
void light_green();
void blink_red();
void blink_green();
};
FATFS sd_fat_fs;
char sd_path[6] = "";
// start app
void AppSdNFC::run() {
// create pin
GpioPin red_led = led_gpio[0];
GpioPin green_led = led_gpio[1];
// TODO open record
red_led_record = &red_led;
green_led_record = &green_led;
// configure pin
gpio_init(red_led_record, GpioModeOutputOpenDrain);
gpio_init(green_led_record, GpioModeOutputOpenDrain);
app_ready();
uint8_t rfal_result = rfalNfcInitialize();
if(rfal_result) {
set_text("rfal init fail");
blink_red();
}
uint8_t bsp_result = BSP_SD_Init();
if(bsp_result) {
set_error("sd init fail");
}
FRESULT result;
result = f_mount(&sd_fat_fs, sd_path, 1);
if(result) {
set_error("sd mount fail");
}
light_green();
set_text("all good");
AppSdNFCEvent event;
while(1) {
if(get_event(&event, 1000)) {
if(event.type == AppSdNFCEvent::EventTypeKey) {
// press events
if(event.value.input.type == InputTypeShort &&
event.value.input.key == InputKeyBack) {
exit();
}
}
}
// signal to force gui update
update_gui();
};
}
// render app
void AppSdNFC::render(Canvas* canvas) {
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 12, state.name);
}
void AppSdNFC::set_error(const char* text) {
light_red();
set_text(text);
update_gui();
while(1)
;
}
void AppSdNFC::set_text(const char* text) {
acquire_state();
state.name = text;
release_state();
}
void AppSdNFC::light_red() {
gpio_write(red_led_record, false);
}
void AppSdNFC::light_green() {
gpio_write(green_led_record, false);
}
void AppSdNFC::blink_red() {
gpio_write(red_led_record, false);
delay(500);
gpio_write(red_led_record, true);
delay(500);
}
void AppSdNFC::blink_green() {
gpio_write(green_led_record, false);
delay(500);
gpio_write(green_led_record, true);
delay(500);
}
// app enter function
extern "C" int32_t sdnfc(void* p) {
AppSdNFC* app = new AppSdNFC();
app->run();
return 0;
}

View File

@ -1,41 +1,26 @@
#include <stdio.h>
#include <furi.h>
// #include "flipper-core.h" TODO: Rust build disabled
#include <api-hal.h>
int run_minunit();
int32_t flipper_test_app(void* p) {
// create pins
GpioPin red = {.pin = LED_RED_Pin, .port = LED_RED_GPIO_Port};
GpioPin green = {.pin = LED_GREEN_Pin, .port = LED_GREEN_GPIO_Port};
GpioPin blue = {.pin = LED_BLUE_Pin, .port = LED_BLUE_GPIO_Port};
GpioPin* red_record = &red;
GpioPin* green_record = &green;
GpioPin* blue_record = &blue;
// configure pins
gpio_init(red_record, GpioModeOutputOpenDrain);
gpio_init(green_record, GpioModeOutputOpenDrain);
gpio_init(blue_record, GpioModeOutputOpenDrain);
gpio_write(red_record, true);
gpio_write(green_record, true);
gpio_write(blue_record, false);
api_hal_light_set(LightRed, 0x00);
api_hal_light_set(LightGreen, 0x00);
api_hal_light_set(LightBlue, 0xFF);
uint32_t exitcode = run_minunit();
if(exitcode == 0) {
// test passed
gpio_write(red_record, true);
gpio_write(green_record, false);
gpio_write(blue_record, true);
api_hal_light_set(LightRed, 0x00);
api_hal_light_set(LightGreen, 0xFF);
api_hal_light_set(LightBlue, 0x00);
} else {
// test failed
gpio_write(red_record, false);
gpio_write(green_record, true);
gpio_write(blue_record, true);
api_hal_light_set(LightRed, 0xFF);
api_hal_light_set(LightGreen, 0x00);
api_hal_light_set(LightBlue, 0x00);
}
return 0;