auto-sync

This commit is contained in:
rusEfi 2015-03-23 08:10:56 -05:00
parent a0028d3483
commit 9ee6f9b9a3
4 changed files with 59 additions and 61 deletions

View File

@ -91,7 +91,8 @@ typedef struct {
float veValue;
float maxDelta;
float minDelta;
int unused3[18];
float currentAccelDelta;
int unused3[17];
} TunerStudioOutputChannels;
#endif /* TUNERSTUDIO_CONFIGURATION_H_ */

View File

@ -276,5 +276,5 @@ int getRusEfiVersion(void) {
return 1; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE[0] == 0)
return 1; // this is here to make the compiler happy about the unused array
return 20150322;
return 20150323;
}

View File

@ -9,86 +9,82 @@
* @author Daniel Hill - Modified to use C++ - Mar 2, 2014
*/
#include "cyclic_buffer.h"
#include <string.h>
//ctor
cyclic_buffer::cyclic_buffer()
{
memset((void*)elements, 0, sizeof(elements)); // I would usually use static_cast, but due to the elements being volatile we cannot.
currentIndex = 0;
count = 0;
cyclic_buffer::cyclic_buffer() : cyclic_buffer(CB_MAX_SIZE) {
}
cyclic_buffer::cyclic_buffer(int size) {
currentIndex = 0;
setSize(size);
}
//cpctor
cyclic_buffer::cyclic_buffer(const cyclic_buffer& cb)
{
//Deep copy the data
currentIndex = cb.currentIndex;
count = cb.count;
for(int i = 0; i < CB_MAX_SIZE; ++i)
{
elements[i] = cb.elements[i];
}
cyclic_buffer::cyclic_buffer(const cyclic_buffer& cb) {
//Deep copy the data
currentIndex = cb.currentIndex;
count = cb.count;
size = cb.size;
for (int i = 0; i < size; ++i) {
elements[i] = cb.elements[i];
}
}
//dtor
cyclic_buffer::~cyclic_buffer()
{
//No dynamic allocation - safe to leave
cyclic_buffer::~cyclic_buffer() {
//No dynamic allocation - safe to leave
}
//overloaded =operator
cyclic_buffer& cyclic_buffer::operator=(const cyclic_buffer& rhCb)
{
//Deep copy
currentIndex = rhCb.currentIndex;
count = rhCb.count;
for(int i = 0; i < CB_MAX_SIZE; ++i)
{
elements[i] = rhCb.elements[i];
}
return *this;
cyclic_buffer& cyclic_buffer::operator=(const cyclic_buffer& rhCb) {
//Deep copy
currentIndex = rhCb.currentIndex;
count = rhCb.count;
for (int i = 0; i < size; ++i) {
elements[i] = rhCb.elements[i];
}
return *this;
}
void cyclic_buffer::add(int value)
{
++currentIndex;
if(currentIndex == CB_MAX_SIZE)
{
currentIndex = 0;
}
elements[currentIndex] = value;
void cyclic_buffer::add(int value) {
++currentIndex;
if (currentIndex == size) {
currentIndex = 0;
}
elements[currentIndex] = value;
++count;
++count;
}
void cyclic_buffer::setSize(int size) {
clear();
this->size = size;
}
void cyclic_buffer::clear() {
memset((void*) elements, 0, sizeof(elements)); // I would usually use static_cast, but due to the elements being volatile we cannot.
count = 0;
count = 0;
}
int cyclic_buffer::sum(int length)
{
if(length > count)
{
length = count;
}
int cyclic_buffer::sum(int length) {
if (length > count) {
length = count;
}
int ci = currentIndex; // local copy to increase thread-safety
int result = 0;
int ci = currentIndex; // local copy to increase thread-safety
int result = 0;
for(int i = 0; i < length; ++i)
{
int index = ci - i;
while (index < 0)
{
index += CB_MAX_SIZE;
for (int i = 0; i < length; ++i) {
int index = ci - i;
while (index < 0) {
index += size;
}
result += elements[index];
}
result += elements[index];
}
return result;
return result;
}

View File

@ -10,13 +10,13 @@
#ifndef CYCLIC_BUFFER_H
#define CYCLIC_BUFFER_H
static const short CB_MAX_SIZE = 16;
static const short CB_MAX_SIZE = 64;
class cyclic_buffer
{
public:
//ctor
cyclic_buffer();
cyclic_buffer();
cyclic_buffer(int size);
//cpctor
cyclic_buffer(const cyclic_buffer& cb);
//dtor
@ -29,13 +29,14 @@ class cyclic_buffer
public:
void add(int value);
int sum(int length);
void setSize(int size);
void clear();
private:
volatile int elements[CB_MAX_SIZE];
volatile int currentIndex;
volatile int count;
int size;
};
#endif //CYCLIC_BUFFER_H