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.

Featured Replies

Geschrieben

Hello,

I have a question about discovery of devices with Ruby. Enumeration supplies the numeric device_identifier for each device, for instance 2103 for a 'LED Strip Bricklet 2.0'.

See documentation.

Next steps would be to load the file defining the matching class, and to initialize an instance of that class:

require 'tinkerforge/bricklet_led_strip_v2'

Tinkerforge::BrickletLEDStripV2.new ...

In other words, I need the name of the matching class for a '2103 device' and the file which defines that class.

Tinkerforge::DEVICE_DISPLAY_NAMES only maps device_identifier to device_display_name.

How do I map numeric device_identifier to class and file?

One way would be to load all 139 device classes, and than loop through all Tinkerforge::Device descendants until I find the one with the matching DEVICE_IDENTIFIER constant. That sounds like a really bad idea.

Has anyone figured this out yet?

bearbeitet von Superp
a %#@& typo

Geschrieben

Tinkerforge::DEVICE_DISPLAY_NAMES is internal for error message purposes.

What you're looking for is a device factory. The Ruby bindings don't have that.

7 hours ago, Superp said:

One way would be to load all 139 device classes, and than loop through all Tinkerforge::Device descendants until I find the one with the matching DEVICE_IDENTIFIER constant. That sounds like a really bad idea.

That's not a bad idea at all, that basically how Brick Viewer solves this problem. But instead of doing a linear search, Brick Viewer builds a dictionary that maps device identifier to device class and then uses that dictionary to do the lookup efficiently.

What are you trying to build that requires a device factory?

Geschrieben
  • Autor

Hi Photron,

Thanks for responding. I am basically just a lazy programmer who likes magic.

What I have done so far is write a little bit of Ruby that 1) takes stock of Device descendants. 2) requires one of TF's source-files. 3) takes stock again and compares to (1) to identify any newly defined class. 4) gets DEVICE_IDENTIFIER and DEVICE_DISPLAY_NAME from the newly defined class. 5) Repeats for all source-files.

This generates a device_info.txt which maps device_identifier, device class, source-file, and device_display_name. You can use any of these four to look up the other three.

This is my third week of using TF and I hope to make it part of a fairly big project. 

Geschrieben
  • Autor

So, I think I found a working solution, which I'll share here in case anyone else runs into the same limitation.

Tinkerforge.device_info 2103
=> [2103, "LED Strip Bricklet 2.0", ["Tinkerforge::BrickletLEDStripV2", "bricklet_led_strip_v2"]]

and

my_devices = Tinkerforge.connect.discover

Source here.

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.