-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update API.md #112
base: master
Are you sure you want to change the base?
Update API.md #112
Conversation
Attempt at clarifying the BLECharacteristic initialisation when using non-string values containing 0's.
Correct typo
@mrvanes thanks for submitting this. Just curious, why are you using a |
I'm really not a C expert so I just use char as a shortcut for 1-byte values and it had the least casting work-arounds. |
@mrvanes what if we add another virtual bool setValue(const unsigned char value[], unsigned char length);
virtual bool setValue(const char value[], unsigned char length); // <-- new
virtual bool setValue(const char* value); |
I must admit that I don't see the difference between char value[] and char* value. Both result in a pointer to an array if I'm not mistaken (please correct me if I'm wrong). Anyway, the problems started when I did something like this:
Assuming I could construct AND initialise the Characteristic to the initial value I made (which fails, due to the 0's in value, the Characteristic will have length 2 and value { 1, 2 }). The solution was to construct using And set the initial value using Having your extra setValue prototype doesn't help IMHO, because the assumption of constructing + initialisation in one command might still happen to newcomers? |
Not sure this is your problem because I'm not quite sure what/how you're using the values in your array, but I think you're mistaking how you use chars. When you're putting in zeroes like that you're actually putting in the ASCII value of zero and not the char '0'. The problem is an ASCII value of zero means 'null' which signifies the end of a string, thus the string you're passing to the function is only two characters long. Again though, maybe you know that and I'm misunderstanding the issue. If I'm not however, simply try putting your values in single-quotes and then you'll be passing in the ASCII value (i.e. the char value) for '0' instead of the literal value 0 which again means null.
|
Yes, my problem was completely caused by my "abuse" of an array of char, assuming I could use any char and rely on passing that to the constuctor. I did need 0x00's, just never realised I'd terminate the string and would fail initialising the characteristic. So the main point I try to raise in this issue is, be careful offering an array of chars as constructor, people (like me) may mistake it for an array of meaningless bytes... |
Attempt at clarifying the BLECharacteristic initialisation when using non-string values containing 0's.