odroid_lcd 0.0.4

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6006d3b5b173420c1df81e8498d1a68b182c7eef
4
+ data.tar.gz: 1904a72869fe8cae59bcb2e94409b9f4e1e07170
5
+ SHA512:
6
+ metadata.gz: 7aba291d2ff468fcc8330544c08f36e103dac6d948bbfd6e6202db21cee80fe1d561c67ce94b15e1f9405ee831f0902972802d8afde4b35a24cb2cb60d2dfc57
7
+ data.tar.gz: 650d24ba418a37ae228ef35198c4ee3cf1a1f3ab0f3196295567929212318a6ddf939a9dd6bd0e466b49fa3a5159b7a794dd901a5f32a88f0be97691e8340a90
data/bin/odroid-lcd ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'odroid_lcd'
4
+
5
+ cli = OdroidLCD::CLI.new
6
+ cli.run(ARGV)
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_library('pthread')
4
+ have_library('wiringPi')
5
+ have_library('wiringPiDev')
6
+
7
+ create_makefile('odroid_lcd/odroid_lcd_hw')
@@ -0,0 +1,139 @@
1
+ //------------------------------------------------------------------------------------------------------------
2
+ // An LCD display wiringPi wrapper for the Hardkernel Odroid C2.
3
+ //
4
+ // Based on: https://dn.odroid.com/source_peripherals/16x2lcdio/example-lcd.c
5
+ //------------------------------------------------------------------------------------------------------------
6
+
7
+ #include "ruby.h"
8
+
9
+ #include <stdio.h>
10
+ #include <stdlib.h>
11
+ #include <stdint.h>
12
+
13
+ #include <unistd.h>
14
+ #include <string.h>
15
+ #include <time.h>
16
+
17
+ #include <wiringPi.h>
18
+ #include <wiringPiI2C.h>
19
+ #include <wiringSerial.h>
20
+ #include <lcd.h>
21
+
22
+
23
+ //------------------------------------------------------------------------------------------------------------
24
+ //
25
+ // WiringPi LCD defines
26
+ //
27
+ //------------------------------------------------------------------------------------------------------------
28
+ #define LCD_ROW 2 // 16 Char
29
+ #define LCD_COL 16 // 2 Line
30
+ #define LCD_BUS 4 // Interface 4 Bit mode
31
+
32
+ #define PORT_LCD_RS 7
33
+ #define PORT_LCD_E 0
34
+ #define PORT_LCD_D4 2
35
+ #define PORT_LCD_D5 3
36
+ #define PORT_LCD_D6 1
37
+ #define PORT_LCD_D7 4
38
+
39
+
40
+ //-----------------
41
+ // Odroidlcd.new
42
+ //
43
+ // Initialize the LCD screen.
44
+ //-----------------
45
+ static VALUE odlcd_init(VALUE self) {
46
+ VALUE lcd_handle;
47
+
48
+ // Initialize the LCD, raises a RuntimeError if we fail.
49
+ wiringPiSetup();
50
+ lcd_handle = rb_funcall(self, rb_intern("system_init"), 0);
51
+
52
+ // We store the wiringPi lcdHandle in an instance variable.
53
+ rb_iv_set(self, "@lcd_handle", lcd_handle);
54
+
55
+ return self;
56
+ }
57
+
58
+ static VALUE odlcd_max_column(VALUE self) {
59
+ return INT2FIX(LCD_COL);
60
+ }
61
+
62
+ static VALUE odlcd_max_row(VALUE self) {
63
+ return INT2FIX(LCD_ROW);
64
+ }
65
+
66
+ //---------------
67
+ // Clear the lcd screen.
68
+ //---------------
69
+ static VALUE odlcd_clear(VALUE self) {
70
+ lcdClear(FIX2INT(rb_iv_get(self, "@lcd_handle")));
71
+ return Qnil;
72
+ }
73
+
74
+ //------------------
75
+ // Update a character on the LCD screen
76
+ //
77
+ // lcd = Odroidlcd.new
78
+ // lcd.set_character(0, 0, "A")
79
+ //
80
+ // Note that row must be lower than LCD_ROW and column must be lower than LCD_COL.
81
+ // Raises a RuntimeError if the row or column is too large.
82
+ //------------------
83
+ static VALUE odlcd_set_character(VALUE self, VALUE row, VALUE column, VALUE character) {
84
+ int lcdHandle;
85
+
86
+ if (FIX2INT(row) >= LCD_ROW) {
87
+ rb_raise(rb_eRuntimeError, "Invalid row \"%i\", should be less than %i", FIX2INT(row), LCD_ROW);
88
+ }
89
+
90
+ if (FIX2INT(column) >= LCD_COL) {
91
+ rb_raise(rb_eRuntimeError, "Invalid column \"%i\", should be less than %i", FIX2INT(column), LCD_COL);
92
+ }
93
+
94
+ lcdHandle = FIX2INT(rb_iv_get(self, "@lcd_handle"));
95
+
96
+ lcdPosition(lcdHandle, FIX2INT(column), FIX2INT(row));
97
+ rb_iv_set(self, "@lcd_handle", INT2FIX(lcdHandle));
98
+
99
+ lcdPutchar(lcdHandle, NUM2CHR(character));
100
+ return Qnil;
101
+ }
102
+
103
+ //------------------------------------------------------------------------------------------------------------
104
+ //
105
+ // system init
106
+ //
107
+ //------------------------------------------------------------------------------------------------------------
108
+ static VALUE odlcd_system_init(VALUE self) {
109
+ int lcdHandle = 0;
110
+
111
+ // LCD Init
112
+ lcdHandle = lcdInit (LCD_ROW, LCD_COL, LCD_BUS,
113
+ PORT_LCD_RS, PORT_LCD_E,
114
+ PORT_LCD_D4, PORT_LCD_D5, PORT_LCD_D6, PORT_LCD_D7, 0, 0, 0, 0);
115
+
116
+ if(lcdHandle < 0) {
117
+ rb_raise(rb_eRuntimeError, "%s : lcdInit failed!\n", __func__);
118
+ }
119
+ return INT2FIX(lcdHandle);
120
+ }
121
+
122
+ //------------------------------------------------------------------------------------------------------------
123
+
124
+ void Init_odroid_lcd_hw() {
125
+ VALUE mOdroidLCD;
126
+ VALUE cOdroidLCD_HW;
127
+
128
+ mOdroidLCD = rb_define_module("OdroidLCD");
129
+ cOdroidLCD_HW = rb_define_class_under(mOdroidLCD, "HW", rb_cObject);
130
+ rb_define_method(cOdroidLCD_HW, "initialize", odlcd_init, 0);
131
+ rb_define_method(cOdroidLCD_HW, "clear", odlcd_clear, 0);
132
+ rb_define_method(cOdroidLCD_HW, "max_column", odlcd_max_column, 0);
133
+ rb_define_method(cOdroidLCD_HW, "max_row", odlcd_max_row, 0);
134
+ rb_define_method(cOdroidLCD_HW, "set_character", odlcd_set_character, 3);
135
+ rb_define_private_method(cOdroidLCD_HW, "system_init", odlcd_system_init, 0);
136
+ }
137
+
138
+ //------------------------------------------------------------------------------------------------------------
139
+ //------------------------------------------------------------------------------------------------------------
@@ -0,0 +1,22 @@
1
+ module OdroidLCD
2
+ class CLI
3
+
4
+ def initialize
5
+ @lcd = OdroidLCD::LCD.new
6
+ end
7
+
8
+ def run(argv)
9
+ string = argv[0]
10
+
11
+ rows = argv[0].lines
12
+ if rows.length > 1
13
+ @lcd.set_string(row: 0, string: rows[0].chomp)
14
+ @lcd.set_string(row: 1, string: rows[1].chomp)
15
+ else
16
+ @lcd.set_string(row: 0, string: rows[0].chomp)
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+
2
+ require 'odroid_lcd/odroid_lcd_hw'
3
+ module OdroidLCD
4
+ class HW
5
+
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+
2
+ module OdroidLCD
3
+ class LCD
4
+
5
+ attr_reader :max_column
6
+ attr_reader :max_row
7
+
8
+ def initialize(mocks: {})
9
+ @hw = mocks[:odroidlcd_hw] || OdroidLCD::HW.new
10
+ @max_column = @hw.max_column
11
+ @max_row = @hw.max_row
12
+ freeze()
13
+ end
14
+
15
+ def clear
16
+ @hw.clear
17
+ end
18
+
19
+ def set_character(row:, column:, character:)
20
+ @hw.set_character(row, column, character)
21
+ end
22
+
23
+ def set_string(row: 0, string:)
24
+ column = 0
25
+ string[0, @max_column].ljust(@max_column - 1).chars do |chr|
26
+ set_character(row: row, column: column, character: chr)
27
+ column += 1
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/odroid_lcd.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+ require 'odroid_lcd/hw'
3
+ require "odroid_lcd/lcd"
4
+ require "odroid_lcd/cli"
5
+
6
+ module OdroidLCD
7
+ end
8
+
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: odroid_lcd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Phil Helliwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Allows writing strings to the LCD screen accessory, see: https://wiki.odroid.com/accessory/display/16x2_lcd_io_shield/c/start'
14
+ email: phil.helliwell@gmail.com
15
+ executables:
16
+ - odroid-lcd
17
+ extensions:
18
+ - ext/odroid_lcd/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/odroid-lcd
22
+ - ext/odroid_lcd/extconf.rb
23
+ - ext/odroid_lcd/odroid_lcd_hw.c
24
+ - lib/odroid_lcd.rb
25
+ - lib/odroid_lcd/cli.rb
26
+ - lib/odroid_lcd/hw.rb
27
+ - lib/odroid_lcd/lcd.rb
28
+ homepage: http://github.com/kill9zombie/odroid_lcd
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements:
47
+ - 'WiringPi patched by Hardkernel, see: https://wiki.odroid.com/accessory/display/16x2_lcd_io_shield/c/start'
48
+ rubyforge_project:
49
+ rubygems_version: 2.6.13
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: LCD screen utils for the Hardkernel Odroid C2
53
+ test_files: []