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