Commit d5bcaa4a authored by Iulian Gheorghiu's avatar Iulian Gheorghiu

Update and optimize some functions

parent 52ce1269
......@@ -101,12 +101,6 @@ public:
void (*charReceive_Callback)(char data);
void *udata;
private:
/*int vsnprintf (char *str, size_t count, const char *fmt, va_list args);
void dopr (char *buffer, size_t maxlen, const char *format, va_list args);
void fmtstr (char *buffer, size_t *currlen, size_t maxlen, char *value, int flags, int min, int max);
void fmtint (char *buffer, size_t *currlen, size_t maxlen, long value, int base, int min, int max, int flags);
void fmtfp (char *buffer, size_t *currlen, size_t maxlen, LDOUBLE fvalue, int min, int max, int flags);
void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );*/
bool isVirtual;
unsigned char unitNr;
......
......@@ -16,11 +16,14 @@ GI::Device::Sensor::Lps25hb::Lps25hb(string hwPath, unsigned char sa)
this->sa = sa;
unsigned long addr = LPS25HB_I2CADDR + sa;
hwIo->ctl(GI::IO::IO_CTL_SET_SLAVE_ADDR, &addr);
setTempAvarage(LPS25HB_TEMP_AVARAGE_8);
setPressAvarage(LPS25HB_PRESS_AVARAGE_16);
setUpdateMode(LPS25HB_UPDATE_MODE_CONTINUOUS);
setDataRate(LPS25HB_ODR_1HZ);
setPowerDown(LPS25HB_PWR_DOWN_FALSE);
if(setTempAvarage(LPS25HB_TEMP_AVARAGE_8) ||
setPressAvarage(LPS25HB_PRESS_AVARAGE_16) ||
setUpdateMode(LPS25HB_UPDATE_MODE_CONTINUOUS) ||
setDataRate(LPS25HB_ODR_1HZ) ||
setPowerDown(LPS25HB_PWR_DOWN_FALSE))
err = SYS_ERR_UNKNOWN;
else
err = SYS_ERR_OK;
}
GI::Device::Sensor::Lps25hb::~Lps25hb()
......@@ -53,7 +56,7 @@ SysErr GI::Device::Sensor::Lps25hb::getRefPress(signed long *ref_press)
SysErr err;
if((err = GI::Sensor::Common::readRegs(hwIo, tmp, LPS25HB_REF_P_XL, 3)) != SYS_ERR_OK)
return err;
*ref_press = tmp[0] + (tmp[1] << 8) + (tmp[2] << 16) + (tmp[2] & 0x80) ? 0xFF000000 : 0x00000000;
*ref_press = tmp[0] + (tmp[1] << 8) + ((unsigned long)tmp[2] << 16) + (tmp[2] & 0x80) ? 0xFF000000 : 0x00000000;
return SYS_ERR_OK;
}
......@@ -233,6 +236,6 @@ SysErr GI::Device::Sensor::Lps25hb::readPress(float *pressure)
return err;
if((err = GI::Sensor::Common::readRegs(hwIo, tmp + 2, LPS25HB_PRESS_OUT_H, 1)) != SYS_ERR_OK)
return err;
*pressure = (tmp[0] + (tmp[1] << 8) + (tmp[2] << 16)) / 4096.0/* + ((tmp[2] & 0x80) ? 0xFF000000 : 0x00000000)*/;
*pressure = (tmp[0] + (tmp[1] << 8) + ((unsigned long)tmp[2] << 16)) / 4096.0/* + ((tmp[2] & 0x80) ? 0xFF000000 : 0x00000000)*/;
return SYS_ERR_OK;
}
......@@ -102,6 +102,7 @@ public:
unsigned char sa;
bool busy;
GI::IO *hwIo;
SysErr err;
};
}
}
......
......@@ -15,14 +15,17 @@ GI::Device::Sensor::Lsm9ds1::Lsm9ds1(string hwPath, unsigned char sa0, unsigned
this->sa1 = sa1;
unsigned long addr = LSM9DS1_ACCEL_GIR_I2CADDR + sa0;
hwIo->ctl(GI::IO::IO_CTL_SET_SLAVE_ADDR, &addr);
setScale(LSM9DS1_SCALE_2000);
setBandwidth(LSM9DS1_BW_0);
setDataRate(LSM9DS1_ODR_59_5HZ);
setMagPerformance(LSM9DS1_MAG_PERFORMANCE_UHIGH);
setMagDataRate(LSM9DS1_MAG_ODR_80HZ);
setMagTempCompensation(LSM9DS1_MAG_TMP_COMP_ON);
setMagScale(LSM9DS1_MAG_SCALE_4G);
setMagOpMode(LSM9DS1_MAG_OP_MODE_CONTINUOUS);
if(setScale(LSM9DS1_SCALE_2000) ||
setBandwidth(LSM9DS1_BW_0) ||
setDataRate(LSM9DS1_ODR_59_5HZ) ||
setMagPerformance(LSM9DS1_MAG_PERFORMANCE_UHIGH) ||
setMagDataRate(LSM9DS1_MAG_ODR_80HZ) ||
setMagTempCompensation(LSM9DS1_MAG_TMP_COMP_ON) ||
setMagScale(LSM9DS1_MAG_SCALE_4G) ||
setMagOpMode(LSM9DS1_MAG_OP_MODE_CONTINUOUS))
err = SYS_ERR_UNKNOWN;
else
err = SYS_ERR_OK;
}
GI::Device::Sensor::Lsm9ds1::~Lsm9ds1()
......
......@@ -187,6 +187,7 @@ public:
unsigned char sa1;
bool busy;
GI::IO *hwIo;
SysErr err;
};
}
}
......
......@@ -310,7 +310,7 @@ void GI::Device::Display::Ssd1331::_drawPixel(void *driverHandlerPtr, signed int
cmds[3] = _X_Coordonate; // end column
cmds[4] = _Y_Coordonate; //end row
cmds[5] = color >> 16; //R
cmds[5] = (unsigned long)color >> 16; //R
cmds[6] = color >> 8; //G
cmds[7] = color; //B
driverHandler->wrCmd(cmds, 8);
......@@ -348,10 +348,10 @@ void GI::Device::Display::Ssd1331::_drawRectangle(void *driverHandlerPtr, signed
cmds[3] = x_end; // end column
cmds[4] = y_end; //end row
cmds[5] = color >> 16; //R
cmds[5] = (unsigned long)color >> 16; //R
cmds[6] = color >> 8; //G
cmds[7] = color; //B
cmds[8] = color >> 16; //R
cmds[8] = (unsigned long)color >> 16; //R
cmds[9] = color >> 8; //G
cmds[10] = color; //B
driverHandler->wrCmd(cmds, 13);
......
This diff is collapsed.
......@@ -23,17 +23,6 @@
#define RGB_TO_UINT(R,G,B) ((R)<<16) | ((G)<<8) | ((B))
/*#####################################################*/
#ifdef HAVE_LONG_DOUBLE
#define LDOUBLE long double
#else
#define LDOUBLE double
#endif
#ifdef __AVR_XMEGA__
extern const gfx_u8 CharTable6x8[] PROGMEM;
#else
extern const gfx_u8 CharTable6x8[];
#endif
#if (__SIZEOF_INT__ == 4)
//#if 4 == sizeof(gfx_u32)
......@@ -126,17 +115,6 @@ namespace Gfx {
gfx_u32 modifyed;
int error;
//bool initialized;
private:
/*int vsnprintf (char *str, size_t count, const char *fmt, va_list args);
void dopr (char *buffer, size_t maxlen, const char *format, va_list args);
void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max);
void fmtint (char *buffer, size_t *currlen, size_t maxlen,
long value, int base, int min, int max, int flags);
void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
LDOUBLE fvalue, int min, int max, int flags);
void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );*/
};
}
}
......
......@@ -12,11 +12,14 @@ GI::String::String()
if (buff)
{
error = SYS_ERR_OK;
}
else
{
error = SYS_ERR_OUT_OF_MEMORY;
}
}
GI::String::String(char *String)
/*GI::String::String(char *String)
{
memset(this, 0, sizeof(*this));
unsigned int len = strlen(String);
......@@ -42,8 +45,60 @@ GI::String::String(GI::String *String)
error = SYS_ERR_OK;
modifyed++;
}
}*/
GI::String::String(const char *String, ...)
{
memset(this, 0, sizeof(*this));
va_list args;
va_start (args, String);
char tmp_buff[1];
s32 len = vsnprintf(tmp_buff, 0, String, args);
va_end (args);
buff = (char *)malloc(len + 1);
if(buff)
{
va_start (args, String);
vsnprintf(buff, len + 1, String, args);
va_end (args);
length = len;
error = SYS_ERR_OK;
modifyed++;
}
else
{
error = SYS_ERR_OUT_OF_MEMORY;
}
}
GI::String::String(GI::String *String, ...)
{
memset(this, 0, sizeof(*this));
va_list args;
char *pcString = String->buff;
va_start (args, pcString);
char tmp_buff[1];
s32 len = vsnprintf(tmp_buff, 0, pcString, args);
va_end (args);
buff = (char *)malloc(len + 1);
if(buff)
{
va_start (args, pcString);
vsnprintf(buff, len + 1, pcString, args);
va_end (args);
length = len;
error = SYS_ERR_OK;
modifyed++;
}
else
{
error = SYS_ERR_OUT_OF_MEMORY;
}
}
GI::String::~String()
{
if(!this)
......
......@@ -10,17 +10,33 @@
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#if defined (__AVR_XMEGA__) || defined (__AVR_MEGA__)
#include <avr/pgmspace.h>
#endif
#include <include/global.h>
#ifdef HAVE_LONG_DOUBLE
#define LDOUBLE long double
#else
#define LDOUBLE double
#endif
#ifdef __AVR_XMEGA__
extern const gfx_u8 CharTable6x8[] PROGMEM;
#else
extern const gfx_u8 CharTable6x8[];
#endif
namespace GI
{
class String
{
public:
String();
String(char *String);
String(GI::String *String);
//String(char *String);
//String(GI::String *String);
String(const char *String, ...);
String(GI::String *String, ...);
~String();
bool equal(char *string);
bool equal(GI::String *string);
......@@ -45,12 +61,12 @@ namespace GI
char *buff;
unsigned int length;
/*
* Private variables.
*/
unsigned int modifyed;
int error;
//bool initialized;
private:
};
}
......
......@@ -103,8 +103,8 @@ GI::Dev::Uart::Uart(ioSettings *cfg)
udata = (void *)UART_BASE_PTRS[unitNr];
unsigned int ubrr = ((FCPU / 8) / int_cfg->speed) -1;
((USART_t*)udata)->BAUDCTRLA = (unsigned char)ubrr;
((USART_t*)udata)->BAUDCTRLB = (unsigned char)((ubrr>>8) & 0x0F);
((FPGA_USART_t*)udata)->BAUDCTRLA = (unsigned char)ubrr;
((FPGA_USART_t*)udata)->BAUDCTRLB = (unsigned char)((ubrr>>8) & 0x0F);
unsigned char tmp = 0;
if(int_cfg->wordLen == CfgUart::WORD_LEN_5)
tmp = FPGA_USART_CHSIZE_5BIT_gc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment