summaryrefslogtreecommitdiff
path: root/ofxHelios/libs/libheliosdac/includes/HeliosDacAPI.h
blob: abf762d0d6edd3e923d1f255d86251196bba3373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
Helios Laser DAC SDK shared library, HEADER
By Gitle Mikkelsen
gitlem@gmail.com

Dependencies:
Libusb 1.0 (GNU Lesser General Public License, see libusb.h)
HeliosDAC class
OpenLaserShowControllerV1.0.0 header and .def file (only on windows)

Standard: C++14

BASIC USAGE:
1.	Call OpenDevices() or OLSC_Initialize() to open devices, returns number of available devices
2.	To send a new frame, first call GetStatus() or OLSC_GetStatus(). If the function returns ready
	(1 for GetStatus, OLSC_STATUS_BUFFER_EMPTY for OLSC_GetStatus), then you can call WriteFrame()
	or OLSC_WriteFrame() / OLSC_WriteFrameEx().
	The status should be polled until it returns ready. It can and sometimes will fail to return ready on the first try.
3.  To stop output, use Stop() or OLSC_Pause(). To restart output you must send a new frame as described above.
4.	When the DAC is no longer needed, free it using CloseDevices() or OLSC_Shutdown()
See OpenLaserShowControllerV1.0.0-Mod.h for documentation on OLSC_* functions. Not recommended for cross-platform apps

The DAC is double-buffered. When it receives its first frame, it starts outputting it. When a second frame is sent to
the DAC while the first frame is being played, the second frame is stored in the DACs memory until the first frame
finishes playback, at which point the second, buffered frame will start playing. If the DAC finished playback of a frame
without having received and buffered a second frame, it will by default loop the first frame until a new frame is
received (but the flag HELIOS_FLAG_SINGLE_MODE will make it stop playback instead).
The GetStatus() function actually checks whether or not the buffer on the DAC is empty or full. If it is full, the DAC
cannot receive a new frame until the currently playing frame finishes, freeing up the buffer.
*/

#pragma once

#include "HeliosDac.h"

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
	#include "OpenLaserShowControllerV1.0.0-Mod.h"
	#define HELIOS_EXPORT extern "C" __declspec (dllexport)
#else
	#define HELIOS_EXPORT extern "C"
#endif

bool inited = false;
bool flipX = true;

HeliosDac* dacController;

//initializes drivers, opens connection to all devices.
//Returns number of available devices.
//NB: To re-scan for newly connected DACs after this function has once been called before, you must first call CloseDevices()
HELIOS_EXPORT int OpenDevices();

//Gets status from the specified dac.
//Return 1 if ready to receive new frame, 0 if not, -1 if communcation failed
HELIOS_EXPORT int GetStatus(unsigned int dacNum);

//writes and outputs a frame to the speficied dac
//dacNum: dac number (0 to n where n+1 is the return value from OpenDevices() )
//pps: rate of output in points per second
//flags: (default is 0)
//	Bit 0 (LSB) = if true, start output immediately, instead of waiting for current frame (if there is one) to finish playing
//	Bit 1 = if true, play frame only once, instead of repeating until another frame is written
//	Bit 2-7 = reserved
//points: pointer to point data. See point structure documentation in HeliosDac.h
//numOfPoints: number of points in the frame
//returns 1 if successful
HELIOS_EXPORT int WriteFrame(unsigned int dacNum, int pps, std::uint8_t flags, HeliosPoint* points, int numOfPoints);

//sets the shutter of the specified dac.
//value 1 = shutter open, value 0 = shutter closed
//returns 1 if successful
HELIOS_EXPORT int SetShutter(unsigned int dacNum, bool shutterValue);

//Returns the firmware version number. Returns -1 if communcation failed.
HELIOS_EXPORT int GetFirmwareVersion(unsigned int dacNum);

//gets a descriptive name of the specified dac
//name is max 32 bytes long, char needs to be able to hold 32 bytes
//returns 1 if successful, return 0 if the proper name couldn't be fetched from the DAC, but name is
//still populated with a fallback numbered name based on order of discovery by the library
//return -1 if unsuccessful and name is not populated.
HELIOS_EXPORT int GetName(unsigned int dacNum, char* name);

//gets a descriptive name of the specified dac
//name is max 31 bytes long including null terminator
//returns 1 if successful, return 0 if the transfer failed
HELIOS_EXPORT int SetName(unsigned int dacNum, char* name);

//stops, blanks and centers output on the specified dac
//returns 1 if successful
HELIOS_EXPORT int Stop(unsigned int dacNum);

//closes connection to all dacs and frees resources
//should be called when library is no longer needed (program exit for example)
HELIOS_EXPORT int CloseDevices();

//Clears the GPNVM1 bit on the DACs microcontroller. This will cause the DAC to boot into SAM-BA bootloader
//which allows new firmware to be uploaded over USB.
HELIOS_EXPORT int EraseFirmware(unsigned int dacNum);