subduino 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,323 +0,0 @@
1
- /*
2
- * Arduin v2
3
- *
4
- *
5
- * /home/nofxx/projects/ardo/control
6
- *
7
- *
8
- */
9
-
10
- #define SEC 1000
11
- #define MIN 60000
12
- #define HOUR 3600000
13
- #define DAY 86400000
14
- #define MAX 50
15
-
16
- // Output
17
- const int rxPin = 0;
18
- const int txPin = 1;
19
- const int d2 = 2;
20
- const int d3 = 3;
21
- const int d4 = 4;
22
- const int d5 = 5;
23
- const int d6 = 6;
24
- const int d7 = 7;
25
- const int d8 = 8;
26
- const int d9 = 9;
27
- //const int d10 = 10;
28
- //const int d11 = 11;
29
- //const int d12 = 12;
30
- const int infoPin = 13;
31
-
32
- // Input
33
- const int i0 = A0;
34
- const int i1 = A1;
35
- const int i2 = A2;
36
- const int i3 = A3;
37
- const int i4 = A4;
38
- const int i5 = A5;
39
- // Digital
40
- const int d10 = 10;
41
- const int d11 = 11;
42
- const int d12 = 12;
43
-
44
- // Intervals (s)
45
- unsigned long sync = 5 * SEC;
46
- unsigned long time_now, last_sync;
47
-
48
- int i = 0;
49
- int btnState = 0;
50
- int touchState = 0;
51
- int motorState = 0;
52
-
53
- char outbuf[MAX];
54
- char cmdbuf[MAX];
55
-
56
- volatile int rx_state = LOW;
57
- volatile int tx_state = LOW;
58
-
59
-
60
- unsigned long mintomilli(unsigned long m) {
61
- return(m * 60000);
62
- }
63
-
64
- int ctoi( int c )
65
- {
66
- return c - '0';
67
- }
68
-
69
- /*
70
-
71
- Read Sensors Data
72
-
73
- */
74
- void read_sensors() {
75
- sprintf(outbuf, "i0:%d,i1:%d,i2:%d,i3:%d,i4:%d,i5:%d,d11:%d,d12:%d",
76
- analogRead(i0),
77
- analogRead(i1),
78
- analogRead(i2),
79
- analogRead(i3),
80
- analogRead(i4),
81
- analogRead(i5),
82
- digitalRead(d11),
83
- digitalRead(d12));
84
-
85
- Serial.println(outbuf);
86
- }
87
-
88
- void switch_pin(int pin) {
89
- analogWrite(pin, digitalRead(pin) == 0 ? 999 : 0);
90
- }
91
-
92
- void pulse_pin(int pin) {
93
- analogWrite(pin, HIGH);
94
- delay(500);
95
- analogWrite(pin, LOW);
96
- }
97
-
98
- /*
99
-
100
- Command Protocol -> NNvvv
101
- 2 bytes pin number NN
102
- 3 bytes value vvv
103
- Split commands with ','
104
-
105
- 13500,130,13999
106
-
107
- Pin 13 -> 500 -> 000 -> 999
108
-
109
- */
110
- void read_commands() {
111
- char c;
112
- while( Serial.available() && c != '\n' ) { // buffer up a line
113
- c = Serial.read();
114
- if (c == '\n' || c == ',') {
115
- Serial.println("<<");
116
- int pin; int val;
117
- pin = (ctoi(cmdbuf[0])*10) + ctoi(cmdbuf[1]);
118
- val = (ctoi(cmdbuf[2])*100) + (ctoi(cmdbuf[3])*10) + ctoi(cmdbuf[4]);
119
- Serial.println("<<");
120
- analogWrite(pin, val);
121
- i = 0;
122
- } else if (c == 'x') {
123
- read_sensors();
124
- } else {
125
- cmdbuf[i++] = c;
126
- }
127
- }
128
- }
129
-
130
- void setup() {
131
- // Atmega defaults INPUT
132
- pinMode(infoPin, OUTPUT);
133
- pinMode(rxPin, OUTPUT);
134
- pinMode(txPin, OUTPUT);
135
- for (int k=0;k<=7;k++)
136
- pinMode(k,OUTPUT);
137
- // pinMode(d2, OUTPUT);
138
- // pinMode(d3, OUTPUT);
139
- // pinMode(d4, OUTPUT);
140
- // pinMode(d5, OUTPUT);
141
- // pinMode(d6, OUTPUT);
142
- // pinMode(d7, OUTPUT);
143
- // pinMode(d10, OUTPUT);
144
- // digitalWrite(rxPin, 0); FAIL
145
- // digitalWrite(txPin, 0);
146
-
147
-
148
- // attachInterrupt(0, btnLed, CHANGE);
149
- Serial.begin(115200);
150
- }
151
-
152
-
153
- void loop() {
154
- time_now = millis();
155
-
156
- read_commands();
157
-
158
- // Sync over wire
159
- if ( abs(time_now - last_sync) >= sync) {
160
- last_sync = time_now;
161
- read_sensors();
162
- }
163
-
164
-
165
- }
166
-
167
-
168
- // void btnLed() {
169
- // if(digitalRead(d2) == 1) {
170
- // Serial.println("BUTTON");
171
- // digitalWrite(infoPin, HIGH);
172
- // analogWrite(d3, 250);
173
- // if (motorState != 0) {
174
- // motorState = 0;
175
- // } else {
176
- // motorState = 1;
177
- // }
178
- // } else {
179
- // digitalWrite(infoPin, LOW);
180
- // analogWrite(d3, LOW);
181
- // }
182
-
183
- // }
184
-
185
-
186
- // if (motorState != 0) {
187
- // analogWrite(d10, (analogRead(i1)/5));
188
- // } else {
189
- // analogWrite(d10, 0);
190
- // }
191
-
192
- // noInterrupts();
193
- // interrupts();
194
-
195
- // Terminate message with a linefeed and a carriage return
196
- // Serial.print(13,BYTE);
197
- // Serial.print(10,BYTE);
198
-
199
- //Serial.println(touchState);
200
- //Serial.print(byte(50));
201
- // * Serial.print(78, BYTE) gives "N"
202
- // * Serial.print(78, BIN) gives "1001110"
203
- // * Serial.print(78, OCT) gives "116"
204
- // * Serial.print(78, DEC) gives "78"
205
- // * Serial.print(78, HEX) gives "4E"
206
- // * Serial.println(1.23456, 0) gives "1"
207
- // * Serial.println(1.23456, 2) gives "1.23"
208
- // * Serial.println(1.23456, 4) gives "1.2346"
209
- // lightVal = buffer;
210
-
211
- // if (analogRead(i2) > 200) {
212
- // analogWrite(d3, 0);
213
- // } else {
214
- // analogWrite(d3, 250);
215
- // }
216
-
217
-
218
-
219
- // void pulseJob(pin) {
220
- // analogWrite(pin, 250);
221
- // delay(2000);
222
- // analogWrite(pin, LOW);
223
- // }
224
-
225
- // From Doorduino
226
- // http://github.com/martymcguire/Doorduino/blob/master/Doorduino.pde
227
- // Log a system message to console
228
- // void log(char* message)
229
- // {
230
- // static char timeString[20];
231
- // getTime(timeString);
232
-
233
- // Serial.print("[");
234
- // Serial.print(timeString);
235
- // Serial.print("] DOOR: ");
236
- // Serial.println(message);
237
-
238
- // }
239
-
240
- // void readRTC(time& currentTime)
241
- // {
242
- // Wire.beginTransmission(DS1307);
243
- // Wire.send(R_SECS);
244
- // Wire.endTransmission();
245
-
246
- // Wire.requestFrom(DS1307, 7);
247
- // currentTime.second = bcd2Dec(Wire.receive());
248
- // currentTime.minute = bcd2Dec(Wire.receive());
249
- // currentTime.hour = bcd2Dec(Wire.receive());
250
- // currentTime.wkDay = bcd2Dec(Wire.receive());
251
- // currentTime.day = bcd2Dec(Wire.receive());
252
- // currentTime.month = bcd2Dec(Wire.receive());
253
- // currentTime.year = bcd2Dec(Wire.receive());
254
- // }
255
-
256
-
257
- // void setRTC(time& newTime)
258
- // {
259
- // Wire.beginTransmission(DS1307);
260
- // Wire.send(dec2Bcd(R_SECS));
261
- // Wire.send(dec2Bcd(newTime.second));
262
- // Wire.send(dec2Bcd(newTime.minute));
263
- // Wire.send(dec2Bcd(newTime.hour));
264
- // Wire.send(dec2Bcd(newTime.wkDay));
265
- // Wire.send(dec2Bcd(newTime.day));
266
- // Wire.send(dec2Bcd(newTime.month));
267
- // Wire.send(dec2Bcd(newTime.year));
268
- // Wire.endTransmission();
269
- // }
270
-
271
-
272
- // Build a human-readable representation of the current time
273
- // @string character array to put the time in, must be 20 bytes long
274
- // void getTime(char* string)
275
- // {
276
- // // Grab the latest time from the RTC
277
- // time currentTime;
278
- // readRTC(currentTime);
279
-
280
- // // And build a formatted string to represent it
281
- // sprintf(string, "20%02d-%02d-%02dT%02d:%02d:%02dZ",
282
- // currentTime.year, currentTime.month, currentTime.day,
283
- // currentTime.hour, currentTime.minute, currentTime.second);
284
- // }
285
-
286
-
287
- // void setTimeFromSerial()
288
- // {
289
- // time newTime;
290
-
291
- // char temp = 0;
292
-
293
- // // Wait for full time to be received
294
- // for (int i = 0; i < 7; i++)
295
- // {
296
- // while (Serial.available() == 0) {}
297
-
298
- // temp = Serial.read();
299
-
300
- // switch (i) {
301
- // case 0: newTime.year = temp; break;
302
- // case 1: newTime.month = temp; break;
303
- // case 2: newTime.day = temp; break;
304
- // case 3: newTime.wkDay = temp; break;
305
- // case 4: newTime.hour = temp; break;
306
- // case 5: newTime.minute = temp; break;
307
- // case 6: newTime.second = temp; break;
308
- // }
309
- // }
310
-
311
- // setRTC(newTime);
312
- // }
313
-
314
-
315
- byte bcd2Dec(byte bcdVal)
316
- {
317
- return bcdVal / 16 * 10 + bcdVal % 16;
318
- }
319
-
320
- byte dec2Bcd(byte decVal)
321
- {
322
- return decVal / 10 * 16 + decVal % 10;
323
- }
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # SCAFFOLD
4
- #
5
- #
6
-
7
- require "rubygems"
8
- require "subduino"
9
-
10
-
11
- Subduino.start do |r|
12
- puts "Received #{r}"
13
- end
14
-
15
- # Subduino.write("Hi")
16
-
@@ -1,5 +0,0 @@
1
-
2
- void testFalse() {
3
- // do something
4
-
5
- }
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # usage: usb-power bus/device port on|off
4
- #
5
- # example:
6
- # usb-power 004/006 2 on
7
- # usb-power 004/006 2 off
8
-
9
- require 'usb'
10
- require 'optparse'
11
-
12
- USB_RT_PORT = USB::USB_TYPE_CLASS | USB::USB_RECIP_OTHER
13
- USB_PORT_FEAT_POWER = 8
14
-
15
- USB.devices.find_all {|d|
16
- # p d
17
- 0x200 <= d.bcdDevice &&
18
- d.bDeviceClass == USB::USB_CLASS_HUB
19
- }
20
-
21
- # require 'pp'
22
-
23
- # def power_on(h, port)
24
- # h.usb_control_msg(USB_RT_PORT, USB::USB_REQ_SET_FEATURE, USB_PORT_FEAT_POWER, port, "", 0)
25
- # end
26
-
27
- # def power_off(h, port)
28
- # h.usb_control_msg(USB_RT_PORT, USB::USB_REQ_CLEAR_FEATURE, USB_PORT_FEAT_POWER, port, "", 0)
29
- # end
30
-
31
- # bus_device = ARGV.shift
32
- # port = ARGV.shift.to_i
33
- # on_off = ARGV.shift
34
-
35
- # %r{/} =~ bus_device
36
- # bus = $`.to_i
37
- # device = $'.to_i
38
-
39
- # USB.find_bus(bus).find_device(device).open {|h|
40
- # if on_off == 'off'
41
- # power_off(h, port)
42
- # else
43
- # power_on(h, port)
44
- # end
45
- # }
@@ -1,187 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /usr/include/ruby-1.9.1
8
- hdrdir = /usr/include/ruby-1.9.1
9
- arch_hdrdir = /usr/include/ruby-1.9.1/$(arch)
10
- VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
11
- prefix = $(DESTDIR)/usr
12
- rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
13
- exec_prefix = $(prefix)
14
- vendorhdrdir = $(rubyhdrdir)/vendor_ruby
15
- sitehdrdir = $(rubyhdrdir)/site_ruby
16
- rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
17
- vendordir = $(rubylibprefix)/vendor_ruby
18
- sitedir = $(rubylibprefix)/site_ruby
19
- ridir = $(datarootdir)/$(RI_BASE_NAME)
20
- mandir = $(datarootdir)/man
21
- localedir = $(datarootdir)/locale
22
- libdir = $(exec_prefix)/lib
23
- psdir = $(docdir)
24
- pdfdir = $(docdir)
25
- dvidir = $(docdir)
26
- htmldir = $(docdir)
27
- infodir = $(datarootdir)/info
28
- docdir = $(datarootdir)/doc/$(PACKAGE)
29
- oldincludedir = $(DESTDIR)/usr/include
30
- includedir = $(prefix)/include
31
- localstatedir = $(prefix)/var
32
- sharedstatedir = $(prefix)/com
33
- sysconfdir = $(prefix)/etc
34
- datadir = $(datarootdir)
35
- datarootdir = $(prefix)/share
36
- libexecdir = $(exec_prefix)/libexec
37
- sbindir = $(exec_prefix)/sbin
38
- bindir = $(exec_prefix)/bin
39
- rubylibdir = $(rubylibprefix)/$(ruby_version)
40
- archdir = $(rubylibdir)/$(arch)
41
- sitelibdir = $(sitedir)/$(ruby_version)
42
- sitearchdir = $(sitelibdir)/$(sitearch)
43
- vendorlibdir = $(vendordir)/$(ruby_version)
44
- vendorarchdir = $(vendorlibdir)/$(sitearch)
45
-
46
- CC = gcc
47
- CXX = g++
48
- LIBRUBY = $(LIBRUBY_SO)
49
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
50
- LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
51
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
52
- OUTFLAG = -o
53
- COUTFLAG = -o
54
-
55
- RUBY_EXTCONF_H =
56
- cflags = $(optflags) $(debugflags) $(warnflags)
57
- optflags = -O3
58
- debugflags = -ggdb
59
- warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long
60
- CFLAGS = -fPIC -march=x86-64 -mtune=generic -O3 -pipe -fPIC -std=c99 -Wall -I.
61
- INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
62
- DEFS =
63
- CPPFLAGS = $(DEFS) $(cppflags)
64
- CXXFLAGS = $(CFLAGS) -march=x86-64 -mtune=generic -O2 -pipe
65
- ldflags = -L. -rdynamic -Wl,-export-dynamic
66
- dldflags =
67
- ARCH_FLAG =
68
- DLDFLAGS = $(ldflags) $(dldflags)
69
- LDSHARED = $(CC) -shared
70
- LDSHAREDXX = $(CXX) -shared
71
- AR = ar
72
- EXEEXT =
73
-
74
- RUBY_BASE_NAME = ruby
75
- RUBY_INSTALL_NAME = ruby
76
- RUBY_SO_NAME = ruby
77
- arch = x86_64-linux
78
- sitearch = $(arch)
79
- ruby_version = 1.9.1
80
- ruby = /usr/bin/ruby
81
- RUBY = $(ruby)
82
- RM = rm -f
83
- RM_RF = $(RUBY) -run -e rm -- -rf
84
- RMDIRS = $(RUBY) -run -e rmdir -- -p
85
- MAKEDIRS = /bin/mkdir -p
86
- INSTALL = /bin/install -c
87
- INSTALL_PROG = $(INSTALL) -m 0755
88
- INSTALL_DATA = $(INSTALL) -m 644
89
- COPY = cp
90
-
91
- #### End of system configuration section. ####
92
-
93
- preload =
94
-
95
- libpath = . $(libdir)
96
- LIBPATH = -L. -L$(libdir)
97
- DEFFILE =
98
-
99
- CLEANFILES = mkmf.log
100
- DISTCLEANFILES =
101
- DISTCLEANDIRS =
102
-
103
- extout =
104
- extout_prefix =
105
- target_prefix =
106
- LOCAL_LIBS =
107
- LIBS = $(LIBRUBYARG_SHARED) -lpthread -lrt -ldl -lcrypt -lm -lc
108
- SRCS = cubduino.c
109
- OBJS = cubduino.o
110
- TARGET = cubduino
111
- DLLIB = $(TARGET).so
112
- EXTSTATIC =
113
- STATIC_LIB =
114
-
115
- BINDIR = $(bindir)
116
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
117
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
118
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
119
- HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
120
- ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
121
-
122
- TARGET_SO = $(DLLIB)
123
- CLEANLIBS = $(TARGET).so
124
- CLEANOBJS = *.o *.bak
125
-
126
- all: $(DLLIB)
127
- static: $(STATIC_LIB)
128
- .PHONY: all install static install-so install-rb
129
- .PHONY: clean clean-so clean-rb
130
-
131
- clean-rb-default::
132
- clean-rb::
133
- clean-so::
134
- clean: clean-so clean-rb-default clean-rb
135
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
136
-
137
- distclean-rb-default::
138
- distclean-rb::
139
- distclean-so::
140
- distclean: clean distclean-so distclean-rb-default distclean-rb
141
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
142
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
143
- @-$(RMDIRS) $(DISTCLEANDIRS)
144
-
145
- realclean: distclean
146
- install: install-so install-rb
147
-
148
- install-so: $(RUBYARCHDIR)
149
- install-so: $(RUBYARCHDIR)/$(DLLIB)
150
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
151
- @-$(MAKEDIRS) $(@D)
152
- $(INSTALL_PROG) $(DLLIB) $(@D)
153
- install-rb: pre-install-rb install-rb-default
154
- install-rb-default: pre-install-rb-default
155
- pre-install-rb: Makefile
156
- pre-install-rb-default: Makefile
157
- $(RUBYARCHDIR):
158
- $(MAKEDIRS) $@
159
-
160
- site-install: site-install-so site-install-rb
161
- site-install-so: install-so
162
- site-install-rb: install-rb
163
-
164
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
165
-
166
- .cc.o:
167
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
168
-
169
- .cxx.o:
170
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
171
-
172
- .cpp.o:
173
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
174
-
175
- .C.o:
176
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
177
-
178
- .c.o:
179
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
180
-
181
- $(DLLIB): $(OBJS) Makefile
182
- @-$(RM) $(@)
183
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
184
-
185
-
186
-
187
- $(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h