git.haldean.org d / 492e732
import roboticscape project skeleton Demo User 2 years ago
3 changed file(s) with 100 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 *.o
1 *.swp
2 d
0 libal: main.c
1 gcc -o $@ $<
0 # This is a general use makefile for robotics cape projects written in C.
1 # Just change the target name to match your main source code filename.
2 TARGET = d
3
4 CC := gcc
5 LINKER := gcc -o
6 CFLAGS := -c -Wall -g
7 LFLAGS := -lm -lrt -lpthread -lroboticscape
8
9 SOURCES := $(wildcard *.c)
10 INCLUDES := $(wildcard *.h)
11 OBJECTS := $(SOURCES:$%.c=$%.o)
12
13 prefix := /usr/local
14 RM := rm -f
15 INSTALL := install -m 4755
16 INSTALLDIR := install -d -m 755
17
18 LINK := ln -s -f
19 LINKDIR := /etc/roboticscape
20 LINKNAME := link_to_startup_program
21
22
23 # linking Objects
24 $(TARGET): $(OBJECTS)
25 @$(LINKER) $(@) $(OBJECTS) $(LFLAGS)
26
27
28 # compiling command
29 $(OBJECTS): %.o : %.c $(INCLUDES)
30 @$(CC) $(CFLAGS) -c $< -o $(@)
31 @echo "Compiled: "$<
32
33 all:
34 $(TARGET)
35
36 debug:
37 $(MAKE) $(MAKEFILE) DEBUGFLAG="-g -D DEBUG"
38 @echo " "
39 @echo "$(TARGET) Make Debug Complete"
40 @echo " "
41
42 install:
43 @$(MAKE) --no-print-directory
44 @$(INSTALLDIR) $(DESTDIR)$(prefix)/bin
45 @$(INSTALL) $(TARGET) $(DESTDIR)$(prefix)/bin
46 @echo "$(TARGET) Install Complete"
47
48 clean:
49 @$(RM) $(OBJECTS)
50 @$(RM) $(TARGET)
51 @echo "$(TARGET) Clean Complete"
52
53 uninstall:
54 @$(RM) $(DESTDIR)$(prefix)/bin/$(TARGET)
55 @echo "$(TARGET) Uninstall Complete"
56
57 runonboot:
58 @$(MAKE) install --no-print-directory
59 @$(LINK) $(DESTDIR)$(prefix)/bin/$(TARGET) $(LINKDIR)/$(LINKNAME)
60 @echo "$(TARGET) Set to Run on Boot"
61
1818
1919 #include <linux/i2c-dev.h>
2020 #include <fcntl.h>
21 #include <roboticscape.h>
2122 #include <stdbool.h>
2223 #include <stdio.h>
2324 #include <string.h>
5051 int i2c;
5152 uint8_t buf[4];
5253
54 if (rc_initialize())
55 {
56 fprintf(stderr,"ERROR: failed to initialize rc_initialize(), are you root?\n");
57 return -1;
58 }
59
60 rc_enable_servo_power_rail();
61 rc_send_servo_pulse_normalized(1, -1);
62 rc_send_servo_pulse_normalized(2, -1);
63 rc_set_state(RUNNING);
64
65 while (rc_get_state() != EXITING)
66 {
67 /*
68 if (rc_get_state() == RUNNING)
69 {
70 rc_set_led(GREEN, ON);
71 rc_set_led(RED, ON);
72 }
73 else if (rc_get_state() == PAUSED)
74 {
75 rc_set_led(GREEN, OFF);
76 rc_set_led(RED, ON);
77 }
78 */
79 usleep(100000);
80 }
81
82 rc_disable_servo_power_rail();
83 rc_cleanup();
84 return 0;
85
86 /*
5387 i2c = open("/dev/i2c-0", O_RDWR);
5488 if (i2c < 0)
5589 {
74108 buf[1] = CONFIG_REF_FILTER | CONFIG_QUICK_TERM;
75109 if (!register_write(i2c, buf, 2))
76110 return 1;
111 */
77112 }