daniel saakes / Olc
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WriterBase.cpp Source File

WriterBase.cpp

00001 #include "WriterBase.h"
00002 
00003 #include "assert.h"
00004 #include "VectorFormat.h"
00005 
00006 // for strlen
00007 #include "string.h"
00008 
00009 olc::WriterBase::WriterBase() :
00010   mData(0),
00011   mPlayHead(0),
00012   mCapacity(0),
00013   mPenDown(0),
00014   mLaserPower(0),
00015   mGalvoX(0),
00016   mGalvoY(0)
00017 {
00018 }
00019 
00020 
00021 bool olc::WriterBase::penUp()
00022 {
00023   if (spaceLeft() < 1) return false;
00024   put((uint8_t)olc::PEN_UP );  
00025   return true;
00026 }
00027 
00028 bool olc::WriterBase::penDown()
00029 {
00030   if (spaceLeft() < 1) return false;
00031   put((uint8_t)olc::PEN_DOWN ); 
00032   return true;
00033 }
00034 
00035 bool olc::WriterBase::wait(uint16_t aWait)
00036 {
00037   if (spaceLeft() < 2) return false;
00038   put( (uint8_t)olc::WAIT );
00039   encodeU16( aWait );
00040   return true; 
00041 }
00042 
00043 
00044 bool olc::WriterBase::moveTo(uint16_t aX, uint16_t aY) {
00045   if (spaceLeft() < 5) return false;
00046   put( (uint8_t)olc::MOVE_TO );
00047   encodeU16( aX );
00048   encodeU16( aY );
00049   return true;
00050 }
00051 
00052 bool olc::WriterBase::lineTo(uint16_t x, uint16_t y) 
00053 {
00054   if (spaceLeft() < 5) return false;
00055   put((uint8_t)olc::LINE_TO );
00056   encodeU16( x );
00057   encodeU16( y );
00058   return true;
00059 }
00060 
00061 bool olc::WriterBase::setLaserPower(uint16_t aPower) 
00062 {
00063   if (spaceLeft() < 2) return false;
00064   put( (uint8_t)olc::LASER_POWER );
00065   encodeU16( aPower );
00066   return true; 
00067 }
00068 
00069 bool olc::WriterBase::setStepSize(uint16_t aStepSize) 
00070 {
00071   if (spaceLeft() < 2) return false;
00072   put( (uint8_t)olc::STEP_SIZE );
00073   encodeU16( aStepSize );
00074   return true; 
00075 }
00076 
00077 bool olc::WriterBase::readColor()
00078 {
00079   if (spaceLeft() < 2) return false;
00080   put( (uint8_t)olc::READ_COLOR );
00081   return true;  
00082 }
00083 
00084 bool olc::WriterBase::reportColor(uint8_t c)
00085 {
00086   if (spaceLeft() < 4) return false;
00087   put( (uint8_t)olc::REPORT_COLOR );
00088   put( c );
00089   return true;
00090 }
00091 
00092 bool olc::WriterBase::reportBufferInSize()
00093 {
00094   if (spaceLeft() < 2) return false;
00095   put( (uint8_t)olc::REPORT_BUFFER_IN_SIZE );
00096   return true;  
00097 }
00098 
00099 bool olc::WriterBase::bufferInSize(uint16_t aSize) 
00100 {
00101   if (spaceLeft() < 3) return false;
00102   put( (uint8_t)olc::BUFFER_IN_SIZE );
00103   encodeU16( aSize );
00104   return true;
00105 }
00106 
00107 bool olc::WriterBase::bitmapU8(uint8_t *aData, uint8_t aSize) 
00108 {
00109   if (spaceLeft() < 2) return false;
00110   put( (uint8_t)olc::BITMAPU8 );
00111   put( aSize );
00112   for(int i=0; i < (int)aSize; i++) {
00113     put( aData[i] );
00114   }
00115   return true; 
00116 }
00117 
00118 bool olc::WriterBase::message(int aLevel, const char *aString) {  
00119   // first calculate size
00120   size_t size = strlen(aString);
00121   if (size > 254 ) return false;
00122   if (spaceLeft() < 4+size) return false;
00123 
00124   put( (uint8_t)olc::MESSAGE );
00125   put( (uint8_t)aLevel );
00126   put( (uint8_t)size );
00127   const char* ptr = &(aString[0]);
00128   while (*ptr != '\0') {
00129     put( *ptr );
00130     ptr++;
00131   }
00132   put ( 0 ); // end message with a zero.
00133   return true;
00134 }
00135 
00136 bool olc::WriterBase::areYouThere() {
00137   if (spaceLeft() < 1) return false;
00138   put( (uint8_t)olc::AYT );
00139   return true;
00140 }
00141 
00142 bool olc::WriterBase::ready() {
00143   if (spaceLeft() < 1) return false;
00144   put( (uint8_t)olc::READY );
00145   return true;
00146 }
00147 
00148 
00149 void olc::WriterBase::setData(uint8_t *aData, int aCapacity) {
00150   assert(aCapacity > 0);
00151   assert(aData != 0);
00152   mPlayHead = 0;
00153   mCapacity = aCapacity;
00154   mData = aData;
00155 }
00156 
00157 
00158