discoverpixy
Data Structures | Typedefs | Functions
Screen
Collaboration diagram for Screen:

Data Structures

struct  SCREEN_S
 

Typedefs

typedef void(* SCREEN_CALLBACK) (void *screen)
 
typedef struct SCREEN_S SCREEN_STRUCT
 

Functions

bool gui_screen_navigate (SCREEN_STRUCT *screen)
 
bool gui_screen_back ()
 
SCREEN_STRUCTgui_screen_get_current ()
 
void gui_screen_update ()
 

Detailed Description

The Screen Submodule provides an api to navigate between different "screens" on the UI. Each screen must provide an enter, update and a leave method; which will be called from this module at the right time. The implemented screens of the application are documented in the Screens module.

Typedef Documentation

typedef void(* SCREEN_CALLBACK) (void *screen)

Prototype for Event Listeners (called when the screen is entered, left or should be updated)

Parameters
screenThe pointer to the SCREEN_STRUCT where the event occurred

Definition at line 47 of file screen.h.

typedef struct SCREEN_S SCREEN_STRUCT

Structure to configure the Screen

Function Documentation

bool gui_screen_back ( )

Navigate one screen back as soon as the app enters the main loop again. It's safe to call this method from an interrupt

Returns
true on success

Definition at line 85 of file screen.c.

86 {
87  if (screen_list == NULL) { //the list head is emtpy, nothing to go back to
88  return false;
89  }
90 
91  SCREEN_STRUCT* current = screen_list;
92  SCREEN_STRUCT* last = NULL;
93 
94  //Find second last element in list
95  while (current->next != NULL) {
96  last = current;
97  current = current->next;
98  }
99 
100  if (last == NULL) {
101  return false; //There's only a single screen, there's no going back here
102  }
103 
104  if (current != screen_current) {
105  return false; //The last entry in the list is not the current screen. List corrupted?
106  }
107 
108  screen_goto = last; //"send message" to main loop, to switch the screen
109  return true;
110 }
struct SCREEN_S * next
Used internally. do not modify, do not initialize.
Definition: screen.h:57
static SCREEN_STRUCT * screen_current
Definition: screen.c:32
static volatile SCREEN_STRUCT * screen_goto
Definition: screen.c:33
static SCREEN_STRUCT * screen_list
Definition: screen.c:31

Here is the caller graph for this function:

SCREEN_STRUCT* gui_screen_get_current ( )

Returns the currently active screen

Returns
A Pointer to the active SCREEN_STRUCT

Definition at line 35 of file screen.c.

36 {
37  return screen_current;
38 }
static SCREEN_STRUCT * screen_current
Definition: screen.c:32
bool gui_screen_navigate ( SCREEN_STRUCT screen)

Navigate to the given screen as soon as the app enters the main loop again (and gui_screen_update() is called) It's safe to call this method from an interrupt

Note
Do not pass a screen which is already in your history of screens!
Parameters
screenA Pointer to the preinitialized SCREEN_STRUCT
Returns
true on success

Definition at line 74 of file screen.c.

75 {
76  if (screen == NULL || screen == screen_current || screen == screen_goto) { //invalid argument passed
77  return false;
78  }
79 
80  screen->next = NULL; //this will become the new tail of the list, so the next pointer must be NULL
81  screen_goto = screen; //"send message" to main loop, to switch the screen
82  return true;
83 }
struct SCREEN_S * next
Used internally. do not modify, do not initialize.
Definition: screen.h:57
static SCREEN_STRUCT * screen_current
Definition: screen.c:32
static volatile SCREEN_STRUCT * screen_goto
Definition: screen.c:33
static SCREEN_STRUCT screen

Here is the caller graph for this function:

void gui_screen_update ( )

Updates the current screen. Switches the screen if gui_screen_navigate() or gui_screen_back() have been called since the last call to this method. This method should be called repeatedly from the main loop (e.g. app_process())

Definition at line 41 of file screen.c.

42 {
43  if (screen_goto != NULL) { //we received the task to switch the screen
44  SCREEN_STRUCT* go = (SCREEN_STRUCT*) screen_goto; //Backup volatile variable
45  screen_goto = NULL; //reset the "goto instruction", since we're processing it now
46 
47  if (go->next != NULL) { //The screen is not the last in the list, so we're going back
48  if (go->next != screen_current) { //this condition should always be false
49  return; //list corrupted?
50  }
51 
52  screen_current->on_leave(screen_current); //let the current screen free/unregister it's resources
53  go->next = NULL; //remove the current screen from the list
54  } else { //we're going forward (to a new screen)
55  if (screen_current != NULL) { //this is not the first screen
56  screen_current->on_leave(screen_current); //let the current screen free/unregister it's resources
57  screen_current->next = go; //append the new screen to the end of the list
58  } else { //first screen ever seen
59  screen_list = go; //set the new screen as list-head
60  }
61  }
62 
63  go->on_enter(go); //let the new screen allocate/register it's resources
64  screen_current = go; //the new screen is now the current screen. Transition done
65  }
66 
67  if (screen_current != NULL) { //A screen has been set
68  screen_current->on_update(screen_current); //Update current screen
69  }
70 }
SCREEN_CALLBACK on_enter
The Callback which is called when the screen is entered. Add/Register all UI-Elements here...
Definition: screen.h:53
struct SCREEN_S * next
Used internally. do not modify, do not initialize.
Definition: screen.h:57
static SCREEN_STRUCT * screen_current
Definition: screen.c:32
static volatile SCREEN_STRUCT * screen_goto
Definition: screen.c:33
static SCREEN_STRUCT * screen_list
Definition: screen.c:31
SCREEN_CALLBACK on_leave
The Callback which is called when the screen is left. Remove/Unregister all UI-Elements here...
Definition: screen.h:54
SCREEN_CALLBACK on_update
The Callback which is called repeatedly when the screen should be updated. Update/Redraw all UI-Eleme...
Definition: screen.h:55

Here is the caller graph for this function: