diff options
Diffstat (limited to 'ofxHelios/src')
| -rw-r--r-- | ofxHelios/src/colourPolyline.cpp | 40 | ||||
| -rw-r--r-- | ofxHelios/src/colourPolyline.h | 39 | ||||
| -rw-r--r-- | ofxHelios/src/ofxHelios.cpp | 78 | ||||
| -rw-r--r-- | ofxHelios/src/ofxHelios.h | 78 |
4 files changed, 235 insertions, 0 deletions
diff --git a/ofxHelios/src/colourPolyline.cpp b/ofxHelios/src/colourPolyline.cpp new file mode 100644 index 0000000..24b1e00 --- /dev/null +++ b/ofxHelios/src/colourPolyline.cpp @@ -0,0 +1,40 @@ +#include "colourPolyline.h" + + +void colourPolyline::addVertex( float x, float y){ + addVertex(ofPoint(x,y)); +} + +void colourPolyline::addVertex( const ofPoint& p ){ + addVertex(p, ofColor(255,255,255)); +} + +void colourPolyline::addVertex( float x, float y, int r, int g, int b){ + addVertex(ofPoint(x,y),ofColor(r,g,b)); +} + +void colourPolyline::addVertex( const ofPoint& p , int r, int g, int b){ + addVertex(p,ofColor(r,g,b)); +} + +void colourPolyline::addVertex( const ofPoint& p , const ofColor& c){ + ofPolyline::addVertex(p); + pointColours.push_back(c); +} + + + +ofColor colourPolyline::getColourAt(int i){ + return pointColours[i]; +} + +void colourPolyline::draw(){ + for (int i=0;i<ofPolyline::size()-1;i++){ + ofSetColor(pointColours[i]); + ofPolyline l; + l.addVertex(ofPolyline::operator[](i)); + l.addVertex(ofPolyline::operator[](i+1)); + l.draw(); + //todo - cache + } +} diff --git a/ofxHelios/src/colourPolyline.h b/ofxHelios/src/colourPolyline.h new file mode 100644 index 0000000..93cefee --- /dev/null +++ b/ofxHelios/src/colourPolyline.h @@ -0,0 +1,39 @@ +#pragma once +#include "ofPolyline.h" +#include "ofMain.h" + +class colourPolyline: public ofPolyline { + public: + + colourPolyline(){} + + colourPolyline(const ofPolyline line,const ofColor colour){ + for (auto& point:line){ + addVertex(point, colour); + } + } + + void clear(){ + ofPolyline::clear(); + pointColours.clear(); + } + + void addVertex( float x, float y); + + void addVertex( const ofPoint& p ); + + void addVertex( float x, float y, int r, int g, int b); + + void addVertex( const ofPoint& p , int r, int g, int b); + + void addVertex( const ofPoint& p , const ofColor& c); + + void draw(); + + ofColor getColourAt(int i); + + private: + + vector <ofColor> pointColours; + +};
\ No newline at end of file diff --git a/ofxHelios/src/ofxHelios.cpp b/ofxHelios/src/ofxHelios.cpp new file mode 100644 index 0000000..d05e062 --- /dev/null +++ b/ofxHelios/src/ofxHelios.cpp @@ -0,0 +1,78 @@ +// +// ofxHelios.cpp +// +// +// Created by Tim Redfern Nov 2017 +// +// + +#include "ofxHelios.h" + +/* +draw a colourpolyline + +put in mid points + +draw a vector of lines + +put in dwell points + +*/ + +int ofxHelios::draw(vector <ofPolyline> &points,ofColor colour,int intensity){ + return 0; +} + +int ofxHelios::draw(ofPolyline &line,ofColor colour,int intensity){ + + colourPolyline col=colourPolyline(line,colour); + return draw(col); + +} + +int ofxHelios::draw(colourPolyline &line, int intensity){ + //todo: move to a thread + //todo: add a transform + //POC + + int xoffs=0x800-(ofGetWidth()/2); + int yoffs=0x800-(ofGetHeight()/2); + + if (device!=OFXHELIOS_NODEVICE){ + while (!dac.GetStatus(device)); //timeout for this? + //assemble data + + HeliosPoint points[line.size()]; + + for (int i=0;i<line.size();i++){ + points[i]=HeliosPoint( + { + (uint16_t)(line[i].x+xoffs), + (uint16_t)(line[i].y+yoffs), + (uint8_t)(((line.getColourAt(i).r)*laserintensity)>>8), + (uint8_t)(((line.getColourAt(i).g)*laserintensity)>>8), + (uint8_t)(((line.getColourAt(i).b)*laserintensity)>>8), + (uint8_t)intensity + }); + } + + if (HELIOS_ERROR==dac.WriteFrame(device, pps, HELIOS_FLAGS_DEFAULT, points, line.size())){ + printf("ofxHelios: write error (%i,%i,%i,%i)\n",device, pps, HELIOS_FLAGS_DEFAULT, (int)line.size()); + return -1; + } + + + } + return 0; +} + + + + +void ofxHelios::threadedFunction(){ + + while(isThreadRunning()) { + + } +} + diff --git a/ofxHelios/src/ofxHelios.h b/ofxHelios/src/ofxHelios.h new file mode 100644 index 0000000..d873706 --- /dev/null +++ b/ofxHelios/src/ofxHelios.h @@ -0,0 +1,78 @@ +// +// ofxHelios.h +// +// +// Created by Tim Redfern Nov 2017 +// +// it would be good if ofxHelios could inherit the current transform + +#ifndef ofxHelios_h +#define ofxHelios_h +#define OFXHELIOS_VERSION 0.1 +#define OFXHELIOS_NODEVICE -1 +#include "ofMain.h" +#include "colourPolyline.h" + +#define BUFFER_POINTS 2048 + +#include <HeliosDac.h> + +class ofxHelios : public ofThread +{ +public: + + ofxHelios(int _pps=20000,int _device = 0) + { + int numdevices=dac.OpenDevices(); + for (int i=0;i<numdevices;i++){ + ofLogNotice() << "ofxHelios v "<<OFXHELIOS_VERSION<<": found laser DAC: firmware v "<<dac.GetFirmwareVersion(i); + } + if (!numdevices){ + ofLogNotice() << "ofxHelios v "<<OFXHELIOS_VERSION<<": no devices found"; + + } + if (_device>=numdevices){ + ofLogNotice() << "ofxHelios v "<<OFXHELIOS_VERSION<<": could not open device "<<_device; + device=OFXHELIOS_NODEVICE; + } + else { + device=_device; + pps=_pps; + //dac.SetShutter(device,true); + } + } + + ~ofxHelios() + { + //stopThread(); + } + + void set_pts(int n){ + pps=n; + ofLogNotice() << "ofxHelios v "<<OFXHELIOS_VERSION<<": set point output to "<<pps; + } + void set_intensity(int i){ + laserintensity=i; + ofLogNotice() << "ofxHelios v "<<OFXHELIOS_VERSION<<": set intensity to "<<laserintensity; + } + int get_pts(){ + return pps; + } + int draw(colourPolyline &line, int intensity=255); + int draw(ofPolyline &points,ofColor colour=ofColor(255,255,255),int intensity=255); + int draw(vector <ofPolyline> &points,ofColor colour=ofColor(255,255,255),int intensity=255); + + void threadedFunction(); + + //isReady() + + private: + + int device; + HeliosDac dac; + int pps; + int laserintensity; + +}; + +#endif |
