Skip to content

Commit

Permalink
Latest Release RM0819-0243-0.89.1-fd3326e on PATREON
Browse files Browse the repository at this point in the history
Upd Sudoku & Add Step Counter WIP
  • Loading branch information
RogueMaster committed Aug 20, 2023
1 parent 32f72f8 commit 20f6091
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ This software is for experimental purposes only and is not meant for any illegal
- Updated: [Advanced Wifi Sniffer (By Sil333033)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/c8e5c3bd8b353092c7fd5b7ed0327d044ee53b74)
- Updated: [PicoPass (iClass) (By Bettse)](https://github.com/flipperdevices/flipperzero-good-faps/tree/dev/picopass)
- Changed SubGHz Test Debug app to be external
- Added: [Mx2125 Step Counter (By 47lecoste a.k.a. grugnoymeme)](https://github.com/grugnoymeme/flipperzero-stepcounter-fap)
- Updated: [Sudoku (By profelis)](https://github.com/profelis/fz-sudoku)

<a name="release">

Expand Down Expand Up @@ -398,6 +400,7 @@ $ ./fbt dolphin_ext
- [Music Player (By DrZlo13)-OFW](https://github.com/flipperdevices/flipperzero-firmware/pull/1189)
- [Music Tracker (By DrZlo13)](https://github.com/DrZlo13/flipper-zero-music-tracker)
- [Mx2125 Dual-Axis Accelerometer (By jamisonderek)](https://github.com/jamisonderek/flipper-zero-tutorials/tree/main/gpio)
- [Mx2125 Step Counter (By 47lecoste a.k.a. grugnoymeme)](https://github.com/grugnoymeme/flipperzero-stepcounter-fap)
- [Name Changer (By ESurge)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/488) (Change Flipper name)
- [NFC/RFID Detector #2795 (By Skorpionm)](https://github.com/flipperdevices/flipperzero-firmware/pull/2795)
- [NFC Magic (By gornekich)](https://github.com/flipperdevices/flipperzero-firmware/pull/1966) with [NFC Magic Gen4 Support #2238 (By nullableVoidPtr)](https://github.com/flipperdevices/flipperzero-firmware/pull/2238)
Expand Down
21 changes: 21 additions & 0 deletions applications/external/step_counter/LICENSE
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.
2 changes: 2 additions & 0 deletions applications/external/step_counter/README.md
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
13 changes: 13 additions & 0 deletions applications/external/step_counter/application.fam
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.",
)
148 changes: 148 additions & 0 deletions applications/external/step_counter/stepcounter.c
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;
}
Binary file added applications/external/step_counter/steps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 30 additions & 10 deletions applications/external/sudoku/sudoku.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct {
GameState state;
int8_t menuCursor;
int8_t lastGameMode;
bool blockInputUntilRelease;
} SudokuState;

#define MENU_ITEMS_COUNT 5
Expand Down Expand Up @@ -93,7 +94,7 @@ static int get_mode_gaps(int index) {
return HARD_GAPS;
}

#define SAVE_VERSION 1
#define SAVE_VERSION 2
#define SAVE_FILE APP_DATA_PATH("save.dat")

static bool load_game(SudokuState* state) {
Expand Down Expand Up @@ -414,6 +415,7 @@ static bool start_game(SudokuState* state) {
state->state = GameStateRunning;
state->cursorX = 0;
state->cursorY = 0;
state->blockInputUntilRelease = false;
init_board(state);
shuffle_board(state, 10);
add_gaps(state, get_mode_gaps(state->lastGameMode));
Expand Down Expand Up @@ -496,23 +498,31 @@ int32_t sudoku_main(void* p) {
}
}

bool invalidLidAndRow =
!(state->horizontalFlags & (1 << state->cursorY) ||
state->vertivalFlags & (1 << state->cursorX));

if(event.type == InputTypePress || event.type == InputTypeLong ||
event.type == InputTypeRepeat) {
switch(event.key) {
case InputKeyLeft:
state->blockInputUntilRelease = false;
state->cursorX = (state->cursorX + BOARD_SIZE - 1) % BOARD_SIZE;
break;
case InputKeyRight:
state->blockInputUntilRelease = false;
state->cursorX = (state->cursorX + 1) % BOARD_SIZE;
break;
case InputKeyUp:
state->blockInputUntilRelease = false;
state->cursorY = (state->cursorY + BOARD_SIZE - 1) % BOARD_SIZE;
break;
case InputKeyDown:
state->blockInputUntilRelease = false;
state->cursorY = (state->cursorY + 1) % BOARD_SIZE;
break;
case InputKeyOk:
if(userInput) {
if(userInput && !state->blockInputUntilRelease) {
int flags = state->board[state->cursorX][state->cursorY] & FLAGS_MASK;
int value = state->board[state->cursorX][state->cursorY] & VALUE_MASK;
state->board[state->cursorX][state->cursorY] = flags | ((value + 1) % 10);
Expand All @@ -522,14 +532,24 @@ int32_t sudoku_main(void* p) {
default:
break;
}
} else if(event.type == InputTypeRelease) {
state->blockInputUntilRelease = false;
}
if(invalidField && validate_board(state)) {
dolphin_deed(DolphinDeedPluginGameWin);
state->state = GameStateVictory;
state->menuCursor = 0;
for(int i = 0; i != BOARD_SIZE; ++i) {
for(int j = 0; j != BOARD_SIZE; ++j) {
state->board[i][j] &= ~USER_INPUT_FLAG;
if(invalidField) {
if(validate_board(state)) {
dolphin_deed(DolphinDeedPluginGameWin);
state->state = GameStateVictory;
state->menuCursor = 0;
for(int i = 0; i != BOARD_SIZE; ++i) {
for(int j = 0; j != BOARD_SIZE; ++j) {
state->board[i][j] &= ~USER_INPUT_FLAG;
}
}
} else {
bool isValidLineOrRow = state->horizontalFlags & (1 << state->cursorY) ||
state->vertivalFlags & (1 << state->cursorX);
if(invalidLidAndRow && isValidLineOrRow) {
state->blockInputUntilRelease = true;
}
}
}
Expand All @@ -555,4 +575,4 @@ int32_t sudoku_main(void* p) {
free(state);

return 0;
}
}

0 comments on commit 20f6091

Please sign in to comment.