add: gpio drivers
This commit is contained in:
parent
ba70677393
commit
3cd6668f9c
8 changed files with 131 additions and 76 deletions
46
handlers/loop.c
Normal file
46
handlers/loop.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <logger.h>
|
||||
#include <models/controller.h>
|
||||
#include <handlers.h>
|
||||
#include <drivers.h>
|
||||
#include <enums.h>
|
||||
#include <helpers.h>
|
||||
#include <wiringPi.h>
|
||||
#include <wiring_debug.h>
|
||||
|
||||
void
|
||||
handler_loop(controller_t *controller)
|
||||
{
|
||||
LOG_DEBUG("===== IDLE LOOP START =====");
|
||||
for(uint_fast8_t i = 0; i < controller->relay_count; ++i)
|
||||
{
|
||||
relay_t *relay = controller->relays[i];
|
||||
if(relay_is_active(relay, time(NULL)))
|
||||
{
|
||||
LOG_DEBUG("relay %d is active", i);
|
||||
if(relay->number >= 2)
|
||||
{
|
||||
driver_gpio_set(relay, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
driver_piface_set(relay, HIGH);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(relay->number >= 2)
|
||||
{
|
||||
driver_gpio_set(relay, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
driver_piface_set(relay, LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
handlers/poll.c
Normal file
50
handlers/poll.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <lmdb.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <logger.h>
|
||||
#include <models/controller.h>
|
||||
#include <database.h>
|
||||
#include <config.h>
|
||||
#include <constants.h>
|
||||
#include <handlers.h>
|
||||
#include <drivers.h>
|
||||
#include <enums.h>
|
||||
#include <helpers.h>
|
||||
#include <wiringPi.h>
|
||||
#include <piFace.h>
|
||||
#include <wiring_debug.h>
|
||||
|
||||
void
|
||||
handler_poll(struct pollfd *fds, controller_t *controller, MDB_env *mdb_env)
|
||||
{
|
||||
/* An event on one of the fds has occurred. */
|
||||
for(int i = 0; i < POLL_FDS_COUNT; i++) {
|
||||
if(fds[i].revents & POLLIN)
|
||||
{
|
||||
/* data may be read on device number i. */
|
||||
LOG_DEBUG("fd %i may read data", fds[i].fd);
|
||||
switch(i)
|
||||
{
|
||||
case POLL_FDS_DISCOVERY:
|
||||
handler_discovery(fds[i].fd, controller);
|
||||
break;
|
||||
case POLL_FDS_COMMAND:
|
||||
handler_command(fds[i].fd, controller);
|
||||
controller_save(controller, mdb_env);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(fds[i].revents & POLLHUP)
|
||||
{
|
||||
/* A hangup has occurred on device number i. */
|
||||
LOG_DEBUG("fd %i got closed", fds[i].fd);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue