moberg.h 3.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
    moberg.h -- interface to moberg I/O system

    Copyright (C) 2019 Anders Blomdell <anders.blomdell@gmail.com>

    This file is part of Moberg.

    Moberg is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/
    
22
23
24
#ifndef __MOBERG_H__
#define __MOBERG_H__

Anders Blomdell's avatar
Anders Blomdell committed
25
#include <stdio.h>
26

Anders Blomdell's avatar
Anders Blomdell committed
27
struct moberg;
28

29
30
31
32
33
34
35
36
37
38
/* Error reporting */

struct moberg_status {
  int result; /* == 0 -> OK 
                 <  0 -> moberg specific error
                 >  0 -> system error (see errno.h */
};

int moberg_OK(struct moberg_status);

Anders Blomdell's avatar
Anders Blomdell committed
39
/* Creation & free */
40

Anders Blomdell's avatar
Anders Blomdell committed
41
struct moberg *moberg_new();
42

Anders Blomdell's avatar
Anders Blomdell committed
43
void moberg_free(struct moberg *moberg);
44

Anders Blomdell's avatar
Anders Blomdell committed
45
/* Input/output */
Anders Blomdell's avatar
Anders Blomdell committed
46

Anders Blomdell's avatar
Anders Blomdell committed
47
48
struct moberg_analog_in {
  struct moberg_channel_analog_in *context;
49
50
  struct moberg_status (*read)(struct moberg_channel_analog_in *,
                               double *value);
Anders Blomdell's avatar
Anders Blomdell committed
51
};
Anders Blomdell's avatar
Anders Blomdell committed
52

Anders Blomdell's avatar
Anders Blomdell committed
53
54
struct moberg_analog_out {
  struct moberg_channel_analog_out *context;
55
56
  struct moberg_status (*write)(struct moberg_channel_analog_out *,
                                double value);
Anders Blomdell's avatar
Anders Blomdell committed
57
};
Anders Blomdell's avatar
Anders Blomdell committed
58

Anders Blomdell's avatar
Anders Blomdell committed
59
60
struct moberg_digital_in {
  struct moberg_channel_digital_in *context;
61
62
  struct moberg_status (*read)(struct moberg_channel_digital_in *,
                               int *value);
Anders Blomdell's avatar
Anders Blomdell committed
63
};
Anders Blomdell's avatar
Anders Blomdell committed
64

Anders Blomdell's avatar
Anders Blomdell committed
65
66
struct moberg_digital_out {
  struct moberg_channel_digital_out *context;
67
68
  struct moberg_status (*write)(struct moberg_channel_digital_out *,
                                int value);
Anders Blomdell's avatar
Anders Blomdell committed
69
};
Anders Blomdell's avatar
Anders Blomdell committed
70

Anders Blomdell's avatar
Anders Blomdell committed
71
72
struct moberg_encoder_in {
  struct moberg_channel_encoder_in *context;
73
74
  struct moberg_status (*read)(struct moberg_channel_encoder_in *,
                               long *value);
Anders Blomdell's avatar
Anders Blomdell committed
75
76
};

77
78
79
80
struct moberg_status moberg_analog_in_open(
  struct moberg *moberg,
  int index,
  struct moberg_analog_in *analog_in);
Anders Blomdell's avatar
Anders Blomdell committed
81

82
83
84
85
struct moberg_status moberg_analog_in_close(
  struct moberg *moberg,
  int index,
  struct moberg_analog_in analog_in);
Anders Blomdell's avatar
Anders Blomdell committed
86

87
88
89
90
struct moberg_status moberg_analog_out_open(
  struct moberg *moberg,
  int index,
  struct moberg_analog_out *analog_out);
Anders Blomdell's avatar
Anders Blomdell committed
91

92
93
94
95
struct moberg_status moberg_analog_out_close(
  struct moberg *moberg,
  int index,
  struct moberg_analog_out analog_out);
Anders Blomdell's avatar
Anders Blomdell committed
96

97
98
99
100
struct moberg_status moberg_digital_in_open(
  struct moberg *moberg,
  int index,
  struct moberg_digital_in *digital_in);
Anders Blomdell's avatar
Anders Blomdell committed
101

102
103
104
105
struct moberg_status moberg_digital_in_close(
  struct moberg *moberg,
  int index,
  struct moberg_digital_in digital_in);
Anders Blomdell's avatar
Anders Blomdell committed
106

107
108
109
110
struct moberg_status moberg_digital_out_open(
  struct moberg *moberg,
  int index,
  struct moberg_digital_out *digital_out);
Anders Blomdell's avatar
Anders Blomdell committed
111

112
113
114
115
struct moberg_status moberg_digital_out_close(
  struct moberg *moberg,
  int index,
  struct moberg_digital_out digital_out);
Anders Blomdell's avatar
Anders Blomdell committed
116

117
118
119
120
struct moberg_status moberg_encoder_in_open(
  struct moberg *moberg,
  int index,
  struct moberg_encoder_in *encoder_in);
Anders Blomdell's avatar
Anders Blomdell committed
121

122
123
124
125
struct moberg_status moberg_encoder_in_close(
  struct moberg *moberg,
  int index,
  struct moberg_encoder_in encoder_in);
Anders Blomdell's avatar
Anders Blomdell committed
126

Anders Blomdell's avatar
Anders Blomdell committed
127
/* System init functionality (systemd/init/...) */
Anders Blomdell's avatar
Anders Blomdell committed
128

129
struct moberg_status moberg_start(
Anders Blomdell's avatar
Anders Blomdell committed
130
131
132
  struct moberg *moberg,
  FILE *f);

133
struct moberg_status moberg_stop(
Anders Blomdell's avatar
Anders Blomdell committed
134
135
  struct moberg *moberg,
  FILE *f);
136
137

#endif