Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Node.js applikation funktioniert nur mit geöffnetem BrickViewer Tab

Featured Replies

Geschrieben

Habe ein sehr seltsames Problem.

 

Hier mein Setup:

 

Master Brick per USB an einem Debian Laptop.

Am Master Brick hängt 1x Segment-Display(4x7), 1x Linear Poti.

Meine Anwendung visualisiert den Wert des Poti (0-100) auf der Segment-Anzeige.

 

Wenn ich den code via nodejs ausführe funktioniert erstmal garnichts. Erst wenn ich den BrickViewer starte und auf den Tab des "Linear Poti" gehe, funktioniert es plötzlich. Kennt dieses Problem jemand, beziehungsweise kann mir jemand weiterhelfen?

 

 

Hier der Code (index.js):

 

var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;

var DIGITS = [
    0x3f,
    0x06,
    0x5b,
    0x4f,
    0x66,
    0x6d,
    0x7d,
    0x07,
    0x7f,
    0x6f
];

var ipcon = new Tinkerforge.IPConnection();

var poti = new Tinkerforge.BrickletLinearPoti('r73', ipcon);
var segment = new Tinkerforge.BrickletSegmentDisplay4x7('pMU', ipcon);

ipcon.connect(HOST, PORT,
    function (error) {
        console.log('Error: ' + error);
    }
);

// Linear poti callback
poti.on(Tinkerforge.BrickletLinearPoti.CALLBACK_POSITION,
    function (position) {
        var number_array = toArray(position);
        var result_segments = [0x00, 0x00, 0x00, 0x00];
        for (var i = 0; i < number_array.length; i++) {
            result_segments[i] = DIGITS[number_array[i]];
        }
        segment.setSegments(result_segments, 5, false);
    }
);
console.log("Press any key to exit ...");

function toArray(number) {
    return number.toString(10).replace(/\D/g, '0').split('').map(Number);
}

function getRandom(from, to) {
    return Math.floor((Math.random() * to) + from);
}

 

Geschrieben
  • Autor

Fixed it, forgot to setup the PositionCallbackPeriod

ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED,
    function(connectReason) {
        // Set Period for position callback to 0.05s (50ms)
        // Note: The position position is only called every 50ms if the
        // position has changed since the last call!
        poti.setPositionCallbackPeriod(50);
    }
);

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.