Hello,
I need to use methods setTime and getTimeStr from the Real Time Clock DS1307 in a project.
I could not find a library for this clock for B4R, so I tried to use inline C to access these methods.
I have no knowledge of C, but I can understand the code, and they are very simple. The problem is with strings, I can't return a string from C code. When I compile I receive an error about converting char to string.
Any advice?
this is my code:
\
b4r_main.cpp:17: error: cannot convert 'char*' to 'B4R::B4RString*' in assignment
b4r_main::_time = time;
I need to use methods setTime and getTimeStr from the Real Time Clock DS1307 in a project.
I could not find a library for this clock for B4R, so I tried to use inline C to access these methods.
I have no knowledge of C, but I can understand the code, and they are very simple. The problem is with strings, I can't return a string from C code. When I compile I receive an error about converting char to string.
Any advice?
this is my code:
\
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Dim time As String
Dim timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
timer1.Initialize("timer1_Tick",1000)
Log("AppStart")
timer1.Enabled=True
End Sub
Sub timer1_tick
RunNative("getTimeStr", Null)
Log("Time: ",time)
End Sub
#if C
#include <DS1307.h> // DS1307 RTC Clock library
DS1307 rtc(5, 4);
// Get Time string
char* getTimeStr(B4R::Object* unused) {
char* time = rtc.getTimeStr();
b4r_main::_time = time;
}
#End if
b4r_main.cpp:17: error: cannot convert 'char*' to 'B4R::B4RString*' in assignment
b4r_main::_time = time;