compilation errors fixed
This commit is contained in:
parent
a2335a9d74
commit
59e8fa59d5
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
*~
|
*~
|
||||||
|
*.o
|
||||||
|
src/upiwin
|
||||||
|
|
12
src/gpio.c
12
src/gpio.c
|
@ -1,6 +1,8 @@
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
@ -62,11 +64,11 @@ static int setup_the_memmap(void)
|
||||||
{
|
{
|
||||||
if ((mem_fd = open("/dev/gpiomem", O_RDWR|O_SYNC)) > 0)
|
if ((mem_fd = open("/dev/gpiomem", O_RDWR|O_SYNC)) > 0)
|
||||||
{
|
{
|
||||||
if ((gpio_map = (unit32_t *)mmap(NULL, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0)) == MAP_FAILED)
|
if ((gpio_map = (uint32_t *)mmap(NULL, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0)) == MAP_FAILED)
|
||||||
{
|
{
|
||||||
gpio_map = NULL;
|
gpio_map = NULL;
|
||||||
close(mem_fd);
|
close(mem_fd);
|
||||||
log(LFATAL, "Unable to map /dev/gpiomem (%d)", errno);
|
Log(LFATAL, "Unable to map /dev/gpiomem (%d)", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +172,7 @@ void Gpio_cleanup(void)
|
||||||
|
|
||||||
if (gpio_map)
|
if (gpio_map)
|
||||||
{
|
{
|
||||||
munmap(gpio_map, BLOCK_SIZE);
|
munmap((void *)gpio_map, BLOCK_SIZE);
|
||||||
gpio_map = NULL;
|
gpio_map = NULL;
|
||||||
}
|
}
|
||||||
if (mem_fd >= 0)
|
if (mem_fd >= 0)
|
||||||
|
@ -200,13 +202,13 @@ int Gpio_poll_buttons(void)
|
||||||
for (ndx = 1, mask = 1; ndx <= 4; ndx++, mask <<= 1)
|
for (ndx = 1, mask = 1; ndx <= 4; ndx++, mask <<= 1)
|
||||||
{
|
{
|
||||||
if (tmp & mask)
|
if (tmp & mask)
|
||||||
log(LDEBUG, "Button %d was released", ndx);
|
Log(LDEBUG, "Button %d was released", ndx);
|
||||||
}
|
}
|
||||||
tmp = new_state & ~last_state;
|
tmp = new_state & ~last_state;
|
||||||
for (ndx = 1, mask = 1; ndx <= 4; ndx++, mask <<= 1)
|
for (ndx = 1, mask = 1; ndx <= 4; ndx++, mask <<= 1)
|
||||||
{
|
{
|
||||||
if (tmp & mask)
|
if (tmp & mask)
|
||||||
log(LDEBUG, "Button %d was pressed", ndx);
|
Log(LDEBUG, "Button %d was pressed", ndx);
|
||||||
}
|
}
|
||||||
last_state = new_state;
|
last_state = new_state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
static const char *severities[] = { "FATAL", "ERROR", "WARN ", "INFO ", "DEBUG" };
|
static const char *severities[] = { "FATAL", "ERROR", "WARN ", "INFO ", "DEBUG" };
|
||||||
|
|
||||||
void log(int level, const char *format, ...)
|
void Log(int level, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list argp;
|
va_list argp;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
@ -18,8 +18,8 @@ void log(int level, const char *format, ...)
|
||||||
vsnprintf(buf, 1024, format, argp);
|
vsnprintf(buf, 1024, format, argp);
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
gettimeofday(&tv);
|
gettimeofday(&tv, NULL);
|
||||||
localtime_r(&(tv.tv_sec), &tm)
|
localtime_r(&(tv.tv_sec), &tm);
|
||||||
strftime(timestamp, 32, "%F %T", &tm);
|
strftime(timestamp, 32, "%F %T", &tm);
|
||||||
printf("%s.%06u %s %s\n", timestamp, tv.tv_usec, severities[level], buf);
|
printf("%s.%06u %s %s\n", timestamp, tv.tv_usec, severities[level], buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
#define LINFO 3
|
#define LINFO 3
|
||||||
#define LDEBUG 4
|
#define LDEBUG 4
|
||||||
|
|
||||||
extern void log(int level, const char *format, ...);
|
extern void Log(int level, const char *format, ...);
|
||||||
|
|
||||||
#endif /* __LOG_H_INCLUDED */
|
#endif /* __LOG_H_INCLUDED */
|
||||||
|
|
|
@ -8,7 +8,7 @@ int main(int argc, char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
atexit(Gpio_cleanup);
|
atexit(Gpio_cleanup);
|
||||||
|
|
||||||
log(LINFO, "System ready.");
|
Log(LINFO, "System ready.");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Gpio_poll_buttons();
|
Gpio_poll_buttons();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user