#include "B4RDefines.h"

B4R::Serial* b4r_main::_serial1;
B4R::B4RSoftwareSerial* b4r_main::_softwareserial1;
B4R::AsyncStreams* b4r_main::_astream;
B4R::Timer* b4r_main::_timer1;
B4R::Pin* b4r_main::_pindata;
B4R::Pin* b4r_main::_pinled;
bool b4r_main::_send;
static B4R::Serial be_gann1_3;
static B4R::B4RSoftwareSerial be_gann2_3;
static B4R::AsyncStreams be_gann3_3;
static B4R::Timer be_gann4_3;
static B4R::Pin be_gann5_3;
static B4R::Pin be_gann5_7;


 void b4r_main::_appstart(){
const UInt cp = B4R::StackMemory::cp;
 //BA.debugLineNum = 17;BA.debugLine="Private Sub AppStart";
 //BA.debugLineNum = 18;BA.debugLine="Serial1.Initialize(115200)";
b4r_main::_serial1->Initialize((ULong) (115200));
 //BA.debugLineNum = 19;BA.debugLine="Log(\"AppStart\")";
B4R::Common::LogHelper(1,102,F("AppStart"));
 //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="pinData.Initialize(pinData.A1, pinData.MODE_INPUT";
b4r_main::_pindata->Initialize(Pin_A1,Pin_MODE_INPUT);
 //BA.debugLineNum = 23;BA.debugLine="pinLED.Initialize(9, pinLED.MODE_OUTPUT)";
b4r_main::_pinled->Initialize((Byte) (9),Pin_MODE_OUTPUT);
 //BA.debugLineNum = 24;BA.debugLine="Timer1.Initialize(\"Timer1_Tick\", 100)";
b4r_main::_timer1->Initialize(_timer1_tick,(ULong) (100));
 //BA.debugLineNum = 25;BA.debugLine="End Sub";
B4R::StackMemory::cp = cp;
}
void b4r_main::_astream_newdata(B4R::Array* _buffer){
const UInt cp = B4R::StackMemory::cp;
 //BA.debugLineNum = 34;BA.debugLine="Private Sub AStream_NewData (Buffer() As Byte)";
 //BA.debugLineNum = 36;BA.debugLine="Send = Buffer(0) = 1			'data received, one byte,";
b4r_main::_send = ((Byte*)_buffer->getData((UInt) (0)))[B4R::Array::staticIndex]==1;
 //BA.debugLineNum = 37;BA.debugLine="pinLED.DigitalWrite(Send)	'sets the LED";
b4r_main::_pinled->DigitalWrite(b4r_main::_send);
 //BA.debugLineNum = 38;BA.debugLine="Timer1.Enabled = Send			'enables or disables the";
b4r_main::_timer1->setEnabled(b4r_main::_send);
 //BA.debugLineNum = 39;BA.debugLine="Log(\"Send\")";
B4R::Common::LogHelper(1,102,F("Send"));
 //BA.debugLineNum = 40;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 Timer1 As Timer";
b4r_main::_timer1 = &be_gann4_3;
 //BA.debugLineNum = 13;BA.debugLine="Private pinData, pinLED As Pin";
b4r_main::_pindata = &be_gann5_3;
b4r_main::_pinled = &be_gann5_7;
 //BA.debugLineNum = 14;BA.debugLine="Private Send As Boolean";
b4r_main::_send = false;
 //BA.debugLineNum = 15;BA.debugLine="End Sub";
}
void b4r_main::_timer1_tick(){
const UInt cp = B4R::StackMemory::cp;
Byte be_ann20_9e1[1];
B4R::Array be_ann20_9e2;
 //BA.debugLineNum = 27;BA.debugLine="Private Sub Timer1_Tick";
 //BA.debugLineNum = 29;BA.debugLine="astream.Write(NumberFormat(pinData.AnalogRead, 0,";
b4r_main::_astream->Write(B4R::__c->NumberFormat(b4r_main::_pindata->AnalogRead(),(Byte) (0),(Byte) (0))->GetBytes());
 //BA.debugLineNum = 30;BA.debugLine="Log(pinData.AnalogRead)";
B4R::Common::LogHelper(1,4,b4r_main::_pindata->AnalogRead());
 //BA.debugLineNum = 31;BA.debugLine="astream.Write(Array As Byte(10)) 'end of line cha";
b4r_main::_astream->Write(be_ann20_9e2.create(be_ann20_9e1,1,1,(Byte) (10)));
 //BA.debugLineNum = 32;BA.debugLine="End Sub";
B4R::StackMemory::cp = cp;
}
