Skip to content

Commit

Permalink
implement autocall, for simple remove/add apps
Browse files Browse the repository at this point in the history
  • Loading branch information
sharandac committed Sep 11, 2023
1 parent 358d69d commit e5bcb0a
Show file tree
Hide file tree
Showing 47 changed files with 852 additions and 1,305 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,9 @@ The development tools have a known issue with the size of the project on Windows
xtensa-esp32-elf-g++: error: CreateProcess: No such file or directory
*** [.pio\build\t-watch2020-v1\firmware.elf] Error 1

This issue has not been seen on Linux or other platforms. If you must compile on Windows you may work around this linker issue by removing apps you do not use from the .\src\main.cpp file.
This issue has not been seen on Linux or other platforms. This is a linker issue and can be fixed by removing apps. To remove unneeded apps you can simply delete the appropriate directory in /src/app. Then simply recompile. App can be added in the same way. But note that the app must support autocall_function . This allows the automatic integration of apps without touching the rest of the code ( [the magic behind autocall_function](autocall.md) ).

You might remove the example app commenting out these lines by adding two slashes (```//```) on these locations:

* main.cpp line 9: ```//#include "app/example_app/example_app.h"```
* main.cpp line 65: ```// example_app_setup();```

(Line numbers are approximate and may change as the system develops.)

Since each app includes a different set of files, you may need to comment out several apps to reduce it small enough for the Windows build. And don't forget to delete the corresponding app files/directories. Commenting out is not enough.
Since each app includes a different set of files, you may need to delete several apps to reduce it small enough for the Windows build.

# How to use

Expand All @@ -100,7 +93,8 @@ Cf. [Usage](USAGE.md)

# For the programmers

Cf. [contribution guide](CONTRIBUTING.md)
Cf. [contribution guide](CONTRIBUTING.md)<br>
app autocall function [the magic behind autocall_function](autocall.md) or add a app without touching the rest

# Interface

Expand Down
21 changes: 21 additions & 0 deletions autocall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# the magic behind autocall_function

How do I make sure that a function is called automatically without being called explicitly in the setup() function in main.c?
Actually this is quite simple. In the file src/gui/app/app.h is a function and type declared which looks like this:

```c
typedef void ( * APP_AUTOCALL_FUNC ) ( void );
int app_autocall_function( APP_AUTOCALL_FUNC function, size_t prio );
```
You pass a function pointer to this function. In this case the registration function ( ```app_setup_function()```) for our app. So far not very exciting.
The trick is to call this function in another file and store the return value in a static variable that has the file as scope. This ensures that this function is called at initialization before the actual program starts. We only need to store this function pointer in a list for later use like.
So only the following code snippet has to be in out app:
```c
#include "gui/app.h"
static int registed = app_autocall_function( &app_setup_function, 0 );
```
Later in the program we can simply process the list with functions pointers at a suitable place.
That was it already. Simple if you think about it.
68 changes: 41 additions & 27 deletions src/app/FindPhone/FindPhone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,74 @@
#include "gui/statusbar.h"
#include "gui/app.h"
#include "gui/widget.h"

/*
* app tiles
*/
uint32_t FindPhone_main_tile_num;
uint32_t FindPhone_setup_tile_num;

// app icon
/*
* app icon and widget
*/
icon_t *FindPhone = NULL;

// widget icon container
icon_t *FindPhone_widget = NULL;

// declare you images or fonts you need
/*
* declare you images or fonts you need
*/
LV_IMG_DECLARE(eye_64px);
LV_IMG_DECLARE(info_1_16px);

// declare callback functions for the app and widget icon to enter the app
/*
* declare callback functions for the app and widget icon to enter the app
*/
static void enter_FindPhone_event_cb( lv_obj_t * obj, lv_event_t event );
//static void enter_FindPhone_widget_event_cb( lv_obj_t * obj, lv_event_t event );

/*
* automatic register the app setup function with explicit call in main.cpp
*/
static int registed = app_autocall_function( &FindPhone_setup, 13 ); /** @brief app autocall function */
/*
* setup routine for example app
*/
void FindPhone_setup( void ) {
/*
* check if app already registered for autocall
*/
if( !registed ) {
return;
}
#if defined( ONLY_ESSENTIAL )
return;
#endif
// register 1 vertical tile and get the first tile number and save it for later use
/*
* register 1 vertical tile and get the first tile number and save it for later use
*/
FindPhone_main_tile_num = mainbar_add_app_tile( 1, 1, "FindPhone" );
FindPhone = app_register( "Find\nPhone", &eye_64px, enter_FindPhone_event_cb );
// init main and setup tile, see FindPhone_main.cpp and FindPhone_setup.cpp
/*
* init main and setup tile, see FindPhone_main.cpp and FindPhone_setup.cpp
*/
FindPhone_main_setup( FindPhone_main_tile_num );
bluetooth_FindPhone_tile_setup();
}

/*
*
/**
* @brief get the app main tile number
*
* @return uint32_t
*/
uint32_t FindPhone_get_app_main_tile_num( void ) {
return( FindPhone_main_tile_num );
}

/*
*
/**
* @brief get the app setup tile number
*
* @return uint32_t
*/
uint32_t FindPhone_get_app_setup_tile_num( void ) {
return( FindPhone_setup_tile_num );
}

/*
*
/**
* @brief call back function to enter the app
*
* @param obj pointer to the object
* @param event the event
*/
static void enter_FindPhone_event_cb( lv_obj_t * obj, lv_event_t event ) {
switch( event ) {
Expand All @@ -88,8 +107,3 @@ static void enter_FindPhone_event_cb( lv_obj_t * obj, lv_event_t event ) {
break;
}
}

/*
*
*/

3 changes: 0 additions & 3 deletions src/app/FindPhone/FindPhone.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
#ifndef _FindPhone_H
#define _FindPhone_H

// #define EXAMPLE_WIDGET // uncomment if an widget need

void FindPhone_setup( void );
//uint32_t FindPhone_get_app_setup_tile_num( void );//No use just yet
uint32_t FindPhone_get_app_main_tile_num( void );

#endif // _FindPhone_H
10 changes: 10 additions & 0 deletions src/app/IRController/IRController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
#include "gui/mainbar/mainbar.h"
#include "gui/widget_styles.h"
#include "hardware/ble/gadgetbridge.h"
#include "gui/app.h"

/*
* automatic register the app setup function with explicit call in main.cpp
*/
static int registed = app_autocall_function( &IRController_setup, 8 ); /** @brief app autocall function */

#ifdef NATIVE_64BIT
void IRController_setup( void ) {
Expand Down Expand Up @@ -57,6 +62,11 @@
* setup routine for IR Controller app
*/
void IRController_setup( void ) {
if( !registed ) {
return;
}


irController.init("IR Remote", &IRController_64px);
// Load config and build user interface
IRController_build_UI(IRControlSettingsAction::Load);
Expand Down
7 changes: 5 additions & 2 deletions src/app/activity/activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "activity.h"
#include "gui/mainbar/mainbar.h"
#include "gui/widget_styles.h"
#include "gui/app.h"
#include "hardware/motion.h"
// #include "hardware/blestepctl.h"
#include "hardware/motor.h"
Expand Down Expand Up @@ -61,10 +62,12 @@ static lv_event_cb_t default_msgbox_cb;
static void build_main_page();
static void refresh_main_page();
static void build_settings();

static void activity_activate_cb();
static void activity_reset_cb(lv_obj_t * obj, lv_event_t event);

/*
* automatic register the app setup function with explicit call in main.cpp
*/
static int registed = app_autocall_function( &activity_app_setup, 8 ); /** @brief app autocall function */
/*
* setup routine for application
*/
Expand Down
32 changes: 24 additions & 8 deletions src/app/alarm_clock/alarm_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gui/statusbar.h"
#include "gui/widget.h"
#include "gui/widget_factory.h"
#include "gui/app.h"
#include "utils/json_psram_allocator.h"
#include "hardware/powermgm.h"
#include "hardware/rtcctl.h"
Expand Down Expand Up @@ -63,20 +64,28 @@ static icon_t *alarm_clock_widget = NULL;

// declare callback functions
static void enter_alarm_clock_event_cb( lv_obj_t * obj, lv_event_t event );

/*
* automatic register the app setup function with explicit call in main.cpp
*/
static int registed = app_autocall_function( &alarm_clock_setup, 1 ); /** @brief app autocall function */

static void create_alarm_app_icon(){
// create an app icon, label it and get the lv_obj_t icon container
/*
* create an app icon, label it and get the lv_obj_t icon container
*/
lv_obj_t * alarm_clock_icon_cont = app_tile_register_app( "alarm");
// set your own icon and register her callback to activate by an click
// remember, an app icon must have an size of 64x64 pixel with an alpha channel
// use https://lvgl.io/tools/imageconverter to convert your images and set "true color with alpha" to get fancy images
// the resulting c-file can put in /app/examples/images/
/*
* set your own icon and register her callback to activate by an click
* remember, an app icon must have an size of 64x64 pixel with an alpha channel
* use https://lvgl.io/tools/imageconverter to convert your images and set "true color with alpha" to get fancy images
* the resulting c-file can put in /app/examples/images/
*/
lv_obj_t * alarm_clock_icon = wf_add_image_button( alarm_clock_icon_cont, alarm_clock_64px, enter_alarm_clock_event_cb );
lv_obj_reset_style_list( alarm_clock_icon, LV_OBJ_PART_MAIN );
lv_obj_align( alarm_clock_icon , alarm_clock_icon_cont, LV_ALIGN_CENTER, 0, 0 );

// make app icon drag scroll the mainbar
/*
* make app icon drag scroll the mainbar
*/
mainbar_add_slide_element(alarm_clock_icon);
}

Expand Down Expand Up @@ -178,6 +187,13 @@ static bool powermgmt_callback( EventBits_t event, void *arg ){

// setup routine for example app
void alarm_clock_setup( void ) {
/*
* check if app already registered for autocall
*/
if( !registed ) {
return;
}

properties.load();

create_alarm_app_icon();
Expand Down
74 changes: 58 additions & 16 deletions src/app/astro/astro_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,88 @@
#else
#include <Arduino.h>
#endif

/*
* app tiles
*/
uint32_t astro_app_main_tile_num;

// app and widget icon
/*
* app and widget icon
*/
icon_t *astro_app = NULL;
icon_t *astro_widget = NULL;

// declare you images or fonts you need
/*
* declare you images or fonts you need
*/
LV_IMG_DECLARE(astro_app_64px);

// declare callback functions
/*
* declare callback functions
*/
static void enter_astro_app_event_cb( lv_obj_t * obj, lv_event_t event );

// setup routine for astro app
/*
* automatic register the app setup function with explicit call in main.cpp
*/
static int registed = app_autocall_function( &astro_app_setup, 8 ); /** @brief app autocall function */
/*
* setup routine for astro app
*/
void astro_app_setup( void ) {
/*
* check if app already registered for autocall
*/
if( !registed ) {
return;
}

astro_app_main_tile_num = mainbar_add_app_tile( 1, 1, "Astro App" );
astro_app = app_register( "astro", &astro_app_64px, enter_astro_app_event_cb );
astro_app_main_setup( astro_app_main_tile_num );
}

/**
* @brief get the app main tile number
*
* @return uint32_t
*/
uint32_t astro_app_get_app_main_tile_num( void ) {
return( astro_app_main_tile_num );
}

/**
* @brief callback function to enter the app
*
* @param obj pointer to the object
* @param event the event
*/
static void enter_astro_app_event_cb( lv_obj_t * obj, lv_event_t event ) {
switch( event ) {
case( LV_EVENT_CLICKED ): astro_app_hide_app_icon_info( true );
mainbar_jump_to_tilenumber( astro_app_main_tile_num, LV_ANIM_OFF );
break;
}
}

/**
* @brief add the widget icon to the widget bar
*/
void astro_add_widget( void ) {
astro_widget = widget_register( "astro", &astro_app_64px, enter_astro_app_event_cb );
}

/**
* @brief remove the widget icon from the widget bar
*/
void astro_remove_widget( void ) {
astro_widget = widget_remove( astro_widget );
}

/**
* @brief update the widget label
*
* @param label the new label
*/
void astro_app_update_widget_label( char *label ) {
widget_set_label( astro_widget, label );
}

/**
* @brief hide the app icon info
*
* @param show true to show, false to hide
*/
void astro_app_hide_app_icon_info( bool show ) {
if ( !show ) {
app_set_indicator( astro_app, ICON_INDICATOR_1 );
Expand All @@ -86,7 +124,11 @@ void astro_app_hide_app_icon_info( bool show ) {
app_hide_indicator( astro_app );
}
}

/**
* @brief hide the widget icon info
*
* @param show true to show, false to hide
*/
void astro_app_hide_widget_icon_info( bool show ) {
if ( !show ) {
widget_set_indicator( astro_widget, ICON_INDICATOR_1 );
Expand Down
Loading

0 comments on commit e5bcb0a

Please sign in to comment.