Comments (7)
Hi Jochen,
the Nuimo SDK runs a D-Bus event loop on the same thread where you call ControllerManager().run
. This said, if you do time.sleep(1)
on the same thread, you will also block the SDK's D-Bus event loop so it won't send and receive Bluetooth messages. Please note that duration
parameter is only a hint how long Nuimo's firmware will display the matrix until it disappears.
You have three options here:
- Call
ControllerManager().run
on a different thread - Call both
time.sleep(1)
anddisplay_matrix()
on a different thread - Use an asynchronous timer function that doesn't block the thread
Please let me know if you need further assistance.
from nuimo-linux-python.
Hmm.. I already put the ControllerManager.run() on a different thread because I noticed that due to that event loop my script wouldn't react to Ctrl-C anymore (for an orderly shutdown & cleanup).
I don't recall why I put sleeps in the old version, but it must've been a similar problem of the durations not working. So, can I expect that calling display_matrix() several times with different patterns and durations will result in those patterns being displayed exactly for those durations?
from nuimo-linux-python.
I would use an asynchronous timer function that makes the next display_matrix()
call only after some seconds. I guess that's the easiest way. But using a seconds thread to call this method should work as well.
If you call display_matrix()
multiple times, it will actually only send the first matrix and the last matrix to Nuimo. Why is that? As soon as you call display_matrix()
, the matrix is immediately sent to Nuimo (this is if you don't block the thread). If you do another display_matrix()
right after the first call, the matrix will immediately overwrite the previous matrix. display_matrix()
's interval
is not the duration how long Nuimo should wait before showing the next matrix. It is the interval how long the matrix should be shown if no other matrix is sent in the meantime.
This said, if you make multiple display_matrix()
calls in a row without waiting between those calls you will only see the first matrix because it is immediately being sent to Nuimo. Subsequent calls will be ignored if Nuimo has not yet acknowledged to have received the first matrix. Hence having no delay between two display_matrix()
calls will only show the first matrix, ignore further calls until a response is (internally) received and then finally send the last matrix after an acknowledgement has been received.
This sounds all very complicated, but it's actually not :) Here are two rules that you can follow:
interval
parameter is the time the matrix is shown on Nuimo before it fades out in case no other matrix is sent in the meanwhile.- If you want to show a sequence of matrices (like in "animation") you as the SDK user are responsible for adding a delay between calls to
display_matrix()
. Make sure that delay doesn't block the same thread whereControllerManager.run()
has been called. I.e. use asynchronous timer functions.
In the future we might add built-in support for showing a sequence of matrices with pre-defined delays between each matrix. For now it's your responsibility to ensure the delay.
Please let us know if it's still unclear and we're happy to support.
from nuimo-linux-python.
@jo-me I had better experience with putting ControllerManager
on the main thread and display manipulation on a different one. I put together a small example here, I hope this helps:
from threading import Thread
from time import sleep
from nuimo import Controller, ControllerManager, ControllerListener, LedMatrix
DEFAULT_ADAPTER_NAME = "hci0"
MAC_ADDRESS = "c4:d7:54:71:e2:ce"
ICON_NUMBER_1 = LedMatrix(" "
" # "
" ## "
" # # "
" # "
" # "
" # "
" ### "
" ")
ICON_NUMBER_2 = LedMatrix(" "
" ## "
" # # "
" # "
" # "
" # "
" # "
" #### "
" ")
ICON_NUMBER_3 = LedMatrix(" "
" ## "
" # # "
" # "
" # "
" # "
" # # "
" ## "
" ")
DOT_MATRIX = [
ICON_NUMBER_1,
ICON_NUMBER_2,
ICON_NUMBER_3,
]
class NuimoListener(ControllerListener):
def __init__(self, controller):
self.controller = controller
self.stopping = False
self.t = Thread(target=self.show_dots)
def connect_succeeded(self):
self.t.start()
def show_dots(self):
i = 0
while not self.stopping:
m = DOT_MATRIX[i]
self.controller.display_matrix(m, interval=3.0, brightness=1.0, fading=True)
i += 1
if i >= len(DOT_MATRIX):
i = 0
sleep(1.5)
def stop(self):
self.controller.disconnect()
self.stopping = True
controller = Controller(adapter_name=DEFAULT_ADAPTER_NAME, mac_address=MAC_ADDRESS)
listener = NuimoListener(controller)
controller.listener = listener
controller.connect()
manager = ControllerManager()
try:
manager.run()
except KeyboardInterrupt:
print("Stopping...")
listener.stop()
manager.stop()
from nuimo-linux-python.
Hi @jo-me, are you now having success implementing a matrix animation? We have added the above example also to the examples folder.
from nuimo-linux-python.
Hi @larsblumberg, I read your and @grunskis explanations & examples but I did not have the time to try them out yet. They do sound very reasonable, though. So, thank you for that! I think the examples will also help others to understand how things are meant to work and quickstart new projects.
from nuimo-linux-python.
Cool – let us know when there's any more question
from nuimo-linux-python.
Related Issues (20)
- suggested changes before initial release HOT 1
- Error in python3: double free or corruption (fasttop) HOT 4
- Raspberry Pi 1 fails due to discover_characteristics HOT 3
- linux sdk not working on ubuntu 16.04 HOT 5
- Disconnect Nuimo controller if service and characteristic initialization failed after a successful connect
- Bluetooth MAC is AA:AA:AA:AA:AA:AA after bluez upgrade HOT 5
- nuimoctl broken after update to 0.24 HOT 2
- Update examples HOT 3
- Exception thrown from `connect_failed` HOT 2
- dbus.connection: Unable to set arguments HOT 4
- connect failed: No such property 'ServicesResolved' HOT 4
- Add option to completely deactivate FLY events
- Compatibility question
- LED Matrix not working HOT 8
- LED matrix does not update with BlueZ 5.50
- Wrong command in readme HOT 1
- Error installing pygattlib on Raspberry 1 HOT 2
- I want to have a delegate method that is called when Nuimo disconnects HOT 1
- TypeError: list indices must be integers, not str HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuimo-linux-python.