bluerobotics / navigator-lib

Library to unleash the hardware capabilities, packed with features and fuel for your coding adventures
https://docs.bluerobotics.com/navigator-lib/python/
MIT License
11 stars 5 forks source link

New function neopixel #25

Closed RaulTrombin closed 1 year ago

RaulTrombin commented 1 year ago

This create a method to set the neopixel.

We need to solve the slice input issue for functions.

It should transform &[ ] to [ ] when compilling on python somehow. Or solve the issue:

RaulTrombin commented 1 year ago

I've tryed different aproaches on cpy-rs, maybe we can make cpy macro just rewrite &[ x , y ] to [ x , y ] when python feature is used.

With &[u8,3] it works fine on Cpp, but triggers the issue for python as pointed.

With [u8;3] it not build the binding for Cpp, as it's FFI unsafe. But works fine on python side. @patrickelectric @joaoantoniocardoso

joaoantoniocardoso commented 1 year ago

I've tryed different aproaches on cpy-rs, maybe we can make cpy macro just rewrite &[ x , y ] to [ x , y ] when python feature is used.

With &[u8,3] it works fine on Cpp, but triggers the issue for python as pointed.

With [u8;3] it not build the binding for Cpp, as it's FFI unsafe. But works fine on python side. @patrickelectric @joaoantoniocardoso

Yeah, I agree, that's the way as it seems to be a language translation limitation

RaulTrombin commented 1 year ago

@patrickelectric it's in sync with cpy-rs, waiting for the next release to rebase it.

RaulTrombin commented 1 year ago

Some major changes was done into this PR,

It was updated to the last cpy-binder version, Now it have an special statement to handle just python or cpp functions.

The set_neopixel method was added for both libraries. A similar rainbow example was added to Cpp and Python source folders.

CI's Clippy warn for unsafe ptr deref needs to disabled.

Now we have set_neopixel like:

Cpp:

  uint8_t rgb_array[3]; 
  // uint8_t rgb_array[3][3];  //lenght shoud be 3. or sizeof(rgb_array)/sizeof(rgb_array[0])
  set_neopixel(&rgb_array, array_lenght);

Python:

  navigator.set_neopixel( [  [rgb_array], ...., ....   ] );

some similar example reference: