Skip to content

Commit

Permalink
Merge pull request #1 from adafruit/tinywirem
Browse files Browse the repository at this point in the history
Small changes for better compatibility with low memory boards like Trinket
  • Loading branch information
tdicola committed May 1, 2015
2 parents 77d1c83 + d964148 commit 2d2897b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
8 changes: 7 additions & 1 deletion Adafruit_BNO055.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
#else
#include "WProgram.h"
#endif
#include "Wire.h"

#ifdef __AVR_ATtiny85__
#include <TinyWireM.h>
#define Wire TinyWireM
#else
#include <Wire.h>
#endif

#include <Adafruit_Sensor.h>
#include <utility/imumaths.h>
Expand Down
16 changes: 8 additions & 8 deletions utility/matrix.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Inertial Measurement Unit Maths Library
Copyright (C) 2013-2014 Samuel Cowen
www.camelsoftware.com
www.camelsoftware.com
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
Expand Down Expand Up @@ -32,17 +32,17 @@ namespace imu
template <uint8_t N> class Matrix
{
public:
Matrix()
{
int r = sizeof(double)*N;
_cell = (double*)malloc(r*r);
Matrix()
{
int r = sizeof(double)*N;
_cell = &_cell_data[0];
memset(_cell, 0, r*r);
}
}

Matrix(const Matrix &v)
{
int r = sizeof(double)*N;
_cell = (double*)malloc(r*r);
_cell = &_cell_data[0];
memset(_cell, 0, r*r);
for (int x = 0; x < N; x++ )
{
Expand All @@ -55,7 +55,6 @@ template <uint8_t N> class Matrix

~Matrix()
{
free(_cell);
}

void operator = (Matrix m)
Expand Down Expand Up @@ -239,6 +238,7 @@ template <uint8_t N> class Matrix

private:
double* _cell;
double _cell_data[N*N];
};


Expand Down
60 changes: 30 additions & 30 deletions utility/vector.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Inertial Measurement Unit Maths Library
Copyright (C) 2013-2014 Samuel Cowen
www.camelsoftware.com
www.camelsoftware.com
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
Expand Down Expand Up @@ -32,57 +32,56 @@ namespace imu
template <uint8_t N> class Vector
{
public:
Vector()
{
p_vec = (double*)malloc(sizeof(double)*N+1);
Vector()
{
p_vec = &p_vec_data[0];
memset(p_vec, 0, sizeof(double)*N);
}
}

Vector(double a)
{
p_vec = (double*)malloc(sizeof(double)*N+1);
Vector(double a)
{
p_vec = &p_vec_data[0];
memset(p_vec, 0, sizeof(double)*N);
p_vec[0] = a;
}
p_vec[0] = a;
}

Vector(double a, double b)
{
p_vec = (double*)malloc(sizeof(double)*N+1);
Vector(double a, double b)
{
p_vec = &p_vec_data[0];
memset(p_vec, 0, sizeof(double)*N);
p_vec[0] = a;
p_vec[1] = b;
}
p_vec[0] = a;
p_vec[1] = b;
}

Vector(double a, double b, double c)
{
p_vec = (double*)malloc(sizeof(double)*N+1);
Vector(double a, double b, double c)
{
p_vec = &p_vec_data[0];
memset(p_vec, 0, sizeof(double)*N);
p_vec[0] = a;
p_vec[1] = b;
p_vec[2] = c;
}
p_vec[0] = a;
p_vec[1] = b;
p_vec[2] = c;
}

Vector(double a, double b, double c, double d)
{
p_vec = (double*)malloc(sizeof(double)*N+1);
p_vec = &p_vec_data[0];
memset(p_vec, 0, sizeof(double)*N);
p_vec[0] = a;
p_vec[1] = b;
p_vec[2] = c;
p_vec[3] = d;
p_vec[1] = b;
p_vec[2] = c;
p_vec[3] = d;
}

Vector(const Vector<N> &v)
{
p_vec = (double*)malloc(sizeof(double)*N);
p_vec = &p_vec_data[0];
memset(p_vec, 0, sizeof(double)*N);
for (int x = 0; x < N; x++ )
p_vec[x] = v.p_vec[x];
}

~Vector()
{
free(p_vec);
}

uint8_t n() { return N; }
Expand Down Expand Up @@ -157,7 +156,7 @@ template <uint8_t N> class Vector
{
for (int x = 0; x < N; x++ )
p_vec[x] = v.p_vec[x];
return *this;
return *this;
}

double& operator [](int n)
Expand Down Expand Up @@ -218,6 +217,7 @@ template <uint8_t N> class Vector

private:
double* p_vec;
double p_vec_data[N];
};


Expand Down

0 comments on commit 2d2897b

Please sign in to comment.