send uart struct

titous
Posts: 1
Joined: Fri Aug 18, 2017 11:48 am

send uart struct

Postby titous » Fri Aug 18, 2017 11:53 am

I'm trying to send a struct over UART to be processed by python by using this guide.

Code: Select all

// we send this to the host, to be processed by python script
struct package {
	uint8_t modifier;
	uint8_t keyboard_keys[6];
};

// instantiate struct
package to_send = {};

// send the contents of keyboard_keys and keyboard_modifier_keys
// https://folk.uio.no/jeanra/Microelectronics/TransmitStructArduinoPython.html
void usb_keyboard_send(void)
{

	to_send.modifier = keyboard_modifier_keys;
	for(uint8_t i = 0; i < 6; i++) {
		to_send.keyboard_keys[i] = keyboard_keys[i];
	}

	printf("S");
	printf((uint8_t *)&to_send, sizeof(to_send));
	printf("E");
}
However I get the error:

Code: Select all

invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]
I'm pretty new to C++, and I've tried all sorts of casting, but I just can't get it to work. Could someone offer guidance please?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: send uart struct

Postby kolban » Sat Aug 26, 2017 9:42 pm

Have you tried casting the parameter you are passing from uint8_t * to const char *?

For example:

uint8_t *pMyData = ....;
myFunc((const char *)pMyData);
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 130 guests