upiwin/src/main.c

70 lines
1.3 KiB
C
Raw Normal View History

2019-11-29 02:05:30 -07:00
#include <stdlib.h>
#include <string.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"
#include "time_func.h"
#include "sysinput.h"
2019-11-29 02:05:30 -07:00
int main(int argc, char *argv[])
{
int running = 1;
MSG msg;
char *tmp;
2019-12-01 15:43:05 -07:00
Time_init();
2019-12-01 18:53:54 -07:00
if (Fb_setup() != 0)
return EXIT_FAILURE;
atexit(Fb_cleanup);
2019-11-29 02:05:30 -07:00
if (Gpio_setup() != 0)
return EXIT_FAILURE;
atexit(Gpio_cleanup);
2019-12-01 15:43:05 -07:00
if (Sys_enable_input() != 0)
return EXIT_FAILURE;
2019-12-01 15:43:05 -07:00
atexit(Sys_disable_input);
2019-11-29 02:05:30 -07:00
/* temporary drawing here */
tmp = (char *)Fb_Ptr;
memset(tmp, 0xFF, Fb-Info->screenbytes / 2);
memset(tmp + (Fb-Info->screenbytes / 2), 0x1B, Fb-Info->screenbytes / 2);
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;
default:
break;
}
}
2019-11-29 02:05:30 -07:00
}
return EXIT_SUCCESS;
2019-11-29 02:05:30 -07:00
}