Kaynağa Gözat

lol: Added Olimex LoL array support, 13x9 LED matrix

Signed-off-by: izard <alexander.komarov@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
izard 10 yıl önce
ebeveyn
işleme
d97ce2378b

+ 3
- 0
examples/CMakeLists.txt Dosyayı Görüntüle

@@ -37,6 +37,7 @@ add_executable (tcs3414cs-example tcs3414cs.cxx)
37 37
 add_executable (th02-example th02.cxx)
38 38
 add_executable (lsm303-example lsm303.cxx)
39 39
 add_executable (joystick12-example joystick12-example.cxx)
40
+add_executable (lol-example lol-example.cxx)
40 41
 
41 42
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
42 43
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -68,6 +69,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/tcs3414cs)
68 69
 include_directories (${PROJECT_SOURCE_DIR}/src/th02)
69 70
 include_directories (${PROJECT_SOURCE_DIR}/src/lsm303)
70 71
 include_directories (${PROJECT_SOURCE_DIR}/src/joystick12)
72
+include_directories (${PROJECT_SOURCE_DIR}/src/lol)
71 73
 
72 74
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
73 75
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@@ -108,3 +110,4 @@ target_link_libraries (tcs3414cs-example tcs3414cs ${CMAKE_THREAD_LIBS_INIT})
108 110
 target_link_libraries (th02-example th02 ${CMAKE_THREAD_LIBS_INIT})
109 111
 target_link_libraries (lsm303-example lsm303 ${CMAKE_THREAD_LIBS_INIT})
110 112
 target_link_libraries (joystick12-example joystick12 ${CMAKE_THREAD_LIBS_INIT})
113
+target_link_libraries (lol-example lol ${CMAKE_THREAD_LIBS_INIT})

+ 67
- 0
examples/lol-example.cxx Dosyayı Görüntüle

@@ -0,0 +1,67 @@
1
+/*
2
+ * Author: Alexander Komarov <alexander.komarov@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 <unistd.h>
26
+#include <iostream>
27
+#include <signal.h>
28
+#include "lol.h"
29
+#include <stdlib.h>
30
+#include <sys/time.h>
31
+
32
+int is_running = 0;
33
+upm::LoL *sensor = NULL;
34
+
35
+void
36
+sig_handler(int signo)
37
+{
38
+    printf("got signal\n");
39
+    if (signo == SIGINT) {
40
+        is_running = 1;
41
+    }
42
+}
43
+
44
+//! [Interesting]
45
+int
46
+main(int argc, char **argv)
47
+{
48
+    sensor = new upm::LoL();
49
+    signal(SIGINT, sig_handler);
50
+
51
+    unsigned char *buffer;
52
+    //buffer = sensor->getFramebuffer();
53
+    int x = 0, y = 0;
54
+    while (!is_running) {
55
+        sensor->setPixel(x, y, !(sensor->getPixel(x, y)));
56
+        if (++x == 13) { x = 0; y++; }
57
+        if (y == 9) y = 0;
58
+        usleep(10000);
59
+    }
60
+
61
+    std::cout << "exiting application" << std::endl;
62
+
63
+    delete sensor;
64
+
65
+    return 0;
66
+}
67
+//! [Interesting]

+ 5
- 0
src/lol/CMakeLists.txt Dosyayı Görüntüle

@@ -0,0 +1,5 @@
1
+set (libname "lol")
2
+set (libdescription "LoL Olimex LoL rev A")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 8
- 0
src/lol/jsupm_lol.i Dosyayı Görüntüle

@@ -0,0 +1,8 @@
1
+%module jsupm_lol
2
+%include "../upm.i"
3
+
4
+%{
5
+    #include "lol.h"
6
+%}
7
+
8
+%include "lol.h"

+ 218
- 0
src/lol/lol.cxx Dosyayı Görüntüle

@@ -0,0 +1,218 @@
1
+/*
2
+ * Author: Alexander Komarov <alexander.komarov@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
+#include <stdlib.h>
28
+#include <functional>
29
+#include <string.h>
30
+#include "lol.h"
31
+
32
+using namespace upm;
33
+
34
+static mraa_gpio_context *m_Ctx;
35
+static unsigned char *buffer;
36
+
37
+static mraa_gpio_context c1, c2, c3, c4;
38
+
39
+static int charlie_pairs [12][22] = {
40
+{3,124, 4,110, 5,96,  6,82,  7,68, 8,54, 9,40, 10,26, 11,12, -1,-1, -1,-1},
41
+{3,122, 4,108, 5,94,  6,80,  7,66, 8,52, 9,38, 10,24, 11,10, -1,-1, -1,-1},
42
+{3,120, 4,106, 5,92,  6,78,  7,64, 8,50, 9,36, 10,22, 11,8,  -1,-1, -1,-1},
43
+{0,125, 1,123, 2,121, 4,98,  5,84, 6,70, 7,56, 8,42,  9,28,  10,14, 11,0},
44
+{0,111, 1,109, 2,107, 3,112, 5,85, 6,71, 7,57, 8,43, 9,29,   10,15, 11,1},
45
+{0,97,  1,95,  2,93,  3,113, 4,99, 6,72, 7,58, 8,44, 9,30,   10,16, 11,2},
46
+{0,83,  1,81,  2,79,  3,114, 4,100,5,86, 7,59, 8,45, 9,31,   10,17, 11,3},
47
+{0,69,  1,67,  2,65,  3,115, 4,101,5,87, 6,73, 8,46, 9,32,   10,18, 11,4},
48
+{0,55,  1,53,  2,51,  3,116, 4,102,5,88, 6,74, 7,60, 9,33,   10,19, 11,5},
49
+{0,41,  1,39,  2,37,  3,117, 4,103,5,89, 6,75, 7,61, 8,47,   10,20, 11,6},
50
+{0,27,  1,25,  2,23,  3,118, 4,104,5,90, 6,76, 7,62, 8,48,   9,34,  11,7},
51
+{0,13,  1,11,  2,9,   3,119, 4,105,5,91, 6,77, 7,63, 8,49,   9,35,  10,21}
52
+};
53
+
54
+//static int gpios_map[] = {
55
+//14,15,28,17,24,27,26,19,16,25,38,39,
56
+//};
57
+
58
+void clear_gpio(int gpio)
59
+{
60
+/* FIXME AK hack around Galileo gen1 issue, to remove
61
+    if(gpio == 0)
62
+    {
63
+    mraa_gpio_mode(c1, MRAA_GPIO_HIZ);	
64
+    mraa_gpio_mode(c2, MRAA_GPIO_HIZ);
65
+    }
66
+    else if (gpio == 1) {
67
+    mraa_gpio_mode(c3, MRAA_GPIO_HIZ);	
68
+    mraa_gpio_mode(c4, MRAA_GPIO_HIZ);	
69
+    } else*/
70
+    mraa_gpio_mode(m_Ctx[gpio], MRAA_GPIO_HIZ);	
71
+
72
+    mraa_gpio_dir(m_Ctx[gpio], MRAA_GPIO_IN);
73
+}
74
+
75
+void clear_prev_cycle(int cycle)
76
+{
77
+	int i;
78
+
79
+// What is prev cycle?
80
+	cycle--;
81
+	if (cycle == -1)
82
+		cycle = 11;
83
+
84
+// Disable all "1"'s
85
+	for (i = 0; i < 11; i++) {
86
+		if (charlie_pairs[cycle][i*2] == -1)
87
+			break;
88
+		if(buffer[charlie_pairs[cycle][i*2 + 1]])
89
+			clear_gpio(charlie_pairs[cycle][i*2]);
90
+	}
91
+
92
+// Disable "0"
93
+	clear_gpio(cycle);
94
+}
95
+
96
+void set_strong_one(int gpio)
97
+{
98
+    mraa_gpio_dir(m_Ctx[gpio], MRAA_GPIO_OUT);
99
+/* FIXME AK hack around Galileo gen1 issue, to remove
100
+    if(gpio == 0)
101
+    {
102
+    mraa_gpio_mode(c1, MRAA_GPIO_STRONG);	
103
+    mraa_gpio_mode(c2, MRAA_GPIO_STRONG);
104
+    }
105
+    else if (gpio == 1) {
106
+    mraa_gpio_mode(c3, MRAA_GPIO_STRONG);	
107
+    mraa_gpio_mode(c4, MRAA_GPIO_STRONG);	
108
+    } else*/
109
+    mraa_gpio_mode(m_Ctx[gpio], MRAA_GPIO_STRONG);	
110
+    mraa_gpio_write(m_Ctx[gpio], 1);
111
+}
112
+
113
+void set_strong_zero(int gpio)
114
+{
115
+    mraa_gpio_dir(m_Ctx[gpio], MRAA_GPIO_OUT);
116
+/* FIXME AK hack around Galileo gen1 issue, to remove
117
+    if(gpio == 0)
118
+    {
119
+    mraa_gpio_mode(c1, MRAA_GPIO_STRONG);	
120
+    mraa_gpio_mode(c2, MRAA_GPIO_STRONG);
121
+    }
122
+    else if (gpio == 1) {
123
+    mraa_gpio_mode(c3, MRAA_GPIO_STRONG);	
124
+    mraa_gpio_mode(c4, MRAA_GPIO_STRONG);	
125
+    } else*/
126
+    mraa_gpio_mode(m_Ctx[gpio], MRAA_GPIO_STRONG);	
127
+    mraa_gpio_write(m_Ctx[gpio], 0);
128
+}
129
+
130
+
131
+static void clear_gpios()
132
+{
133
+    int i;
134
+    for (i = 0; i < 12; i++)
135
+        clear_gpio(i);
136
+}
137
+
138
+void *do_draw(void *arg)
139
+{
140
+/*    c1 = mraa_gpio_init_raw(31);
141
+    c2 = mraa_gpio_init_raw(32);
142
+    c3 = mraa_gpio_init_raw(30);
143
+    c4 = mraa_gpio_init_raw(18);
144
+*/
145
+
146
+    clear_gpios();
147
+
148
+    while (1) {
149
+        int i, cur;
150
+        uint8_t cycle = 0;
151
+// 12 Cycles of Matrix
152
+        for (cycle = 0; cycle < 12; cycle++)
153
+        {
154
+            if (cycle == 12) cycle = 0;
155
+
156
+            clear_prev_cycle(cycle);
157
+// set strong/0 on current cycle line
158
+            set_strong_zero(cycle);
159
+
160
+// draw ones from framebuffer
161
+            for (i = 0; i < 11; i++) {
162
+                cur = charlie_pairs[cycle][i*2];
163
+                if (cur == -1) break;
164
+
165
+                if (buffer[charlie_pairs[cycle][i*2 + 1]]) {
166
+                    set_strong_one(cur);
167
+//	printf("cycle %d %d %d %d\n", cycle, i, charlie_pairs[cycle][i*2 + 1],
168
+//           buffer[charlie_pairs[cycle][i*2 + 1]]);
169
+                }
170
+            }
171
+        }
172
+
173
+    }
174
+}
175
+
176
+LoL::LoL() {
177
+    int i = 0;
178
+    mraa_result_t error;
179
+    for (i = 0; i < 12; i++)
180
+        m_LoLCtx[i] = mraa_gpio_init(i+2);
181
+
182
+    memset(framebuffer, 0, LOL_X*LOL_Y);
183
+
184
+    // I am optimistic and stupid - thread creation 
185
+    // always works in my world
186
+    buffer = (unsigned char*)framebuffer;
187
+    m_Ctx = m_LoLCtx;
188
+    pthread_create (&drawer_thread, NULL, do_draw, NULL);
189
+}
190
+
191
+LoL::~LoL() {
192
+    int i = 0;
193
+    mraa_result_t error;
194
+    for (i = 0; i < 12; i++)
195
+        mraa_gpio_close(m_LoLCtx[i]);
196
+}
197
+
198
+unsigned char* LoL::getFramebuffer() {
199
+    return framebuffer;
200
+}
201
+
202
+unsigned char LoL::setPixel(int x, int y, unsigned char pixel)
203
+{
204
+    if (x < 0 || y < 0 || x >= LOL_X || y >= LOL_Y)
205
+        return -1;
206
+
207
+    framebuffer[x + LOL_X*y] = (pixel == 0) ? 0 : 1;
208
+    return 0;
209
+}
210
+
211
+unsigned char LoL::getPixel(int x, int y)
212
+{
213
+    if (x < 0 || y < 0 || x >= LOL_X || y >= LOL_Y)
214
+        return -1;
215
+
216
+    return (framebuffer[x + LOL_X*y] == 0) ? 0 : 1;
217
+}
218
+

+ 93
- 0
src/lol/lol.h Dosyayı Görüntüle

@@ -0,0 +1,93 @@
1
+/*
2
+ * Author: Alexander Komarov <alexander.komarov@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 <mraa/gpio.h>
28
+#include <mraa/aio.h>
29
+#include <pthread.h>
30
+
31
+namespace upm {
32
+
33
+#define LOL_X 14
34
+#define LOL_Y 9
35
+/**
36
+ * @brief C++ API for Olimex LoL array
37
+ *
38
+ * This file defines the LoL API and implemntation for 
39
+ * a simple framebuffer
40
+ *
41
+ * @snippet lol-example.cxx Interesting
42
+ *
43
+ */
44
+class LoL {
45
+    public:
46
+        /**
47
+         * Instantiates a LoL object
48
+         * singleton
49
+         */
50
+        LoL();
51
+
52
+        /**
53
+         * LoL object destructor
54
+         */
55
+        ~LoL();
56
+
57
+        /**
58
+         * Get framebuffer pointer
59
+         * @return 0 on success
60
+         */
61
+        unsigned char *getFramebuffer();
62
+
63
+        /**
64
+         * Gets pixel at coordinates
65
+         * @param x coordinate x
66
+         * @param y coordinate y
67
+         * @return 1 if pixel is on, 0 if off, -1 on error
68
+         */
69
+        unsigned char getPixel(int x, int y);
70
+
71
+        /**
72
+         * sets pixel at coordinates
73
+         * @param x coordinate x
74
+         * @param y coordinate y
75
+         * @param pixel 0 is off, 1 is on
76
+         * @return 0 on success, -1 on error
77
+         */
78
+        unsigned char setPixel(int x, int y, unsigned char pixel);
79
+
80
+        /**
81
+         * Get framebuffer pointer
82
+         * @return 1 if pixel is on, 0 if off, -1 on error
83
+         */
84
+        unsigned char getBit(int x, int y);
85
+
86
+
87
+    private:
88
+        mraa_gpio_context    m_LoLCtx[14];
89
+        unsigned char framebuffer[LOL_X*LOL_Y];
90
+        pthread_t        drawer_thread;
91
+};
92
+};
93
+

+ 11
- 0
src/lol/pyupm_lol.i Dosyayı Görüntüle

@@ -0,0 +1,11 @@
1
+%module pyupm_lol
2
+%include "../upm.i"
3
+
4
+%include "stdint.i"
5
+
6
+%feature("autodoc", "3");
7
+
8
+%include "lol.h"
9
+%{
10
+    #include "lol.h"
11
+%}