Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dragon project #1

Merged
merged 9 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
dragon
23 changes: 16 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ es: Los usuarios ahora pueden mantener presionado y presionar brevemente con un
- [⬅️ Go left button screen](#️-go-left-button-screen)
- [⬆️ Go up button screen](#️-go-up-button-screen)
- [➡️ Go right button screen](#️-go-right-button-screen)
- [Dragon Graphics Motor](#dragon-graphics-motor)
- [License](#license)

### Installation
Expand All @@ -64,9 +65,9 @@ es: Ejecuta `./fbt`.

### Create the app

Then you will see this log on console log from the [log](./other/01.log)
Then you will see this log on console log from the [log](./assets/01.log)

es: Luego verás este registro en el registro de la consola desde el [log](./other/01.log).
es: Luego verás este registro en el registro de la consola desde el [log](./assets/01.log).

We put the code inside the folder applications_user/my_first_app.

Expand All @@ -76,10 +77,10 @@ es: Ponemos el código dentro de la carpeta applications_user/mi_primera_app.

Inside my_first_app we add 2 files:

es: Dentro de mi_primera_app agregamos 2 archivos:
es: Dentro de mi primera app "button" agregamos 2 archivos:

- [my_first_app.c](./my_first_app/my_first_app.c)
- [application.fam](./my_first_app/application.fam)
- [button.c](./applications_user/button.c)
- [application.fam](./applications_user/application.fam)

### Compile

Expand All @@ -91,9 +92,9 @@ es: Ahora podemos compilar la aplicación:
./fbt fap_dist
```

Then you will see this log on console log from the [log](./other/02.log)
Then you will see this log on console log from the [log](./assets/02.log)

es: Luego verás este registro en el registro de la consola desde el [log](./other/02.log).
es: Luego verás este registro en el registro de la consola desde el [log](./assets/02.log).

`D:/unleashed-firmware/build/latest/.extapps/my_first_app.fap` will need to drag and drop to the qFlipper.

Expand Down Expand Up @@ -149,6 +150,14 @@ es: En tocar, cualquier botón interactúa, con esto puedes crear un juego de
### ➡️ Go right button screen
![➡️ Go right button screen](https://github.com/miguelgargallo/flipperzero/assets/5947268/20ab20f1-7a43-479e-b852-9a8f3636f557)

## Dragon Graphics Motor

Here you have the DRAGON Graphics Engine. The idea behind my developments is to encourage the community to program their apps, either inspired by my code via forks, or because they want to contribute directly to me.

es: Aquí tenéis al DRAGON Graphics Motor. La idea que hay detrás de mis desarrollos es enfatizar a la comunidad a que programen sus apps, a partir de la inspiración de mi codigo, ya sea por forks o bien porque quieran contribuir directamente conmigo.

[See the code](./human/human.c)

## License

[PYLAR AI CREATIVE ML LICENSE](License.md)
Expand Down
1 change: 1 addition & 0 deletions applications_user/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put your custom applications in this folder.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Clicks SDK by [Miguel Gargallo](https://twitter.com/miguelgargallo)
# Button by [Miguel Gargallo](https://twitter.com/miguelgargallo)

## PYLAR AI CREATIVE ML LICENSE

Expand Down
9 changes: 9 additions & 0 deletions applications_user/button/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
App(
appid="button",
name="button",
apptype=FlipperAppType.EXTERNAL,
entry_point="button_main",
requires=["gui"],
stack_size=1 * 1024,
fap_category="miguelgargallo",
)
126 changes: 69 additions & 57 deletions my_first_app/my_first_app.c → applications_user/button/button.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/**************************|
| o myFlipperApps o |
| o by MiguelGargallo o |
| o 001 - My First App o |
| o Version: 3.0.0b o |
| o Date: 06-28-2023 o |
| o o |
**************************/
/***************************|
| o o |
| o myFlipperApps o |
| o by MiguelGargallo o |
| o 002 - Button o |
| o Version: 3.0.0b o |
| o Date: 06-28-2023 o |
| o o |
****************************/

#include <stdio.h>
#include <furi.h>
#include <gui/gui.h>

// Create messages to display based on user input
static char* message = "Press any button...";
static char* exitMessage = "";
static char numberMessage[2] = ""; // Create a new message string for numbers
static char *message = "Press any button...";
static char *exitMessage = "";
static char numberMessage[2] = ""; // Create a new message string for numbers

// Create a variable to keep track of long press count
static int longPressCount = 0;

// Function to clear canvas and draw GUI elements
static void drawGui(Canvas* canvas, void* context) {
static void drawGui(Canvas *canvas, void *context)
{
UNUSED(context);
canvas_clear(canvas);

Expand All @@ -41,71 +43,79 @@ static void drawGui(Canvas* canvas, void* context) {
}

// Function to handle user input
static void handleInput(InputEvent* input_event, void* context) {
FuriMessageQueue* event_queue = context;
static void handleInput(InputEvent *input_event, void *context)
{
FuriMessageQueue *event_queue = context;
furi_assert(event_queue != NULL);

// Check if the button was long-pressed or not
bool longPress = (input_event->type == InputTypeLong) ? true : false;

// Change the message depending on which key was pressed
switch(input_event->key) {
case InputKeyUp:
message = longPress ? "You long-pressed ^^^" : "You pressed ^";
break;
case InputKeyDown:
message = longPress ? "You long-pressed vvv" : "You pressed v";
break;
case InputKeyLeft:
message = longPress ? "You long-pressed <<<" : "You pressed <";
break;
case InputKeyRight:
message = longPress ? "You long-pressed >>>" : "You pressed >";
break;
case InputKeyOk:
message = longPress ? "You long-pressed ooo" : "You pressed o";
break;
case InputKeyBack:
message = longPress ? "You long-pressed ---" : "You pressed -";
exitMessage = longPress ? "Exiting the App." : "Long press to exit.";
break;
default:
message = "Press any button...";
switch (input_event->key)
{
case InputKeyUp:
message = longPress ? "You long-pressed ^^^" : "You pressed ^";
break;
case InputKeyDown:
message = longPress ? "You long-pressed vvv" : "You pressed v";
break;
case InputKeyLeft:
message = longPress ? "You long-pressed <<<" : "You pressed <";
break;
case InputKeyRight:
message = longPress ? "You long-pressed >>>" : "You pressed >";
break;
case InputKeyOk:
message = longPress ? "You long-pressed ooo" : "You pressed o";
break;
case InputKeyBack:
message = longPress ? "You long-pressed ---" : "You pressed -";
exitMessage = longPress ? "Exiting the App." : "Long press to exit.";
break;
default:
message = "Press any button...";
}

// Update the longPressCount and numberMessage based on the type of press
if (longPress) {
if (longPress)
{
longPressCount++;
switch (longPressCount) {
case 1:
snprintf(numberMessage, sizeof(numberMessage), "1");
break;
case 2:
snprintf(numberMessage, sizeof(numberMessage), "2");
break;
case 3:
snprintf(numberMessage, sizeof(numberMessage), "3");
break;
switch (longPressCount)
{
case 1:
snprintf(numberMessage, sizeof(numberMessage), "1");
break;
case 2:
snprintf(numberMessage, sizeof(numberMessage), "2");
break;
case 3:
snprintf(numberMessage, sizeof(numberMessage), "3");
break;
}
} else {
longPressCount = 0; // Reset the count on a short press
numberMessage[0] = '\0'; // Clear the string
}
else
{
longPressCount = 0; // Reset the count on a short press
numberMessage[0] = '\0'; // Clear the string
}

furi_message_queue_put(event_queue, input_event, FuriWaitForever);
}

// Main function of the app
int32_t my_first_app_main(void* parameter) {
int32_t button_main(void *parameter)
{
UNUSED(parameter);

// Create an event queue and a viewport for GUI
InputEvent input_event;
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
ViewPort* viewport = view_port_alloc();
FuriMessageQueue *event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
ViewPort *viewport = view_port_alloc();

// Error checking
if(!event_queue || !viewport) {
if (!event_queue || !viewport)
{
printf("Error: Failed to allocate event_queue or viewport!\n");
return -1;
}
Expand All @@ -115,17 +125,19 @@ int32_t my_first_app_main(void* parameter) {
view_port_input_callback_set(viewport, handleInput, event_queue);

// Create a GUI and associate it with the viewport
Gui* gui = furi_record_open(RECORD_GUI);
Gui *gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, viewport, GuiLayerFullscreen);

// Main event loop
while(true) {
while (true)
{
// Check the queue for events
FuriStatus status = furi_message_queue_get(event_queue, &input_event, FuriWaitForever);
furi_check(status == FuriStatusOk);

// Exit the loop if the back button is long-pressed
if(input_event.type == InputTypeLong && input_event.key == InputKeyBack) {
if (input_event.type == InputTypeLong && input_event.key == InputKeyBack)
{
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PYLAR AI CREATIVE ML LICENSE
# DRAGON Graphics Motor by [Miguel Gargallo](https://twitter.com/miguelgargallo)

## PYLAR AI CREATIVE ML LICENSE

[OFFICIAL REFERENCE](https://huggingface.co/spaces/superdatas/LICENSE)

Expand Down
7 changes: 7 additions & 0 deletions applications_user/human/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DRAGON Graphics Motor by [Miguel Gargallo](https://twitter.com/miguelgargallo)

Here you have the DRAGON Graphics Engine. The idea behind my developments is to encourage the community to program their apps, either inspired by my code via forks, or because they want to contribute directly to me.

es: Aquí tenéis al DRAGON Graphics Motor. La idea que hay detrás de mis desarrollos es enfatizar a la comunidad a que programen sus apps, a partir de la inspiración de mi codigo, ya sea por forks o bien porque quieran contribuir directamente conmigo.

[See the code](./human.c)
9 changes: 9 additions & 0 deletions applications_user/human/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
App(
appid="human",
name="Graphics Motor Dragon",
apptype=FlipperAppType.EXTERNAL,
entry_point="human_main",
requires=["gui"],
stack_size=1 * 1024,
fap_category="miguelgargallo",
)
Loading