|
|
|
@ -14,8 +14,38 @@ typedef struct
|
|
|
|
int address;
|
|
|
|
int address;
|
|
|
|
double value;
|
|
|
|
double value;
|
|
|
|
int valid;
|
|
|
|
int valid;
|
|
|
|
|
|
|
|
int enabled;
|
|
|
|
} sensor_t;
|
|
|
|
} sensor_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int sensor_matches(const sensor_t *sensor, const char *name)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return strcmp(sensor->name, name) == 0 ||
|
|
|
|
|
|
|
|
(strcmp(sensor->name, "temperature") == 0 && strcmp(name, "rtd") == 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void enable_requested_sensors(sensor_t *sensors, size_t sensor_count, int argc, char *argv[])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t index = 0; index < sensor_count; index++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sensors[index].enabled = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int arg = 2; arg < argc; arg++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t index = 0; index < sensor_count; index++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sensor_matches(&sensors[index], argv[arg]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sensors[index].enabled = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int select_sensor(int fd, int address)
|
|
|
|
static int select_sensor(int fd, int address)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ioctl(fd, I2C_SLAVE, address);
|
|
|
|
return ioctl(fd, I2C_SLAVE, address);
|
|
|
|
@ -81,18 +111,19 @@ static int receive_reading(int fd, sensor_t *sensor)
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Uso: EZO_ACQUIRE /dev/i2c-1\n");
|
|
|
|
fprintf(stderr, "Uso: EZO_ACQUIRE /dev/i2c-1 [temperature|ph|do|ec]\n");
|
|
|
|
return 2;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sensor_t sensors[] = {
|
|
|
|
sensor_t sensors[] = {
|
|
|
|
{"temperature", 0x66, 0.0, 0},
|
|
|
|
{"temperature", 0x66, 0.0, 0, 0},
|
|
|
|
{"ph", 0x63, 0.0, 0},
|
|
|
|
{"ph", 0x63, 0.0, 0, 0},
|
|
|
|
{"do", 0x61, 0.0, 0},
|
|
|
|
{"do", 0x61, 0.0, 0, 0},
|
|
|
|
{"ec", 0x64, 0.0, 0}};
|
|
|
|
{"ec", 0x64, 0.0, 0, 0}};
|
|
|
|
const size_t sensor_count = sizeof(sensors) / sizeof(sensors[0]);
|
|
|
|
const size_t sensor_count = sizeof(sensors) / sizeof(sensors[0]);
|
|
|
|
|
|
|
|
enable_requested_sensors(sensors, sensor_count, argc, argv);
|
|
|
|
int lock_fd = open(
|
|
|
|
int lock_fd = open(
|
|
|
|
"/tmp/photobioreactor-i2c.lock",
|
|
|
|
"/tmp/photobioreactor-i2c.lock",
|
|
|
|
O_CREAT | O_RDWR,
|
|
|
|
O_CREAT | O_RDWR,
|
|
|
|
@ -115,9 +146,12 @@ int main(int argc, char *argv[])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t index = 0; index < sensor_count; index++)
|
|
|
|
for (size_t index = 0; index < sensor_count; index++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sensors[index].enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
request_reading(fd, &sensors[index]);
|
|
|
|
request_reading(fd, &sensors[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
usleep(1000000);
|
|
|
|
usleep(1000000);
|
|
|
|
|
|
|
|
|
|
|
|
|