Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions openBeken_win32_mvsc2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
<ClCompile Include="src\driver\drv_adcButton.c" />
<ClCompile Include="src\driver\drv_adcSmoother.c" />
<ClCompile Include="src\driver\drv_aht2x.c" />
<ClCompile Include="src\driver\drv_bmp280.c" />
<ClCompile Include="src\driver\drv_battery.c" />
<ClCompile Include="src\driver\drv_bkPartitions.c" />
<ClCompile Include="src\driver\drv_bl0937.c" />
Expand Down Expand Up @@ -266,6 +267,11 @@
<ClCompile Include="src\driver\drv_sgp.c" />
<ClCompile Include="src\driver\drv_shiftRegister.c" />
<ClCompile Include="src\driver\drv_sht3x.c" />
<ClCompile Include="src\driver\drv_shtxx.c" />
<ClCompile Include="src\driver\drv_xhtxx.c" />
<ClCompile Include="src\driver\drv_veml7700.c" />
<ClCompile Include="src\driver\drv_soft_i2c_sim.c" />
<ClCompile Include="src\driver\drv_soft_i2c_sim_sensors.c" />
<ClCompile Include="src\driver\drv_simpleEEPROM.c" />
<ClCompile Include="src\driver\drv_sm15155e.c" />
<ClCompile Include="src\driver\drv_sm16703P.c" />
Expand Down Expand Up @@ -969,6 +975,9 @@
<ClInclude Include="src\driver\drv_rc.h" />
<ClInclude Include="src\driver\drv_sgp.h" />
<ClInclude Include="src\driver\drv_sht3x.h" />
<ClInclude Include="src\driver\drv_xhtxx.h" />
<ClInclude Include="src\driver\drv_veml7700.h" />
<ClInclude Include="src\driver\drv_soft_i2c_sim.h" />
<ClInclude Include="src\driver\drv_sm2235.h" />
<ClInclude Include="src\driver\drv_soft_spi.h" />
<ClInclude Include="src\driver\drv_spiLED.h" />
Expand Down
5 changes: 5 additions & 0 deletions openBeken_win32_mvsc2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<ClCompile Include="src\driver\drv_sgp.c" />
<ClCompile Include="src\driver\drv_shiftRegister.c" />
<ClCompile Include="src\driver\drv_sht3x.c" />
<ClCompile Include="src\driver\drv_shtxx.c" />
<ClCompile Include="src\driver\drv_soft_i2c_sim.c" />
<ClCompile Include="src\driver\drv_soft_i2c_sim_sensors.c" />
<ClCompile Include="src\driver\drv_sm2135.c" />
<ClCompile Include="src\driver\drv_sm2235.c" />
<ClCompile Include="src\driver\drv_soft_i2c.c" />
Expand Down Expand Up @@ -442,6 +445,8 @@
<ClInclude Include="src\driver\drv_pt6523_font.h" />
<ClInclude Include="src\driver\drv_sgp.h" />
<ClInclude Include="src\driver\drv_sht3x.h" />
<ClInclude Include="src\driver\drv_shtxx.h" />
<ClInclude Include="src\driver\drv_soft_i2c_sim.h" />
<ClInclude Include="src\driver\drv_sm2235.h" />
<ClInclude Include="src\driver\drv_test_drivers.h" />
<ClInclude Include="src\driver\drv_tm1637.h" />
Expand Down
3 changes: 3 additions & 0 deletions platforms/obk_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ set(OBKM_SRC
${OBK_SRCS}driver/drv_sgp.c
${OBK_SRCS}driver/drv_shiftRegister.c
${OBK_SRCS}driver/drv_sht3x.c
${OBK_SRCS}driver/drv_shtxx.c
${OBK_SRCS}driver/drv_xhtxx.c
${OBK_SRCS}driver/drv_veml7700.c
${OBK_SRCS}driver/drv_sm2135.c
${OBK_SRCS}driver/drv_sm2235.c
${OBK_SRCS}driver/drv_soft_i2c.c
Expand Down
3 changes: 3 additions & 0 deletions platforms/obk_main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ OBKM_SRC += $(OBK_SRCS)driver/drv_rn8209.c
OBKM_SRC += $(OBK_SRCS)driver/drv_sgp.c
OBKM_SRC += $(OBK_SRCS)driver/drv_shiftRegister.c
OBKM_SRC += $(OBK_SRCS)driver/drv_sht3x.c
OBKM_SRC += $(OBK_SRCS)driver/drv_shtxx.c
OBKM_SRC += $(OBK_SRCS)driver/drv_xhtxx.c
OBKM_SRC += $(OBK_SRCS)driver/drv_veml7700.c
OBKM_SRC += $(OBK_SRCS)driver/drv_sm15155e.c
OBKM_SRC += $(OBK_SRCS)driver/drv_sm16703P.c
OBKM_SRC += $(OBK_SRCS)driver/drv_simpleEEPROM.c
Expand Down
13 changes: 13 additions & 0 deletions src/cmnds/cmd_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ enum LightMode {
#define TOKENIZER_FORCE_SINGLE_ARGUMENT_MODE 8
#define TOKENIZER_ALLOW_ESCAPING_QUOTATIONS 16
#define TOKENIZER_EXPAND_EARLY 32
// allow quotes in a named argument - so '"' is not at beginning or after a whitespace
// but e.g. in a string like
// mystr="that's my string"
// w/o this, it will be tokenized as
// mystr="that's
// my
// string"
// but we want the string to be one token
// we need this together with TOKENIZER_ALLOW_QUOTES !
#define TOKENIZER_ALLOW_QUOTES_IN_NAMEDARG_VALUE (64 | TOKENIZER_ALLOW_QUOTES)

// cmd_tokenizer.c
int Tokenizer_GetArgsCount();
Expand All @@ -226,6 +236,9 @@ bool Tokenizer_IsArgInteger(int i);
float Tokenizer_GetArgFloat(int i);
int Tokenizer_GetArgIntegerRange(int i, int rangeMax, int rangeMin);
void Tokenizer_TokenizeString(const char* s, int flags);
const char *Tokenizer_GetArgEqualDefault(const char *search, const char *def);
int Tokenizer_GetArgEqualInteger(const char *search, const int def);
int Tokenizer_GetPinEqual(const char *search, const int def);
// cmd_repeatingEvents.c
void RepeatingEvents_Init();
void RepeatingEvents_RunUpdate(float deltaTimeSeconds);
Expand Down
97 changes: 97 additions & 0 deletions src/cmnds/cmd_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,75 @@ void expandQuotes(char* str) {
str[writeIndex] = 0;
}


// "parse" arguments to search for a "named" argument:
// will accept
// -<name> <value> like "-port 80"
// <name>=<value> like "port=80"
// we can never know, if the "name" is present at all, so a default is needed to return in case its not found
const char *Tokenizer_GetArgEqualDefault(const char *name, const char *def) {
size_t name_len = strlen(name);

for (int i = 0; i < g_numArgs; i++) {
char* p = strstr(g_args[i], name);
if (p != NULL) {
size_t arg_len = strlen(g_args[i]);

// Pattern 1: <name>=<value>
// --> g_arg[i] must be "<name>=<value>" so
// p must point to the beginning of g_arg[i], so it p == g_args[i]
// g_args[i] must be at least two chars longer than <name> (one is '=' + at least one for the value)
// following the <name> there must be the char '=' --> g_args[i][name_len] == '='
// g_args[i] must start with '-'
if (p == g_args[i] &&
arg_len >= name_len + 2 &&
g_args[i][name_len] == '='
) {
return g_args[i] + name_len + 1;
}

// Pattern 2: -<name> <value>
// --> g_arg[i] must be "-<name>" so
// g_args[i] must be exactly one char longer than <name>
// p must point to second char, so it p > g_args[i]
// p - 1 == g_args[i] no need to test, must be the case if the first two are true
// g_args[i] must start with '-'
if (arg_len - 1 == name_len &&
p > g_args[i] &&
// p - 1 == g_args[i] &&
g_args[i][0] == '-'
) {
if (i + 1 < g_numArgs) {
return g_args[i + 1];
}
}
}
}
return def;
}
// search for a "named" integer argument like channel=5
// with Tokenizer_GetGetArgEqualInteger("channel")
int Tokenizer_GetArgEqualInteger(const char *search, const int def) {
int ret=def;
const char* found=Tokenizer_GetArgEqualDefault(search, NULL); // search for argument, default must be no number
if(found && found[0] == '0' && (found[1] == 'x' || found[1] == 'X') ) { // also handle hex numbers (e.g. i2c addreses)
sscanf(found, "%x", &ret);
return ret;
}
if (strIsInteger(found)) ret = atoi(found); // will check for number - use default else
return ret;
}

// search for a "named" pin argument like
// will return pin or default pin
int Tokenizer_GetPinEqual(const char *search, const int def) {
const char* found=Tokenizer_GetArgEqualDefault(search, NULL); // search for argument, default must neither be a number nor a valid pin name
if (found == NULL) return def;
int temp = PIN_FindIndexFromString(found); // will check for number and pin names
if (temp != -1) return temp;
return def;
}

void Tokenizer_TokenizeString(const char *s, int flags) {
char *p;

Expand Down Expand Up @@ -384,6 +453,34 @@ void Tokenizer_TokenizeString(const char *s, int flags) {
g_numArgs++;
}
}
// special handling to allow quotes with named arguments like
// myarg="that's my arg"
// in this case, the quote is "inside" the arg (no whitespace before the '"' - but a '=')
//
// We will pretend it's -myarg "that's my arg"
// by shifting the argument one char to the right and prepend '-'
// --> so if we had
// myarg="that's my arg"
// we now have
// -myarg"thats my arg"
//
// and immediately jump to "quote:"
// This works, because in "quote" first code will change the '"' to '\0' so we have the "name" string terminated by \0
// Then the next arg is started after the " (turned to \0 before) and continued until the closing '"'
//
// we know p[1] must be present, even if string is ending, it will be there as '\0', so it's safe to compare p[1] to '"'
if ((flags & TOKENIZER_ALLOW_QUOTES_IN_NAMEDARG_VALUE) == TOKENIZER_ALLOW_QUOTES_IN_NAMEDARG_VALUE && *p == '=' && p[1] == '"'){

// shift the nem one to the left ...
for (int j = p - g_args[g_numArgs-1]; j > 0; j--){
g_args[g_numArgs-1][j]=g_args[g_numArgs-1][j-1];
}
// ... and make first char a '-'
g_args[g_numArgs-1][0]='-';
// forward to '"' (*p was '=')
p=p+1;
goto quote;
}
//if(*p == ',') {
// *p = 0;
// g_args[g_numArgs] = p+1;
Expand Down
37 changes: 22 additions & 15 deletions src/driver/BMP280.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

#define BMP280_SOFT_RESET 0xB6

int32_t adc_T, adc_P, adc_H, t_fine;
static int32_t adc_T, adc_P, adc_H, t_fine;

// BMP280 sensor modes, register ctrl_meas mode[1:0]
typedef enum
Expand Down Expand Up @@ -126,8 +126,9 @@ struct
// writes 1 byte '_data' to register 'reg_addr'
void BMP280_Write8(uint8_t reg_addr, uint8_t _data)
{
BMP280_Start();
BMP280_Write(g_softI2C.address8bit);
// BMP280_Start();
// BMP280_Write(g_softI2C.address8bit);
BMP280_Start_new(g_softI2C.address8bit);
BMP280_Write(reg_addr);
BMP280_Write(_data);
BMP280_Stop();
Expand All @@ -138,12 +139,14 @@ uint8_t BMP280_Read8(uint8_t reg_addr)
{
uint8_t ret;

BMP280_Start();
BMP280_Write(g_softI2C.address8bit);
// BMP280_Start();
// BMP280_Write(g_softI2C.address8bit);
BMP280_Start_new(g_softI2C.address8bit);
BMP280_Write(reg_addr);
Soft_I2C_Stop(&g_softI2C);
BMP280_Start();
BMP280_Write(g_softI2C.address8bit | 1);
// BMP280_Start();
// BMP280_Write(g_softI2C.address8bit | 1);
BMP280_Start_new(g_softI2C.address8bit | 1);
ret = BMP280_Read(0);
BMP280_Stop();

Expand All @@ -159,12 +162,14 @@ uint16_t BMP280_Read16(uint8_t reg_addr)
uint16_t w;
} ret;

BMP280_Start();
BMP280_Write(g_softI2C.address8bit);
// BMP280_Start();
// BMP280_Write(g_softI2C.address8bit);
BMP280_Start_new(g_softI2C.address8bit);
BMP280_Write(reg_addr);
Soft_I2C_Stop(&g_softI2C);
BMP280_Start();
BMP280_Write(g_softI2C.address8bit | 1);
// BMP280_Start();
// BMP280_Write(g_softI2C.address8bit | 1);
BMP280_Start_new(g_softI2C.address8bit | 1);
ret.b[0] = BMP280_Read(1);
ret.b[1] = BMP280_Read(0);
BMP280_Stop();
Expand Down Expand Up @@ -286,12 +291,14 @@ void BMP280_Update()
} ret;
ret.b[3] = 0x00;

BMP280_Start();
BMP280_Write(g_softI2C.address8bit);
// BMP280_Start();
// BMP280_Write(g_softI2C.address8bit);
BMP280_Start_new(g_softI2C.address8bit);
BMP280_Write(BMP280_REG_PRESS_MSB);
Soft_I2C_Stop(&g_softI2C);
BMP280_Start();
BMP280_Write(g_softI2C.address8bit | 1);
// BMP280_Start();
// BMP280_Write(g_softI2C.address8bit | 1);
BMP280_Start_new(g_softI2C.address8bit | 1);
ret.b[2] = BMP280_Read(1);
ret.b[1] = BMP280_Read(1);
ret.b[0] = BMP280_Read(1);
Expand Down
9 changes: 9 additions & 0 deletions src/driver/drv_aht2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,17 @@ void AHT2X_Init()
channel_temp = Tokenizer_GetArgIntegerDefault(3, -1);
channel_humid = Tokenizer_GetArgIntegerDefault(4, -1);

// test, if extended arguments are present
g_softI2C.pin_clk = Tokenizer_GetPinEqual("SCL", g_softI2C.pin_clk);
g_softI2C.pin_data = Tokenizer_GetPinEqual("SDA", g_softI2C.pin_data);
channel_temp = Tokenizer_GetArgEqualInteger("chan_t", channel_temp);
channel_humid = Tokenizer_GetArgEqualInteger("chan_h", channel_humid);

Soft_I2C_PreInit(&g_softI2C);
rtos_delay_milliseconds(100);
setPinUsedString(g_softI2C.pin_clk, "AHT2X SCL");
setPinUsedString(g_softI2C.pin_data, "AHT2X SDA");


AHT2X_Initialization();

Expand Down
6 changes: 6 additions & 0 deletions src/driver/drv_bmp280.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ unsigned short BMP280_Start(void) {
Soft_I2C_Start_Internal(&g_softI2C);
return 0;
}
unsigned short BMP280_Start_new(uint8_t addr) {
Soft_I2C_Start(&g_softI2C,addr);
return 0;
}
unsigned short BMP280_Write(byte data_) {
Soft_I2C_WriteByte(&g_softI2C, data_);
return 0;
Expand Down Expand Up @@ -53,6 +57,8 @@ void BMP280_Init() {
g_softI2C.address8bit = Tokenizer_GetArgIntegerDefault(6, 236);

Soft_I2C_PreInit(&g_softI2C);
setPinUsedString(g_softI2C.pin_clk, "BMP280 SCL");
setPinUsedString(g_softI2C.pin_data, "BMP280 SDA");

usleep(100);
if (BMP280_begin(MODE_NORMAL, SAMPLING_X1, SAMPLING_X1, SAMPLING_X1, FILTER_OFF, STANDBY_0_5) == 0) {
Expand Down
Loading
Loading