-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.c
69 lines (63 loc) · 1.69 KB
/
gpio.c
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
69
//
// ptt.c
// TMAControl-CClient
//
// Created by Ronan LE MEILLAT on 25/03/2021.
//
//
#include "gpio.h"
#include <stdio.h>
#include <unistd.h>
int power_on_radio(){
#ifdef HAVE_LIBWIRINGPI
wiringPiSetup();
pinMode(POWER_PIN, OUTPUT);
digitalWrite(PTT_PIN,HIGH);
return 0;
#else
fprintf(stderr,"NO GPIO Found install libwiringPi need to put port wPi#%d to %d\n",POWER_PIN,HIGH);
return -1;
#endif
}
int power_off_radio(){
#ifdef HAVE_LIBWIRINGPI
digitalWrite(POWER_PIN,LOW);
return 0;
#else
fprintf(stderr,"NO GPIO Found install libwiringPi need to put port wPi#%d to %d\n",POWER_PIN,LOW);
return -1;
#endif
}
int push_to_talk_setup(){
#ifdef HAVE_LIBWIRINGPI
wiringPiSetup();
pinMode(PTT_PIN, OUTPUT);
digitalWrite(PTT_PIN,PTT_OFF);
return 0;
#else
fprintf(stderr,"NO GPIO Found install libwiringPi need to put port wPi#%d to %d\n",PTT_PIN,PTT_OFF);
return -1;
#endif
}
int push_to_talk_on(){
usleep(PRE_ON*1000);
#ifdef HAVE_LIBWIRINGPI
fprintf(stderr,"Putting pin GPIO.%d to %d\n",PTT_PIN,PTT_ON);
digitalWrite(PTT_PIN,PTT_ON); //PTT is active low on Motorola but GPIO is inverted with opto-isolator
return 0;
#else
fprintf(stderr,"NO GPIO Found install libwiringPi need to put port wPi#%d to %d\n",PTT_PIN,PTT_ON);
return -1;
#endif
}
int push_to_talk_off(){
usleep(POST_ON*1000);
#ifdef HAVE_LIBWIRINGPI
fprintf(stderr,"Putting pin GPIO.%d to %d\n",PTT_PIN,PTT_OFF);
digitalWrite(PTT_PIN,PTT_OFF); //PTT is active low on Motorola but GPIIO is inverted with opti-isolator
return 0;
#else
fprintf(stderr,"NO GPIO Found install libwiringPi need to put port wPi#%d to %d\n",PTT_PIN,PTT_OFF);
return -1;
#endif
}