raspberry_pi_iot 0.0.8 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +5 -5
  2. data/doc/IoT.html +8 -6
  3. data/doc/{Bus.html → RaspberryPiIoT.html} +21 -26
  4. data/doc/_index.html +84 -77
  5. data/doc/class_list.html +1 -1
  6. data/doc/file.LICENSE.html +92 -0
  7. data/doc/file.README.html +63 -29
  8. data/doc/file_list.html +5 -0
  9. data/doc/frames.html +1 -1
  10. data/doc/index.html +63 -29
  11. data/doc/method_list.html +170 -202
  12. data/doc/top-level-namespace.html +4 -6
  13. data/lib/bus.rb +0 -2
  14. data/lib/iot.rb +4 -2
  15. data/lib/iot/actuator.rb +7 -0
  16. data/lib/iot/bh1750.rb +54 -0
  17. data/lib/iot/binary_actuator.rb +7 -0
  18. data/lib/iot/binary_effector.rb +11 -0
  19. data/lib/iot/binary_receptor.rb +20 -0
  20. data/lib/iot/binary_sensor.rb +7 -0
  21. data/lib/iot/bmx_sensor.rb +73 -0
  22. data/lib/iot/button.rb +100 -0
  23. data/lib/iot/dht_sensor.rb +41 -0
  24. data/lib/iot/digital_actuator.rb +7 -0
  25. data/lib/iot/digital_effector.rb +67 -0
  26. data/lib/iot/digital_receptor.rb +17 -0
  27. data/lib/iot/digital_sensor.rb +7 -0
  28. data/lib/iot/ds18b20.rb +25 -0
  29. data/lib/iot/effector.rb +32 -0
  30. data/lib/iot/hcsr501.rb +8 -0
  31. data/lib/iot/humiture_sensor.rb +27 -0
  32. data/lib/iot/led.rb +64 -0
  33. data/lib/iot/led_pwm.rb +8 -0
  34. data/lib/iot/led_rgb.rb +86 -0
  35. data/lib/iot/max44009.rb +84 -0
  36. data/lib/iot/receptor.rb +38 -0
  37. data/lib/iot/sensor.rb +8 -0
  38. data/lib/iot/temperature_sensor.rb +51 -0
  39. data/lib/raspberry_pi.rb +46 -1
  40. data/lib/raspberry_pi_iot.rb +9 -3
  41. data/lib/raspberry_pi_iot/version.rb +3 -0
  42. data/lib/thermal_sensor.rb +2 -3
  43. data/test/test.sh +17 -0
  44. data/test/test.txt +173 -0
  45. data/test/test_Raspberry_Pi_IoT.rb +10 -0
  46. data/test/test_bh1750.rb +9 -4
  47. data/test/{standalone_test_bmp280.rb → test_bme280.rb} +24 -19
  48. data/test/test_bmp280.rb +52 -0
  49. data/test/test_button.rb +25 -14
  50. data/test/test_dht11.rb +3 -3
  51. data/test/test_dht22.rb +35 -0
  52. data/test/test_ds18b20.rb +4 -3
  53. data/test/test_helper.rb +6 -0
  54. data/test/test_info.rb +24 -3
  55. data/test/test_ky008.rb +41 -0
  56. data/test/test_led.rb +9 -9
  57. data/test/test_led_rgb.rb +28 -5
  58. data/test/test_max44009_gy49.rb +4 -4
  59. data/test/test_thermal.rb +27 -0
  60. metadata +103 -59
  61. data/doc/Actuator.html +0 -145
  62. data/doc/BH1750.html +0 -541
  63. data/doc/BME280.html +0 -276
  64. data/doc/BMP280.html +0 -276
  65. data/doc/BMxSensor.html +0 -557
  66. data/doc/BinaryActuator.html +0 -177
  67. data/doc/BinaryEffector.html +0 -246
  68. data/doc/BinaryReceptor.html +0 -387
  69. data/doc/BinarySensor.html +0 -168
  70. data/doc/Button.html +0 -986
  71. data/doc/DHT11.html +0 -287
  72. data/doc/DHT22.html +0 -287
  73. data/doc/DHTxxSensor.html +0 -361
  74. data/doc/DS18B20.html +0 -339
  75. data/doc/DigitalActuator.html +0 -164
  76. data/doc/DigitalEffector.html +0 -636
  77. data/doc/DigitalReceptor.html +0 -242
  78. data/doc/DigitalSensor.html +0 -162
  79. data/doc/Effector.html +0 -257
  80. data/doc/HCSR501.html +0 -172
  81. data/doc/HumitureSensor.html +0 -453
  82. data/doc/LED.html +0 -784
  83. data/doc/MAX44009.html +0 -830
  84. data/doc/RaspberryPi.html +0 -317
  85. data/doc/Receptor.html +0 -257
  86. data/doc/Sensor.html +0 -145
  87. data/doc/TemperatureSensor.html +0 -644
  88. data/lib/bh1750.rb +0 -46
  89. data/lib/binary_actuator.rb +0 -5
  90. data/lib/binary_effector.rb +0 -12
  91. data/lib/binary_receptor.rb +0 -19
  92. data/lib/binary_sensor.rb +0 -5
  93. data/lib/bmx_sensor.rb +0 -85
  94. data/lib/button.rb +0 -70
  95. data/lib/dht_sensor.rb +0 -36
  96. data/lib/digital_actuator.rb +0 -5
  97. data/lib/digital_effector.rb +0 -69
  98. data/lib/digital_receptor.rb +0 -16
  99. data/lib/digital_sensor.rb +0 -5
  100. data/lib/ds18b20.rb +0 -24
  101. data/lib/effector.rb +0 -32
  102. data/lib/hcsr501.rb +0 -7
  103. data/lib/humiture_sensor.rb +0 -26
  104. data/lib/led.rb +0 -58
  105. data/lib/led_pwm.rb +0 -6
  106. data/lib/led_rgb.rb +0 -101
  107. data/lib/max44009.rb +0 -77
  108. data/lib/receptor.rb +0 -33
  109. data/lib/temperature_sensor.rb +0 -49
@@ -1,7 +0,0 @@
1
- require 'binary_receptor'
2
-
3
- # HCSR501 - PIR sensor
4
- class HCSR501 < BinarySensor
5
- # TODO: implement and test
6
-
7
- end
@@ -1,26 +0,0 @@
1
- require 'temperature_sensor'
2
-
3
- # HumitureSensor - combined humidity & temperature sensor
4
- class HumitureSensor < TemperatureSensor
5
- @humidity = 0.0
6
- @temperature = 0.0
7
-
8
- def initialize
9
- @humidity, @temperature = read_data
10
- end
11
-
12
- def read_data
13
- [@humidity, @temperature]
14
- end
15
-
16
- # Humidity in per cents
17
- def humidity
18
- @humidity
19
- end
20
-
21
- # Temperature & humidity as a string
22
- def to_s
23
- sprintf "%5.2f°, %5.2f %%", @temperature, @humidity
24
- end
25
- end
26
-
data/lib/led.rb DELETED
@@ -1,58 +0,0 @@
1
- require 'binary_effector'
2
-
3
- # LED - Light Emitting Diode
4
- class LED < BinaryEffector
5
- def initialize(pin)
6
- super(pin)
7
- self.name = 'LED'
8
- end
9
-
10
- def on(pin=@pin)
11
- super(pin)
12
- end
13
-
14
- def off(pin=@pin)
15
- super(pin)
16
- end
17
-
18
- # Repeat 'repeat' times: light the LED for 'switched_on' secs, then pause for 'switched_off' secs
19
- def blink(repeat=3, switched_on=0.25, switched_off=0.5)
20
- repeat.times do |n|
21
- on
22
- sleep switched_on
23
- off
24
- sleep switched_off
25
- end
26
- end
27
-
28
- def on_for(seconds=1)
29
- on
30
- sleep seconds
31
- off
32
- end
33
-
34
- def off_for(seconds=1)
35
- off
36
- sleep seconds
37
- on
38
- end
39
- end
40
-
41
- # Experimental methods with names in Russian
42
- class LED
43
- def LED.создать(pin = 25)
44
- LED.new(pin)
45
- end
46
-
47
- def включить
48
- on
49
- end
50
-
51
- def выключить
52
- off
53
- end
54
-
55
- def мигать(repeat=3, switched_on=0.25, switched_off=0.5)
56
- blink(repeat, switched_on, switched_off)
57
- end
58
- end
@@ -1,6 +0,0 @@
1
- require 'led'
2
-
3
- class LED
4
- class PWM
5
- end
6
- end
@@ -1,101 +0,0 @@
1
- require 'led'
2
-
3
- class LED
4
- class RGB < DigitalEffector
5
- @red = nil # GPIO pins
6
- @green = nil #
7
- @blue = nil #
8
-
9
- def initialize(red = 17, green = 27, blue = 22)
10
- super({:red => red, :green => green, :blue => blue}, :low)
11
- @red = red
12
- @green = green
13
- @blue = blue
14
- self.name = 'RGB LED'
15
- end
16
-
17
- def red_on
18
- DigitalEffector.on @red
19
- end
20
-
21
- def red_off
22
- DigitalEffector.off @red
23
- end
24
-
25
- def green_on
26
- DigitalEffector.on @green
27
- end
28
-
29
- def green_off
30
- DigitalEffector.off @green
31
- end
32
-
33
- def blue_on
34
- DigitalEffector.on @blue
35
- end
36
-
37
- def blue_off
38
- DigitalEffector.off @blue
39
- end
40
-
41
- def on(color)
42
- color = :aoi if color == :aqua
43
- case color
44
- when :red
45
- red_on
46
- when :green
47
- green_on
48
- when :blue
49
- blue_on
50
- when :yellow
51
- red_on
52
- green_on
53
- when :aoi
54
- blue_on
55
- green_on
56
- else
57
- end
58
- end
59
-
60
- def off(color=:all)
61
- color = :aoi if color == :aqua
62
- case color
63
- when :red
64
- red_off
65
- when :green
66
- green_off
67
- when :blue
68
- blue_off
69
- when :yellow
70
- red_off
71
- green_off
72
- when :aoi
73
- blue_off
74
- green_off
75
- when :all
76
- all_off
77
- else
78
- all_off
79
- end
80
- end
81
-
82
- def all_off
83
- red_off
84
- green_off
85
- blue_off
86
- end
87
-
88
-
89
- def blink(list = :all, repeat=3, switched_on=0.25, switched_off=0.5)
90
- colors = (list == :all) ? [:red, :green, :blue] : (list.class == Array ? list : [list])
91
- repeat.times do |n|
92
- colors.each do |color|
93
- on color
94
- sleep switched_on
95
- off color
96
- sleep switched_off
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,77 +0,0 @@
1
- require 'bus'
2
-
3
- # MAX44009 - low-power ambient Light Sensor
4
- # Output: digital, Bus: I²C, Range: 0.045..188,000 Lux, VCC: 1.7..3.6V, Operating Current: 0.65µA
5
- # https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf
6
- class MAX44009
7
- MAX44009_DEFAULT_ADDRESS = 0x4A
8
- # MAX44009 Register Map
9
- MAX44009_REG_INTR_STATUS = 0x00 # Interrupt Status Register
10
- MAX44009_REG_INTR_ENABLE = 0x01 # Interrupt Enable Register
11
- MAX44009_REG_CONFIG = 0x02 # Configuration Register
12
- MAX44009_REG_LUX_HIGH = 0x03 # Lux High Byte
13
- MAX44009_REG_LUX_LOW = 0x04 # Lux Low Byte
14
- MAX44009_REG_THRES_UP_HI = 0x05 # Upper Threshold High Byte
15
- MAX44009_REG_THRES_LO_HI = 0x06 # Upper Threshold Low Byte
16
- MAX44009_REG_THRES_TIMER = 0x07 # Threshold Timer
17
- # MAX44009 INTERRUPT ENABLE REGISTER
18
- MAX44009_REG_INTR_ENABLE_NO_ASSRT = 0x00 # The INT pin and the INTS bit are not asserted even if an interrupt event has occurred
19
- MAX44009_REG_INTR_ENABLE_TRIGGER = 0x01 # Detection of an interrupt event triggers a hardware interrupt
20
- # MAX44009 CONFIGURATION REGISTER
21
- MAX44009_REG_CONFIG_CONTMODE_DEFAULT = 0x00 # Default mode
22
- MAX44009_REG_CONFIG_CONTMODE_CONTIN = 0x80 # Continuous mode
23
- MAX44009_REG_CONFIG_MANUAL_DEFAULT = 0x00 # Default mode of configuration is used for the IC
24
- MAX44009_REG_CONFIG_MANUAL_MODEON = 0x40 # Manual mode of configuration is used for the IC
25
- MAX44009_REG_CONFIG_CDR_NODIVIDED = 0x00 # Current not divided. All of the photodiode current goes to the ADC
26
- MAX44009_REG_CONFIG_CDR_DIVIDED = 0x08 # Current divided by 8
27
- MAX44009_REG_CONFIG_INTRTIMER_800 = 0x00 # Integration Time = 800ms, This is a preferred mode for boosting low-light sensitivity
28
- MAX44009_REG_CONFIG_INTRTIMER_400 = 0x01 # Integration Time = 400ms
29
- MAX44009_REG_CONFIG_INTRTIMER_200 = 0x02 # Integration Time = 200ms
30
- MAX44009_REG_CONFIG_INTRTIMER_100 = 0x03 # Integration Time = 100ms, This is a preferred mode for high-brightness applications
31
- MAX44009_REG_CONFIG_INTRTIMER_50 = 0x04 # Integration Time = 50ms, Manual Mode only
32
- MAX44009_REG_CONFIG_INTRTIMER_25 = 0x05 # Integration Time = 25ms, Manual Mode only
33
- MAX44009_REG_CONFIG_INTRTIMER_12_5 = 0x06 # Integration Time = 12.5ms, Manual Mode only
34
- MAX44009_REG_CONFIG_INTRTIMER_6_25 = 0x07 # Integration Time = 6.25ms, Manual Mode only
35
-
36
- DEVICE = MAX44009_DEFAULT_ADDRESS # I2C sensor address
37
-
38
- def initialize(i2c_bus='/dev/i2c-1')
39
- @sensor_name = 'MAX44009'
40
- @i2c_bus = i2c_bus
41
- @device = I2CDevice.new(address: DEVICE, driver: I2CDevice::Driver::I2CDev.new(@i2c_bus))
42
- write_config()
43
- @length = 2
44
- @value = read_sensor
45
- end
46
-
47
- def write_config()
48
- # Select the configuration register data from the given provided values
49
- config = (MAX44009_REG_CONFIG_CONTMODE_CONTIN | MAX44009_REG_CONFIG_MANUAL_MODEON | MAX44009_REG_CONFIG_CDR_NODIVIDED | MAX44009_REG_CONFIG_INTRTIMER_800)
50
- @device.i2cset(MAX44009_REG_CONFIG, config)
51
- end
52
-
53
- def read_sensor
54
- # Read data back from MAX44009_REG_LUX_HIGH(0x03), 2 bytes, luminance MSB, luminance LSB
55
- data = @device.i2cget(MAX44009_REG_LUX_HIGH, 2)
56
- @value = data_to_lux(data)
57
- end
58
-
59
- # Return
60
- def lux
61
- read_sensor
62
- @value
63
- end
64
-
65
- private
66
- # Convert the data to lux
67
- def data_to_lux(data)
68
- exponent = (data[0].ord & 0xF0) >> 4
69
- mantissa = ((data[0].ord & 0x0F) << 4) | (data[1].ord & 0x0F)
70
- luminance = ((2 ** exponent) * mantissa) * 0.045
71
- end
72
-
73
- # convert sensor data to a float number
74
- def to_f(data)
75
- return ((data[1].ord + (256 * data[0].ord)) / 1.2)
76
- end
77
- end
@@ -1,33 +0,0 @@
1
- require 'rpi_gpio'
2
-
3
- RPi::GPIO.set_warnings(false)
4
- RPi::GPIO.set_numbering :bcm
5
-
6
- # Receptor - physical device that can provide info about real world
7
- class Receptor
8
- @model = 'N/A'
9
- @name = 'N/A'
10
- @value = nil
11
-
12
- def name
13
- @name
14
- end
15
-
16
- def model_name
17
- @model
18
- end
19
-
20
- protected
21
- def name=(name)
22
- @name = name
23
- end
24
-
25
- def model_name=(name)
26
- @model_name = name
27
- end
28
- end
29
-
30
- # Sensor - a synonym for Receptor
31
- class Sensor < Receptor
32
-
33
- end
@@ -1,49 +0,0 @@
1
- require 'digital_sensor'
2
-
3
- # TemperatureSensor - temperature sensing receptor
4
- class TemperatureSensor < DigitalSensor
5
- @temperature = 0.0
6
-
7
- def initialize
8
- @temperature = read_data
9
- end
10
-
11
- def read_data
12
- @temperature
13
- end
14
- def celsius
15
- @temperature
16
- end
17
-
18
- def fahrenheit
19
- @temperature * 9.0 / 5.0 + 32
20
- end
21
-
22
- def kelvin
23
- @temperature + 273.15
24
- end
25
-
26
- def reaumur
27
- @temperature * 0.8
28
- end
29
-
30
- def to_s
31
- sprintf "%5.2f°C", @temperature
32
- end
33
-
34
- def temperature(mode=:celsius)
35
- case mode
36
- when :celsius
37
- celsius
38
- when :fahrenheit
39
- fahrenheit
40
- when :kelvin
41
- kelvin
42
- when :reaumur
43
- reaumur
44
- else
45
- celsius
46
- end
47
- end
48
- end
49
-