Пример #1
0
/**
  * @brief EXTI line detection callbacks
  * @param GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if (GPIO_Pin == GPIO_PIN_13)
  {
	    int32_t d1, d2, d3, d4, d5, d6, d7, d8;
	    int32_t data[3];
	    int32_t gdata[6];

	    if(BSP_HUM_TEMP_isInitialized()) {
	        BSP_HUM_TEMP_GetHumidity((float *)&HUMIDITY_Value);
	        BSP_HUM_TEMP_GetTemperature((float *)&TEMPERATURE_Value);
	        floatToInt(HUMIDITY_Value, &d1, &d2, 2);
	        float tempF = celsius2fahrenheit(TEMPERATURE_Value);
	        floatToInt(tempF, &d3, &d4, 2);
            sprintf(dataOut, "HUM: %d.%02d rH     TEMP: %d.%02d (f)\n\r", (int)d1, (int)d2, (int)d3, (int)d4);
	        printf(dataOut);
	    }

	    if(BSP_PRESSURE_isInitialized())
	    {
	        BSP_PRESSURE_GetPressure((float *)&PRESSURE_Value);
	        BSP_PRESSURE_GetTemperature((float *)&TEMPERATURE2_Value);
	        floatToInt(PRESSURE_Value, &d5, &d6, 2);
	        float tempF2 = celsius2fahrenheit(TEMPERATURE2_Value);
	        floatToInt(tempF2, &d7, &d8, 2);
            sprintf(dataOut, "PRESS: %d.%02d hPa     TEMP: %d.%02d (f)\n\r", (int)d5, (int)d6, (int)d7, (int)d8);
	        printf(dataOut);
	    }

	    if(BSP_MAGNETO_isInitialized())
	    {
	        BSP_MAGNETO_M_GetAxesRaw((AxesRaw_TypeDef *)&MAG_Value);
            data[0] = MAG_Value.AXIS_X;
            data[1] = MAG_Value.AXIS_Y;
            data[2] = MAG_Value.AXIS_Z;

            sprintf(dataOut, "MAG_X: %d, MAG_Y: %d, MAG_Z: %d\n\r", (int)data[0], (int)data[1], (int)data[2]);
	        printf(dataOut);
	    }


	    if(BSP_IMU_6AXES_isInitialized()) {
	        BSP_IMU_6AXES_X_GetAxesRaw((AxesRaw_TypeDef *)&ACC_Value);
	        BSP_IMU_6AXES_G_GetAxesRaw((AxesRaw_TypeDef *)&GYR_Value);
            gdata[0] = ACC_Value.AXIS_X;
            gdata[1] = ACC_Value.AXIS_Y;
            gdata[2] = ACC_Value.AXIS_Z;
            gdata[3] = GYR_Value.AXIS_X;
            gdata[4] = GYR_Value.AXIS_Y;
            gdata[5] = GYR_Value.AXIS_Z;

            sprintf(dataOut, "ACC_X: %d, ACC_Y: %d, ACC_Z: %d\n\r", (int)gdata[0], (int)gdata[1], (int)gdata[2]);
	        printf(dataOut);
            sprintf(dataOut, "GYR_X: %d, GYR_Y: %d, GYR_Z: %d\n\r", (int)gdata[3], (int)gdata[4], (int)gdata[5]);
	        printf(dataOut);

	    }
  }
}
Пример #2
0
main() {
    int i;

    printf("  °C    °F\n");
    printf(" ==========\n");
    for (i = 0; i < 100; ++i) {
        printf("%4d %5.1f\n", i, celsius2fahrenheit(i));
    }
    return 0;
}
Пример #3
0
/* handles incoming structured data by dumping it */
void data_acquired_handler(data_t *data)
{
    if (conversion_mode == CONVERT_SI) {
        for (data_t *d = data; d; d = d->next) {
            if ((d->type == DATA_DOUBLE) &&
                !strcmp(d->key, "temperature_F")) {
                    *(double*)d->value = fahrenheit2celsius(*(double*)d->value);
					free(d->key);
                    d->key = strdup("temperature_C");
                    char *pos;
                    if (d->format &&
                        (pos = strrchr(d->format, 'F'))) {
                        *pos = 'C';
                    }
            }
        }
    }
    if (conversion_mode == CONVERT_CUSTOMARY) {
        for (data_t *d = data; d; d = d->next) {
            if ((d->type == DATA_DOUBLE) &&
                !strcmp(d->key, "temperature_C")) {
                    *(double*)d->value = celsius2fahrenheit(*(double*)d->value);
					free(d->key);
                    d->key = strdup("temperature_F");
                    char *pos;
                    if (d->format &&
                        (pos = strrchr(d->format, 'C'))) {
                        *pos = 'F';
                    }
            }
        }
    }

    for (output_handler_t *output = output_handler; output; output = output->next) {
        data_print(data, output->file, output->printer, output->aux);
    }
    data_free(data);
}
Пример #4
0
static int acurite_txr_callback(bitbuffer_t *bitbuf) {
    int browlen;
    uint8_t *bb;
    float tempc, tempf, wind_dird, rainfall = 0.0, wind_speedmph;
    uint8_t humidity, sensor_status, repeat_no, message_type;
    char channel, *wind_dirstr = "";
    uint16_t sensor_id;
    int wind_speed, raincounter;


    local_time_str(0, time_str);

    if (debug_output > 1) {
        fprintf(stderr,"acurite_txr\n");
        bitbuffer_print(bitbuf);
    }

    for (uint16_t brow = 0; brow < bitbuf->num_rows; ++brow) {
	browlen = (bitbuf->bits_per_row[brow] + 7)/8;
	bb = bitbuf->bb[brow];

	if (debug_output > 1)
	    fprintf(stderr,"acurite_txr: row %d bits %d, bytes %d \n", brow, bitbuf->bits_per_row[brow], browlen);

	if (bitbuf->bits_per_row[brow] < ACURITE_TXR_BITLEN ||
	    bitbuf->bits_per_row[brow] > ACURITE_5N1_BITLEN + 1) {
	    if (debug_output > 1 && bitbuf->bits_per_row[brow] > 16)
		fprintf(stderr,"acurite_txr: skipping wrong len\n");
	    continue;
	}

	// There will be 1 extra false zero bit added by the demod.
	// this forces an extra zero byte to be added
	if (bb[browlen - 1] == 0)
	    browlen--;

	if (!acurite_crc(bb,browlen - 1)) {
	    if (debug_output) {
		fprintf(stderr, "%s Acurite bad checksum:", time_str);
		for (uint8_t i = 0; i < browlen; i++)
		    fprintf(stderr," 0x%02x",bb[i]);
		fprintf(stderr,"\n");
	    }
	    continue;
	}

	if (debug_output) {
	    fprintf(stderr, "acurite_txr Parity: ");
	    for (uint8_t i = 0; i < browlen; i++) {
		fprintf(stderr,"%d",byteParity(bb[i]));
	    }
	    fprintf(stderr,"\n");
	}


	// tower sensor messages are 7 bytes.
	// @todo - see if there is a type in the message that
	// can be used instead of length to determine type
	if (browlen == ACURITE_TXR_BITLEN / 8) {
	    channel = acurite_getChannel(bb[0]);
	    sensor_id = acurite_txr_getSensorId(bb[0],bb[1]);
	    sensor_status = bb[2]; // @todo, uses parity? & 0x07f
	    humidity = acurite_getHumidity(bb[3]);
	    tempc = acurite_txr_getTemp(bb[4], bb[5]);
	    tempf = celsius2fahrenheit(tempc);

	    printf("%s Acurite tower sensor 0x%04X Ch %c: %3.1F C %3.1F F %d %% RH\n",
		   time_str, sensor_id, channel, tempc, tempf, humidity);

	    // currently 0x44 seens to be a normal status and/or type
	    // for tower sensors.  Battery OK/Normal == 0x40
	    if (sensor_status != 0x44)
		printf("%s Acurite tower sensor 0x%04X Ch %c, Status %02X\n",
		       time_str, sensor_id, channel, sensor_status);

	}

	// The 5-n-1 weather sensor messages are 8 bytes.
	if (browlen == ACURITE_5N1_BITLEN / 8) {
	    channel = acurite_getChannel(bb[0]);
	    sensor_id = acurite_5n1_getSensorId(bb[0],bb[1]);
	    repeat_no = acurite_5n1_getMessageCaught(bb[0]);
	    message_type = bb[2] & 0x3f;


	    if (message_type == 0x31) {
		// Wind speed, wind direction, and rain fall
	        wind_speed = acurite_getWindSpeed(bb[3], bb[4]);
		wind_speedmph = kmph2mph(wind_speed);
		wind_dird = acurite_5n1_winddirections[bb[4] & 0x0f];
		wind_dirstr = acurite_5n1_winddirection_str[bb[4] & 0x0f];
		raincounter = acurite_getRainfallCounter(bb[5], bb[6]);
		if (acurite_raincounter > 0) {
		    // track rainfall difference after first run
		    rainfall = ( raincounter - acurite_raincounter ) * 0.01;
		    if (raincounter < acurite_raincounter) {
			printf("%s Acurite 5n1 sensor 0x%04X Ch %c, rain counter reset or wrapped around (old %d, new %d)\n",
			       time_str, sensor_id, channel, acurite_raincounter, raincounter);
			acurite_raincounter = raincounter;
		    }
		} else {
		    // capture starting counter
		    acurite_raincounter = raincounter;
		    printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Total rain fall since last reset: %0.2f\n",
			   time_str, sensor_id, channel, raincounter * 0.01);
		}

		printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Msg %02x, Wind %d kmph / %0.1f mph %0.1f° %s (%d), rain gauge %0.2f in.\n",
		       time_str, sensor_id, channel, message_type,
		       wind_speed, wind_speedmph,
		       wind_dird, wind_dirstr, bb[4] & 0x0f, rainfall);

	    } else if (message_type == 0x38) {
		// Wind speed, temperature and humidity
		wind_speed = acurite_getWindSpeed(bb[3], bb[4]);
		wind_speedmph = kmph2mph((float) wind_speed);
		tempf = acurite_getTemp(bb[4], bb[5]);
		tempc = fahrenheit2celsius(tempf);
		humidity = acurite_getHumidity(bb[6]);

		printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Msg %02x, Wind %d kmph / %0.1f mph, %3.1F C %3.1F F %d %% RH\n",
		       time_str, sensor_id, channel, message_type,
		       wind_speed, wind_speedmph, tempc, tempf, humidity);
	    } else {
		printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Status %02X, Unknown message type 0x%02x\n",
			time_str, sensor_id, channel, bb[3], message_type);
	    }
	}
    }

    return 0;
}