#include "B4RDefines.h"

B4R::Serial* b4r_main::_serial1;
B4R::B4RSoftwareSerial* b4r_main::_softwareserial1;
B4R::AsyncStreams* b4r_main::_astream;
B4R::Pin* b4r_main::_yellowled;
B4R::Timer* b4r_main::_timer1;
static B4R::Serial be_gann1_3;
static B4R::B4RSoftwareSerial be_gann2_3;
static B4R::AsyncStreams be_gann3_3;
static B4R::Pin be_gann4_3;
static B4R::Timer be_gann5_3;


 void b4r_main::_appstart(){
const UInt cp = B4R::StackMemory::cp;
 //BA.debugLineNum = 16;BA.debugLine="Private Sub AppStart";
 //BA.debugLineNum = 17;BA.debugLine="Serial1.Initialize(115200)";
b4r_main::_serial1->Initialize((ULong) (115200));
 //BA.debugLineNum = 18;BA.debugLine="Log(\"AppStart\")";
B4R::Common::LogHelper(1,102,F("AppStart"));
 //BA.debugLineNum = 19;BA.debugLine="YellowLED.Initialize(9, YellowLED.MODE_OUTPUT)";
b4r_main::_yellowled->Initialize((Byte) (9),Pin_MODE_OUTPUT);
 //BA.debugLineNum = 20;BA.debugLine="SoftwareSerial1.Initialize(9600, 11, 12) 'softwar";
b4r_main::_softwareserial1->Initialize((ULong) (9600),(Byte) (11),(Byte) (12));
 //BA.debugLineNum = 21;BA.debugLine="astream.Initialize(SoftwareSerial1.Stream, \"astre";
b4r_main::_astream->Initialize(b4r_main::_softwareserial1->getStream(),_astream_newdata,NULL);
 //BA.debugLineNum = 22;BA.debugLine="Timer1.Initialize(\"timer1_Tick\", 1000)";
b4r_main::_timer1->Initialize(_timer1_tick,(ULong) (1000));
 //BA.debugLineNum = 23;BA.debugLine="Timer1.Enabled = True";
b4r_main::_timer1->setEnabled(Common_True);
 //BA.debugLineNum = 24;BA.debugLine="End Sub";
B4R::StackMemory::cp = cp;
}
void b4r_main::_astream_newdata(B4R::Array* _buffer){
const UInt cp = B4R::StackMemory::cp;
UInt _value = 0;
 //BA.debugLineNum = 32;BA.debugLine="Sub AStream_NewData (Buffer() As Byte)";
 //BA.debugLineNum = 33;BA.debugLine="Dim value As UInt = Buffer(0)";
_value = (UInt) (((Byte*)_buffer->getData((UInt) (0)))[B4R::Array::staticIndex]);
 //BA.debugLineNum = 34;BA.debugLine="Log(value)";
B4R::Common::LogHelper(1,4,_value);
 //BA.debugLineNum = 35;BA.debugLine="YellowLED.AnalogWrite(value)";
b4r_main::_yellowled->AnalogWrite(_value);
 //BA.debugLineNum = 36;BA.debugLine="End Sub";
B4R::StackMemory::cp = cp;
}

void b4r_main::initializeProcessGlobals() {
     B4R::StackMemory::buffer = (byte*)malloc(STACK_BUFFER_SIZE);
     b4r_main::_process_globals();

   
}
void b4r_main::_process_globals(){
const UInt cp = B4R::StackMemory::cp;
 //BA.debugLineNum = 8;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 9;BA.debugLine="Public Serial1 As Serial";
b4r_main::_serial1 = &be_gann1_3;
 //BA.debugLineNum = 10;BA.debugLine="Private SoftwareSerial1 As SoftwareSerial";
b4r_main::_softwareserial1 = &be_gann2_3;
 //BA.debugLineNum = 11;BA.debugLine="Private astream As AsyncStreams";
b4r_main::_astream = &be_gann3_3;
 //BA.debugLineNum = 12;BA.debugLine="Private YellowLED As Pin";
b4r_main::_yellowled = &be_gann4_3;
 //BA.debugLineNum = 13;BA.debugLine="Private Timer1 As Timer";
b4r_main::_timer1 = &be_gann5_3;
 //BA.debugLineNum = 14;BA.debugLine="End Sub";
}
void b4r_main::_timer1_tick(){
const UInt cp = B4R::StackMemory::cp;
B4R::B4RString be_ann17_4;
Byte be_ann19_9e1[1];
B4R::Array be_ann19_9e2;
 //BA.debugLineNum = 26;BA.debugLine="Sub Timer1_Tick";
 //BA.debugLineNum = 27;BA.debugLine="astream.Write(\"Millis here: \".GetBytes)";
b4r_main::_astream->Write(be_ann17_4.wrap("Millis here: ")->GetBytes());
 //BA.debugLineNum = 28;BA.debugLine="astream.Write(NumberFormat(Millis, 0, 0).GetBytes";
b4r_main::_astream->Write(B4R::__c->NumberFormat(Common_Millis(),(Byte) (0),(Byte) (0))->GetBytes());
 //BA.debugLineNum = 29;BA.debugLine="astream.Write(Array As Byte(10)) 'end of line cha";
b4r_main::_astream->Write(be_ann19_9e2.create(be_ann19_9e1,1,1,(Byte) (10)));
 //BA.debugLineNum = 30;BA.debugLine="End Sub";
B4R::StackMemory::cp = cp;
}
