ModmataC  1.0
A C library for Arduino communication
ModmataC.h
Go to the documentation of this file.
1 /*
2 ModmataC
3 Copyright © char* teamName <shutche@siue.edu>
4 Licensed under LGPL-2.1
5 */
6 
7 #ifndef MODMATA_H
8 #define MODMATA_H
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <signal.h>
13 #include <errno.h>
14 #include <time.h>
15 
16 #include "modbus/modbus.h"
17 
18 #define IDLE 0
19 #define PINMODE 1
20 #define DIGITALWRITE 2
21 #define DIGITALREAD 3
22 #define ANALOGREFERENCE 4
23 #define ANALOGWRITE 5
24 #define ANALOGREAD 6
25 #define SERVOATTACH 7
26 #define SERVODETACH 8
27 #define SERVOWRITE 9
28 #define SERVOREAD 10
29 #define WIREBEGIN 11
30 #define WIREEND 12
31 #define WIRECLOCK 13
32 #define WIREWRITE 14
33 #define WIREREAD 15
34 #define SPIBEGIN 16
35 #define SPISETTINGS 17
36 #define SPITRANSFER 18
37 #define SPIEND 19
38 
39 #define INPUT 0
40 #define OUTPUT 1
41 
42 #define LOW 0
43 #define HIGH 1
44 
45 #define LSBFIRST 0
46 #define MSBFIRST 1
47 
48 #define SPI_MODE0 0x00
49 #define SPI_MODE1 0x04
50 #define SPI_MODE2 0x08
51 #define SPI_MODE3 0x0C
52 
53 static modbus_t* arduino;
54 
60 static void safe_exit(int signal);
61 
67 void closeConnection();
68 
74 void delay(int millis);
75 
76 void delayMicroseconds(int micros);
77 
83 int isValidPin(int pinNum);
84 
92 int connectArduino(char *port, int baudRate, int id);
93 
100 void pinMode(uint8_t pinNum, uint8_t mode);
101 
108 void digitalWrite(uint8_t pinNum, uint8_t input);
109 
115 int digitalRead(uint8_t pinNum);
116 
123 void analogWrite(uint8_t pinNum, uint16_t input);
124 
130 int analogRead(uint16_t pinNum);
131 
137 void servoAttach(uint16_t pinNum);
138 
144 void servoDetach(uint16_t pinNum);
145 
152 void servoWrite(uint16_t pinNum, uint16_t input);
153 
159 int servoRead(uint16_t pinNum);
160 
165 void wireBegin();
166 
171 void wireEnd();
172 
178 void wireSetClock(uint32_t);
179 
188 void wireWrite(uint8_t addr, uint8_t reg, uint8_t num_bytes, uint8_t* data);
189 
197 uint8_t* wireRead(uint8_t addr, uint8_t reg, int num_bytes);
198 
203 void spiBegin();
204 
212 uint8_t* spiTransferBuf(int CS_pin, uint8_t *buf, uint8_t length);
213 
221 void spiSettings(uint32_t speed, uint8_t order, uint8_t mode);
222 
227 void spiEnd();
228 
229 void transmitRegisters(uint8_t fn_code, uint8_t argc, uint8_t* argv);
230 
231 #endif
void wireWrite(uint8_t addr, uint8_t reg, uint8_t num_bytes, uint8_t *data)
Definition: ModmataC.c:340
void delayMicroseconds(int micros)
Definition: ModmataC.c:62
int connectArduino(char *port, int baudRate, int id)
Definition: ModmataC.c:93
int digitalRead(uint8_t pinNum)
Definition: ModmataC.c:161
void spiBegin()
Definition: ModmataC.c:388
uint8_t * wireRead(uint8_t addr, uint8_t reg, int num_bytes)
Definition: ModmataC.c:362
void pinMode(uint8_t pinNum, uint8_t mode)
Definition: ModmataC.c:121
void wireEnd()
Definition: ModmataC.c:317
int isValidPin(int pinNum)
Definition: ModmataC.c:74
uint8_t * spiTransferBuf(int CS_pin, uint8_t *buf, uint8_t length)
Definition: ModmataC.c:400
void servoWrite(uint16_t pinNum, uint16_t input)
Definition: ModmataC.c:264
int analogRead(uint16_t pinNum)
Definition: ModmataC.c:212
void spiSettings(uint32_t speed, uint8_t order, uint8_t mode)
Definition: ModmataC.c:439
void closeConnection()
Definition: ModmataC.c:51
void wireBegin()
Definition: ModmataC.c:308
void servoDetach(uint16_t pinNum)
Definition: ModmataC.c:250
void servoAttach(uint16_t pinNum)
Definition: ModmataC.c:237
void delay(int millis)
Definition: ModmataC.c:56
void analogWrite(uint8_t pinNum, uint16_t input)
Definition: ModmataC.c:190
void wireSetClock(uint32_t)
Definition: ModmataC.c:327
void transmitRegisters(uint8_t fn_code, uint8_t argc, uint8_t *argv)
Definition: ModmataC.c:457
int servoRead(uint16_t pinNum)
Definition: ModmataC.c:281
void spiEnd()
Definition: ModmataC.c:448
void digitalWrite(uint8_t pinNum, uint8_t input)
Definition: ModmataC.c:143