bonekit 0.0.4-arm-linux → 0.0.5-arm-linux

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ # This is the most basic ntp configuration file
2
+ # The driftfile must remain in a place specific to this
3
+ # machine - it records the machine specific clock error
4
+
5
+ driftfile /etc/ntp.drift
6
+ logfile /var/log/ntpd.log
7
+
8
+ # NTP Servers for Ireland from www.pool.ntp.org
9
+ server 0.pool.ntp.org
10
+ server 1.pool.ntp.org
11
+ server 2.pool.ntp.org
12
+ server 3.pool.ntp.org
13
+
14
+ # Using local hardware clock as fallback
15
+ # Disable this when using ntpd -q -g -x as ntpdate or it will sync to itself
16
+ # server 127.127.1.0
17
+ # fudge 127.127.1.0 stratum 14
18
+
19
+ # Defining a default security setting
20
+ restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
@@ -0,0 +1,12 @@
1
+ [Unit]
2
+ Description=Network Time Service (one-shot ntpdate mode)
3
+ Before=ntpd.service
4
+
5
+ [Service]
6
+ Type=oneshot
7
+ ExecStart=/usr/bin/ntpd -q -g -x
8
+ ExecStart=/sbin/hwclock --systohc
9
+ RemainAfterExit=yes
10
+
11
+ [Install]
12
+ WantedBy=multi-user.target
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+
3
+ # system
4
+ opkg update
5
+ opkg upgrade
6
+
7
+ # ntp
8
+ opkg install ntp
9
+ cp ntp.conf /etc/ntp.conf
10
+ rm /etc/localtime
11
+ ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
12
+ systemctl enable ntpdate.service
13
+ systemctl enable ntpd.service
14
+ cp ntpdate.service /lib/systemd/system/ntpdate.service
15
+
16
+ # ruby
17
+ opkg install ruby
18
+ cp mkmf.rb /usr/lib/ruby/mkmf.rb
19
+
@@ -0,0 +1,33 @@
1
+ #! /bin/sh
2
+ # /etc/init.d/wifi
3
+ #
4
+
5
+ DESC="Wifi script"
6
+
7
+ case "$1" in
8
+ start)
9
+ echo -n "Starting $DESC: "
10
+ sleep 5
11
+ kill -9 `pgrep wpa`
12
+ wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf -B
13
+ sleep 5
14
+ /sbin/udhcpc -iwlan0 > /var/log/wifi_init.log &
15
+ ;;
16
+ stop)
17
+ echo -n "Stopping $DESC: "
18
+ ;;
19
+ restart)
20
+ echo -n "Restarting $DESC: "
21
+ kill -9 `pgrep wpa`
22
+ wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf -B
23
+ sleep 5
24
+ /sbin/udhcpc -iwlan0 > /var/log/wifi_init.log &
25
+ ;;
26
+ *)
27
+ N=/etc/init.d/$NAME
28
+ echo "Usage: $N {start|stop|restart}" >&2
29
+ exit 1
30
+ ;;
31
+ esac
32
+
33
+ exit 0
@@ -0,0 +1,19 @@
1
+ # Accelerometer - Simple test of the functionality of the ADXL345 3-Axis Digital Accelerometer IC
2
+ #
3
+ # Connections:
4
+ # CS to pin P9-4 (VDD_3V3)
5
+ # VCC to pin P9-4 (VDD_3V3)
6
+ # GND to pin P9-2 (DGND)
7
+ # SCL to P9_19 (I2C2_SCL)
8
+ # SDA to P9_20 (I2C2_SDA)
9
+ #
10
+
11
+ require 'bonekit'
12
+
13
+ accelerometer = ADXL345.new
14
+
15
+ loop do
16
+ raw_acceleration = accelerometer.raw_acceleration
17
+ puts "Raw Acceleration:\nx #{raw_acceleration[0]}\ny #{raw_acceleration[1]}\nz #{raw_acceleration[2]}\n"
18
+ sleep(0.1)
19
+ end
data/ext/bonekit/adc.h CHANGED
@@ -25,8 +25,8 @@
25
25
 
26
26
  */
27
27
 
28
- #ifndef BONEKIT_ADC_H__
29
- #define BONEKIT_ADC_H__
28
+ #ifndef __BONEKIT_ADC_H__
29
+ #define __BONEKIT_ADC_H__
30
30
 
31
31
  #ifdef __cplusplus
32
32
  extern "C" {
@@ -0,0 +1,90 @@
1
+ /*
2
+
3
+ adxl345.c
4
+ BoneKit
5
+
6
+ Copyright (cc) 2012 Luis Laugga.
7
+ Some rights reserved, all wrongs deserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
10
+ this software and associated documentation files (the "Software"), to deal in
11
+ the Software without restriction, including without limitation the rights to
12
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
+ the Software, and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ */
27
+
28
+ #include "adxl345.h"
29
+
30
+ #define ADXL345_Address 0x53
31
+
32
+ #define ADXL345_Register_Power_Control 0x2d
33
+ #define ADXL345_Register_Data_Format 0x31
34
+ #define ADXL345_Register_Data_Begin 0x32
35
+
36
+ #define ADXL345_Mode_Measurement 0x08 // Register 0x2D—POWER_CTL (Read/Write), Measure bit (D3) set to 1, 0b00001000
37
+ #define ADXL345_Mode_Range_4G 0x01 // Register 0x31—DATA_FORMAT (Read/Write), Range bits (D0-D1) set to 1, 0x00000001
38
+
39
+ #include <math.h>
40
+
41
+ #define M_180_div_PI 57.2957795131
42
+ #define M_2PI 6.28318530718
43
+
44
+ adxl345_t * adxl345_create()
45
+ {
46
+ adxl345_t * obj;
47
+ obj = malloc(sizeof(struct adxl345_s));
48
+ if(obj)
49
+ {
50
+ // Initialize
51
+ obj->_i2c = i2c_alloc();
52
+ i2c_init(obj->_i2c, ADXL345_Address);
53
+
54
+ // Setup mode
55
+ uint8_t data_setup[2] = {ADXL345_Register_Data_Format, ADXL345_Mode_Range_4G};
56
+ i2c_write(obj->_i2c, data_setup, 2);
57
+ uint8_t power_setup[2] = {ADXL345_Register_Power_Control, ADXL345_Mode_Measurement};
58
+ i2c_write(obj->_i2c, power_setup, 2);
59
+ }
60
+
61
+ return obj;
62
+ }
63
+
64
+ void adxl345_destroy(adxl345_t * obj)
65
+ {
66
+ if(obj)
67
+ {
68
+ i2c_destroy(obj->_i2c);
69
+ free(obj);
70
+ }
71
+ }
72
+
73
+ adxl345_vec3_raw_t * adxl345_raw_acceleration(adxl345_t * obj)
74
+ {
75
+ uint8_t write_data[1] = {ADXL345_Register_Data_Begin};
76
+ uint8_t read_data[6];
77
+
78
+ i2c_write(obj->_i2c, write_data, 1); // check if success before read
79
+ i2c_read(obj->_i2c, read_data, 6); // check if success before calculate heading
80
+
81
+ int x = (read_data[1] << 8) | read_data[0];
82
+ int y = (read_data[3] << 8) | read_data[2];
83
+ int z = (read_data[5] << 8) | read_data[4];
84
+
85
+ obj->_raw_acceleration.x = x;
86
+ obj->_raw_acceleration.y = y;
87
+ obj->_raw_acceleration.z = z;
88
+
89
+ return &(obj->_raw_acceleration);
90
+ }
@@ -0,0 +1,67 @@
1
+ /*
2
+
3
+ adxl345.h
4
+ BoneKit
5
+
6
+ Copyright (cc) 2012 Luis Laugga.
7
+ Some rights reserved, all wrongs deserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
10
+ this software and associated documentation files (the "Software"), to deal in
11
+ the Software without restriction, including without limitation the rights to
12
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
+ the Software, and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ */
27
+
28
+ #ifndef __BONEKIT_ADXL345_H__
29
+ #define __BONEKIT_ADXL345_H__
30
+
31
+ #ifdef __cplusplus
32
+ extern "C" {
33
+ #endif
34
+
35
+ #include "i2c.h"
36
+
37
+ typedef struct
38
+ {
39
+ float x;
40
+ float y;
41
+ float z;
42
+ } adxl345_vec3_scaled_t;
43
+
44
+ typedef struct
45
+ {
46
+ int x;
47
+ int y;
48
+ int z;
49
+ } adxl345_vec3_raw_t;
50
+
51
+ struct adxl345_s
52
+ {
53
+ adxl345_vec3_raw_t _raw_acceleration;
54
+ i2c_t * _i2c;
55
+ };
56
+
57
+ typedef struct adxl345_s adxl345_t;
58
+
59
+ adxl345_t * adxl345_create();
60
+ void adxl345_destroy(adxl345_t *);
61
+ adxl345_vec3_raw_t * adxl345_raw_acceleration(adxl345_t * obj);
62
+
63
+ #ifdef __cplusplus
64
+ }
65
+ #endif
66
+
67
+ #endif
@@ -0,0 +1,86 @@
1
+ /*
2
+
3
+ adxl345_class.h
4
+ BoneKit
5
+
6
+ Copyright (cc) 2012 Luis Laugga.
7
+ Some rights reserved, all wrongs deserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
10
+ this software and associated documentation files (the "Software"), to deal in
11
+ the Software without restriction, including without limitation the rights to
12
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
+ the Software, and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ */
27
+
28
+ #include "adxl345_class.h"
29
+
30
+ #include "ruby.h"
31
+ #include "bonekit.h"
32
+
33
+ VALUE cBoneKit_ADXL345;
34
+
35
+ static void ADXL345_free(void * ptr)
36
+ {
37
+ if(ptr == NULL)
38
+ return;
39
+
40
+ adxl345_destroy(ptr);
41
+ }
42
+
43
+ /*
44
+ * call-seq:
45
+ * initialize() -> ADXL345
46
+ *
47
+ * Returns a new ADXL345 object.
48
+ */
49
+ static VALUE ADXL345_new(VALUE class)
50
+ {
51
+ adxl345_t * ptr = adxl345_create();
52
+ VALUE wrap_struct = Data_Wrap_Struct(class, 0, ADXL345_free, ptr);
53
+ return wrap_struct;
54
+ }
55
+
56
+ /*
57
+ * call-seq:
58
+ * raw_acceleration() -> Array
59
+ *
60
+ * Returns an Array with the raw acceleration values ([x,y,z]).
61
+ * The ADXL345 is pre-configured for measuring values in the +/-4g range.
62
+ */
63
+ static VALUE ADXL345_raw_acceleration(VALUE self)
64
+ {
65
+ adxl345_t * ptr;
66
+ Data_Get_Struct(self, adxl345_t, ptr);
67
+
68
+ adxl345_vec3_raw_t * raw_acceleration = adxl345_raw_acceleration(ptr);
69
+
70
+ VALUE value = rb_ary_new2(3);
71
+
72
+ rb_ary_push(value, INT2FIX(raw_acceleration->x));
73
+ rb_ary_push(value, INT2FIX(raw_acceleration->y));
74
+ rb_ary_push(value, INT2FIX(raw_acceleration->z));
75
+
76
+ return value;
77
+ }
78
+
79
+ void BoneKit_ADXL345_class_init()
80
+ {
81
+ cBoneKit_ADXL345 = rb_define_class("ADXL345", rb_cObject);
82
+
83
+ rb_define_singleton_method(cBoneKit_ADXL345, "new", ADXL345_new, 0);
84
+
85
+ rb_define_method(cBoneKit_ADXL345, "raw_acceleration", ADXL345_raw_acceleration, 0);
86
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+
3
+ adxl345_class.h
4
+ BoneKit
5
+
6
+ Copyright (cc) 2012 Luis Laugga.
7
+ Some rights reserved, all wrongs deserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
10
+ this software and associated documentation files (the "Software"), to deal in
11
+ the Software without restriction, including without limitation the rights to
12
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
+ the Software, and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ */
27
+
28
+ #ifndef __BONEKIT_ADXL345_CLASS_H__
29
+ #define __BONEKIT_ADXL345_CLASS_H__
30
+
31
+ void BoneKit_ADXL345_class_init();
32
+
33
+ #endif
@@ -25,8 +25,8 @@
25
25
 
26
26
  */
27
27
 
28
- #ifndef BONEKIT_BEAGLEBONE_H__
29
- #define BONEKIT_BEAGLEBONE_H__
28
+ #ifndef __BONEKIT_BEAGLEBONE_H__
29
+ #define __BONEKIT_BEAGLEBONE_H__
30
30
 
31
31
  #ifdef __cplusplus
32
32
  extern "C" {
@@ -25,11 +25,11 @@
25
25
 
26
26
  */
27
27
 
28
- #ifndef BONEKIT_BEAGLEBONE_GLOBAL_CONST_H__
29
- #define BONEKIT_BEAGLEBONE_GLOBAL_CONST_H__
28
+ #ifndef __BONEKIT_BEAGLEBONE_GLOBAL_CONST_H__
29
+ #define __BONEKIT_BEAGLEBONE_GLOBAL_CONST_H__
30
30
 
31
31
  #include "ruby.h"
32
- #include "beaglebone.h"
32
+ #include "bonekit.h"
33
33
 
34
34
  int Beaglebone_global_const_check_type(VALUE);
35
35
  beaglebone_t * Beaglebone_global_const_to_beaglebone_t(VALUE);
@@ -0,0 +1,49 @@
1
+ /*
2
+
3
+ bonekit.h
4
+ BoneKit
5
+
6
+ Copyright (cc) 2012 Luis Laugga.
7
+ Some rights reserved, all wrongs deserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
10
+ this software and associated documentation files (the "Software"), to deal in
11
+ the Software without restriction, including without limitation the rights to
12
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
+ the Software, and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ */
27
+
28
+ #ifndef __BONEKIT_BONEKIT_H__
29
+ #define __BONEKIT_BONEKIT_H__
30
+
31
+ #include <signal.h>
32
+ #include <unistd.h>
33
+
34
+ #include <stdio.h>
35
+ #include <stdlib.h>
36
+ #include <stdbool.h>
37
+ #include <string.h>
38
+
39
+ #include "beaglebone.h"
40
+ #include "gpio.h"
41
+ #include "adc.h"
42
+ #include "pwm.h"
43
+ #include "pin.h"
44
+
45
+ #include "i2c.h"
46
+ #include "hmc5883l.h"
47
+ #include "adxl345.h"
48
+
49
+ #endif