In B4R could not find a builtin function for Chr to convert an AscII DEC code to a Char literal (i.e. Chr(76) = 'L').
Workout a solution using Inline C combined with a Sub, but wondering if there is a simpler way for the Chr function. Any suggestions?
Workout a solution using Inline C combined with a Sub, but wondering if there is a simpler way for the Chr function. Any suggestions?
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private asciiChar As String
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Chr(76) 'L
Chr(77) 'M
End Sub
' Convert ascii dec 48 (0) to 90 (Z)
' Runs inline c to update global var asciiChar
Private Sub Chr(asciiCode As Int)
RunNative("convertAscII", asciiCode)
Log(asciiCode, "=", asciiChar)
End Sub
#if c
// Convert ascii dec to b4r string using Arduino C/C++ function: char(x) - Converts a value to the char data type
// Requires global var asciichar as string
void convertAscII(B4R::Object* o) {
String buffer = String(char(o->toULong()));
B4R::PrintToMemory pm;
B4R::B4RString* s = B4R::B4RString::PrintableToString(NULL);
pm.print(buffer);
B4R::StackMemory::buffer[B4R::StackMemory::cp++] = 0;
b4r_main::_asciichar = s;
}
#End If