Skip to content

Commit

Permalink
Tvoc maths (#677)
Browse files Browse the repository at this point in the history
* do not convert

* separate calibration

* gettvoc 2

* set

* fix bug

* Revert "do not convert"

This reverts commit 130d73c.

* cleanup
  • Loading branch information
zer0page authored and plasticchris committed Oct 28, 2016
1 parent d9e6c8d commit 4930a83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions kitsune/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,7 @@ tCmdLineEntry g_sCmdTable[] = {
{"inttemp", Cmd_inttemp, "" }, //internal temperature
{ "thp", Cmd_read_temp_hum_press, "" },
{ "tv", Cmd_meas_TVOC, "" },
{"tvenv", Cmd_set_tvenv, ""},

{ "uv", Cmd_read_uv, "" },
{ "light", Cmd_readlight, "" },
Expand Down
26 changes: 16 additions & 10 deletions kitsune/i2c_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,37 +568,42 @@ int init_tvoc(int measmode) {
}

xSemaphoreGiveRecursive(i2c_smphr);



return 0;
}
#define DBG_TVOC LOGI
int get_tvoc(int * tvoc, int * eco2, int * current, int * voltage, int temp, unsigned int humid ) {
static int set_tvoc_env(int temp, unsigned int humid){
unsigned char b[8];
LOGI("setting tv temp %d humid %d\r\n", temp, humid);
assert(xSemaphoreTakeRecursive(i2c_smphr, 30000));

vTaskDelay(10);
//environmental
b[0] = 0x05;

humid *= 10;
// see cc-000803-an-4-ccs811_programming_and_interfacing_guide.pdf page 19, 20
b[1] = ((humid % 1000) / 100) > 7 ? (humid/1000 + 1)<<1 : (humid/1000)<<1;
if(((humid % 1000) / 100) > 2 && (((humid) / 100) < 8))
if(((humid % 1000) / 100) > 2 && (((humid % 1000) / 100) < 8))
{
b[1] |= 1;
}
b[2] = 0;

temp *= 10;
temp += 25000;
b[3] = ((temp % 1000) / 100) > 7 ? (temp / 1000 + 1) << 1 : (temp) << 1;
b[3] = ((temp % 1000) / 100) > 7 ? (temp / 1000 + 1) << 1 : (temp / 1000) << 1;
if (((temp % 1000) / 100) > 2 && (((temp % 1000) / 100) < 8)) {
b[3] |= 1;
}
b[4] = 0;
(I2C_IF_Write(0x5a, b, 5, 1));
vTaskDelay(10);
xSemaphoreGiveRecursive(i2c_smphr);
return 0;
}
int Cmd_set_tvenv(int argc, char * argv[]){
return set_tvoc_env(atoi(argv[1]), atoi(argv[2]));
}
#define DBG_TVOC LOGI
int get_tvoc(int * tvoc, int * eco2, int * current, int * voltage, int temp, unsigned int humid ) {
unsigned char b[8];
assert(xSemaphoreTakeRecursive(i2c_smphr, 30000));

b[0] = 2;
(I2C_IF_Write(0x5a, b, 1, 1));
Expand Down Expand Up @@ -632,6 +637,7 @@ int get_tvoc(int * tvoc, int * eco2, int * current, int * voltage, int temp, uns

vTaskDelay(10);
xSemaphoreGiveRecursive(i2c_smphr);
set_tvoc_env(temp,humid);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion kitsune/i2c_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int read_zopt(zopt_mode selection);
int Cmd_read_uv(int argc, char *argv[]);
int Cmd_uvr(int argc, char *argv[]);
int Cmd_uvw(int argc, char *argv[]);

int Cmd_set_tvenv(int argc, char * argv[]);
int init_humid_sensor();
int init_temp_sensor();

Expand Down

0 comments on commit 4930a83

Please sign in to comment.