#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
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
Public serial2 As SoftwareSerial 'Additional software serial port
Private astream As AsyncStreams
Private lat,lon As Long
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
serial2.Initialize(9600,5,6) ', rx 5, TX is 6
astream.Initialize(serial2.Stream,"astream_newdata",Null)
Log("AppStart")
RunNative("setup",Null)
End Sub
Sub astream_newdata(Buffer() As Byte)
RunNative("gpsread",Null)
Log(Buffer)
End Sub
#if C
#include "TinyGPS.h"
#define PIN_TX 6
#define PIN_RX 5
SoftwareSerial serial2(PIN_TX,PIN_RX);
TinyGPS gps;
void setup(B4R::Object* o){
serial2.begin(9600);
}
void gpsread (B4R::Object* o) {
int c = serial2.read();
gps.encode(c);
long slat, slong;
gps.f_get_position(&slat,&slong);
b4r_main::_lat = slat;
b4r_main::_lon = slong;
}
#End if