Skip to content
Snippets Groups Projects
Commit 5e7aa87b authored by jsiegle's avatar jsiegle
Browse files

Merge branch 'master' of github.com:open-ephys/GUI

parents 0bb9a7d7 5193fb92
No related branches found
No related tags found
No related merge requests found
......@@ -138,19 +138,19 @@ void ChannelSelector::refreshButtonBoundaries()
{
parameterButtons[i]->setBounds(columnWidth/2 + offsetLR +
columnWidth*((i)%nColumns),
floor((i)/nColumns)*rowHeight+offsetUD + topOffset,
floor(double(i)/nColumns)*rowHeight+offsetUD + topOffset,
columnWidth, rowHeight);
if (isNotSink)
{
recordButtons[i]->setBounds(columnWidth/2 + offsetLR +
columnWidth*((i)%nColumns) - getDesiredWidth(),
floor((i)/nColumns)*rowHeight+offsetUD + topOffset,
floor(double(i)/nColumns)*rowHeight+offsetUD + topOffset,
columnWidth, rowHeight);
audioButtons[i]->setBounds(columnWidth/2 + offsetLR +
columnWidth*((i)%nColumns) -
getDesiredWidth()*2,
floor((i)/nColumns)*rowHeight+offsetUD + topOffset,
floor(double(i)/nColumns)*rowHeight+offsetUD + topOffset,
columnWidth, rowHeight);
}
......
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2012 Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SpikeObject.h"
#include "memory.h"
#include <stdlib.h>
#include "time.h"
// Simple method for serializing a SpikeObject into a string of bytes
int packSpike(SpikeObject *s, uint8_t* buffer, int bufferSize){
//int reqBytes = 1 + 4 + 2 + 2 + 2 + 2 * s->nChannels * s->nSamples + 2 * s->nChannels * 2;
int idx = 0;
s->eventType = SPIKE_EVENT_CODE;
memcpy(buffer+idx, &(s->eventType), 1);
idx += 1;
memcpy(buffer+idx, &(s->timestamp), 4);
idx += 4;
memcpy(buffer+idx, &(s->source), 2);
idx +=2;
memcpy(buffer+idx, &(s->nChannels), 2);
idx +=2;
memcpy(buffer+idx, &(s->nSamples), 2);
idx +=2;
memcpy(buffer+idx, &(s->data), s->nChannels * s->nSamples * 2);
idx += s->nChannels * s->nSamples * 2;
memcpy(buffer+idx, &(s->gain), s->nChannels * 2);
idx += s->nChannels * 2;
memcpy(buffer+idx, &(s->threshold), s->nChannels * 2);
idx += s->nChannels * 2;
if (idx >= MAX_SPIKE_BUFFER_LEN){
std::cout<<"Spike is larger than it should be. Size was:"<<idx<<" Max Size is:"<<MAX_SPIKE_BUFFER_LEN<<std::endl;
}
// makeBufferValid(buffer, bufferSize);
return idx;
}
// Simple method for deserializing a string of bytes into a Spike object
bool unpackSpike(SpikeObject *s, uint8_t* buffer, int bufferSize){
// if !(isBufferValid(buffer, bufferSize));
// return false;
int idx = 0;
memcpy (&(s->eventType), buffer+idx, 1);
idx += 1;
memcpy( &(s->timestamp), buffer+idx, 4);
idx += 4;
memcpy( &(s->source), buffer+idx, 2);
idx += 2;
memcpy( &(s->nChannels), buffer+idx, 2);
idx +=2;
memcpy( &(s->nSamples), buffer+idx, 2);
idx +=2;
memcpy( &(s->data), buffer+idx, s->nChannels * s->nSamples * 2);
idx += s->nChannels * s->nSamples * 2;
memcpy( &(s->gain), buffer+idx, s->nChannels * 2);
idx += s->nChannels * 2;
memcpy( &(s->threshold), buffer+idx, s->nChannels *2);
idx += s->nChannels * 2;
// if (idx >= bufferSize)
// std::cout<<"Buffer Overrun! More data extracted than was given!"<<std::endl;
return true;
}
// Checks the validity of the buffer, this should be run before unpacking and after packing the buffer
bool isBufferValid(uint8_t *buffer, int bufferSize){
if (! CHECK_BUFFER_VALIDITY )
return true;
uint16_t runningSum = 0;
uint16_t value = 0;
int idx = 0;
for (idx; idx < bufferSize-2; idx += 2){
memcpy(buffer + idx, &value, 2);
runningSum += value;
}
uint16_t integrityCheck = 0;
memcpy(buffer + idx, &integrityCheck, 2);
std::cout<<integrityCheck<<" == "<< runningSum <<std::endl;
return (integrityCheck == runningSum);
}
void makeBufferValid(uint8_t *buffer, int bufferSize){
if (! CHECK_BUFFER_VALIDITY )
return;
uint16_t runningSum = 0;
uint16_t value = 0;
int idx = 0;
for (idx; idx < bufferSize-2; idx += 2){
memcpy(buffer + idx, &value, 2);
runningSum += value;
}
memcpy(&runningSum, buffer + idx, 2);
}
void generateSimulatedSpike(SpikeObject *s, uint64_t timestamp, int noise)
{
//std::cout<<"generateSimulatedSpike()"<<std::endl;
uint16_t trace[][32] =
{
{ 880, 900, 940, 1040, 1290, 1790, 2475, 2995, 3110, 2890,
2505, 2090, 1720, 1410, 1155, 945, 775, 635, 520, 420,
340, 265, 205, 155, 115, 80, 50, 34, 10, 34, 50, 80},
{ 1040, 1090, 1190, 1350, 1600, 1960, 2380, 2790, 3080, 3140,
2910, 2430, 1810, 1180, 680, 380, 270, 320, 460, 630,
770, 870, 940, 970, 990, 1000, 1000, 1000, 1000, 1000, 1000, 1000},
{ 1000, 1000, 1000, 1000, 1000, 1040, 1140, 1440, 2040, 2240,
2400, 2340, 2280, 1880, 1640, 920, 520, 300, 140, 040,
20, 20, 40, 100, 260, 500, 740, 900, 960, 1000, 1000, 1000}
};
// We don't want to shift the waveform but scale it, and we don't want to scale
// the baseline, just the peak of the waveform
float scale[32] =
{ 1.0, 1.0, 1.0, 1.0, 1.1, 1.2, 1.3, 1.5, 1.7, 2.0, 2.1, 2.2, 2.1, 2.0, 1.7, 1.5,
1.3, 1.2, 1.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
uint16_t gain = 2000;
s->eventType = SPIKE_EVENT_CODE;
s->timestamp = timestamp;
s->source = 0;
s->nChannels = 4;
s->nSamples = 32;
int idx=0;
int waveType = rand()%2; // Pick one of the three predefined waveshapes to generate
int shift = 1000 + 32768;
for (int i=0; i<4; i++)
{
s->gain[i] = gain;
s->threshold[i] = 4000;
double scaleExponent = (double)(rand()%26+2) / 10.0f; // Scale the wave between 50% and 150%
for (int j=0; j<32; j++){
int n = 0;
if (noise>0){
n = rand() % noise - noise/2;
}
s->data[idx] = (trace[waveType][j] + n) * pow(scale[j],scaleExponent) + shift;
idx = idx+1;
}
}
}
void generateEmptySpike(SpikeObject *s, int nChannels){
s->eventType = SPIKE_EVENT_CODE;
s->timestamp = 0;
s->source = 0;
s->nChannels = 4;
s->nSamples = 32;
int idx = 0;
for (int i=0; i<4; i++)
{
s->gain[i] = 0;
s->threshold[i] = 0;
for (int j=0; j<32; j++){
s->data[idx] = 0;
idx = idx+1;
}
}
}
void printSpike(SpikeObject *s){
std::cout<< " SpikeObject:\n";
std::cout<< "\tTimestamp:" << s->timestamp;
std::cout<< "\tSource:" << s->source;
std::cout<< "\tnChannels:" <<s->nChannels;
std::cout<<"\tnSamples" << s->nSamples;
std::cout<<"\n\t 8 Data Samples:";
for (int i=0; i<8; i++)
std::cout<<s->data+i<<" ";
std::cout<<std::endl;
}
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2012 Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SpikeObject.h"
#include "memory.h"
#include <stdlib.h>
#include "time.h"
// Simple method for serializing a SpikeObject into a string of bytes
int packSpike(SpikeObject *s, uint8_t* buffer, int bufferSize){
//int reqBytes = 1 + 4 + 2 + 2 + 2 + 2 * s->nChannels * s->nSamples + 2 * s->nChannels * 2;
int idx = 0;
s->eventType = SPIKE_EVENT_CODE;
memcpy(buffer+idx, &(s->eventType), 1);
idx += 1;
memcpy(buffer+idx, &(s->timestamp), 4);
idx += 4;
memcpy(buffer+idx, &(s->source), 2);
idx +=2;
memcpy(buffer+idx, &(s->nChannels), 2);
idx +=2;
memcpy(buffer+idx, &(s->nSamples), 2);
idx +=2;
memcpy(buffer+idx, &(s->data), s->nChannels * s->nSamples * 2);
idx += s->nChannels * s->nSamples * 2;
memcpy(buffer+idx, &(s->gain), s->nChannels * 2);
idx += s->nChannels * 2;
memcpy(buffer+idx, &(s->threshold), s->nChannels * 2);
idx += s->nChannels * 2;
if (idx >= MAX_SPIKE_BUFFER_LEN){
std::cout<<"Spike is larger than it should be. Size was:"<<idx<<" Max Size is:"<<MAX_SPIKE_BUFFER_LEN<<std::endl;
}
// makeBufferValid(buffer, bufferSize);
return idx;
}
// Simple method for deserializing a string of bytes into a Spike object
bool unpackSpike(SpikeObject *s, uint8_t* buffer, int bufferSize){
// if !(isBufferValid(buffer, bufferSize));
// return false;
int idx = 0;
memcpy (&(s->eventType), buffer+idx, 1);
idx += 1;
memcpy( &(s->timestamp), buffer+idx, 4);
idx += 4;
memcpy( &(s->source), buffer+idx, 2);
idx += 2;
memcpy( &(s->nChannels), buffer+idx, 2);
idx +=2;
memcpy( &(s->nSamples), buffer+idx, 2);
idx +=2;
memcpy( &(s->data), buffer+idx, s->nChannels * s->nSamples * 2);
idx += s->nChannels * s->nSamples * 2;
memcpy( &(s->gain), buffer+idx, s->nChannels * 2);
idx += s->nChannels * 2;
memcpy( &(s->threshold), buffer+idx, s->nChannels *2);
idx += s->nChannels * 2;
// if (idx >= bufferSize)
// std::cout<<"Buffer Overrun! More data extracted than was given!"<<std::endl;
return true;
}
// Checks the validity of the buffer, this should be run before unpacking and after packing the buffer
bool isBufferValid(uint8_t *buffer, int bufferSize){
if (! CHECK_BUFFER_VALIDITY )
return true;
uint16_t runningSum = 0;
uint16_t value = 0;
int idx = 0;
for (idx; idx < bufferSize-2; idx += 2){
memcpy(buffer + idx, &value, 2);
runningSum += value;
}
uint16_t integrityCheck = 0;
memcpy(buffer + idx, &integrityCheck, 2);
std::cout<<integrityCheck<<" == "<< runningSum <<std::endl;
return (integrityCheck == runningSum);
}
void makeBufferValid(uint8_t *buffer, int bufferSize){
if (! CHECK_BUFFER_VALIDITY )
return;
uint16_t runningSum = 0;
uint16_t value = 0;
int idx = 0;
for (idx; idx < bufferSize-2; idx += 2){
memcpy(buffer + idx, &value, 2);
runningSum += value;
}
memcpy(&runningSum, buffer + idx, 2);
}
void generateSimulatedSpike(SpikeObject *s, uint64_t timestamp, int noise)
{
//std::cout<<"generateSimulatedSpike()"<<std::endl;
uint16_t trace[][32] =
{
{ 880, 900, 940, 1040, 1290, 1790, 2475, 2995, 3110, 2890,
2505, 2090, 1720, 1410, 1155, 945, 775, 635, 520, 420,
340, 265, 205, 155, 115, 80, 50, 34, 10, 34, 50, 80},
{ 1040, 1090, 1190, 1350, 1600, 1960, 2380, 2790, 3080, 3140,
2910, 2430, 1810, 1180, 680, 380, 270, 320, 460, 630,
770, 870, 940, 970, 990, 1000, 1000, 1000, 1000, 1000, 1000, 1000},
{ 1000, 1000, 1000, 1000, 1000, 1040, 1140, 1440, 2040, 2240,
2400, 2340, 2280, 1880, 1640, 920, 520, 300, 140, 040,
20, 20, 40, 100, 260, 500, 740, 900, 960, 1000, 1000, 1000}
};
// We don't want to shift the waveform but scale it, and we don't want to scale
// the baseline, just the peak of the waveform
float scale[32] =
{ 1.0, 1.0, 1.0, 1.0, 1.1, 1.2, 1.3, 1.5, 1.7, 2.0, 2.1, 2.2, 2.1, 2.0, 1.7, 1.5,
1.3, 1.2, 1.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
uint16_t gain = 2000;
s->eventType = SPIKE_EVENT_CODE;
s->timestamp = timestamp;
s->source = 0;
s->nChannels = 4;
s->nSamples = 32;
int idx=0;
int waveType = rand()%2; // Pick one of the three predefined waveshapes to generate
int shift = 1000 + 32768;
for (int i=0; i<4; i++)
{
s->gain[i] = gain;
s->threshold[i] = 4000;
double scaleExponent = (double)(rand()%26+2) / 10.0f; // Scale the wave between 50% and 150%
for (int j=0; j<32; j++){
int n = 0;
if (noise>0){
n = rand() % noise - noise/2;
}
s->data[idx] = (trace[waveType][j] + n) * pow(double(scale[j]),scaleExponent) + shift;
idx = idx+1;
}
}
}
void generateEmptySpike(SpikeObject *s, int nChannels){
s->eventType = SPIKE_EVENT_CODE;
s->timestamp = 0;
s->source = 0;
s->nChannels = 4;
s->nSamples = 32;
int idx = 0;
for (int i=0; i<4; i++)
{
s->gain[i] = 0;
s->threshold[i] = 0;
for (int j=0; j<32; j++){
s->data[idx] = 0;
idx = idx+1;
}
}
}
void printSpike(SpikeObject *s){
std::cout<< " SpikeObject:\n";
std::cout<< "\tTimestamp:" << s->timestamp;
std::cout<< "\tSource:" << s->source;
std::cout<< "\tnChannels:" <<s->nChannels;
std::cout<<"\tnSamples" << s->nSamples;
std::cout<<"\n\t 8 Data Samples:";
for (int i=0; i<8; i++)
std::cout<<s->data+i<<" ";
std::cout<<std::endl;
}
#include "PlotUtils.h"
void checkGlError(){
GLenum errCode;
const GLubyte *errString;
if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf (stderr, "OpenGL Error: %s\n", errString);
exit(1);
}
else
std::cout<<"OpenGL Okay!"<<std::endl;
}
void drawString(float x, float y, void *f, const char *string){
glRasterPos2f(x, y);
int len = strlen(string);
// glColor3f(1.0, 1.0, 1.0);
for (int i = 0; i < len; i++) {
//glutBitmapCharacter(f, string[i]);
}
}
void drawString(float x, float y, int size, String s, FTPixmapFont* f){
glRasterPos2f(x, y);
f->FaceSize(size);
f->Render(s);
}
void drawViewportEdge(){
glPushMatrix();
glLoadIdentity();
glBegin(GL_LINE_LOOP);
glVertex2f(-.995, -.995);
glVertex2f( .995, -.995);
glVertex2f( .995, .995);
glVertex2f(-.995, .995);
glEnd();
glPopMatrix();
}
void drawViewportCross(){
glColor3f(0.0,1.0,1.0);
glPushMatrix();
glLoadIdentity();
glBegin(GL_LINE_LOOP);
glVertex2f(-.995, -.995);
glVertex2f( .995, .995);
glVertex2f( .995, -.995);
glVertex2f(-.995, .995);
glEnd();
glPopMatrix();
}
void setViewportRange(int xMin,int yMin,int xMax,int yMax){
float dx = xMax-xMin;
float dy = yMax-yMin;
// printf("Setting viewport to:%d,%d %d,%d with dims%d,%d %d,%d\n", x,y,w,h, xMin, xMin, xMax,yMax);
// printf("Dx:%f Dy:%f, Scaling viewport by:%f,%f \n", dx,dy,2.0/dx, 2.0/dy);
glLoadIdentity();
glTranslatef(-1.0,-1.0,0.0);
glScalef(2.0f/dx, 2.0f/dy, 1.0);
glTranslatef(0-xMin, 0-yMin, 0);
}
int roundUp(int numToRound, int multiple)
{
if(multiple == 0)
{
return numToRound;
}
int remainder = numToRound % multiple;
if (remainder == 0)
return numToRound;
return numToRound + multiple - remainder;
}
double ad16ToUv(int x, int gain){
int result = (double)(x * 20e6) / (double)(gain * pow(2,16));
return result;
}
void makeLabel(int val, int gain, bool convert, char * s){
if (convert){
double volt = ad16ToUv(val, gain)/1000.;
if (abs(val)>1e6){
//val = val/(1e6);
sprintf(s, "%.2fV", volt);
}
else if(abs(val)>1e3){
//val = val/(1e3);
sprintf(s, "%.2fmV", volt);
}
else
sprintf(s, "%.2fuV", volt);
}
else
sprintf(s,"%d", (int)val);
}
void n2ProjIdx(int proj, int *p1, int *p2){
int d1, d2;
if (proj==PROJ1x2){
d1 = 0;
d2 = 1;
}
else if(proj==PROJ1x3){
d1 = 0;
d2 = 2;
}
else if(proj==PROJ1x4){
d1 = 0;
d2 = 3;
}
else if(proj==PROJ2x3){
d1 = 1;
d2 = 2;
}
else if(proj==PROJ2x4){
d1 = 1;
d2 = 3;
}
else if (proj==PROJ3x4){
d1 = 2;
d2 = 3;
}
else{
std::cout<<"Invalid projection:"<<proj<<"! Cannot determine d1 and d2"<<std::endl;
*p1 = -1;
*p2 = -1;
return;
}
*p1 = d1;
*p2 = d2;
}
bool isFrameBufferExtensionSupported(){
std::cout<<"Checking to see if the OpenGL Frame Buffer Extension is Supported"<<std::endl;
char* str = 0;
char* tok = 0;
std::string fboExt = "GL_EXT_framebuffer_object";
str = (char*)glGetString(GL_EXTENSIONS);
if(str)
{
std::vector <std::string> extensions;
tok = strtok((char*)str, " ");
while(tok)
{
std::string ext = tok;
if (ext == fboExt)
return true;
tok = strtok(0, " ");
}
return false;
}
else
return false;
}
bool checkFramebufferStatus()
{
// check FBO status
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
return status == GL_FRAMEBUFFER_COMPLETE_EXT;
switch(status)
{
case GL_FRAMEBUFFER_COMPLETE_EXT:
std::cout << "Framebuffer complete." << std::endl;
return true;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Attachment is NOT complete." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
std::cout << "[ERROR] Framebuffer incomplete: No image is attached to FBO." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Attached images have different dimensions." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Color attached images have different internal formats." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Draw buffer." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Read buffer." << std::endl;
return false;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
std::cout << "[ERROR] Unsupported by FBO implementation." << std::endl;
return false;
default:
std::cout << "[ERROR] Unknown error." << std::endl;
return false;
}
}
// std::addressof was introduced in C++11, an equivalent function is defined below
// definition from http://en.cppreference.com/w/cpp/memory/addressof
#include "PlotUtils.h"
void checkGlError(){
GLenum errCode;
const GLubyte *errString;
if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf (stderr, "OpenGL Error: %s\n", errString);
exit(1);
}
else
std::cout<<"OpenGL Okay!"<<std::endl;
}
void drawString(float x, float y, void *f, const char *string){
glRasterPos2f(x, y);
int len = strlen(string);
// glColor3f(1.0, 1.0, 1.0);
for (int i = 0; i < len; i++) {
//glutBitmapCharacter(f, string[i]);
}
}
void drawString(float x, float y, int size, String s, FTPixmapFont* f){
glRasterPos2f(x, y);
f->FaceSize(size);
f->Render(s);
}
void drawViewportEdge(){
glPushMatrix();
glLoadIdentity();
glBegin(GL_LINE_LOOP);
glVertex2f(-.995, -.995);
glVertex2f( .995, -.995);
glVertex2f( .995, .995);
glVertex2f(-.995, .995);
glEnd();
glPopMatrix();
}
void drawViewportCross(){
glColor3f(0.0,1.0,1.0);
glPushMatrix();
glLoadIdentity();
glBegin(GL_LINE_LOOP);
glVertex2f(-.995, -.995);
glVertex2f( .995, .995);
glVertex2f( .995, -.995);
glVertex2f(-.995, .995);
glEnd();
glPopMatrix();
}
void setViewportRange(int xMin,int yMin,int xMax,int yMax){
float dx = xMax-xMin;
float dy = yMax-yMin;
// printf("Setting viewport to:%d,%d %d,%d with dims%d,%d %d,%d\n", x,y,w,h, xMin, xMin, xMax,yMax);
// printf("Dx:%f Dy:%f, Scaling viewport by:%f,%f \n", dx,dy,2.0/dx, 2.0/dy);
glLoadIdentity();
glTranslatef(-1.0,-1.0,0.0);
glScalef(2.0f/dx, 2.0f/dy, 1.0);
glTranslatef(0-xMin, 0-yMin, 0);
}
int roundUp(int numToRound, int multiple)
{
if(multiple == 0)
{
return numToRound;
}
int remainder = numToRound % multiple;
if (remainder == 0)
return numToRound;
return numToRound + multiple - remainder;
}
double ad16ToUv(int x, int gain){
int result = (double)(x * 20e6) / (double)(gain * pow(2.0,16));
return result;
}
void makeLabel(int val, int gain, bool convert, char * s){
if (convert){
double volt = ad16ToUv(val, gain)/1000.;
if (abs(val)>1e6){
//val = val/(1e6);
sprintf(s, "%.2fV", volt);
}
else if(abs(val)>1e3){
//val = val/(1e3);
sprintf(s, "%.2fmV", volt);
}
else
sprintf(s, "%.2fuV", volt);
}
else
sprintf(s,"%d", (int)val);
}
void n2ProjIdx(int proj, int *p1, int *p2){
int d1, d2;
if (proj==PROJ1x2){
d1 = 0;
d2 = 1;
}
else if(proj==PROJ1x3){
d1 = 0;
d2 = 2;
}
else if(proj==PROJ1x4){
d1 = 0;
d2 = 3;
}
else if(proj==PROJ2x3){
d1 = 1;
d2 = 2;
}
else if(proj==PROJ2x4){
d1 = 1;
d2 = 3;
}
else if (proj==PROJ3x4){
d1 = 2;
d2 = 3;
}
else{
std::cout<<"Invalid projection:"<<proj<<"! Cannot determine d1 and d2"<<std::endl;
*p1 = -1;
*p2 = -1;
return;
}
*p1 = d1;
*p2 = d2;
}
bool isFrameBufferExtensionSupported(){
std::cout<<"Checking to see if the OpenGL Frame Buffer Extension is Supported"<<std::endl;
char* str = 0;
char* tok = 0;
std::string fboExt = "GL_EXT_framebuffer_object";
str = (char*)glGetString(GL_EXTENSIONS);
if(str)
{
std::vector <std::string> extensions;
tok = strtok((char*)str, " ");
while(tok)
{
std::string ext = tok;
if (ext == fboExt)
return true;
tok = strtok(0, " ");
}
return false;
}
else
return false;
}
bool checkFramebufferStatus()
{
// check FBO status
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
return status == GL_FRAMEBUFFER_COMPLETE_EXT;
switch(status)
{
case GL_FRAMEBUFFER_COMPLETE_EXT:
std::cout << "Framebuffer complete." << std::endl;
return true;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Attachment is NOT complete." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
std::cout << "[ERROR] Framebuffer incomplete: No image is attached to FBO." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Attached images have different dimensions." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Color attached images have different internal formats." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Draw buffer." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Read buffer." << std::endl;
return false;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
std::cout << "[ERROR] Unsupported by FBO implementation." << std::endl;
return false;
default:
std::cout << "[ERROR] Unknown error." << std::endl;
return false;
}
}
// std::addressof was introduced in C++11, an equivalent function is defined below
// definition from http://en.cppreference.com/w/cpp/memory/addressof
......@@ -208,16 +208,16 @@ void Clock::drawTime()
if (isRecording)
{
glColor4f(1.0, 0.0, 0.0, 1.0);
m = floor(totalRecordTime/60000);
s = floor((totalRecordTime - m*60000)/1000);
m = floor(totalRecordTime/60000.0);
s = floor((totalRecordTime - m*60000.0)/1000.0);
} else {
if (isRunning)
glColor4f(1.0, 1.0, 0.0, 1.0);
else
glColor4f(1.0, 1.0, 1.0, 1.0);
m = floor(totalTime/60000);
s = floor((totalTime - m*60000)/1000);
m = floor(totalTime/60000.0);
s = floor((totalTime - m*60000.0)/1000.0);
}
String timeString = "";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment