apiotics_factory 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apiotics_factory/version.rb +1 -1
- data/lib/templates/grove_pi/grove_pi.rb +221 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f137425415fd6512e90917aca6c4194f1fc5dd
|
4
|
+
data.tar.gz: e3523a68a0fe694390f1b41b38f54dd0270e66b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9409c26df76ea46c9f33d120a381a474669ec1d299f9e488a47e1d41e5cda5b7aed469543a4bd491a4b8f171eadc903b781661827aa62720ac56b20f18b9f062
|
7
|
+
data.tar.gz: 2b8d0848116dc2593743637288658eb9bd47cb5ae6056994674d9391a00b4e513f69e395ee97573fe0a1dee9fbde6d718e20fe5e771bbae02d3169ca989daa2c
|
@@ -10,8 +10,22 @@ module GrovePi
|
|
10
10
|
CMD_READ_ANALOG = 3
|
11
11
|
CMD_WRITE_ANALOG = 4
|
12
12
|
CMD_PIN_MODE = 5
|
13
|
+
|
14
|
+
CMD_ULTRASONIC_READ = 7
|
13
15
|
CMD_READ_FIRMWARE_VERSION = 8
|
14
16
|
|
17
|
+
CMD_READ_TEMP_HUM = 40
|
18
|
+
|
19
|
+
CMD_4DIG_INIT = 70
|
20
|
+
CMD_4DIG_BRIGHTNESS = 71
|
21
|
+
CMD_4DIG_VALUE = 72
|
22
|
+
CMD_4DIG_VALUE_ZEROS = 73
|
23
|
+
CMD_4DIG_DIGIT = 74
|
24
|
+
CMD_4DIG_LEDS = 75
|
25
|
+
CMD_4DIG_CLOCK = 76
|
26
|
+
CMD_4DIG_ON = 78
|
27
|
+
|
28
|
+
|
15
29
|
# Arduino pin mappings.
|
16
30
|
A0 = 14
|
17
31
|
A1 = 15
|
@@ -37,6 +51,11 @@ module GrovePi
|
|
37
51
|
CONFIG_RETRIES = 10
|
38
52
|
GROVE_PI_I2C_SLAVE_ADDRESS = 4
|
39
53
|
|
54
|
+
# LCD RGB display - I2C addresses
|
55
|
+
DISPLAY_TEXT_ADDRESS = 0x3e #0x3e
|
56
|
+
DISPLAY_RGB_ADDRESS = 0x62 #0x62
|
57
|
+
|
58
|
+
|
40
59
|
# The initialized I2C object.
|
41
60
|
@_i2c_grove_pi = nil
|
42
61
|
|
@@ -266,5 +285,207 @@ module GrovePi
|
|
266
285
|
end
|
267
286
|
end
|
268
287
|
|
288
|
+
#
|
289
|
+
# Additional functions for Ultrasonic Ranger, Temperature and Humidity Sensor, Four-Digit Display,
|
290
|
+
# and LCD RGB display
|
291
|
+
#
|
292
|
+
|
293
|
+
|
294
|
+
# Ultrasonic Ranger
|
295
|
+
|
296
|
+
# Read distance from ultrasonic ranger
|
297
|
+
def self.ultrasonic_read(pin)
|
298
|
+
self._ensure_init
|
299
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_ULTRASONIC_READ, pin, 0, 0)
|
300
|
+
|
301
|
+
sleep(0.06) #firmware has a time of 50ms so wait for more than that
|
302
|
+
|
303
|
+
@_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 1)
|
304
|
+
numbers = @_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 3).chars
|
305
|
+
|
306
|
+
return (numbers[1].ord) * 256 + (numbers[2].ord)
|
307
|
+
end
|
308
|
+
|
309
|
+
|
310
|
+
# Temperature and Humidity Sensor
|
311
|
+
|
312
|
+
# Read temperature and humidity values from sensor
|
313
|
+
def self.read_temp_humidity(pin)
|
314
|
+
self._ensure_init
|
315
|
+
|
316
|
+
module_type = 1 # if sensor is white: module_type = 1, if sensor is blue: module_type = 0
|
317
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_READ_TEMP_HUM, pin, module_type, 0)
|
318
|
+
|
319
|
+
for i in 0..CONFIG_RETRIES - 1
|
320
|
+
begin
|
321
|
+
# read one byte
|
322
|
+
@_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 1)
|
323
|
+
|
324
|
+
# read 10 more bytes
|
325
|
+
number = @_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 9)
|
326
|
+
|
327
|
+
temp_value = number[1..4].unpack('f')[0].round(2) * 9/5 + 32 #convert to F
|
328
|
+
humidity_value = number[5..8].unpack('f')[0].round(2)
|
329
|
+
|
330
|
+
return temp_value, humidity_value
|
331
|
+
rescue Errno::EREMOTEIO
|
332
|
+
next
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
# Four-Digit Display
|
340
|
+
|
341
|
+
|
342
|
+
# Initialize four-digit display
|
343
|
+
def self.fourDigit_init(pin)
|
344
|
+
self._ensure_init
|
345
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_INIT, pin, 0, 0)
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
# Set individual digit
|
350
|
+
# segment = 0-3
|
351
|
+
# value = 0-15 or 0-F
|
352
|
+
def self.fourDigit_writeDigit(pin, segment, value)
|
353
|
+
self._ensure_init
|
354
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_DIGIT, pin, segment, value)
|
355
|
+
sleep(0.05)
|
356
|
+
end
|
357
|
+
|
358
|
+
# Turn on entire display (88:88)
|
359
|
+
def self.fourDigit_displayOn(pin)
|
360
|
+
self._ensure_init
|
361
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_ON, pin, 0, 0)
|
362
|
+
sleep(0.05)
|
363
|
+
end
|
364
|
+
|
365
|
+
# Display a decimal value without leading zeros
|
366
|
+
# value = 0 - 9999
|
367
|
+
def self.fourDigit_displayDec(pin, string)
|
368
|
+
self._ensure_init
|
369
|
+
value = string.to_i
|
370
|
+
|
371
|
+
# split into 2 bytes
|
372
|
+
byte1 = value & 255
|
373
|
+
byte2 = value >> 8
|
374
|
+
|
375
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_VALUE, pin, byte1, byte2)
|
376
|
+
|
377
|
+
sleep(0.05)
|
378
|
+
end
|
379
|
+
|
380
|
+
# Display a string
|
381
|
+
# string can consist of 0-9
|
382
|
+
def self.fourDigit_displayString(pin, string)
|
383
|
+
self._ensure_init
|
384
|
+
|
385
|
+
if string.include? ":"
|
386
|
+
string.delete ":"
|
387
|
+
end
|
388
|
+
|
389
|
+
digits = string.chars
|
390
|
+
i = 0
|
391
|
+
|
392
|
+
while (digits.length < 4)
|
393
|
+
digits.unshift(" ")
|
394
|
+
end
|
395
|
+
|
396
|
+
#for each space added or each unaccepted character, display an empty space
|
397
|
+
#otherwise display the character
|
398
|
+
digits.each do |digit|
|
399
|
+
if (digit == " ") | ((digit.to_i(16) == 0) & (digit != "0"))
|
400
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_LEDS, pin, i, 0)
|
401
|
+
else
|
402
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_DIGIT, pin, i, digit.to_i(16))
|
403
|
+
end
|
404
|
+
i += 1
|
405
|
+
sleep(0.05)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
# Set brightness of display
|
410
|
+
# brightness = 0-7
|
411
|
+
def self.fourDigit_setBrightness(pin, brightness)
|
412
|
+
self._ensure_init
|
413
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_BRIGHTNESS, pin, brightness.to_i, 0)
|
414
|
+
sleep(0.05)
|
415
|
+
end
|
416
|
+
|
417
|
+
|
418
|
+
# Display digits and center colon
|
419
|
+
# string can contain digits (0-9)
|
420
|
+
def self.fourDigit_displayClock(pin, string)
|
421
|
+
self._ensure_init
|
422
|
+
string.delete! ":" # make sure there is no colon in the string
|
423
|
+
value = string.to_i
|
424
|
+
left = value/100
|
425
|
+
right = value % 100
|
426
|
+
@_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_4DIG_CLOCK, pin, left, right)
|
427
|
+
return left, right
|
428
|
+
end
|
429
|
+
|
430
|
+
|
431
|
+
# LCD RGB Display
|
432
|
+
|
433
|
+
|
434
|
+
# Helper function for communicating with LCD RGB display
|
435
|
+
def self.write_lcd_rgb_i2c(i2c_slave_address, *data)
|
436
|
+
self._ensure_init
|
437
|
+
|
438
|
+
if !@_i2c_slave_addresses.key?(i2c_slave_address)
|
439
|
+
path =
|
440
|
+
@_i2c_grove_pi.instance_variable_get(:@driver)
|
441
|
+
.instance_variable_get(:@path)
|
442
|
+
|
443
|
+
@_i2c_slave_addresses[i2c_slave_address] = I2CDevice.new address: i2c_slave_address,
|
444
|
+
driver: I2CDevice::Driver::I2CDev.new(path)
|
445
|
+
end
|
446
|
+
|
447
|
+
@_i2c_slave_addresses[i2c_slave_address].i2cset *data
|
448
|
+
end
|
449
|
+
|
450
|
+
# Set the color of the LCD RGB display
|
451
|
+
# red = 0-255
|
452
|
+
# green = 0-255
|
453
|
+
# blue = 0-255
|
454
|
+
def self.setRGB(red,green,blue)
|
455
|
+
write_lcd_rgb_i2c(DISPLAY_RGB_ADDRESS, 0, 0)
|
456
|
+
write_lcd_rgb_i2c(DISPLAY_RGB_ADDRESS, 1, 0)
|
457
|
+
write_lcd_rgb_i2c(DISPLAY_RGB_ADDRESS, 0x08, 0xaa)
|
458
|
+
write_lcd_rgb_i2c(DISPLAY_RGB_ADDRESS, 4, red.to_i)
|
459
|
+
write_lcd_rgb_i2c(DISPLAY_RGB_ADDRESS, 3, green.to_i)
|
460
|
+
write_lcd_rgb_i2c(DISPLAY_RGB_ADDRESS, 2, blue.to_i)
|
461
|
+
end
|
462
|
+
|
463
|
+
# Set the text on the LCD RGB display
|
464
|
+
def self.setText(text)
|
465
|
+
write_lcd_rgb_i2c(DISPLAY_TEXT_ADDRESS, 0x80, 0x01)
|
466
|
+
sleep(0.05)
|
467
|
+
write_lcd_rgb_i2c(DISPLAY_TEXT_ADDRESS, 0x80, 0x08 | 0x04)
|
468
|
+
write_lcd_rgb_i2c(DISPLAY_TEXT_ADDRESS, 0x80, 0x28)
|
469
|
+
sleep(0.05)
|
470
|
+
count = 0
|
471
|
+
row = 0
|
472
|
+
text.chars.each do |c|
|
473
|
+
if c == '\n' or count == 16
|
474
|
+
count = 0
|
475
|
+
row += 1
|
476
|
+
if row == 2
|
477
|
+
break
|
478
|
+
end
|
479
|
+
write_lcd_rgb_i2c(DISPLAY_TEXT_ADDRESS, 0x80, 0xc0)
|
480
|
+
if c == '\n'
|
481
|
+
next
|
482
|
+
end
|
483
|
+
end
|
484
|
+
count += 1
|
485
|
+
write_lcd_rgb_i2c(DISPLAY_TEXT_ADDRESS, 0x40, c.ord)
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
269
489
|
# TODO: Implement rest of the commands that are supported by the firmware.
|
490
|
+
|
270
491
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiotics_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Apiotics
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.6.10
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: A Gem To Generate Apiotics Drivers
|