Skip to content

Commit f386cef

Browse files
committed
sdk as class, and example app
1 parent d87ad88 commit f386cef

11 files changed

Lines changed: 454 additions & 131 deletions
Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
/*
2-
Driver API for Helios Laser DACs
3-
By Gitle Mikkelsen, Creative Commons Attribution-NonCommercial 4.0 International Public License
1+
#include "HeliosDacClass.h"
42

5-
See HeliosDacAPI.h for documentation
63

7-
Dependencies:
8-
Libusb 1.0 (GNU Lesser General Public License, see libusb.h)
9-
HeliosDAC class (part of this driver)
10-
*/
4+
HeliosDacClass::HeliosDacClass()
5+
{
6+
inited = false;
7+
}
8+
119

12-
#include "HeliosDacAPI.h"
10+
HeliosDacClass::~HeliosDacClass()
11+
{
12+
CloseDevices();
13+
}
1314

1415

15-
int OpenDevices()
16+
int HeliosDacClass::OpenDevices()
1617
{
1718
CloseDevices();
1819

@@ -25,13 +26,11 @@ int OpenDevices()
2526
else
2627
inited = true;
2728

28-
printf("OpenDevices() found: %d", result);
29-
3029
return result;
3130
}
3231

3332

34-
int WriteFrame(int dacNum, int pps, uint8_t flags, HeliosPoint* points, int numOfPoints)
33+
int HeliosDacClass::WriteFrame(int dacNum, int pps, uint8_t flags, HeliosPoint* points, int numOfPoints)
3534
{
3635
if ((!inited) || (points == NULL))
3736
return 0;
@@ -60,7 +59,7 @@ int WriteFrame(int dacNum, int pps, uint8_t flags, HeliosPoint* points, int numO
6059
return dacController->SendFrame(dacNum, &frameBuffer[0], bufPos);
6160
}
6261

63-
int Stop(int dacNum)
62+
int HeliosDacClass::Stop(int dacNum)
6463
{
6564
if (!inited)
6665
return 0;
@@ -73,7 +72,7 @@ int Stop(int dacNum)
7372
}
7473

7574

76-
int GetName(int dacNum, char* name)
75+
int HeliosDacClass::GetName(int dacNum, char* name)
7776
{
7877
if (!inited)
7978
return -1;
@@ -101,7 +100,7 @@ int GetName(int dacNum, char* name)
101100
return 0;
102101
}
103102

104-
int SetName(int dacNum, char* name)
103+
int HeliosDacClass::SetName(int dacNum, char* name)
105104
{
106105
if (!inited)
107106
return -1;
@@ -112,7 +111,7 @@ int SetName(int dacNum, char* name)
112111
}
113112

114113

115-
int GetStatus(int dacNum)
114+
int HeliosDacClass::GetStatus(int dacNum)
116115
{
117116
if (!inited)
118117
return -1;
@@ -133,12 +132,12 @@ int GetStatus(int dacNum)
133132
return 0;
134133
}
135134
}
136-
else
137-
return -1;
135+
136+
return -1;
138137
}
139138

140139

141-
int SetShutter(int dacNum, bool value)
140+
int HeliosDacClass::SetShutter(int dacNum, bool value)
142141
{
143142
if (!inited)
144143
return 0;
@@ -147,7 +146,7 @@ int SetShutter(int dacNum, bool value)
147146
return dacController->SendControl(dacNum, &ctrlBuffer[0], 2);
148147
}
149148

150-
int GetFirmwareVersion(int dacNum)
149+
int HeliosDacClass::GetFirmwareVersion(int dacNum)
151150
{
152151
if (!inited)
153152
return -1;
@@ -163,16 +162,16 @@ int GetFirmwareVersion(int dacNum)
163162
if ((ctrlBuffer[0]) == 0x84) //if received control byte is as expected
164163
{
165164
return ((ctrlBuffer[1] << 0) |
166-
(ctrlBuffer[2] << 8) |
167-
(ctrlBuffer[3] << 16) |
168-
(ctrlBuffer[4] << 24));
165+
(ctrlBuffer[2] << 8) |
166+
(ctrlBuffer[3] << 16) |
167+
(ctrlBuffer[4] << 24));
169168
}
170169
}
171170
else
172171
return 0;
173172
}
174173

175-
int EraseFirmware(int dacNum)
174+
int HeliosDacClass::EraseFirmware(int dacNum)
176175
{
177176
if (!inited)
178177
return -1;
@@ -181,7 +180,7 @@ int EraseFirmware(int dacNum)
181180
return dacController->SendControl(dacNum, &ctrlBuffer[0], 2);
182181
}
183182

184-
int CloseDevices()
183+
int HeliosDacClass::CloseDevices()
185184
{
186185
if (inited)
187186
{
@@ -191,4 +190,4 @@ int CloseDevices()
191190
}
192191
else
193192
return 0;
194-
}
193+
}

sdk/HeliosDacClass.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include "HeliosDac.h"
2+
3+
#pragma once
4+
class HeliosDacClass
5+
{
6+
public:
7+
HeliosDacClass();
8+
~HeliosDacClass();
9+
10+
bool inited;
11+
HeliosDac* dacController;
12+
13+
//point data structure
14+
typedef struct
15+
{
16+
uint16_t x; //12 bit (from 0 to 0xFFF)
17+
uint16_t y; //12 bit (from 0 to 0xFFF)
18+
uint8_t r; //8 bit (from 0 to 0xFF)
19+
uint8_t g; //8 bit (from 0 to 0xFF)
20+
uint8_t b; //8 bit (from 0 to 0xFF)
21+
uint8_t i; //8 bit (from 0 to 0xFF)
22+
} HeliosPoint;
23+
24+
//initializes drivers, opens connection to all devices.
25+
//Returns number of available devices.
26+
int OpenDevices();
27+
28+
//Gets status from the specified dac.
29+
//Return 1 if ready to receive new frame, 0 if not, -1 if communcation failed
30+
int GetStatus(int dacNum);
31+
32+
//writes and outputs a frame to the speficied dac
33+
//dacNum: dac number (0 to n where n+1 is the return value from OpenDevices() )
34+
//pps: rate of output in points per second
35+
//flags: (default is 0)
36+
// Bit 0 (LSB) = if true, start output immediately, instead of waiting for current frame (if there is one) to finish playing
37+
// Bit 1 = if true, play frame only once, instead of repeating until another frame is written
38+
// Bit 2-7 = reserved
39+
//points: pointer to point data. See point structure documentation in main.h
40+
//numOfPoints: number of points in the frame
41+
//returns 1 if successful
42+
int WriteFrame(int dacNum, int pps, uint8_t flags, HeliosPoint* points, int numOfPoints);
43+
44+
//sets the shutter of the specified dac.
45+
//value 1 = shutter on, value 0 = shutter off
46+
//returns 1 if successful
47+
int SetShutter(int dacNum, bool shutterValue);
48+
49+
//Returns the firmware version number. Returns -1 if communcation failed.
50+
int GetFirmwareVersion(int dacNum);
51+
52+
//gets a descriptive name of the specified dac
53+
//name is max 32 bytes long, char needs to be able to hold 32 bytes
54+
//returns 1 if successful, return 0 if the proper name couldn't be fetched from the DAC, but name is
55+
//still populated with a fallback numbered name based on order of discovery by the library
56+
//return -1 if unsuccessful and name is not populated.
57+
int GetName(int dacNum, char* name);
58+
59+
//gets a descriptive name of the specified dac
60+
//name is max 31 bytes long including null terminator
61+
//returns 1 if successful, return 0 if the transfer failed
62+
int SetName(int dacNum, char* name);
63+
64+
//stops, blanks and centers output on the specified dac
65+
//returns 1 if successful
66+
int Stop(int dacNum);
67+
68+
//closes connection to all dacs and frees resources
69+
//should be called when library is no longer needed (program exit for example)
70+
int CloseDevices();
71+
72+
//Clears the GPNVM1 bit on the DACs microcontroller. This will cause the DAC to boot into SAM-BA bootloader
73+
//which allows new firmware to be uploaded over USB.
74+
int EraseFirmware(int dacNum);
75+
};
76+

sdk/example/HeliosDacAPI.h

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)