-
Notifications
You must be signed in to change notification settings - Fork 1
/
threadx_app.c
105 lines (84 loc) · 2.8 KB
/
threadx_app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Copyright (c) Microsoft Corporation.
Licensed under the MIT License. */
// Standard headers
#include <stdio.h>
#include <stdbool.h>
// ThreadX and GUIX headers
#include "tx_api.h"
#include "gx_api.h"
#include "flipdot_guix_resources.h"
#include "flipdot_guix_specifications.h"
#include "flipdot_graphics_driver.h"
// GuiX Thread resources
#define GUIX_THREAD_STACK_SIZE 4096
#define GUIX_THREAD_PRIORITY 4
TX_THREAD guix_thread;
UCHAR guix_thread_stack[GUIX_THREAD_STACK_SIZE];
// GUIX Windows
GX_WINDOW_ROOT *root;
// Timer for ticker refresh
#define CLOCK_TIMER 20
static bool ticker_on = false;
// GUIX main thread
VOID guix_thread_entry(ULONG thread_input)
{
GX_WINDOW_ROOT *root;
/* Initialize GUIX. */
gx_system_initialize();
/* Setup graphics-related hardware and create the display. */
gx_studio_display_configure(DISPLAY, flipdot_graphics_driver_setup, LANGUAGE_ENGLISH, DISPLAY_THEME_1, &root);
/* create the main screen */
gx_studio_named_widget_create("window", (GX_WIDGET *) root, GX_NULL);
/* Show the root window to make it visible. */
gx_widget_show(root);
/* start GUIX thread */
gx_system_start();
}
// Main window event processing
UINT main_event_process(GX_WINDOW *wnd, GX_EVENT *event_ptr) {
switch (event_ptr->gx_event_type)
{
case GX_EVENT_SHOW:
// Start a timer to update text at regular intervals
gx_system_timer_start((GX_WIDGET *)wnd, CLOCK_TIMER, TX_TIMER_TICKS_PER_SECOND/2,TX_TIMER_TICKS_PER_SECOND/2);
// Call default event process
return gx_window_event_process(wnd, event_ptr);
case GX_EVENT_TIMER:
// If the timer id is our clock timer, change what's on the display
if (event_ptr->gx_event_payload.gx_event_timer_id == CLOCK_TIMER)
{
gx_multi_line_text_view_text_set(&window.window_text_view, ticker_on?"Hello World .":"Hello World");
ticker_on = !ticker_on;
}
break;
default:
return gx_window_event_process(wnd, event_ptr);
}
return GX_SUCCESS;
}
// ThreadX app main entry point
int main(void)
{
/* Enter the ThreadX kernel. */
tx_kernel_enter();
return 0;
}
// ThreadX application setup
void tx_application_define(void *first_unused_memory)
{
// Create the GUI thread.
UINT status = tx_thread_create(&guix_thread,
"GUIX Thread",
guix_thread_entry,
0,
guix_thread_stack,
GUIX_THREAD_STACK_SIZE,
GUIX_THREAD_PRIORITY,
GUIX_THREAD_PRIORITY,
TX_NO_TIME_SLICE,
TX_AUTO_START);
if (status != TX_SUCCESS)
{
printf("GUI Init failed, please restart\r\n");
}
}