void Save_AllSensorsToOneNet(void) { EdpPacket* send_pkg; uint16_t f; uint16_t hum[1], temperature[1]; int16_t adxl[3], hmc5883l[3]; /*读取温湿度*/ memset(data_string_dst, 0, sizeof(data_string_dst)); SHT20_read_user_reg(); mDelay(200);//延迟,设备没有那么快的响应时间,否则总线处理忙等 SHT2x_MeasureHM(SHT20_Measurement_T_HM, temperature); mDelay(1000); SHT2x_MeasureHM(SHT20_Measurement_RH_HM, hum); mDelay(400); f = (uint16_t)Read_BH1750(); snprintf(data_string_t, sizeof(data_string_t), ",;BH1750FVI,%d;SHT20_temperature,%d;SHT20_hum,%d;", (uint16_t)f, (uint16_t)temperature[0], (uint16_t)hum[0]); /*读取BH1750FVI*/ printf("%s\n", data_string_t); mDelay(400); /*读取ADXL345*/ ADXL345_GETXYZ(adxl); snprintf(data_string_adxl, sizeof(data_string_adxl), "ADXL345_x,0x%x;ADXL345_y,0x%0x;ADXL345_z,0x%x;", (uint16_t)adxl[0], (uint16_t)adxl[1], (uint16_t)adxl[2]); printf("%s\n", data_string_adxl); mDelay(400); /*读取HMC588CL*/ HMC5883L_GetXYZ(hmc5883l); snprintf(data_string_hmc5883l, sizeof(data_string_hmc5883l), "HMC5883L_x,0x%x;HMC5883L_y,0x%x;HMC5883L_z,0x%x", (uint16_t)hmc5883l[0], (uint16_t)hmc5883l[2], (uint16_t)hmc5883l[1]); printf("%s\n", data_string_hmc5883l); strcat(data_string_dst, data_string_t); strcat(data_string_dst, data_string_adxl); strcat(data_string_dst, data_string_hmc5883l); printf("%s\n", data_string_dst); send_pkg = PacketSavedataSimpleString(NULL, data_string_dst); DoSend(0, (const uint8_t *)send_pkg->_data, send_pkg->_write_pos); DeleteBuffer(&send_pkg); mDelay(1000); }
/** * @brief Handler for the systick timer; increments counters, etc. */ void SysTick_Handler(void) { //static uint32_t blink_counter = 0; static uint32_t sample_counter_temp = 0; static uint32_t sample_counter_rh = 10; static uint32_t sample_counter_mag = 20; static int_fp mag_x=0, mag_y=0, mag_z=0; static uint32_t sample_counter_range = 30; static uint32_t left_sw_hold_counter = 0; static uint8_t left_sw_engaged = 0; static uint32_t right_sw_hold_counter = 0; static uint8_t right_sw_engaged = 0; g_delayms_counter += MS_PER_TICK; sample_counter_temp++; if (sample_counter_temp > SAMPLE_PERIOD_TEMP) { Plot_AddSample(&g_plot_temp, HTU21D_GetTemp(&g_HTU21D)); sample_counter_temp = 0; } sample_counter_rh++; if (sample_counter_rh > SAMPLE_PERIOD_RH) { Plot_AddSample(&g_plot_rh, HTU21D_GetRH(&g_HTU21D)); sample_counter_rh = 0; } sample_counter_mag++; if (sample_counter_mag > SAMPLE_PERIOD_MAG) { HMC5883L_GetXYZ(&g_HMC5883L, &mag_x, &mag_y, &mag_z); Plot_AddSample(&g_plot_mag, mag_z); Compass_UpdateXY(&g_compass, mag_x, -mag_y); sample_counter_mag = 0; } sample_counter_range++; if (sample_counter_range > SAMPLE_PERIOD_RANGE) { if (g_adc_sample_ready) { g_adc_sample_ready = 0; sample_counter_range = 0; g_range_raw = ADC_DR_RESULT(Chip_ADC_GetDataReg(LPC_ADC, MoonLander_IO8_ADC)); Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX); } } if (left_sw_engaged) { if (Chip_GPIO_GetPinState(LPC_GPIO_PORT, 0, SW_LEFT)) { left_sw_engaged = 0; left_sw_hold_counter = 0; } else { left_sw_hold_counter += MS_PER_TICK; if (left_sw_hold_counter >= SW_OFF_HOLD_TIME_MS) { g_go_to_sleep = 1; left_sw_hold_counter = 0; left_sw_engaged = 0; } } } if (right_sw_engaged) { if (Chip_GPIO_GetPinState(LPC_GPIO_PORT, 0, SW_RIGHT)) { right_sw_engaged = 0; right_sw_hold_counter = 0; } else { right_sw_hold_counter += MS_PER_TICK; if (right_sw_hold_counter >= SW_OFF_HOLD_TIME_MS) { g_go_to_sleep = 1; right_sw_hold_counter = 0; right_sw_engaged = 0; } } } if (g_sw_left_debouncing) { left_sw_engaged = 1; g_sw_left_debounce_counter += MS_PER_TICK; if (g_sw_left_debounce_counter >= SW_DEBOUNCE_MS) { g_sw_left_debouncing = 0; g_sw_left_debounce_counter = 0; } } if (g_sw_right_debouncing) { right_sw_engaged = 1; g_sw_right_debounce_counter += MS_PER_TICK; if (g_sw_right_debounce_counter >= SW_DEBOUNCE_MS) { g_sw_right_debouncing = 0; g_sw_right_debounce_counter = 0; } } g_millis_counter += MS_PER_TICK; }