PIco in host mode works but I need to declare a global variable #9235
-
OK I was able to switch micropython in usb host mode to get a USB gamepad working. I want to get ridd of the Pi to read the gamepad and send udp datagram to my small robot! https://www.youtube.com/watch?v=nC8gTRUxHxI I just add some c funtion to poll the usbhost to the the gamepad. It was working !!! yeah But I made a mistake and now I can't remember how I declare a a 10 byte variable. I was using MP_REGISTER_ROOT_POINTER(uint8_t gamepad[10]) and MP_STATE_VM(gamepad) to set and get the variable but now micropython can't compile anymore. It was working before. Did I use the correct stuff to implement my variable Question 1 . How to I declare a global variable of 10 bytes that my c function in gamepad module could read. I though it was MP_STATE_VM but obviously its not or I missed something. Question 2. I create a function to poll the gamepad but I need to put in in a loop when a script is running. Works Well if I use Thonny and not running a scrirpt. So where is the best place to put the poll_gamepad() to empty the usb host and get my gamepad data. compile gives error! GamePadData is not define anymore uint8_t * pt = (uint8_t *) MP_STATE_VM(GamePadData); memcpy(pt,report,10); //for(loop=0;loop<sizeR;loop++) and my gamepad.get() uint8_t * pt = (uint8_t *) MP_STATE_VM(Game_PadData);
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Since
If you are registering |
Beta Was this translation helpful? Give feedback.
-
oops typo on my part. MP_REGISTER_ROOT_POINTER(uint8_t GamePadData[10]) and MP_STATE_VM(GamePadData) is the real term i'm using on my code. I tried (void *) , (uint8_t *) and got the same result. is there another way to have a global variable that could be link to a module. The example in C aren't very good to explain how to manipulate object . |
Beta Was this translation helpful? Give feedback.
-
OK I found my bug! I forget to add the file gamepad_var.c into the CMakLists.txt MICROPY_SOURCE_QSTR this file gamepad_var.c is simple
Now Where do I put the poll to read the usb host in a loop to be able to get information about the gamepad when the Pico run a script. |
Beta Was this translation helpful? Give feedback.
OK I found my bug! I forget to add the file gamepad_var.c into the CMakLists.txt MICROPY_SOURCE_QSTR
this file gamepad_var.c is simple
Now Where do I put the poll to read the usb host in a loop to be able to get information about the gamepad when the Pico run a script.