-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathops.h
68 lines (52 loc) · 1.72 KB
/
ops.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright (c) 2009 Miguel Lechon */
/*
This file is part of Cyrano. Cyrano 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.
Cyrano 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
Cyrano. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _OPS_H
#define _OPS_H
#include "WProgram.h"
typedef unsigned char uchar;
typedef unsigned short int uint;
uint pin_mode(uint pin, uint mode, uint){ // Input: 0, Output: 1
pinMode(pin, mode);
return 0;
}
uint digital_read(uint pin, uint, uint){
return digitalRead(pin);
}
uint digital_write(uint pin, uint value, uint){
digitalWrite(pin, value);
return 0;
}
uint analog_reference(uint type, uint, uint){
analogReference(type);
return 0;
}
uint analog_read(uint pin, uint, uint){
return analogRead(pin);
}
uint analog_write(uint pin, uint value, uint){
analogWrite(pin, value);
return 0;
}
typedef uint (*fp)(uint, uint, uint);
fp functions[] = {
(fp)pin_mode, (fp)digital_read, (fp)digital_write,
(fp)analog_reference, (fp)analog_read, (fp)analog_write
};
int n_args[] = {
/*pin_mode*/ 2, /*digital_read*/ 1, /*digital_write*/ 2,
/*analog_reference*/ 1, /*analog_read*/ 1, /*analog_write*/ 2
};
inline uint call(uint cmd, uint args[3]){
return (functions[cmd])(args[0], args[1], args[2]);
}
#endif // _OPS_H