Committer:
daan
Date:
Fri Dec 16 07:14:05 2011 +0000
Revision:
1:578d6bbe9f09
Child:
2:ce4c7e5ab241

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daan 1:578d6bbe9f09 1 #include "WriterBase.h"
daan 1:578d6bbe9f09 2
daan 1:578d6bbe9f09 3 #include "assert.h"
daan 1:578d6bbe9f09 4 #include "VectorFormat.h"
daan 1:578d6bbe9f09 5
daan 1:578d6bbe9f09 6 // for strlen
daan 1:578d6bbe9f09 7 #include "string.h"
daan 1:578d6bbe9f09 8
daan 1:578d6bbe9f09 9 olc::WriterBase::WriterBase() :
daan 1:578d6bbe9f09 10 mData(0),
daan 1:578d6bbe9f09 11 mPlayHead(0),
daan 1:578d6bbe9f09 12 mCapacity(0),
daan 1:578d6bbe9f09 13 mPenDown(0),
daan 1:578d6bbe9f09 14 mLaserPower(0),
daan 1:578d6bbe9f09 15 mGalvoX(0),
daan 1:578d6bbe9f09 16 mGalvoY(0)
daan 1:578d6bbe9f09 17 {
daan 1:578d6bbe9f09 18 }
daan 1:578d6bbe9f09 19
daan 1:578d6bbe9f09 20
daan 1:578d6bbe9f09 21 bool olc::WriterBase::penUp()
daan 1:578d6bbe9f09 22 {
daan 1:578d6bbe9f09 23 if (spaceLeft() < 1) return false;
daan 1:578d6bbe9f09 24 put((uint8_t)olc::PEN_UP );
daan 1:578d6bbe9f09 25 return true;
daan 1:578d6bbe9f09 26 }
daan 1:578d6bbe9f09 27
daan 1:578d6bbe9f09 28 bool olc::WriterBase::penDown()
daan 1:578d6bbe9f09 29 {
daan 1:578d6bbe9f09 30 if (spaceLeft() < 1) return false;
daan 1:578d6bbe9f09 31 put((uint8_t)olc::PEN_DOWN );
daan 1:578d6bbe9f09 32 return true;
daan 1:578d6bbe9f09 33 }
daan 1:578d6bbe9f09 34
daan 1:578d6bbe9f09 35 bool olc::WriterBase::wait(uint16_t aWait)
daan 1:578d6bbe9f09 36 {
daan 1:578d6bbe9f09 37 if (spaceLeft() < 2) return false;
daan 1:578d6bbe9f09 38 put( (uint8_t)olc::WAIT );
daan 1:578d6bbe9f09 39 encodeU16( aWait );
daan 1:578d6bbe9f09 40 return true;
daan 1:578d6bbe9f09 41 }
daan 1:578d6bbe9f09 42
daan 1:578d6bbe9f09 43
daan 1:578d6bbe9f09 44 bool olc::WriterBase::moveTo(uint16_t aX, uint16_t aY) {
daan 1:578d6bbe9f09 45 if (spaceLeft() < 5) return false;
daan 1:578d6bbe9f09 46 put( (uint8_t)olc::MOVE_TO );
daan 1:578d6bbe9f09 47 encodeU16( aX );
daan 1:578d6bbe9f09 48 encodeU16( aY );
daan 1:578d6bbe9f09 49 return true;
daan 1:578d6bbe9f09 50 }
daan 1:578d6bbe9f09 51
daan 1:578d6bbe9f09 52 bool olc::WriterBase::lineTo(uint16_t x, uint16_t y)
daan 1:578d6bbe9f09 53 {
daan 1:578d6bbe9f09 54 if (spaceLeft() < 5) return false;
daan 1:578d6bbe9f09 55 put((uint8_t)olc::LINE_TO );
daan 1:578d6bbe9f09 56 encodeU16( x );
daan 1:578d6bbe9f09 57 encodeU16( y );
daan 1:578d6bbe9f09 58 return true;
daan 1:578d6bbe9f09 59 }
daan 1:578d6bbe9f09 60
daan 1:578d6bbe9f09 61 bool olc::WriterBase::setLaserPower(uint16_t aPower)
daan 1:578d6bbe9f09 62 {
daan 1:578d6bbe9f09 63 if (spaceLeft() < 2) return false;
daan 1:578d6bbe9f09 64 put( (uint8_t)olc::LASER_POWER );
daan 1:578d6bbe9f09 65 encodeU16( aPower );
daan 1:578d6bbe9f09 66 return true;
daan 1:578d6bbe9f09 67 }
daan 1:578d6bbe9f09 68
daan 1:578d6bbe9f09 69 bool olc::WriterBase::setStepSize(uint16_t aStepSize)
daan 1:578d6bbe9f09 70 {
daan 1:578d6bbe9f09 71 if (spaceLeft() < 2) return false;
daan 1:578d6bbe9f09 72 put( (uint8_t)olc::STEP_SIZE );
daan 1:578d6bbe9f09 73 encodeU16( aStepSize );
daan 1:578d6bbe9f09 74 return true;
daan 1:578d6bbe9f09 75 }
daan 1:578d6bbe9f09 76
daan 1:578d6bbe9f09 77 bool olc::WriterBase::readRgb()
daan 1:578d6bbe9f09 78 {
daan 1:578d6bbe9f09 79 if (spaceLeft() < 2) return false;
daan 1:578d6bbe9f09 80 put( (uint8_t)olc::READ_RGB );
daan 1:578d6bbe9f09 81 return true;
daan 1:578d6bbe9f09 82 }
daan 1:578d6bbe9f09 83
daan 1:578d6bbe9f09 84 bool olc::WriterBase::reportRgb(uint8_t r, uint8_t g, uint8_t b)
daan 1:578d6bbe9f09 85 {
daan 1:578d6bbe9f09 86 if (spaceLeft() < 4) return false;
daan 1:578d6bbe9f09 87 put( (uint8_t)olc::REPORT_RGB );
daan 1:578d6bbe9f09 88 put( r );
daan 1:578d6bbe9f09 89 put( g );
daan 1:578d6bbe9f09 90 put( b );
daan 1:578d6bbe9f09 91 return true;
daan 1:578d6bbe9f09 92 }
daan 1:578d6bbe9f09 93
daan 1:578d6bbe9f09 94 bool olc::WriterBase::bitmapU8(uint8_t *aData, uint8_t aSize) {
daan 1:578d6bbe9f09 95 if (spaceLeft() < 2) return false;
daan 1:578d6bbe9f09 96 put( (uint8_t)olc::BITMAPU8 );
daan 1:578d6bbe9f09 97 put( aSize );
daan 1:578d6bbe9f09 98 for(int i=0; i < (int)aSize; i++) {
daan 1:578d6bbe9f09 99 put( aData[i] );
daan 1:578d6bbe9f09 100 }
daan 1:578d6bbe9f09 101 return true;
daan 1:578d6bbe9f09 102 }
daan 1:578d6bbe9f09 103
daan 1:578d6bbe9f09 104 bool olc::WriterBase::message(int aLevel, const char *aString) {
daan 1:578d6bbe9f09 105 // first calculate size
daan 1:578d6bbe9f09 106 size_t size = strlen(aString);
daan 1:578d6bbe9f09 107 if (size > 254 ) return false;
daan 1:578d6bbe9f09 108 if (spaceLeft() < 4+size) return false;
daan 1:578d6bbe9f09 109
daan 1:578d6bbe9f09 110 put( (uint8_t)olc::MESSAGE );
daan 1:578d6bbe9f09 111 put( (uint8_t)aLevel );
daan 1:578d6bbe9f09 112 put( (uint8_t)size );
daan 1:578d6bbe9f09 113 const char* ptr = &(aString[0]);
daan 1:578d6bbe9f09 114 while (*ptr != '\0') {
daan 1:578d6bbe9f09 115 put( *ptr );
daan 1:578d6bbe9f09 116 ptr++;
daan 1:578d6bbe9f09 117 }
daan 1:578d6bbe9f09 118 put ( 0 ); // end message with a zero.
daan 1:578d6bbe9f09 119 return true;
daan 1:578d6bbe9f09 120 }
daan 1:578d6bbe9f09 121
daan 1:578d6bbe9f09 122 bool olc::WriterBase::areYouThere() {
daan 1:578d6bbe9f09 123 if (spaceLeft() < 1) return false;
daan 1:578d6bbe9f09 124 put( (uint8_t)olc::AYT );
daan 1:578d6bbe9f09 125 return true;
daan 1:578d6bbe9f09 126 }
daan 1:578d6bbe9f09 127
daan 1:578d6bbe9f09 128 bool olc::WriterBase::ready() {
daan 1:578d6bbe9f09 129 if (spaceLeft() < 1) return false;
daan 1:578d6bbe9f09 130 put( (uint8_t)olc::READY );
daan 1:578d6bbe9f09 131 return true;
daan 1:578d6bbe9f09 132 }
daan 1:578d6bbe9f09 133
daan 1:578d6bbe9f09 134
daan 1:578d6bbe9f09 135 void olc::WriterBase::setData(uint8_t *aData, int aCapacity) {
daan 1:578d6bbe9f09 136 assert(aCapacity > 0);
daan 1:578d6bbe9f09 137 assert(aData != 0);
daan 1:578d6bbe9f09 138 mPlayHead = 0;
daan 1:578d6bbe9f09 139 mCapacity = aCapacity;
daan 1:578d6bbe9f09 140 mData = aData;
daan 1:578d6bbe9f09 141 }
daan 1:578d6bbe9f09 142
daan 1:578d6bbe9f09 143
daan 1:578d6bbe9f09 144