summaryrefslogtreecommitdiff
path: root/src/trigger.c
blob: 4b7cc49eb3d3fa58cfab84fbcc4f4134c4287e02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "trigger.h"

#include "close.h"
#include "ndelay.h"
#include "open.h"
#include "select.h"

static int fd = -1;

void trigger_set()
{
  if (fd != -1) close(fd);
  fd = open_read("lock/trigger");
}

void trigger_selprep(int *nfds, fd_set *rfds)
{
  if (fd != -1) {
    FD_SET(fd, rfds);
    if (*nfds < fd + 1) *nfds = fd + 1;
  }
}

int trigger_pulled(fd_set *rfds)
{
  if (fd != -1)
    if (FD_ISSET(fd, rfds)) return 1;
  return 0;
}

void write(); /* compiler warning (temp) */

void triggerpull()
{
  int fd;

  fd = open_write("lock/trigger");
  if (fd >= 0) {
    ndelay_on(fd);
    write(fd, "", 1); /* if it fails, bummer */
    close(fd);
  }
}