dropped non-working Badger2040 due to unsatisfied import

This commit is contained in:
RogueMaster
2022-11-11 17:17:29 -05:00
parent 3efc8ff3c0
commit cea2e76ce2
7 changed files with 1 additions and 260 deletions
-2
View File
@@ -16,7 +16,6 @@
- Added: [USB Midi (By DrZlo13)](https://github.com/DrZlo13/flipper-zero-usb-midi)
- Cleanup for: Settings: Rename from App [(Thanks to E_Surge)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/409)
- Added: [Air Mouse (By ginkage)](https://github.com/ginkage/FlippAirMouse/)
- Added: [Badger 2040 (By jakebacker)](https://github.com/jakebacker/flipperzero-firmware-wPlugins)
<table width="100%" border="0" cellspacing="0">
<tr> <td colspan=2> <h3>This software is for experimental purposes only and is not meant for any illegal activity/purposes. We do not condone illegal activity and strongly encourage keeping transmissions to legal/valid uses allowed by law.</h3> </td> </tr>
@@ -206,7 +205,6 @@ $ ./fbt plugin_dist
- [Air Mouse (By ginkage)](https://github.com/ginkage/FlippAirMouse/)
- [Authenticator/TOTP (By akopachov)](https://github.com/akopachov/flipper-zero_authenticator)
- [Badger 2040 (By jakebacker)](https://github.com/jakebacker/flipperzero-firmware-wPlugins)
- [Barcode Generator (By McAzzaMan)](https://github.com/McAzzaMan/flipperzero-firmware/tree/UPC-A_Barcode_Generator/applications/barcode_generator)
- [Bluetooth Remote (By Cutch)[OFW]](https://github.com/flipperdevices/flipperzero-firmware/pull/1330)
- [BPM Tapper (By panki27)](https://github.com/panki27/bpm-tapper)
@@ -5,5 +5,5 @@ App(
entry_point="air_mouse_app",
stack_size=10 * 1024,
fap_icon="mouse_10px.png",
fap_category="GPIO",
fap_category="NeedsTesting",
)
@@ -1 +0,0 @@
This is an extremely basic plugin for interacting with a [badger2040](https://shop.pimoroni.com/products/badger-2040).
@@ -1,15 +0,0 @@
App(
appid="Badger2040",
name="Badger2040",
apptype=FlipperAppType.EXTERNAL,
entry_point="badger2040_app",
cdefines=["APP_BADGER2040"],
requires=[
"gui",
"dialogs",
],
stack_size=1 * 1024,
order=30,
fap_icon="dap_link.png",
fap_category="NeedsTesting",
)
@@ -1,230 +0,0 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <input/input.h>
#include "badger2040.h"
#define ADDRESS_QUESTION_X 5
#define ADDRESS_QUESTION_Y 10
#define DATA_X 5
#define DATA_Y 20
#define ERROR_X 5
#define ERROR_Y 55
#define DEBUG true
#define ERROR
typedef enum {
EventTypeTick,
EventTypeKey,
} EventType;
typedef enum { BadgerGetAddress, BadgerSend } STATE;
typedef struct {
EventType type;
InputEvent input;
} PluginEvent;
typedef struct {
STATE state;
bool get_failed;
uint8_t address;
uint8_t data;
bool send_failed;
} PluginState;
static void badger2040_state_init(PluginState* const plugin_state) {
plugin_state->state = BadgerGetAddress;
plugin_state->get_failed = false;
plugin_state->address = FIRST_NON_RESERVED_I2C_ADDRESS;
plugin_state->data = 0;
plugin_state->send_failed = false;
}
static void render_callback(Canvas* const canvas, void* ctx) {
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
if(plugin_state == NULL) {
return;
}
canvas_set_color(canvas, ColorBlack);
char str[32];
if(plugin_state->state == BadgerGetAddress) {
sprintf(str, "Selected Address: %d", plugin_state->address);
canvas_draw_str(canvas, ADDRESS_QUESTION_X, ADDRESS_QUESTION_Y, str);
if(plugin_state->get_failed) {
strcpy(str, "Error! Device not found!");
canvas_draw_str(canvas, ERROR_X, ERROR_Y, str);
}
} else if(plugin_state->state == BadgerSend) {
sprintf(str, "Sending to Address: %d", plugin_state->address);
canvas_draw_str(canvas, ADDRESS_QUESTION_X, ADDRESS_QUESTION_Y, str);
sprintf(str, "Data: %d", plugin_state->data);
canvas_draw_str(canvas, DATA_X, DATA_Y, str);
if(plugin_state->send_failed) {
strcpy(str, "Error! Unable to send data!");
canvas_draw_str(canvas, ERROR_X, ERROR_Y, str);
}
}
release_mutex((ValueMutex*)ctx, plugin_state);
}
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
furi_assert(event_queue);
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
furi_message_queue_put(event_queue, &event, FuriWaitForever);
}
bool device_exists(int address) {
if(DEBUG) return true;
uint32_t response_timeout_ticks = furi_ms_to_ticks(5.f);
return furi_hal_i2c_is_device_ready(
&furi_hal_i2c_handle_external, address << 1, response_timeout_ticks);
}
bool sendData(uint8_t address, uint8_t data) {
if(DEBUG) return true;
uint32_t response_timeout_ticks = furi_ms_to_ticks(5.f);
return furi_hal_i2c_tx(
&furi_hal_i2c_handle_external, address, &data, 1, response_timeout_ticks);
}
int32_t badger2040_app(void* p) {
UNUSED(p);
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
PluginState* plugin_state = malloc(sizeof(PluginState));
badger2040_state_init(plugin_state);
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
FURI_LOG_E("badger2040", "cannot create mutex\r\n");
free(plugin_state);
return 255;
}
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
// Set system callbacks
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex);
view_port_input_callback_set(view_port, input_callback, event_queue);
// Open GUI and register view_port
Gui* gui = furi_record_open("gui");
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
PluginEvent event;
for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex);
if(event_status == FuriStatusOk) {
// press events
if(event.type == EventTypeKey) {
if((event.input.type == InputTypePress) || (event.input.type == InputTypeRepeat)) {
// Reset failed status to clear display after key press
if(plugin_state->state == BadgerGetAddress) {
plugin_state->get_failed = false;
} else if(plugin_state->state == BadgerSend) {
plugin_state->send_failed = false;
}
switch(event.input.key) {
case InputKeyUp:
if(plugin_state->state == BadgerGetAddress) {
uint8_t prevAddr = plugin_state->address;
if(prevAddr == HIGHEST_I2C_ADDRESS) {
plugin_state->address = FIRST_NON_RESERVED_I2C_ADDRESS;
} else {
plugin_state->address = prevAddr + 1;
}
} else if(plugin_state->state == BadgerSend) {
uint8_t prevData = plugin_state->data;
if(prevData == MAX_DATA) {
plugin_state->data = MIN_DATA;
} else {
plugin_state->data = prevData + 1;
}
}
break;
case InputKeyDown:
if(plugin_state->state == BadgerGetAddress) {
uint8_t prevAddr = plugin_state->address;
if(prevAddr == FIRST_NON_RESERVED_I2C_ADDRESS) {
plugin_state->address = HIGHEST_I2C_ADDRESS;
} else {
plugin_state->address = prevAddr - 1;
}
} else if(plugin_state->state == BadgerSend) {
uint8_t prevData = plugin_state->data;
if(prevData == MIN_DATA) {
plugin_state->data = MAX_DATA;
} else {
plugin_state->data = prevData - 1;
}
}
break;
case InputKeyRight:
break;
case InputKeyLeft:
break;
case InputKeyOk:
if(plugin_state->state == BadgerGetAddress) {
if(device_exists(plugin_state->address)) {
if(plugin_state->state == BadgerGetAddress) {
plugin_state->state = BadgerSend;
}
} else {
plugin_state->get_failed = true;
}
} else if(plugin_state->state == BadgerSend) {
if(!sendData) {
plugin_state->send_failed = true;
}
}
break;
case InputKeyBack:
processing = false;
break;
default:
break;
}
}
}
} else {
FURI_LOG_D("badger2040", "osMessageQueue: event timeout");
// event timeout
}
view_port_update(view_port);
release_mutex(&state_mutex, plugin_state);
}
view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port);
furi_record_close("gui");
view_port_free(view_port);
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
furi_message_queue_free(event_queue);
return 0;
}
@@ -1,11 +0,0 @@
#pragma once
#define FIRST_NON_RESERVED_I2C_ADDRESS 8
#define HIGHEST_I2C_ADDRESS 127
#define MIN_DATA 0
#define MAX_DATA 255
#include <furi_hal_i2c.h>
#include <stdlib.h>
#include <stdint.h>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 B