Kestrel Interface
Loading...
Searching...
No Matches
kest_desktop.c
Go to the documentation of this file.
1#include "kest_int.h"
2
3#define PRINTLINES_ALLOWED 0
4#include <SDL2/SDL.h>
5#include <time.h>
6
7static const char *FNAME = "kest_desktop.c";
8
9int init_sd_card() {return NO_ERROR;}
13
15
16static lv_display_t *disp;
17static SDL_Window *window;
18static SDL_Renderer *renderer;
19static SDL_Texture *texture;
20
21static void flush_cb(lv_display_t *d,
22 const lv_area_t *area,
23 uint8_t *px_map)
24{
25 int32_t w = lv_area_get_width(area);
26 int32_t h = lv_area_get_height(area);
27
28 SDL_UpdateTexture(texture,
29 &(SDL_Rect){area->x1, area->y1, w, h},
30 px_map,
31 w * 4);
32
33 lv_display_flush_ready(d);
34}
35static void mouse_read(lv_indev_t *indev, lv_indev_data_t *data)
36{
37 int x, y;
38 uint32_t buttons = SDL_GetMouseState(&x, &y);
39
40 data->point.x = x;
41 data->point.y = y;
42
43 data->state = (buttons & SDL_BUTTON_LMASK)
44 ? LV_INDEV_STATE_PRESSED
45 : LV_INDEV_STATE_RELEASED;
46}
47
48void main_task(void *arg)
49{
50 int ret_val;
51
52 srand(time(0));
53
55
56 SDL_Init(SDL_INIT_VIDEO);
57
58 window = SDL_CreateWindow("M",
59 SDL_WINDOWPOS_CENTERED,
60 SDL_WINDOWPOS_CENTERED,
62 0);
63
64 renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
65 texture = SDL_CreateTexture(renderer,
66 SDL_PIXELFORMAT_ARGB8888,
67 SDL_TEXTUREACCESS_STREAMING,
69
70 lv_init();
71 disp = lv_display_create(DISPLAY_HRES, DISPLAY_VRES);
72
73 static lv_color_t buf[DISPLAY_HRES * 40];
74 lv_display_set_buffers(disp,
75 buf,
76 NULL,
77 sizeof(buf),
78 LV_DISPLAY_RENDER_MODE_PARTIAL);
79
80 lv_display_set_flush_cb(disp, flush_cb);
81
82 lv_indev_t *mouse = lv_indev_create();
83 lv_indev_set_type(mouse, LV_INDEV_TYPE_POINTER);
84 lv_indev_set_read_cb(mouse, mouse_read);
85
86 init_representation_updater();
90
91 xTaskCreate(
93 NULL,
94 4096,
95 NULL,
96 8,
97 NULL
98 );
99 xTaskCreate(kest_param_update_task, NULL, 4096, NULL, 8, NULL);
100
102
103 //if (load_state_from_file(&global_cxt.state, SETTINGS_FNAME) == ERR_FOPEN_FAIL)
104 // save_state_to_file(&global_cxt.state, SETTINGS_FNAME);
105
107 init_effect_selector_eff(&global_cxt.pages.effect_selector);
110
111 kest_create_ui(NULL);
112
113 kest_state state;
114 ret_val = load_state_from_file(&state, SETTINGS_FNAME);
115
116 if (ret_val == NO_ERROR)
117 {
118 ret_val = kest_cxt_restore_state(&global_cxt, &state);
119
120 KEST_PRINTF("Restored state from disk with error code \"%s\"\n", kest_error_code_to_string(ret_val));
121 }
122 else
123 {
124 KEST_PRINTF("Unable to restore state from disk: \"%s\"\n", kest_error_code_to_string(ret_val));
125 }
126
127 int running = 1;
128 SDL_Event e;
129
130 while (running)
131 {
132 while (SDL_PollEvent(&e))
133 {
134 if (e.type == SDL_QUIT)
135 {
136 running = 0;
137 }
138 }
139
140 lv_timer_handler();
141 SDL_RenderClear(renderer);
142 SDL_RenderCopy(renderer, texture, NULL, NULL);
143 SDL_RenderPresent(renderer);
144 SDL_Delay(1);
145 }
146
147 SDL_DestroyTexture(texture);
148 SDL_DestroyRenderer(renderer);
149 SDL_DestroyWindow(window);
150 SDL_Quit();
151
152 vTaskEndScheduler();
153 vTaskDelete(NULL);
154}
155
156int main(int argc, char **argv)
157{
158 xTaskCreate(main_task,
159 NULL,
160 64 * 1024,
161 NULL,
162 8,
163 NULL);
164
165 vTaskStartScheduler();
166
167 return 0;
168}
169
171{
172 abort();
173}
174
175void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
176{
177 printf("Stack overflow in %s\n", pcTaskName);
178 abort();
179}
181{
182 lv_tick_inc(1);
183}
int kest_init_context(kest_context *cxt)
int kest_context_init_effect_list(kest_context *cxt)
int kest_sd_mode_local()
int init_sd_card()
Definition kest_desktop.c:9
int main(int argc, char **argv)
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
int kest_sd_mode_msc()
int kest_sd_toggle_msc()
void vApplicationTickHook(void)
void main_task(void *arg)
void vApplicationMallocFailedHook(void)
int init_effect_selector_eff(kest_ui_page *page)
const char * kest_error_code_to_string(int error_code)
#define NO_ERROR
int load_saved_sequences(kest_context *cxt)
int load_state_from_file(kest_state *state, const char *fname)
Definition kest_files.c:298
int kest_init_directories()
Definition kest_files.c:697
int load_saved_profiles(kest_context *cxt)
Definition kest_files.c:960
int load_effects(kest_context *cxt)
#define SETTINGS_FNAME
Definition kest_files.h:24
void kest_fpga_comms_task(void *param)
kest_context global_cxt
Definition kest_int.c:12
void kest_param_update_task(void *arg)
void kest_printf_init()
Definition kest_printf.c:11
#define KEST_PRINTF(...)
Definition kest_printf.h:10
int kest_cxt_restore_state(kest_context *cxt, kest_state *state)
Definition kest_state.c:94
int kest_init_global_pages(kest_global_pages *pages)
Definition kest_ui.c:78
void kest_create_ui(lv_disp_t *disp)
Definition kest_ui.c:121
#define DISPLAY_VRES
Definition kest_ui.h:11
#define DISPLAY_HRES
Definition kest_ui.h:12