Browse Source

lcd: added grove-lcd rgb and deleted the old lcm1602 folder

Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
Yevgeniy Kiveisha 10 years ago
parent
commit
c60b342e0f

+ 4
- 2
examples/CMakeLists.txt View File

@@ -2,15 +2,17 @@ add_executable (compass compass.cxx)
2 2
 add_executable (groveled groveled.cxx)
3 3
 add_executable (grovetemp grovetemp.cxx)
4 4
 add_executable (lcm-lcd lcm-lcd.cxx)
5
+add_executable (rgb-lcd rgb-lcd.cxx)
5 6
 add_executable (buzzer-sound buzzer-sound.cxx)
6 7
 
7 8
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
8 9
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
9
-include_directories (${PROJECT_SOURCE_DIR}/src/lcm1602)
10
+include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
10 11
 include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
11 12
 
12 13
 target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
13 14
 target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
14 15
 target_link_libraries (grovetemp grove ${CMAKE_THREAD_LIBS_INIT})
15
-target_link_libraries (lcm-lcd lcm1602 ${CMAKE_THREAD_LIBS_INIT})
16
+target_link_libraries (lcm-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
17
+target_link_libraries (rgb-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
16 18
 target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT})

+ 4
- 4
examples/lcm-lcd.cxx View File

@@ -28,13 +28,13 @@ int
28 28
 main(int argc, char **argv)
29 29
 {
30 30
     upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
31
-    lcd->cursor(0,0);
31
+    lcd->setCursor(0,0);
32 32
     lcd->write("Hello World");
33
-    lcd->cursor(1,2);
33
+    lcd->setCursor(1,2);
34 34
     lcd->write("Hello World");
35
-    lcd->cursor(2,4);
35
+    lcd->setCursor(2,4);
36 36
     lcd->write("Hello World");
37
-    lcd->cursor(3,6);
37
+    lcd->setCursor(3,6);
38 38
     lcd->write("Hello World");
39 39
     lcd->close();
40 40
 }

+ 37
- 0
examples/rgb-lcd.cxx View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Author: Yevgeniy Kiveish <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include "jhd1313m1.h"
26
+
27
+int
28
+main(int argc, char **argv)
29
+{
30
+	// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
31
+    upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
32
+	lcd->setCursor(0,0);
33
+    lcd->write("Hello World");
34
+    lcd->setCursor(1,2);
35
+    lcd->write("Hello World");
36
+    lcd->close();
37
+}

+ 1
- 1
src/CMakeLists.txt View File

@@ -1,4 +1,4 @@
1 1
 add_subdirectory (hmc5883l)
2 2
 add_subdirectory (grove)
3
-add_subdirectory (lcm1602)
3
+add_subdirectory (lcd)
4 4
 add_subdirectory (buzzer)

+ 4
- 0
src/lcd/CMakeLists.txt View File

@@ -0,0 +1,4 @@
1
+set (libname "i2clcd")
2
+add_library (i2clcd SHARED iiclcd.cxx lcm1602.cxx jhd1313m1.cxx)
3
+include_directories (${MAA_INCLUDE_DIR})
4
+target_link_libraries (i2clcd ${MAA_LIBRARIES})

+ 53
- 0
src/lcd/iiclcd.cxx View File

@@ -0,0 +1,53 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <iostream>
26
+#include <unistd.h>
27
+
28
+#include "iiclcd.h"
29
+
30
+using namespace upm;
31
+
32
+IICLcd::IICLcd (int bus, int lcdAddress) {
33
+	m_lcd_control_address = lcdAddress;
34
+    m_bus = bus;
35
+
36
+    m_i2c_lcd_control = maa_i2c_init(m_bus);
37
+
38
+    maa_result_t ret = maa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
39
+	if (ret != MAA_SUCCESS) {
40
+        fprintf(stderr, "Messed up i2c bus\n");
41
+    }
42
+}
43
+
44
+maa_result_t 
45
+IICLcd::write (int row, int column, std::string msg) {
46
+	setCursor (row, column);
47
+	write (msg);
48
+}
49
+
50
+maa_result_t
51
+IICLcd::close() {
52
+	return maa_i2c_stop(m_i2c_lcd_control);
53
+}

+ 90
- 0
src/lcd/iiclcd.h View File

@@ -0,0 +1,90 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+#pragma once
25
+
26
+#include <string>
27
+#include <maa/i2c.h>
28
+
29
+namespace upm {
30
+
31
+// commands
32
+#define LCD_CLEARDISPLAY 0x01
33
+#define LCD_RETURNHOME 0x02
34
+#define LCD_ENTRYMODESET 0x04
35
+#define LCD_DISPLAYCONTROL 0x08
36
+#define LCD_CURSORSHIFT 0x10
37
+#define LCD_FUNCTIONSET 0x20
38
+#define LCD_SETCGRAMADDR 0x40
39
+#define LCD_SETDDRAMADDR 0x80
40
+
41
+#define LCD_BACKLIGHT 0x08
42
+#define LCD_NOBACKLIGHT 0x00
43
+
44
+// flags for display entry mode
45
+#define LCD_ENTRYRIGHT 0x00
46
+#define LCD_ENTRYLEFT 0x02
47
+#define LCD_ENTRYSHIFTINCREMENT 0x01
48
+#define LCD_ENTRYSHIFTDECREMENT 0x00
49
+
50
+// flags for display on/off control
51
+#define LCD_DISPLAYON 0x04
52
+#define LCD_DISPLAYOFF 0x00
53
+#define LCD_CURSORON 0x02
54
+#define LCD_CURSOROFF 0x00
55
+#define LCD_BLINKON 0x01
56
+#define LCD_BLINKOFF 0x00
57
+
58
+// flags for function set
59
+#define LCD_8BITMODE 0x10
60
+#define LCD_4BITMODE 0x00
61
+#define LCD_2LINE 0x08
62
+#define LCD_1LINE 0x00
63
+#define LCD_5x10DOTS 0x04
64
+#define LCD_5x8DOTS 0x00
65
+
66
+#define LCD_EN 0x04 // Enable bit
67
+#define LCD_RW 0x02 // Read/Write bit
68
+#define LCD_RS 0x01 // Register select bit
69
+
70
+class IICLcd {
71
+	public:
72
+		IICLcd (int bus, int lcdAddress);
73
+		virtual maa_result_t write (std::string msg) = 0;
74
+		maa_result_t write (int x, int y, std::string msg);
75
+		virtual maa_result_t setCursor (int row, int column) = 0;
76
+		virtual maa_result_t clear () = 0;
77
+		virtual maa_result_t home () = 0;
78
+		maa_result_t close();
79
+		std::string name()
80
+        {
81
+            return m_name;
82
+        }
83
+	protected:
84
+		std::string m_name;
85
+		int m_lcd_control_address;
86
+	    int m_bus;
87
+		maa_i2c_context m_i2c_lcd_control;
88
+};
89
+
90
+}

+ 140
- 0
src/lcd/jhd1313m1.cxx View File

@@ -0,0 +1,140 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <iostream>
26
+#include <unistd.h>
27
+
28
+#include "jhd1313m1.h"
29
+
30
+using namespace upm;
31
+
32
+Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : IICLcd(bus, lcdAddress) {
33
+	maa_result_t error = MAA_SUCCESS;
34
+
35
+	m_rgb_address = rgbAddress;
36
+	m_i2c_lcd_rgb = maa_i2c_init(m_bus);
37
+
38
+	maa_result_t ret = maa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
39
+	if (ret != MAA_SUCCESS) {
40
+        fprintf(stderr, "Messed up i2c bus\n");
41
+    }
42
+
43
+	usleep(50000);
44
+    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
45
+	usleep(4500);
46
+	cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
47
+	usleep(4500);
48
+	cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
49
+	usleep(4500);
50
+	cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
51
+
52
+	cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
53
+	clear ();
54
+	usleep(4500);
55
+	
56
+    cmd (m_i2c_lcd_control, 	LCD_ENTRYMODESET | 
57
+							LCD_ENTRYLEFT | 
58
+							LCD_ENTRYSHIFTDECREMENT);
59
+
60
+	setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
61
+	setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
62
+	setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
63
+
64
+	setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
65
+    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
66
+    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
67
+}
68
+
69
+Jhd1313m1::~Jhd1313m1() {
70
+	
71
+}
72
+
73
+/*
74
+ * **************
75
+ *  virtual area
76
+ * **************
77
+ */
78
+maa_result_t
79
+Jhd1313m1::write (std::string msg) {
80
+	maa_result_t error = MAA_SUCCESS;
81
+	uint8_t data[2] = {0x40, 0};
82
+	for (std::string::size_type i = 0; i < msg.size(); ++i) {
83
+		data[1] = msg[i];
84
+		error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
85
+		error = maa_i2c_write (m_i2c_lcd_control, data, 2);
86
+    }
87
+
88
+	return error;
89
+}
90
+
91
+maa_result_t 
92
+Jhd1313m1::setCursor (int row, int column) {
93
+	maa_result_t error = MAA_SUCCESS;
94
+
95
+	int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
96
+	uint8_t offset = ((column % 16) + row_addr[row]);
97
+
98
+	uint8_t data[2] = { 0x80, offset }; 
99
+	error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
100
+	error = maa_i2c_write (m_i2c_lcd_control, data, 2);
101
+
102
+	return error;
103
+}
104
+
105
+maa_result_t 
106
+Jhd1313m1::clear () {
107
+	return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
108
+}
109
+
110
+maa_result_t 
111
+Jhd1313m1::home () {
112
+	return cmd (m_i2c_lcd_control, LCD_RETURNHOME);
113
+}
114
+
115
+/*
116
+ * **************
117
+ *  private area
118
+ * **************
119
+ */
120
+maa_result_t 
121
+Jhd1313m1::setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
122
+	maa_result_t error = MAA_SUCCESS;
123
+
124
+	uint8_t data[2] = { addr, value };
125
+	error = maa_i2c_address (ctx, deviceAdress);
126
+	error = maa_i2c_write (ctx, data, 2);
127
+
128
+	return error;
129
+}
130
+
131
+maa_result_t 
132
+Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) {
133
+	maa_result_t error = MAA_SUCCESS;
134
+
135
+	uint8_t data[2] = { 0x80, value };
136
+	error = maa_i2c_address (ctx, m_lcd_control_address);
137
+	error = maa_i2c_write (ctx, data, 2);
138
+
139
+	return error;
140
+}

+ 48
- 0
src/lcd/jhd1313m1.h View File

@@ -0,0 +1,48 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+#pragma once
25
+
26
+#include <string>
27
+#include "iiclcd.h"
28
+
29
+namespace upm {
30
+
31
+class Jhd1313m1 : public IICLcd {
32
+    public:
33
+		Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
34
+		~Jhd1313m1 ();
35
+		maa_result_t write (std::string msg);
36
+		maa_result_t setCursor (int row, int column);
37
+		maa_result_t clear ();
38
+		maa_result_t home ();
39
+
40
+	private:
41
+		maa_result_t cmd (maa_i2c_context ctx, uint8_t value);
42
+		maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
43
+
44
+		int m_rgb_address;
45
+		maa_i2c_context m_i2c_lcd_rgb;
46
+};
47
+
48
+}

+ 7
- 0
src/lcd/jsupm_jhd1313m1.i View File

@@ -0,0 +1,7 @@
1
+%module jsupm_jhd1313m1
2
+
3
+%{
4
+    #include "jhd1313m1.h"
5
+%}
6
+
7
+%include "jhd1313m1.h"

src/lcm1602/jsupm_lcm1602.i → src/lcd/jsupm_lcm1602.i View File


src/lcm1602/lcm1602.cxx → src/lcd/lcm1602.cxx View File

@@ -30,56 +30,13 @@
30 30
 
31 31
 #include "lcm1602.h"
32 32
 
33
-#define LCD_CLEARDISPLAY 0x01
34
-#define LCD_RETURNHOME 0x02
35
-#define LCD_ENTRYMODESET 0x04
36
-#define LCD_DISPLAYCONTROL 0x08
37
-#define LCD_CURSORSHIFT 0x10
38
-#define LCD_FUNCTIONSET 0x20
39
-#define LCD_SETCGRAMADDR 0x40
40
-#define LCD_SETDDRAMADDR 0x80
41
-#define LCD_BACKLIGHT 0x08
42
-#define LCD_NOBACKLIGHT 0x00
43
-
44
-#define LCD_ENTRYRIGHT 0x00
45
-#define LCD_ENTRYLEFT 0x02
46
-#define LCD_ENTRYSHIFTINCREMENT 0x01
47
-#define LCD_ENTRYSHIFTDECREMENT 0x00
48
-
49
-#define LCD_DISPLAYON 0x04
50
-#define LCD_DISPLAYOFF 0x00
51
-#define LCD_CURSORON 0x02
52
-#define LCD_CURSOROFF 0x00
53
-#define LCD_BLINKON 0x01
54
-#define LCD_BLINKOFF 0x00
55
-
56
-#define LCD_8BITMODE 0x10
57
-#define LCD_4BITMODE 0x00
58
-#define LCD_2LINE 0x08
59
-#define LCD_1LINE 0x00
60
-#define LCD_5x10DOTS 0x04
61
-#define LCD_5x8DOTS 0x00
62
-
63
-#define LCD_EN 0x04 // Enable bit
64
-#define LCD_RW 0x02 // Read/Write bit
65
-#define LCD_RS 0x01 // Register select bit
66
-
67 33
 using namespace upm;
68 34
 
69
-Lcm1602::Lcm1602(int bus_in, int addr_in)
70
-{
71
-    m_address = addr_in;
72
-    m_bus = bus_in;
73
-
74
-    m_i2c = maa_i2c_init(m_bus);
35
+Lcm1602::Lcm1602(int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
36
+	maa_result_t error = MAA_SUCCESS;
75 37
 
76
-    maa_result_t ret = maa_i2c_address(m_i2c, m_address);
77
-    if (ret != MAA_SUCCESS) {
78
-        fprintf(stderr, "Messed up i2c bus\n");
79
-    }
80
-
81
-    usleep(50000);
82
-    expandWrite(LCD_BACKLIGHT);
38
+	usleep(50000);
39
+	expandWrite(LCD_BACKLIGHT);
83 40
     usleep(100000);
84 41
 
85 42
     write4bits(0x03 << 4);
@@ -103,47 +60,52 @@ Lcm1602::Lcm1602(int bus_in, int addr_in)
103 60
     home();
104 61
 }
105 62
 
106
-int
107
-Lcm1602::clear()
108
-{
109
-    return send(LCD_CLEARDISPLAY, 0);
63
+Lcm1602::~Lcm1602 () {
64
+	
110 65
 }
111 66
 
112
-int
113
-Lcm1602::home()
114
-{
115
-    return send(LCD_RETURNHOME, 0);
67
+/*
68
+ * **************
69
+ *  virtual area
70
+ * **************
71
+ */
72
+maa_result_t
73
+Lcm1602::write (std::string msg) {
74
+	maa_result_t error = MAA_SUCCESS;
75
+    for (std::string::size_type i = 0; i < msg.size(); ++i) {
76
+        error = send (msg[i], LCD_RS);
77
+    }
78
+    return error;
116 79
 }
117 80
 
118
-int
119
-Lcm1602::cursor(int row, int column)
120
-{
121
-    if (row > 3)
122
-        return 99;
123
-    int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
124
-    return send(LCD_SETDDRAMADDR | ((column % 16) + row_addr[row]),0);
81
+maa_result_t 
82
+Lcm1602::setCursor (int row, int column) {
83
+	maa_result_t error = MAA_SUCCESS;
84
+
85
+	int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
86
+	uint8_t offset = ((column % 16) + row_addr[row]);
87
+
88
+	return send (LCD_SETDDRAMADDR | offset, 0);
125 89
 }
126 90
 
127
-maa_result_t
128
-Lcm1602::write(std::string msg)
129
-{
130
-    maa_result_t ret = MAA_SUCCESS;
131
-    for(std::string::size_type i = 0; i < msg.size(); ++i) {
132
-        ret = send(msg[i], LCD_RS);
133
-    }
134
-    return ret;
91
+maa_result_t 
92
+Lcm1602::clear () {
93
+	return send(LCD_CLEARDISPLAY, 0);
135 94
 }
136 95
 
137
-maa_result_t
138
-Lcm1602::close()
139
-{
140
-    return maa_i2c_stop(m_i2c);
96
+maa_result_t 
97
+Lcm1602::home () {
98
+	return send(LCD_RETURNHOME, 0);
141 99
 }
142 100
 
143
-maa_result_t
144
-Lcm1602::send(uint8_t value, int mode)
145
-{
146
-    maa_result_t ret = MAA_SUCCESS;
101
+/*
102
+ * **************
103
+ *  private area
104
+ * **************
105
+ */
106
+maa_result_t 
107
+Lcm1602::send (uint8_t value, int mode) {
108
+	maa_result_t ret = MAA_SUCCESS;
147 109
     uint8_t h = value & 0xf0;
148 110
     uint8_t l = (value << 4) & 0xf0;
149 111
     ret = write4bits(h | mode);
@@ -164,7 +126,7 @@ maa_result_t
164 126
 Lcm1602::expandWrite(uint8_t value)
165 127
 {
166 128
     uint8_t buffer = value | LCD_BACKLIGHT;
167
-    return maa_i2c_write_byte(m_i2c, buffer);
129
+    return maa_i2c_write_byte(m_i2c_lcd_control, buffer);
168 130
 }
169 131
 
170 132
 maa_result_t

src/lcm1602/lcm1602.h → src/lcd/lcm1602.h View File

@@ -28,37 +28,28 @@
28 28
 #pragma once
29 29
 
30 30
 #include <string>
31
-#include <maa/i2c.h>
31
+#include "iiclcd.h"
32 32
 
33 33
 namespace upm {
34 34
 
35
-class Lcm1602 {
36
-public:
37
-    /** LCM1602 Constructor.
38
-     * Calls MAA initialisation functions.
39
-     * @param bus i2c bus to use
40
-     * @param address the slave address the lcd is registered on.
41
-     */
42
-    Lcm1602(int bus, int address);
43
-
44
-    // Clear the screen
45
-    int clear();
46
-    // Set the cursor to home
47
-    int home();
48
-    // change cursor to row,column.
49
-    int cursor(int row, int column);
50
-    //write a string at the position
51
-    maa_result_t write(std::string msg);
52
-    maa_result_t close();
53
-
54
-private:
55
-    int m_address;
56
-    int m_bus;
57
-    maa_result_t send(uint8_t value, int mode);
58
-    maa_result_t write4bits(uint8_t value);
59
-    maa_result_t expandWrite(uint8_t value);
60
-    maa_result_t pulseEnable(uint8_t value);
61
-    maa_i2c_context m_i2c;
62
-};
35
+class Lcm1602 : public IICLcd {
36
+	public:
37
+		/** LCM1602 Constructor.
38
+		 * Calls MAA initialisation functions.
39
+		 * @param bus i2c bus to use
40
+		 * @param address the slave address the lcd is registered on.
41
+		 */
42
+		Lcm1602(int bus, int address);
43
+		~Lcm1602();
44
+		maa_result_t write (std::string msg);
45
+		maa_result_t setCursor (int row, int column);
46
+		maa_result_t clear ();
47
+		maa_result_t home ();
63 48
 
49
+	private :
50
+		maa_result_t send (uint8_t value, int mode);
51
+		maa_result_t write4bits(uint8_t value);
52
+		maa_result_t expandWrite(uint8_t value);
53
+		maa_result_t pulseEnable(uint8_t value);
54
+	};
64 55
 }

+ 8
- 0
src/lcd/pyupm_jhd1313m1.i View File

@@ -0,0 +1,8 @@
1
+%module pyupm_jhd1313m1
2
+
3
+%feature("autodoc", "3");
4
+
5
+%include "jhd1313m1.h"
6
+%{
7
+    #include "jhd1313m1.h"
8
+%}

src/lcm1602/pyupm_lcm1602.i → src/lcd/pyupm_lcm1602.i View File


+ 0
- 39
src/lcm1602/CMakeLists.txt View File

@@ -1,39 +0,0 @@
1
-set (libname "lcm1602")
2
-add_library (lcm1602 SHARED lcm1602.cxx)
3
-include_directories (${MAA_INCLUDE_DIR})
4
-target_link_libraries (lcm1602 ${MAA_LIBRARIES})
5
-
6
-if (SWIG_FOUND)
7
-  find_package (PythonLibs)
8
-
9
-  include_directories (
10
-    ${PYTHON_INCLUDE_PATH}
11
-    ${PYTHON_INCLUDE_DIRS}
12
-    ${MAA_INCLUDE_DIR}
13
-    .
14
-  )
15
-
16
-  set_source_files_properties (pyupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
17
-  set_source_files_properties (jsupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
18
-  set_source_files_properties (jsupm_lcm1602.i PROPERTIES SWIG_FLAGS "-node")
19
-
20
-  swig_add_module (pyupm_lcm1602 python pyupm_lcm1602.i lcm1602.cxx)
21
-#  swig_add_module (jsupm_lcm1602 javascript jsupm_lcm1602.i lcm1602.cxx)
22
-
23
-  swig_link_libraries (pyupm_lcm1602 ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
24
-#  swig_link_libraries (jsupm_lcm1602 ${MAA_LIBRARIES})
25
-
26
-  if (DOXYGEN_FOUND)
27
-    set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
28
-    add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
29
-      COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
30
-        ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
31
-        ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
32
-        DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
33
-    )
34
-    add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
35
-    add_dependencies (${libname}doc_i doc)
36
-    add_dependencies (${SWIG_MODULE_pyupm_lcm1602_REAL_NAME} ${libname}doc_i)
37
-  endif ()
38
-
39
-endif ()