From 952810f16ae27f654f129b97cead599839431184 Mon Sep 17 00:00:00 2001 From: RogueMaster Date: Sat, 29 Oct 2022 03:21:22 -0400 Subject: [PATCH] FLASHLIGHT --- ReadMe.md | 2 + applications/plugins/flashlight/LICENSE | 21 +++ applications/plugins/flashlight/README.md | 7 + .../plugins/flashlight/application.fam | 14 ++ applications/plugins/flashlight/flash10px.png | Bin 0 -> 148 bytes applications/plugins/flashlight/flashlight.c | 128 ++++++++++++++++++ 6 files changed, 172 insertions(+) create mode 100644 applications/plugins/flashlight/LICENSE create mode 100644 applications/plugins/flashlight/README.md create mode 100644 applications/plugins/flashlight/application.fam create mode 100644 applications/plugins/flashlight/flash10px.png create mode 100644 applications/plugins/flashlight/flashlight.c diff --git a/ReadMe.md b/ReadMe.md index 7ef851b78..b50cd63d5 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -19,6 +19,7 @@ - Added Discovered Work [Archive: File Browser Ordering (By Dig03)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/389) - Fixed SubGHz_Remote.fap load - Added: [T-Rex (By gelin)](https://github.com/gelin/t-rex-runner) WIP +- Added: [Flashlight (By xMasterX)](https://github.com/xMasterX/flipper-flashlight)
TO DO / REMOVED
@@ -225,6 +226,7 @@ $ ./fbt plugin_dist - [Dolphin Backup (By nminaylov)[OFW]](https://github.com/flipperdevices/flipperzero-firmware/pull/1384) Modified by RogueMaster - [Dolphin Restorer (By nminaylov)](https://github.com/flipperdevices/flipperzero-firmware/pull/1384) Cloned by RogueMaster - [DTMF Dolphin (By litui)](https://github.com/litui/dtmf_dolphin) +- [Flashlight (By xMasterX)](https://github.com/xMasterX/flipper-flashlight) - [GPS (By ezod)](https://github.com/ezod/flipperzero-gps) `Req: NMEA 0183` - [i2c Tools (By NaejEL)](https://github.com/NaejEL/flipperzero-i2ctools) - [IFTTT Virtual Button (By Ferrazzi)](https://github.com/Ferrazzi/FlipperZero_IFTTT_Virtual_Button) `Req: ESP8266 w/ IFTTT FW Flashed` diff --git a/applications/plugins/flashlight/LICENSE b/applications/plugins/flashlight/LICENSE new file mode 100644 index 000000000..28d693a7c --- /dev/null +++ b/applications/plugins/flashlight/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 MX + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/applications/plugins/flashlight/README.md b/applications/plugins/flashlight/README.md new file mode 100644 index 000000000..a40cb2d5a --- /dev/null +++ b/applications/plugins/flashlight/README.md @@ -0,0 +1,7 @@ +# Flashlight Plugin for Flipper Zero + +Simple Flashlight special for @Svaarich by @xMasterX + +Enables 3.3v on pin 7/C3 and leaves it on when you exit app + +**Connect LED to (+ -> 7/C3) | (GND -> GND)** diff --git a/applications/plugins/flashlight/application.fam b/applications/plugins/flashlight/application.fam new file mode 100644 index 000000000..d6d5aa791 --- /dev/null +++ b/applications/plugins/flashlight/application.fam @@ -0,0 +1,14 @@ +App( + appid="Flashlight", + name="Flashlight", + apptype=FlipperAppType.EXTERNAL, + entry_point="flashlight_app", + cdefines=["APP_FLASHLIGHT"], + requires=[ + "gui", + ], + stack_size=2 * 1024, + order=20, + fap_icon="flash10px.png", + fap_category="GPIO", +) \ No newline at end of file diff --git a/applications/plugins/flashlight/flash10px.png b/applications/plugins/flashlight/flash10px.png new file mode 100644 index 0000000000000000000000000000000000000000..963a9ab5fc0bde61515c25ee9860f7522e7b7547 GIT binary patch literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4F%}28J29*~C-V}>@$+gTe~DWM4fVB0fn literal 0 HcmV?d00001 diff --git a/applications/plugins/flashlight/flashlight.c b/applications/plugins/flashlight/flashlight.c new file mode 100644 index 000000000..233c8efcf --- /dev/null +++ b/applications/plugins/flashlight/flashlight.c @@ -0,0 +1,128 @@ +// by @xMasterX + +#include +#include +#include +#include +#include +#include + +typedef enum { + EventTypeTick, + EventTypeKey, +} EventType; + +typedef struct { + EventType type; + InputEvent input; +} PluginEvent; + +typedef struct { + bool is_on; +} PluginState; + +static void render_callback(Canvas* const canvas, void* ctx) { + const PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); + if(plugin_state == NULL) { + return; + } + + canvas_set_font(canvas, FontPrimary); + elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Flashlight"); + + canvas_set_font(canvas, FontSecondary); + + if(!plugin_state->is_on) { + elements_multiline_text_aligned( + canvas, 64, 28, AlignCenter, AlignTop, "Press OK button turn on"); + } else { + elements_multiline_text_aligned(canvas, 64, 28, AlignCenter, AlignTop, "Light is on!"); + elements_multiline_text_aligned( + canvas, 64, 40, AlignCenter, AlignTop, "Press OK button to off"); + } + + 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); +} + +static void flash_toggle(PluginState* const plugin_state) { + furi_hal_gpio_write(&gpio_ext_pc3, false); + furi_hal_gpio_init(&gpio_ext_pc3, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh); + + if(plugin_state->is_on) { + furi_hal_gpio_write(&gpio_ext_pc3, false); + plugin_state->is_on = false; + } else { + furi_hal_gpio_write(&gpio_ext_pc3, true); + plugin_state->is_on = true; + } +} + +int32_t flashlight_app() { + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); + + PluginState* plugin_state = malloc(sizeof(PluginState)); + + ValueMutex state_mutex; + if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { + FURI_LOG_E("flashlight", "cannot create mutex\r\n"); + furi_message_queue_free(event_queue); + free(plugin_state); + return 255; + } + + // 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(RECORD_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) { + switch(event.input.key) { + case InputKeyUp: + case InputKeyDown: + case InputKeyRight: + case InputKeyLeft: + break; + case InputKeyOk: + flash_toggle(plugin_state); + break; + case InputKeyBack: + processing = false; + break; + } + } + } + } + + 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(RECORD_GUI); + view_port_free(view_port); + furi_message_queue_free(event_queue); + delete_mutex(&state_mutex); + + return 0; +} \ No newline at end of file