Skip to content

Commit

Permalink
some better commenting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Grix committed Jun 13, 2017
1 parent 1284d2f commit 61ea3e3
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 43 deletions.
32 changes: 17 additions & 15 deletions sdk/HeliosDac.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Driver API for Helios Laser DAC class, SOURCE
SDK for Helios Laser DAC class, SOURCE
By Gitle Mikkelsen
[email protected]
Expand Down Expand Up @@ -354,7 +354,23 @@ int HeliosDac::HeliosDacDevice::SendFrame(unsigned int pps, std::uint8_t flags,
}
}

//sends frame to DAC
int HeliosDac::HeliosDacDevice::DoFrame()
{
if (closed)
return HELIOS_ERROR;

int actualLength = 0;
int transferResult = libusb_bulk_transfer(usbHandle, EP_BULK_OUT, frameBuffer, frameBufferSize, &actualLength, 8 + (frameBufferSize >> 5));

if (transferResult == LIBUSB_SUCCESS)
return HELIOS_SUCCESS;
else
return HELIOS_ERROR;
}

//continually running thread, when a frame is ready, it is sent to the DAC
//only used if HELIOS_FLAGS_DONT_BLOCK is used with writeframe
void HeliosDac::HeliosDacDevice::FrameHandler()
{
while (!closed)
Expand All @@ -372,20 +388,6 @@ void HeliosDac::HeliosDacDevice::FrameHandler()
}
}

//sends frame to DAC
int HeliosDac::HeliosDacDevice::DoFrame()
{
if (closed)
return HELIOS_ERROR;

int actualLength = 0;
int transferResult = libusb_bulk_transfer(usbHandle, EP_BULK_OUT, frameBuffer, frameBufferSize, &actualLength, 8 + (frameBufferSize >> 5));

if (transferResult == LIBUSB_SUCCESS)
return HELIOS_SUCCESS;
else
return HELIOS_ERROR;
}

//Gets firmware version of DAC
int HeliosDac::HeliosDacDevice::GetFirmwareVersion()
Expand Down
12 changes: 10 additions & 2 deletions sdk/HeliosDac.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Driver API for Helios Laser DAC class, HEADER
SDK for Helios Laser DAC class, HEADER
By Gitle Mikkelsen
[email protected]
Expand All @@ -11,11 +11,19 @@ git repo: https://github.com/Grix/helios_dac.git
BASIC USAGE:
1. Call OpenDevices() to open devices, returns number of available devices.
2. To send a new frame, first call GetStatus(). If the function returns ready (1),
2. To send a frame to the DAC, first call GetStatus(). If the function returns ready (1),
then you can call WriteFrame(). 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(). To restart output you must send a new frame as described above.
4. When the DAC is no longer needed, destroy the instance (destructors will free everything and close the connection)
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
Expand Down
5 changes: 3 additions & 2 deletions sdk/HeliosDacAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
Driver API for Helios Laser DACs
Helios Laser DAC SDK shared library
By Gitle Mikkelsen
See HeliosDacAPI.h for documentation
Dependencies:
Libusb 1.0 (GNU Lesser General Public License, see libusb.h)
HeliosDAC class (part of this driver)
HeliosDAC class
OpenLaserShowControllerV1.0.0 header and .def file (only on windows)
git repo: https://github.com/Grix/helios_dac.git
*/
Expand Down
16 changes: 12 additions & 4 deletions sdk/HeliosDacAPI.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
/*
Driver API for Helios Laser DAC shared library , HEADER
Helios Laser DAC SDK shared library, HEADER
By Gitle Mikkelsen
[email protected]
Dependencies:
Libusb 1.0 (GNU Lesser General Public License, see libusb.h)
HeliosDAC class (part of this driver)
OpenLaserShowControllerV1.0.0 header and .def file (only supports windows)
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
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
Expand Down
Binary file modified sdk/HeliosLaserDAC.dll
Binary file not shown.
42 changes: 25 additions & 17 deletions sdk/examples/cpp/HeliosDac.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Driver API for Helios Laser DAC class, SOURCE
SDK for Helios Laser DAC class, SOURCE
By Gitle Mikkelsen
[email protected]
Expand Down Expand Up @@ -313,12 +313,18 @@ int HeliosDac::HeliosDacDevice::SendFrame(unsigned int pps, std::uint8_t flags,
return HELIOS_ERROR;

unsigned int bufPos = 0;

//this is a bug workaround, the mcu won't correctly receive transfers with these sizes
unsigned int ppsActual = pps;
unsigned int numOfPointsActual = numOfPoints;
if ((((int)numOfPoints-45) % 64) == 0)
{
numOfPointsActual--;
//adjust pps to keep the same frame duration even with one less point
ppsActual = (unsigned int)((pps * (double)numOfPointsActual / (double)numOfPoints) + 0.5);
}

//prepare frame buffer
for (unsigned int i = 0; i < numOfPointsActual; i++)
{
frameBuffer[bufPos++] = (points[i].x >> 4);
Expand All @@ -329,8 +335,8 @@ int HeliosDac::HeliosDacDevice::SendFrame(unsigned int pps, std::uint8_t flags,
frameBuffer[bufPos++] = points[i].b;
frameBuffer[bufPos++] = points[i].i;
}
frameBuffer[bufPos++] = (pps & 0xFF);
frameBuffer[bufPos++] = (pps >> 8);
frameBuffer[bufPos++] = (ppsActual & 0xFF);
frameBuffer[bufPos++] = (ppsActual >> 8);
frameBuffer[bufPos++] = (numOfPointsActual & 0xFF);
frameBuffer[bufPos++] = (numOfPointsActual >> 8);
frameBuffer[bufPos++] = flags;
Expand All @@ -348,7 +354,23 @@ int HeliosDac::HeliosDacDevice::SendFrame(unsigned int pps, std::uint8_t flags,
}
}

//sends frame to DAC
int HeliosDac::HeliosDacDevice::DoFrame()
{
if (closed)
return HELIOS_ERROR;

int actualLength = 0;
int transferResult = libusb_bulk_transfer(usbHandle, EP_BULK_OUT, frameBuffer, frameBufferSize, &actualLength, 8 + (frameBufferSize >> 5));

if (transferResult == LIBUSB_SUCCESS)
return HELIOS_SUCCESS;
else
return HELIOS_ERROR;
}

//continually running thread, when a frame is ready, it is sent to the DAC
//only used if HELIOS_FLAGS_DONT_BLOCK is used with writeframe
void HeliosDac::HeliosDacDevice::FrameHandler()
{
while (!closed)
Expand All @@ -366,20 +388,6 @@ void HeliosDac::HeliosDacDevice::FrameHandler()
}
}

//sends frame to DAC
int HeliosDac::HeliosDacDevice::DoFrame()
{
if (closed)
return HELIOS_ERROR;

int actualLength = 0;
int transferResult = libusb_bulk_transfer(usbHandle, EP_BULK_OUT, frameBuffer, frameBufferSize, &actualLength, 8 + (frameBufferSize >> 5));

if (transferResult == LIBUSB_SUCCESS)
return HELIOS_SUCCESS;
else
return HELIOS_ERROR;
}

//Gets firmware version of DAC
int HeliosDac::HeliosDacDevice::GetFirmwareVersion()
Expand Down
13 changes: 10 additions & 3 deletions sdk/examples/cpp/HeliosDac.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Driver API for Helios Laser DAC class, HEADER
SDK for Helios Laser DAC class, HEADER
By Gitle Mikkelsen
[email protected]
Expand All @@ -11,11 +11,19 @@ git repo: https://github.com/Grix/helios_dac.git
BASIC USAGE:
1. Call OpenDevices() to open devices, returns number of available devices.
2. To send a new frame, first call GetStatus(). If the function returns ready (1),
2. To send a frame to the DAC, first call GetStatus(). If the function returns ready (1),
then you can call WriteFrame(). 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(). To restart output you must send a new frame as described above.
4. When the DAC is no longer needed, destroy the instance (destructors will free everything and close the connection)
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
Expand All @@ -28,7 +36,6 @@ BASIC USAGE:
#include <vector>
#include <memory>
#include <chrono>
#include <future>

#define HELIOS_SDK_VERSION 6

Expand Down

0 comments on commit 61ea3e3

Please sign in to comment.