forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Latest Release RM0819-0243-0.89.1-fd3326e on PATREON
Upd Sudoku & Add Step Counter WIP
- Loading branch information
1 parent
32f72f8
commit 20f6091
Showing
7 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 47LeCoste | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# WIP-flipperzero-StepCounter-fap | ||
Simple StepCounter/Pedometer for FlipperZero using a Memsic2125 module. Thanks to @jamisonderek |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
App( | ||
appid="stepcounter", | ||
name="[Mx2125] Step Counter", | ||
apptype=FlipperAppType.EXTERNAL, | ||
entry_point="step_counter_app", | ||
stack_size=2 * 1024, | ||
fap_icon="steps.png", | ||
fap_category="GPIO", | ||
fap_author="47lecoste a.k.a. grugnoymeme", | ||
fap_weburl="https://github.com/grugnoymeme/flipperzero-stepcounter-fap", | ||
fap_version=(1,0), | ||
fap_description="Step Counter/Pedometer using Memsic2125 module.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#include <furi.h> | ||
#include <furi_hal.h> | ||
#include <furi_hal_gpio.h> | ||
#include <furi_hal_resources.h> | ||
#include <gui/gui.h> | ||
#include <input/input.h> | ||
#include <locale/locale.h> | ||
#include <notification/notification.h> | ||
#include <notification/notification_messages.h> | ||
|
||
#define TAG_MEMSIC "memsic_2125_app" | ||
#define TAG_COUNTER "step_counter_app" | ||
|
||
typedef struct { | ||
const GpioPin* pin; | ||
bool prevState; | ||
uint32_t stepCount; | ||
bool counting; | ||
} StepCounterData; | ||
|
||
typedef enum { | ||
StepCounterEventTypeStep, | ||
StepCounterEventTypeKey, | ||
} StepCounterEventType; | ||
|
||
typedef struct { | ||
StepCounterEventType type; | ||
InputEvent input_event; | ||
} StepCounterEvent; | ||
|
||
typedef struct { | ||
FuriMessageQueue* queue; | ||
StepCounterData* data; | ||
ViewPort* view_port; | ||
} StepCounterContext; | ||
|
||
// Pin the accelerometer is connected to. | ||
const GpioPin* const gpio_accelerometer = &gpio_ext_pa7; | ||
|
||
void step_callback(void* ctx) { | ||
StepCounterContext* context = (StepCounterContext*)ctx; | ||
StepCounterData* stepData = context->data; | ||
|
||
if(stepData->counting) { | ||
bool currentState = furi_hal_gpio_read(stepData->pin); | ||
|
||
if(currentState != stepData->prevState) { | ||
stepData->prevState = currentState; | ||
stepData->stepCount++; | ||
|
||
StepCounterEvent event = {.type = StepCounterEventTypeStep}; | ||
furi_message_queue_put(context->queue, &event, 0); | ||
} | ||
} | ||
} | ||
|
||
static void input_callback(InputEvent* input_event, FuriMessageQueue* queue) { | ||
StepCounterEvent event = { | ||
.type = StepCounterEventTypeKey, | ||
.input_event.key = input_event->key, | ||
.input_event.type = input_event->type, | ||
}; | ||
furi_message_queue_put(queue, &event, FuriWaitForever); | ||
} | ||
|
||
static void render_callback(Canvas* canvas, void* ctx) { | ||
StepCounterContext* stepContext = (StepCounterContext*)ctx; | ||
StepCounterData* stepData = stepContext->data; | ||
|
||
char stepText[20]; | ||
snprintf(stepText, sizeof(stepText), "Steps: %ld", stepData->stepCount); | ||
canvas_draw_str_aligned(canvas, 1, 1, AlignLeft, AlignTop, stepText); | ||
|
||
char buttonText[10]; | ||
snprintf(buttonText, sizeof(buttonText), stepData->counting ? "STOP" : "START"); | ||
canvas_draw_str_aligned( | ||
canvas, | ||
canvas_width(canvas) / 2, | ||
canvas_height(canvas) - 1, | ||
AlignCenter, | ||
AlignBottom, | ||
buttonText); | ||
} | ||
|
||
int32_t step_counter_app(void* p) { | ||
UNUSED(p); | ||
|
||
StepCounterContext* stepContext = malloc(sizeof(StepCounterContext)); | ||
stepContext->data = malloc(sizeof(StepCounterData)); | ||
stepContext->data->pin = gpio_accelerometer; | ||
stepContext->data->prevState = furi_hal_gpio_read(stepContext->data->pin); | ||
stepContext->data->stepCount = 0; | ||
stepContext->data->counting = false; | ||
|
||
stepContext->queue = furi_message_queue_alloc(8, sizeof(StepCounterEvent)); | ||
|
||
furi_hal_gpio_init( | ||
stepContext->data->pin, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedVeryHigh); | ||
furi_hal_gpio_add_int_callback(stepContext->data->pin, step_callback, stepContext); | ||
|
||
ViewPort* view_port = view_port_alloc(); | ||
view_port_draw_callback_set(view_port, render_callback, stepContext); | ||
view_port_input_callback_set(view_port, input_callback, stepContext->queue); | ||
|
||
Gui* gui = furi_record_open(RECORD_GUI); | ||
gui_add_view_port(gui, view_port, GuiLayerFullscreen); | ||
|
||
StepCounterEvent event; | ||
bool processing = true; | ||
do { | ||
if(furi_message_queue_get(stepContext->queue, &event, FuriWaitForever) == FuriStatusOk) { | ||
switch(event.type) { | ||
case StepCounterEventTypeKey: | ||
if(event.input_event.type == InputTypeShort && | ||
event.input_event.key == InputKeyBack) { | ||
processing = false; | ||
} else if( | ||
event.input_event.type == InputTypeShort && | ||
event.input_event.key == InputKeyOk) { | ||
stepContext->data->counting = !stepContext->data->counting; | ||
// Aggiorna l'interfaccia utente per riflettere il cambio di stato. | ||
view_port_update(view_port); | ||
} | ||
break; | ||
case StepCounterEventTypeStep: | ||
// Aggiorna l'interfaccia utente per riflettere il cambio di stato. | ||
view_port_update(view_port); | ||
break; | ||
default: | ||
break; | ||
} | ||
view_port_update(view_port); | ||
} else { | ||
processing = false; | ||
} | ||
} while(processing); | ||
|
||
furi_hal_gpio_remove_int_callback(stepContext->data->pin); | ||
view_port_enabled_set(view_port, false); | ||
gui_remove_view_port(gui, view_port); | ||
view_port_free(view_port); | ||
furi_record_close(RECORD_GUI); | ||
furi_message_queue_free(stepContext->queue); | ||
free(stepContext->data); | ||
free(stepContext); | ||
|
||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters