PlayerBase.h@2:ce4c7e5ab241, 2011-12-22 (annotated)
- Committer:
- daan
- Date:
- Thu Dec 22 09:44:29 2011 +0000
- Revision:
- 2:ce4c7e5ab241
- Parent:
- 1:578d6bbe9f09
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
daan | 0:01be2d5eaf72 | 1 | #ifndef PLAYER_BASE_H |
daan | 0:01be2d5eaf72 | 2 | #define PLAYER_BASE_H |
daan | 0:01be2d5eaf72 | 3 | |
daan | 0:01be2d5eaf72 | 4 | #include "stdint.h" |
daan | 0:01be2d5eaf72 | 5 | |
daan | 0:01be2d5eaf72 | 6 | namespace olc { |
daan | 0:01be2d5eaf72 | 7 | |
daan | 0:01be2d5eaf72 | 8 | class PlayerBase |
daan | 0:01be2d5eaf72 | 9 | { |
daan | 0:01be2d5eaf72 | 10 | public: |
daan | 0:01be2d5eaf72 | 11 | PlayerBase(); |
daan | 0:01be2d5eaf72 | 12 | virtual void setGalvo(uint16_t x, uint16_t y); |
daan | 0:01be2d5eaf72 | 13 | virtual void setLaserPower(uint16_t power); |
daan | 1:578d6bbe9f09 | 14 | virtual void wait(uint16_t ms); |
daan | 2:ce4c7e5ab241 | 15 | virtual void reportBufferInSize() {}; |
daan | 1:578d6bbe9f09 | 16 | |
daan | 1:578d6bbe9f09 | 17 | // this is for scanning to calibrate camera. |
daan | 1:578d6bbe9f09 | 18 | virtual void calibrationScan() {}; |
daan | 1:578d6bbe9f09 | 19 | virtual void point(uint16_t x, uint16_t y) {}; |
daan | 0:01be2d5eaf72 | 20 | |
daan | 1:578d6bbe9f09 | 21 | // this is for color scanning |
daan | 2:ce4c7e5ab241 | 22 | virtual void readColor() {}; |
daan | 1:578d6bbe9f09 | 23 | virtual void setLaserPowerRgb(uint8_t red, uint8_t green, uint8_t blue) {}; |
daan | 1:578d6bbe9f09 | 24 | |
daan | 1:578d6bbe9f09 | 25 | virtual void ready() {}; |
daan | 1:578d6bbe9f09 | 26 | virtual void areYouThere() {}; |
daan | 1:578d6bbe9f09 | 27 | virtual void message(int aLevel, int aLength, char *aString) {}; |
daan | 1:578d6bbe9f09 | 28 | |
daan | 1:578d6bbe9f09 | 29 | |
daan | 0:01be2d5eaf72 | 30 | inline void penDown() { |
daan | 0:01be2d5eaf72 | 31 | mPenDown = true; |
daan | 0:01be2d5eaf72 | 32 | setLaserPower(mLaserPower); |
daan | 0:01be2d5eaf72 | 33 | } |
daan | 0:01be2d5eaf72 | 34 | inline void penUp() { |
daan | 0:01be2d5eaf72 | 35 | mPenDown = false; |
daan | 0:01be2d5eaf72 | 36 | setLaserPower(0); |
daan | 0:01be2d5eaf72 | 37 | } |
daan | 0:01be2d5eaf72 | 38 | |
daan | 0:01be2d5eaf72 | 39 | void setData(uint8_t *data, int size); |
daan | 0:01be2d5eaf72 | 40 | void setStepSize(uint16_t s) { mStepSize = s; }; |
daan | 0:01be2d5eaf72 | 41 | uint16_t getStepSize() { return mStepSize; }; |
daan | 0:01be2d5eaf72 | 42 | void setDelay(uint16_t ms) { mDelay = ms; }; |
daan | 0:01be2d5eaf72 | 43 | void reset(); |
daan | 0:01be2d5eaf72 | 44 | bool hasNext(); |
daan | 0:01be2d5eaf72 | 45 | bool playOne(); |
daan | 0:01be2d5eaf72 | 46 | |
daan | 1:578d6bbe9f09 | 47 | uint16_t getX() { return mGalvoX; }; |
daan | 1:578d6bbe9f09 | 48 | uint16_t getY() { return mGalvoY; }; |
daan | 1:578d6bbe9f09 | 49 | |
daan | 0:01be2d5eaf72 | 50 | protected: |
daan | 0:01be2d5eaf72 | 51 | void rasterLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int step=1); |
daan | 0:01be2d5eaf72 | 52 | |
daan | 0:01be2d5eaf72 | 53 | |
daan | 0:01be2d5eaf72 | 54 | inline virtual int bytesLeft() { |
daan | 0:01be2d5eaf72 | 55 | return mSize - mPlayHead; |
daan | 0:01be2d5eaf72 | 56 | } |
daan | 0:01be2d5eaf72 | 57 | inline virtual uint8_t get() { |
daan | 0:01be2d5eaf72 | 58 | mPlayHead++; |
daan | 0:01be2d5eaf72 | 59 | return mData[mPlayHead-1]; |
daan | 0:01be2d5eaf72 | 60 | } |
daan | 0:01be2d5eaf72 | 61 | |
daan | 1:578d6bbe9f09 | 62 | // TODO(dps): take care of endian |
daan | 0:01be2d5eaf72 | 63 | inline uint16_t decodeU16() { |
daan | 0:01be2d5eaf72 | 64 | uint16_t i; |
daan | 0:01be2d5eaf72 | 65 | i = (uint16_t)get() << 8; |
daan | 0:01be2d5eaf72 | 66 | i |= (uint16_t)get(); |
daan | 0:01be2d5eaf72 | 67 | return i; |
daan | 0:01be2d5eaf72 | 68 | } |
daan | 0:01be2d5eaf72 | 69 | |
daan | 0:01be2d5eaf72 | 70 | |
daan | 0:01be2d5eaf72 | 71 | uint8_t *mData; |
daan | 0:01be2d5eaf72 | 72 | int mSize; |
daan | 0:01be2d5eaf72 | 73 | int mPlayHead; |
daan | 0:01be2d5eaf72 | 74 | |
daan | 0:01be2d5eaf72 | 75 | bool mPenDown; |
daan | 0:01be2d5eaf72 | 76 | uint16_t mLaserPower; |
daan | 0:01be2d5eaf72 | 77 | uint16_t mGalvoX; |
daan | 0:01be2d5eaf72 | 78 | uint16_t mGalvoY; |
daan | 0:01be2d5eaf72 | 79 | uint16_t mDelay; |
daan | 0:01be2d5eaf72 | 80 | uint16_t mStepSize; |
daan | 0:01be2d5eaf72 | 81 | }; |
daan | 0:01be2d5eaf72 | 82 | |
daan | 0:01be2d5eaf72 | 83 | |
daan | 0:01be2d5eaf72 | 84 | }; // end namespace ol |
daan | 0:01be2d5eaf72 | 85 | |
daan | 0:01be2d5eaf72 | 86 | #endif // PLAYER_BASE_H |