Skip to content

Commit 5567117

Browse files
author
Martin Schuhfuss
committed
feat(rpi2-support): build-process and artifacts
updates the build-process to provide two independent bindings for the old raspberry-pi (based on jgarff/rpi_ws281x) and the raspberry-pi 2 (based on the fork richardghirst/rpi_ws281x).
1 parent 38e07ab commit 5567117

File tree

8 files changed

+76
-24
lines changed

8 files changed

+76
-24
lines changed

.gitmodules

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
[submodule "src/rpi_ws281x"]
2-
path = src/rpi_ws281x
1+
[submodule "src/rpi1_ws281x"]
2+
path = src/rpi1_ws281x
3+
url = git@github.com:jgarff/rpi_ws281x.git
4+
[submodule "src/rpi2_ws281x"]
5+
path = src/rpi2_ws281x
36
url = git@github.com:richardghirst/rpi_ws281x.git

binding.gyp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,44 @@
55
'targets': [
66
{
77
'target_name': 'rpi_ws281x',
8-
'sources': ['./src/rpi-ws281x.cc'],
9-
'dependencies': ['libws2811'],
8+
'type': 'none',
9+
'dependencies': ['rpi1_ws281x', 'rpi2_ws281x']
10+
},
11+
12+
{
13+
'target_name': 'rpi1_ws281x',
14+
'sources': ['./src/rpi1-ws281x.cc'],
15+
'dependencies': ['rpi1_libws2811'],
16+
'include_dirs': ['<!(node -e "require(\'nan\')")']
17+
},
18+
19+
{
20+
'target_name': 'rpi2_ws281x',
21+
'sources': ['./src/rpi2-ws281x.cc'],
22+
'dependencies': ['rpi2_libws2811'],
1023
'include_dirs': ['<!(node -e "require(\'nan\')")']
1124
},
1225

1326
{
14-
'target_name': 'libws2811',
27+
'target_name': 'rpi1_libws2811',
28+
'type': 'static_library',
29+
'sources': [
30+
'./src/rpi1_ws281x/ws2811.c',
31+
'./src/rpi1_ws281x/pwm.c',
32+
'./src/rpi1_ws281x/dma.c'
33+
],
34+
'cflags': ['-O2', '-Wall']
35+
},
36+
37+
{
38+
'target_name': 'rpi2_libws2811',
1539
'type': 'static_library',
1640
'sources': [
17-
'./src/rpi_ws281x/ws2811.c',
18-
'./src/rpi_ws281x/pwm.c',
19-
'./src/rpi_ws281x/dma.c',
20-
'./src/rpi_ws281x/mailbox.c',
21-
'./src/rpi_ws281x/board_info.c'
41+
'./src/rpi2_ws281x/ws2811.c',
42+
'./src/rpi2_ws281x/pwm.c',
43+
'./src/rpi2_ws281x/dma.c',
44+
'./src/rpi2_ws281x/mailbox.c',
45+
'./src/rpi2_ws281x/board_info.c'
2246
],
2347
'cflags': ['-O2', '-Wall']
2448
},
@@ -29,7 +53,10 @@
2953
'dependencies': ['rpi_ws281x'],
3054
'copies': [{
3155
'destination': './lib/binding/',
32-
'files': ['<(PRODUCT_DIR)/rpi_ws281x.node']
56+
'files': [
57+
'<(PRODUCT_DIR)/rpi1_ws281x.node',
58+
'<(PRODUCT_DIR)/rpi2_ws281x.node'
59+
]
3360
}]
3461
}
3562
]

lib/ws281x-native.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@ function getNativeBindings() {
66
// test for matches the raspberry-pi before loading the native-module
77
if(process.arch === 'arm' || process.platform === 'linux') {
88

9-
// will only work on the Broadcom BCM2709
10-
var isBCM2708_9 = (function() {
11-
var cpuInfo = require('fs').readFileSync('/proc/cpuinfo').toString();
12-
13-
return /hardware\s*:\s*bcm2708/i.test(cpuInfo) || /hardware\s*:\s*bcm2709/i.test(cpuInfo);
9+
// will only work on RPi1 (Broadcom BCM2708) and RPi2 (BCM2709) and
10+
// this is the best check i could come up with to see which one we are
11+
// dealing with.
12+
var raspberryVersion = (function() {
13+
var cpuInfo = require('fs').readFileSync('/proc/cpuinfo').toString(),
14+
socFamily = cpuInfo.match(/hardware\s*:\s*(bcm270[89])/i);
15+
16+
if(!socFamily) { return 0; }
17+
18+
switch(socFamily[1].toLowerCase()) {
19+
case 'bcm2708': return 1;
20+
case 'bcm2709': return 2;
21+
default: return 0;
22+
}
1423
} ());
1524

16-
if(isBCM2708_9) {
17-
return require('./binding/rpi_ws281x.node');
25+
if(raspberryVersion === 1) {
26+
return require('./binding/rpi1_ws281x.node');
27+
} else if(raspberryVersion === 2) {
28+
return require('./binding/rpi2_ws281x.node');
1829
}
1930
}
2031

@@ -27,8 +38,8 @@ var ws281xNative = getNativeBindings();
2738
if(!ws281xNative) {
2839
process.stderr.write(
2940
'[rpi-ws281x-native] it looks like you are not running the module ' +
30-
'on a raspberry pi. Will only return stubs for native ' +
31-
'interface-functions.\n'
41+
'on a raspberry pi so there will be no functionality exposed by this ' +
42+
'module. For convenience, stub-implementations are provided.\n'
3243
);
3344

3445
ws281xNative = {

src/rpi-ws281x.cc renamed to src/rpi-ws281x-common.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <algorithm>
1010

1111
extern "C" {
12-
#include "rpi_ws281x/ws2811.h"
12+
#include "rpi1_ws281x/ws2811.h"
1313
}
1414

1515
using namespace v8;
@@ -147,6 +147,4 @@ void initialize(Handle<Object> exports) {
147147
exports->Set(NanNew<String>("init"), NanNew<FunctionTemplate>(Init)->GetFunction());
148148
exports->Set(NanNew<String>("reset"), NanNew<FunctionTemplate>(Reset)->GetFunction());
149149
exports->Set(NanNew<String>("render"), NanNew<FunctionTemplate>(Render)->GetFunction());
150-
}
151-
152-
NODE_MODULE(rpi_ws281x, initialize)
150+
}

src/rpi1-ws281x.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <node.h>
2+
#include "rpi-ws281x-common.cc"
3+
4+
using namespace v8;
5+
6+
NODE_MODULE(rpi1_ws281x, initialize)

src/rpi2-ws281x.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <node.h>
2+
#include "rpi-ws281x-common.cc"
3+
4+
using namespace v8;
5+
6+
NODE_MODULE(rpi2_ws281x, initialize)

src/rpi2_ws281x

Submodule rpi2_ws281x added at 39afaac

0 commit comments

Comments
 (0)