From 3db862c41bf782994a8777e431c0e950fec4ac95 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:58:43 -0400 Subject: [PATCH] added temp --- afsk/telem.c | 71 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index cdbe39e7..9c2ab81c 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -152,8 +152,8 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { return data; } -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +struct SensorConfig sensorV; +struct SensorData readingV; struct SensorConfig tempSensor; int main(int argc, char *argv[]) { @@ -166,32 +166,59 @@ int main(int argc, char *argv[]) { printf("\n"); - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - reading = read_sensor_data(sensor[PLUS_X]); - printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); + sensorV = config_sensor("/dev/i2c-1", 0x40, 400); + readingV = read_sensor_data(sensorV); + printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_X, readingV.voltage, readingV.current, readingV.power); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - reading = read_sensor_data(sensor[PLUS_Y]); - printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - PLUS_Y , reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); + sensorV = config_sensor("/dev/i2c-1", 0x41, 400); + readingV = read_sensor_data(sensorV); + printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_Y, readingV.voltage, readingV.current, readingV.power); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); -// read_sensor_data(sensor[]); -// printf("+ | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// , reading[].voltage, reading[].current, reading[].power); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); + sensorV = config_sensor("/dev/i2c-1", 0x44, 400); + readingV = read_sensor_data(sensorV); + printf("+Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_Z, readingV.voltage, readingV.current, readingV.power); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); + sensorV = config_sensor("/dev/i2c-0", 0x40, 400); + readingV = read_sensor_data(sensorV); + printf("-X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + MINUS_X, readingV.voltage, readingV.current, readingV.power); + + sensorV = config_sensor("/dev/i2c-0", 0x41, 400); + readingV = read_sensor_data(sensorV); + printf("-Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + MINUS_Y, readingV.voltage, readingV.current, readingV.power); + + sensorV = config_sensor("/dev/i2c-0", 0x44, 400); + readingV = read_sensor_data(sensorV); + printf("-Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + MINUS_Z, readingV.voltage, readingV.current, readingV.power); + + + sensorV = config_sensor("/dev/i2c-1", 0x45, 400); + readingV = read_sensor_data(sensorV); + printf("Bat | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + BAT, readingV.voltage, readingV.current, readingV.power); + + sensorV = config_sensor("/dev/i2c-1", 0x4a, 2000); + readingV = read_sensor_data(sensorV); + printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + BUS, readingV.voltage, readingV.current, readingV.power); tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + sensorV = config_sensor("/dev/i2c-1", 0x45, 400); + + if (sensorV.fd != OFF) { + int tempValue = wiringPiI2CReadReg16(SensorV.fd, 0); + uint8_t upper = (uint8_t) (tempValue >> 8); + uint8_t lower = (uint8_t) (tempValue & 0xff); + float temp = (float)lower + ((float)upper / 0x100); + printf("T | % 4.1f C \n", temp); + } + printf("\n\n"); return 0;