diff --git a/debian/changelog b/debian/changelog index d0173be..4cc7a9b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +matrixio-malos (0.3.4) unstable; urgency=medium + + * Bug Fix: Handle Everloop in MATRIX Voice and MATRIX Creator. + * Info: Comptible with protoc >= 0.3.5 + * Bug Fix: Handle Bus init error. + + -- MATRIX Labs Wed, 30 Apr 2018 15:02:53 +0000 + matrixio-malos (0.3.3) unstable; urgency=medium * Support changes in libmatrixio-creator-hal. diff --git a/src/driver_everloop.cpp b/src/driver_everloop.cpp index 3bf85d4..00c41ee 100644 --- a/src/driver_everloop.cpp +++ b/src/driver_everloop.cpp @@ -28,16 +28,7 @@ namespace matrix_malos { bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { pb::io::EverloopImage image(config.image()); - if (image.led_size() != matrix_hal::kMatrixCreatorNLeds) { - std::string error_msg("35, Invalid number of leds for "); - error_msg += kEverloopDriverName; - error_msg += ". MATRIX Creator has " + - std::to_string(matrix_hal::kMatrixCreatorNLeds) + " leds."; - zmq_push_error_->Send(error_msg); - return false; - } - - matrix_hal::EverloopImage image_for_hal; + matrix_hal::EverloopImage image_for_hal(MatrixLeds()); int idx = 0; for (const pb::io::LedValue& value : image.led()) { image_for_hal.leds[idx].red = value.red(); @@ -55,4 +46,15 @@ bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { return writer_->Write(&image_for_hal); } +bool EverloopDriver::SendUpdate() { + pb::io::EverloopImage everloop_pb; + int32_t matrix_leds = MatrixLeds(); + + everloop_pb.set_everloop_length(matrix_leds); + + std::string buffer; + everloop_pb.SerializeToString(&buffer); + zqm_push_update_->Send(buffer); + return true; +} } // namespace matrix_malos diff --git a/src/driver_everloop.h b/src/driver_everloop.h index b19ae68..b4967bf 100644 --- a/src/driver_everloop.h +++ b/src/driver_everloop.h @@ -31,26 +31,32 @@ namespace matrix_malos { class EverloopDriver : public MalosWishboneBase { public: + EverloopDriver() : MalosWishboneBase(kEverloopDriverName) { - SetProvidesUpdates(false); - SetNeedsKeepalives(false); SetNotesForHuman( - "Write-only. There are 35 leds. Values range from 0 to 255. Check " + "Write-only. There are N leds. Values range from 0 to 255. Check " "message EverloopImage (protocol buffer)"); } + int32_t MatrixLeds(){return matrix_leds_;} + // Receive a copy of the shared wishbone bus. Not owned. void SetupMatrixIOBus(matrix_hal::MatrixIOBus* wishbone) override { writer_.reset(new matrix_hal::Everloop); writer_->Setup(wishbone); + matrix_leds_ = wishbone->MatrixLeds(); } // Read configuration of LEDs (from the outside world). bool ProcessConfig(const pb::driver::DriverConfig& config) override; + // Send update to 0MQ zqm_push_update_ queue when called. + bool SendUpdate() override; + private: // Everloop writer. std::unique_ptr writer_; + int32_t matrix_leds_; }; } // namespace matrix_malos diff --git a/src/js_test/package.json b/src/js_test/package.json index 6cc7f84..174d8eb 100644 --- a/src/js_test/package.json +++ b/src/js_test/package.json @@ -7,7 +7,7 @@ "repository": "https://github.com/matrix-io/matrix-creator-malos", "devDependencies": {}, "dependencies": { - "matrix-protos": "0.0.17", + "matrix-protos":"", "mic": "^2.1.1", "zmq": "^2.15.3" } diff --git a/src/js_test/test_everloop.js b/src/js_test/test_everloop.js index 0e44d1d..5d6044a 100644 --- a/src/js_test/test_everloop.js +++ b/src/js_test/test_everloop.js @@ -17,42 +17,67 @@ var zmq = require('zmq') // Import MATRIX Proto messages var matrix_io = require('matrix-protos').matrix_io - // To trigger an error message you can send an invalid configuration to the driver. // For instance, set a number of leds != 35. var errorSocket = zmq.socket('sub') errorSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 2)) errorSocket.subscribe('') errorSocket.on('message', (error_message) => { - console.log('Message received: Pressure error: ' + error_message.toString('utf8')) + console.log('Message received: Pressure error: ' + error_message.toString('utf8')) }); var configSocket = zmq.socket('push') -configSocket.connect('tcp://' + creator_ip + ':' + creator_everloop_base_port /* config */) +configSocket.connect('tcp://' + creator_ip + ':' + creator_everloop_base_port /* config */ ) + +var config = matrix_io.malos.v1.driver.DriverConfig.create({ + delayBetweenUpdates: 2.0, // 2 seconds between updates + timeoutAfterLastPing: 6.0, // Stop sending updates 6 seconds after pings. +}) + +configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()) var max_intensity = 50 var intensity_value = max_intensity +var matrix_device_leds = 0 + +var updateSocket = zmq.socket('sub') +updateSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 3)) +updateSocket.subscribe('') +updateSocket.on('message', (buffer) => { + var data = matrix_io.malos.v1.io.EverloopImage.decode(buffer) + matrix_device_leds = data.everloopLength +}); + +var pingSocket = zmq.socket('push') +pingSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 1)) +console.log('Sending pings every 5 seconds'); +pingSocket.send(''); // Ping the first time. +setInterval(() => { + pingSocket.send(''); +}, 5000); + function setEverloop(led_values) { - var image = matrix_io.malos.v1.io.EverloopImage.create() - for (var j = 0; j < 35; ++j) { - var led_conf = matrix_io.malos.v1.io.LedValue.create(led_values); - image.led.push(led_conf) - } - var config = matrix_io.malos.v1.driver.DriverConfig.create({ - image: image - }) - configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()); + + var image = matrix_io.malos.v1.io.EverloopImage.create() + for (var j = 0; j < matrix_device_leds; ++j) { + var led_conf = matrix_io.malos.v1.io.LedValue.create(led_values); + image.led.push(led_conf) + } + var config = matrix_io.malos.v1.driver.DriverConfig.create({ + image: image + }) + configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()); } setInterval(() => { - intensity_value -= 1 - if (intensity_value < 0) - intensity_value = max_intensity - setEverloop({ - red: 0, - green: intensity_value, - blue: 0, - white: 0 - }) -}, 50); + intensity_value -= 1 + if (intensity_value < 0) + intensity_value = max_intensity + setEverloop({ + red: 0, + green: intensity_value, + blue: 0, + white: 0 + }) +}, 50); \ No newline at end of file diff --git a/src/malos.cpp b/src/malos.cpp index 78b1e58..d560474 100644 --- a/src/malos.cpp +++ b/src/malos.cpp @@ -47,7 +47,8 @@ int RunServer() { std::cerr << std::endl; matrix_hal::MatrixIOBus* bus = new matrix_hal::MatrixIOBus(); - bus->Init(); + + if (!bus->Init()) return false; DriverManager driver_manager(kBasePort, kUnsecureBindScope); std::cerr << "You can query specific driver info using port " +