Skip to content

Commit 05b6c7c

Browse files
christianrauchCleoQc
authored andcommitted
Add led_toggle to header (DexterInd#286)
* constant i2c filename and addresses * clear whitespaces * make 'led_toggle' available in header
1 parent e7537e3 commit 05b6c7c

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Software/C/gopigo.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@
3232
#define READ_BUF_SIZE 32
3333

3434
int fd;
35-
char *fileName = "/dev/i2c-1";
36-
int address = 0x08;
35+
const char *fileName = "/dev/i2c-1";
36+
const int address = 0x08;
3737
unsigned char w_buf[WRITE_BUF_SIZE],r_buf[READ_BUF_SIZE];
38-
unsigned long reg_addr=0;
38+
const unsigned long reg_addr=0;
3939
int version=200; //Initialized with invalid version
40-
int v16_thresh=790;
41-
int LED_L=1,LED_R=0;
40+
const int v16_thresh=790;
4241

4342
int init(void)
4443
{

Software/C/gopigo.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// ####################################################################################
2-
// This library is used for communicating with the GoPiGo.
3-
// http://www.dexterindustries.com/GoPiGo/
1+
// ####################################################################################
2+
// This library is used for communicating with the GoPiGo.
3+
// http://www.dexterindustries.com/GoPiGo/
44
// History
55
// ------------------------------------------------
66
// Date Comments
@@ -43,10 +43,11 @@
4343
#include <stdbool.h>
4444

4545
extern int fd;
46-
extern char *fileName;
47-
extern int address;
46+
extern const char *fileName;
47+
extern const int address;
4848
extern unsigned char w_buf[5],r_buf[32];
49-
extern unsigned long reg_addr;
49+
extern const unsigned long reg_addr;
50+
const bool LED_L=1,LED_R=0;
5051

5152
#define fwd_cmd 119 //Move forward with PID
5253
#define motor_fwd_cmd 105 //Move forward without PID
@@ -72,7 +73,7 @@ extern unsigned long reg_addr;
7273
#define en_enc_cmd 51 //Enable the encoders
7374
#define dis_enc_cmd 52 //Disable the encoders
7475
#define read_enc_status_cmd 53 //Read encoder status
75-
#define en_servo_cmd 61 //Enable the servo's
76+
#define en_servo_cmd 61 //Enable the servo's
7677
#define dis_servo_cmd 60 //Disable the servo's
7778
#define set_left_speed_cmd 70 //Set the speed of the right motor
7879
#define set_right_speed_cmd 71 //Set the speed of the left motor
@@ -82,7 +83,7 @@ extern unsigned long reg_addr;
8283
#define enc_read_cmd 53 //Read encoder values
8384
#define trim_test_cmd 30 //Test the trim values
8485
#define trim_write_cmd 31 //Write the trim values
85-
#define trim_read_cmd 32
86+
#define trim_read_cmd 32
8687

8788
#define digital_write_cmd 12 //Digital write on a port
8889
#define digital_read_cmd 13 //Digital read on a port
@@ -103,7 +104,7 @@ char read_byte(void);
103104
//Get voltage
104105
float volt(void);
105106

106-
//Sleep in ms
107+
//Sleep in ms
107108
void pi_sleep(int t);
108109

109110
//Control Motor 1
@@ -124,7 +125,7 @@ int bwd(void);
124125
//Move GoPiGo back without PID control
125126
int motor_bwd(void);
126127

127-
//Turn GoPiGo Left slow (one motor off, better control)
128+
//Turn GoPiGo Left slow (one motor off, better control)
128129
int left(void);
129130

130131
//Rotate GoPiGo left in same position (both motors moving in the opposite direction)
@@ -184,6 +185,12 @@ int us_dist(int pin);
184185
// speed -> pointer to array of 2 bytes [motor1, motor2], allocated before
185186
void read_motor_speed(unsigned char* speed);
186187

188+
//Turn led on or off
189+
// arg:
190+
// l_id: 1 for left LED and 0 for right LED
191+
// onoff: 0 off, 1 on
192+
int led_toggle(int l_id, bool onoff);
193+
187194
//Turn led on
188195
// arg:
189196
// l_id: 1 for left LED and 0 for right LED

0 commit comments

Comments
 (0)