brick-pi 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e63e867f917f20a008427c1096e7ba94b267c890
4
- data.tar.gz: 78a16b7c6cb6a76bf6c94bcea3091a2e52d0eedb
3
+ metadata.gz: 52a6145f0302f94616c86ac57f985b411ccee798
4
+ data.tar.gz: baa03984e55a2445f2351b46cef2c4a47baf0891
5
5
  SHA512:
6
- metadata.gz: 34a9ac8a0def422ffd6d6fb5109d58e52288ec7efdcb4058395c6433a2b186896468c9e8b19f8d5494397da5091a78de95978a6676ca1c1f4856c1b1d395b43b
7
- data.tar.gz: 2d082af9c7dc6311e142864f3f7164328e0c190a21dd817faef757fa657249576245649beeebdcfb66a70e3fe8017f908bf63edf48f591d2632d87a8dc236d77
6
+ metadata.gz: 8f1caeaf3d1d7b2daad62daabaa713cb7522bb6debf10891949c28d619b2f65591f2c82ab5b8df88da1372d697b84c2ad4597a50550bf4dd22aaffa10f2a2ab6
7
+ data.tar.gz: f0d2e46ab5af41b6315e3315a939a239f624bba3b05daf625fbf5fe01ee902f1f9350909bbf25155adc808921f49a4d6beb961714277b74d4a4c493baab26fef
data/README.md CHANGED
@@ -2,14 +2,21 @@
2
2
 
3
3
  ruby wrappers for the BrickPi Lego Mindstorms C library
4
4
 
5
- TODO: Write a gem description
6
- TODO: Tag, version, and publish as gem
5
+ ## What you need:
6
+
7
+ You need to have a few things to use this:
8
+
9
+ - The wonderful [BrickPi](http://www.dexterindustries.com/BrickPi.html) from Dexter Industries
10
+ - A Raspberry Pi (if you didn't get one with the BrickPi)
11
+ - Lego Mindstorms NXT 2.0 motors and/or sensors
7
12
 
8
13
  ## Installation
9
14
 
15
+ **Note: This gem will currently only install on a Raspberry Pi set up with BrickPi software. It relies on the `WiringPi.h` C program to function and compile.
16
+
10
17
  Add this line to your application's Gemfile:
11
18
 
12
- gem 'brick_pi'
19
+ gem 'brick-pi'
13
20
 
14
21
  And then execute:
15
22
 
@@ -17,7 +24,7 @@ And then execute:
17
24
 
18
25
  Or install it yourself as:
19
26
 
20
- $ gem install brick_pi
27
+ $ gem install brick-pi
21
28
 
22
29
  ## Usage
23
30
 
@@ -5,6 +5,11 @@
5
5
  VALUE bprb_BrickPiSetup(VALUE self) {
6
6
  return INT2FIX(BrickPiSetup());
7
7
  }
8
+
9
+ VALUE bprb_BrickPiSetupSensors(VALUE self) {
10
+ return INT2FIX(BrickPiSetupSensors());
11
+ }
12
+
8
13
  VALUE bprb_ClearTick(VALUE self) {
9
14
  return INT2FIX(ClearTick());
10
15
  }
@@ -32,6 +37,22 @@ VALUE bprb_Timeout_set(VALUE self, VALUE timeout) {
32
37
  return timeout;
33
38
  }
34
39
 
40
+ VALUE bprb_SensorType_set(VALUE self, VALUE key, VALUE value) {
41
+ int index = FIX2INT(key);
42
+ BrickPi.SensorType[index] = FIX2INT(value);
43
+ return value;
44
+ }
45
+
46
+ VALUE bprb_Sensor_get(VALUE self, VALUE key) {
47
+ int index = FIX2INT(key);
48
+ return INT2FIX(BrickPi.Sensor[index]);
49
+ }
50
+
51
+ VALUE bprb_Encoder_get(VALUE self, VALUE key) {
52
+ int index = FIX2INT(key);
53
+ return INT2FIX(BrickPi.Encoder[index]);
54
+ }
55
+
35
56
  VALUE bprb_BrickPiSetTimeout(VALUE self) {
36
57
  return INT2FIX(BrickPiSetTimeout());
37
58
  }
@@ -44,6 +65,7 @@ void Init_native() {
44
65
  VALUE BrickPi = rb_define_module("BrickPi");
45
66
  VALUE Native = rb_define_module_under(BrickPi, "Native");
46
67
  rb_define_singleton_method(Native, "BrickPiSetup", bprb_BrickPiSetup, 0);
68
+ rb_define_singleton_method(Native, "BrickPiSetupSensors", bprb_BrickPiSetupSensors, 0);
47
69
  rb_define_singleton_method(Native, "ClearTick", bprb_ClearTick, 0);
48
70
  VALUE MotorSpeed = rb_define_module_under(Native, "MotorSpeed");
49
71
  rb_define_singleton_method(MotorSpeed, "[]=", bprb_MotorSpeed_set, 2);
@@ -51,6 +73,13 @@ void Init_native() {
51
73
  rb_define_singleton_method(MotorEnable, "[]=", bprb_MotorEnable_set, 2);
52
74
  VALUE Address = rb_define_module_under(Native, "Address");
53
75
  rb_define_singleton_method(Address, "[]=", bprb_Address_set, 2);
76
+ VALUE SensorType = rb_define_module_under(Native, "SensorType");
77
+ rb_define_singleton_method(SensorType, "[]=", bprb_SensorType_set, 2);
78
+ VALUE Sensor = rb_define_module_under(Native, "Sensor");
79
+ rb_define_singleton_method(Sensor, "[]", bprb_Sensor_get, 1);
80
+ VALUE Encoder = rb_define_module_under(Native, "Encoder");
81
+ rb_define_singleton_method(Encoder, "[]", bprb_Encoder_get, 1);
82
+
54
83
  rb_define_singleton_method(Native, "Timeout=", bprb_Timeout_set, 1);
55
84
  rb_define_singleton_method(Native, "BrickPiSetTimeout", bprb_BrickPiSetTimeout, 0);
56
85
  rb_define_singleton_method(Native, "BrickPiUpdateValues", bprb_BrickPiUpdateValues, 0);
@@ -62,4 +91,13 @@ void Init_native() {
62
91
  rb_define_const(Native, "PORT_2", INT2FIX(1));
63
92
  rb_define_const(Native, "PORT_3", INT2FIX(2));
64
93
  rb_define_const(Native, "PORT_4", INT2FIX(3));
94
+ rb_define_const(Native, "US_PORT", INT2FIX(2));
95
+ rb_define_const(Native, "TYPE_SENSOR_TOUCH", INT2FIX(32));
96
+ rb_define_const(Native, "TYPE_SENSOR_ULTRASONIC_CONT", INT2FIX(33));
97
+ rb_define_const(Native, "TYPE_SENSOR_ULTRASONIC_SS", INT2FIX(34));
98
+ rb_define_const(Native, "TYPE_SENSOR_COLOR_FULL", INT2FIX(36));
99
+ rb_define_const(Native, "TYPE_SENSOR_COLOR_RED", INT2FIX(37));
100
+ rb_define_const(Native, "TYPE_SENSOR_COLOR_GREEN", INT2FIX(38));
101
+ rb_define_const(Native, "TYPE_SENSOR_COLOR_BLUE", INT2FIX(39));
102
+ rb_define_const(Native, "TYPE_SENSOR_COLOR_NONE", INT2FIX(40));
65
103
  }
@@ -3,7 +3,7 @@ include BrickPi
3
3
 
4
4
  module BrickPi
5
5
  class Bot
6
- attr_accessor :motor1, :motor2
6
+ attr_accessor :motor1, :motor2, :motor3, :motor4
7
7
 
8
8
  def initialize
9
9
  Native.BrickPiSetup()
@@ -12,6 +12,12 @@ module BrickPi
12
12
  Native::MotorSpeed[@port] = motor_speed
13
13
  end
14
14
 
15
+ # Encoder reads the position of the motor in .5-degree increments,
16
+ # Divide by 2 to get degrees
17
+ def position
18
+ Native::Encoder[@port] / 2
19
+ end
20
+
15
21
  def stop
16
22
  spin 0
17
23
  end
@@ -0,0 +1,32 @@
1
+ module BrickPi
2
+ class Sensor
3
+ SENSOR_TYPES = {
4
+ touch: Native::TYPE_SENSOR_TOUCH,
5
+ ultrasonic: Native::TYPE_SENSOR_ULTRASONIC_CONT,
6
+ color: Native::TYPE_SENSOR_COLOR_FULL,
7
+ color_red: Native::TYPE_SENSOR_COLOR_RED,
8
+ color_green: Native::TYPE_SENSOR_COLOR_GREEN,
9
+ color_blue: Native::TYPE_SENSOR_COLOR_BLUE,
10
+ color_none: Native::TYPE_SENSOR_COLOR_NONE
11
+ }
12
+
13
+ PORTS = {
14
+ port_1: Native::PORT_1,
15
+ port_2: Native::PORT_2,
16
+ port_3: Native::PORT_3,
17
+ port_4: Native::PORT_4
18
+ }
19
+
20
+ # So you can be all like `BrickPi::Sensor.new(:port_3, :ultrasonic)`
21
+ def initialize(port, sensor_type)
22
+ @port = port
23
+ @sensor_type = sensor_type
24
+ Native::SensorType[PORT_MAP[@port]] = SENSOR_TYPES[@sensor_type]
25
+ Native::BrickPiSetupSensors()
26
+ end
27
+
28
+ def read
29
+ Native::Sensor[@port]
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module BrickPi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick-pi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hays
@@ -63,6 +63,7 @@ files:
63
63
  - lib/brick_pi.rb
64
64
  - lib/brick_pi/bot.rb
65
65
  - lib/brick_pi/motor.rb
66
+ - lib/brick_pi/sensor.rb
66
67
  - lib/brick_pi/version.rb
67
68
  homepage: ''
68
69
  licenses: