upiwin/src/main.c

108 lines
2.4 KiB
C
Raw Normal View History

2019-11-29 02:05:30 -07:00
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "scode.h"
#include "config.h"
2019-11-29 02:05:30 -07:00
#include "gpio.h"
#include "log.h"
2019-12-01 18:53:54 -07:00
#include "fbinit.h"
2019-12-06 23:26:13 -07:00
#include "fbprimitive.h"
#include "time_func.h"
#include "sysinput.h"
2019-11-29 02:05:30 -07:00
2019-12-01 20:57:36 -07:00
static void do_draw(void)
{
2019-12-06 23:26:13 -07:00
Fb_filled_rectangle(10, 10, 50, 50, FBPRIMCLR_RED, FALSE);
Fb_filled_rectangle(60, 10, 100, 50, FBPRIMCLR_GREEN, FALSE);
Fb_filled_rectangle(110, 10, 150, 50, FBPRIMCLR_BLUE, FALSE);
2019-12-06 23:26:13 -07:00
Fb_filled_rectangle(10, 60, 50, 100, FBPRIMCLR_CYAN, FALSE);
Fb_filled_rectangle(60, 60, 100, 100, FBPRIMCLR_MAGENTA, FALSE);
Fb_filled_rectangle(110, 60, 150, 100, FBPRIMCLR_YELLOW, FALSE);
Fb_rectangle(10, 110, 150, 150, PBPRIMCLR_WHITE, FALSE);
Fb_line(10, 110, 150, 150, FBPRIMCLR_WHITE, FALSE);
Fb_line(10, 150, 150, 110, FBPRIMCLR_WHITE, FALSE);
2019-12-01 20:57:36 -07:00
}
static void log_touch(const char *event, UINT_PTR x, UINT_PTR y)
{
Log(LINFO, "Touch %s at (%u, %u)", event, x, y);
}
2019-11-29 02:05:30 -07:00
int main(int argc, char *argv[])
{
2019-12-06 22:37:20 -07:00
HRESULT hr;
int running = 1;
MSG msg;
char *tmp;
2019-12-01 15:43:05 -07:00
Time_init();
2019-12-06 22:37:20 -07:00
hr = Config_setup(argc, argv);
if (FAILED(hr))
return EXIT_FAILURE;
2019-12-06 22:37:20 -07:00
else if (hr != S_OK)
return EXIT_SUCCESS;
if (FAILED(Fb_setup()))
2019-12-01 18:53:54 -07:00
return EXIT_FAILURE;
if (FAILED(Gpio_setup()))
2019-11-29 02:05:30 -07:00
return EXIT_FAILURE;
if (FAILED(Sys_enable_input()))
return EXIT_FAILURE;
Log(LINFO, "Pausing at startup.");
sleep(5); /* wait to show off splash screen */
2019-11-29 02:05:30 -07:00
Fb_clear();
/* temporary drawing here */
2019-12-01 20:57:36 -07:00
do_draw();
2019-11-29 02:18:02 -07:00
Log(LINFO, "System ready.");
2019-11-29 02:05:30 -07:00
while (running)
{
2019-12-01 15:43:05 -07:00
if (Mq_peek(Sys_Queue, &msg, PEEK_REMOVE))
{
switch (msg.message)
{
case WM_HWBUTTONDOWN:
Log(LINFO, "Button %d was pressed.", (int)(msg.attrs[0]));
break;
case WM_HWBUTTONUP:
Log(LINFO, "Button %d was released.", (int)(msg.attrs[0]));
2019-12-01 14:34:57 -07:00
if (msg.attrs[0] == 1)
{
Log(LINFO, "Backlight ON.");
2019-12-01 15:45:46 -07:00
Gpio_set_backlight(GSB_BACKLIGHT_MAX);
2019-12-01 14:34:57 -07:00
}
if (msg.attrs[0] == 2)
{
Log(LINFO, "Backlight OFF.");
Gpio_set_backlight(0);
}
if (msg.attrs[0] == 4)
{
Log(LINFO, "Quitting the message loop.");
running = 0;
}
break;
case WM_TOUCHDOWN:
log_touch("DOWN", msg.attrs[0], msg.attrs[1]);
break;
case WM_TOUCHMOVE:
log_touch("MOVE", msg.attrs[0], msg.attrs[1]);
break;
case WM_TOUCHUP:
log_touch("UP", msg.attrs[0], msg.attrs[1]);
break;
default:
break;
}
}
2019-11-29 02:05:30 -07:00
}
return EXIT_SUCCESS;
2019-11-29 02:05:30 -07:00
}