Diff: PlayerBase.cpp
- Revision:
- 1:578d6bbe9f09
- Parent:
- 0:01be2d5eaf72
- Child:
- 2:ce4c7e5ab241
--- a/PlayerBase.cpp Mon Oct 31 02:34:13 2011 +0000 +++ b/PlayerBase.cpp Fri Dec 16 07:14:05 2011 +0000 @@ -50,11 +50,22 @@ bool olc::PlayerBase::playOne() { if ( bytesLeft() == 0 ) return true; + // definition of variables neccesairy due to the switch statement. maybe + // use the if else if construction. + uint16_t x; uint16_t y; uint8_t header = get(); - uint8_t size; + + // this cannot be a byte because we overflow with 255 packets. + int size; uint16_t power; + char messageString[256]; + char *mesgPtr; + uint8_t messageLength; + uint8_t messageLevel; + uint16_t delay; + uint8_t r,g,b; switch (header) { case olc::MOVE_TO: @@ -67,6 +78,7 @@ setGalvo(mGalvoX,mGalvoY); //std::cout << "move to [" << mGalvoX << "," << mGalvoY << "]" << std::endl; break; + case olc::LINE_TO: // if pen was up, make it go down. if (!mPenDown) { @@ -82,46 +94,89 @@ // setGalvo(mGalvoX,mGalvoY); //std::cout << "line to [" << mGalvoX << "," << mGalvoY << "]" << std::endl; break; - case olc::STEP_SIZE: - // std::cout << "step size" << std::endl; - mStepSize = decodeU16(); - break; case olc::STEP_DELAY: mDelay = decodeU16(); break; - case olc::LASER_POWER: - //std::cout << "laser power" << std::endl; - mLaserPower = decodeU16(); - setLaserPower(mLaserPower); - break; case olc::PEN_DOWN: penDown(); break; case olc::PEN_UP: penUp(); break; + case olc::STEP_SIZE: + // std::cout << "step size" << std::endl; + mStepSize = decodeU16(); + break; + // sending a message. length is as strlen: number of characters + // preceeding the terminating /0 character + case olc::WAIT: - wait( decodeU16() ); + delay = decodeU16(); + wait(delay); + break; + case olc::MESSAGE: + messageLevel = get(); + messageLength = get(); + assert(messageLength < 255); + // now skip x bytes + mesgPtr = &(messageString[0]); + while(1) { + *mesgPtr = get(); + if (*mesgPtr == '\0') break; + mesgPtr++; + // check for buffer overflow. + if ( mesgPtr - &(messageString[0]) == 256 ) break; + } + message(messageLevel, messageLength, &(messageString[0])); + break; + + case olc::CALIBRATION_SCAN: + calibrationScan(); + break; + case olc::POINT: + x = decodeU16(); + y = decodeU16(); + point(x,y); + break; + case olc::READ_RGB: + readRgb(); break; + case olc::AYT: + areYouThere(); + break; + case olc::READY: + ready(); + break; + + case olc::LASER_POWER_RGB: + r = get(); + g = get(); + b = get(); + setLaserPowerRgb(r,g,b); + + case olc::LASER_POWER: + //std::cout << "laser power" << std::endl; + mLaserPower = decodeU16(); + //setLaserPower(mLaserPower); + break; case olc::BITMAPU8: //std::cout << "bitmapU8" << std::endl; penDown(); - size = get(); - for( int i = 0; i < (int)size; i++ ) { + size = (int)get(); + for( int i = 0; i < size; i++ ) { uint16_t delay = ((uint16_t) get() ) << 4; wait(delay); // setLaserPower( power ); mGalvoX += mStepSize; setGalvo(mGalvoX, mGalvoY); //std::cout << "power " << (int)power << std::endl; - } - + } break; default: //std::cout << "found unknown code " << (int)header << std::endl; - assert(0); + return false; } - if (mPlayHead >= mSize) return false; + // if (mPlayHead >= mSize) return false; return true; }