bugfixes battery read
This commit is contained in:
		
							parent
							
								
									ede1cd77a5
								
							
						
					
					
						commit
						34cdbdd5b1
					
				| @ -218,19 +218,19 @@ device answers with it's current configuration. The configuration is a C structu | ||||
| 	byte 13:		Wifi antenna switch (0=internal, 1=external) | ||||
| 	byte 14:		Vendorfilter mode (0=disabled, 1=enabled) | ||||
| 	byte 15:		RGB LED luminosity (0..100 %) | ||||
| 	bytes 16-25:		Software version (ASCII format) | ||||
| 	bytes 16-26:		Software version (ASCII format, terminating with zero) | ||||
| 
 | ||||
| 0x81 get device uptime | ||||
| 
 | ||||
| 	bytes 1-7:		uptime in seconds (little endian format) | ||||
| 	bytes 1-8:		uptime in seconds (little endian format) | ||||
| 
 | ||||
| 0x82 get device cpu temperature | ||||
| 
 | ||||
| 	bytes 1-3:		chip temperature in degrees celsius (little endian format) | ||||
| 	bytes 1-4:		chip temperature in degrees celsius (little endian format) | ||||
| 
 | ||||
| 0x83 get device battery voltage | ||||
| 
 | ||||
| 	bytes 1-3:		battery voltage in millivolt, 0 if unreadable (little endian format) | ||||
| 	bytes 1-2:		battery voltage in millivolt, 0 if unreadable (little endian format) | ||||
| 
 | ||||
| # License | ||||
| 
 | ||||
|  | ||||
| @ -28,6 +28,7 @@ uint16_t read_voltage(void) | ||||
| { | ||||
|     static const adc1_channel_t channel = HAS_BATTERY_PROBE; | ||||
|     static const adc_atten_t atten = ADC_ATTEN_DB_11; | ||||
|     static const adc_unit_t unit = ADC_UNIT_1; | ||||
| 
 | ||||
|     //configure ADC1
 | ||||
|     ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12)); | ||||
| @ -35,9 +36,8 @@ uint16_t read_voltage(void) | ||||
| 
 | ||||
|     //calibrate ADC1
 | ||||
|     esp_adc_cal_characteristics_t *adc_chars = (esp_adc_cal_characteristics_t *) calloc(1, sizeof(esp_adc_cal_characteristics_t)); | ||||
|     #ifdef VERBOSE | ||||
|         print_char_val_type(esp_adc_cal_characterize(ADC_UNIT_1, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars)); | ||||
|     #endif | ||||
|     esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars); | ||||
|     print_char_val_type(val_type); | ||||
| 
 | ||||
|     //multisample ADC1
 | ||||
|     uint32_t adc_reading = 0; | ||||
| @ -48,7 +48,7 @@ uint16_t read_voltage(void) | ||||
|     adc_reading /= NO_OF_SAMPLES; | ||||
| 
 | ||||
|     //Convert adc_reading to voltage in mV
 | ||||
|     uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars); | ||||
|     uint16_t voltage = (uint16_t) esp_adc_cal_raw_to_voltage(adc_reading, adc_chars); | ||||
|     #ifdef BATT_FACTOR | ||||
|         voltage *= BATT_FACTOR; | ||||
|     #endif | ||||
|  | ||||
| @ -211,51 +211,38 @@ void set_noop (uint8_t val) { | ||||
| void get_config (uint8_t val) { | ||||
|     ESP_LOGI(TAG, "Remote command: get configuration"); | ||||
|     int size = sizeof(configData_t); | ||||
|     // declare send buffer (char byte array)
 | ||||
|     unsigned char *sendData = new unsigned char[size]; | ||||
|     // copy current configuration (struct) to send buffer
 | ||||
|     memcpy(sendData, &cfg, size); | ||||
|     LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port
 | ||||
|     delete sendData; // free memory
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); | ||||
|     LMIC_setTxData2(RCMDPORT, (byte*)&cfg, size, 0); // send data unconfirmed on RCMD Port
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size); | ||||
| }; | ||||
| 
 | ||||
| void get_uptime (uint8_t val) { | ||||
|     ESP_LOGI(TAG, "Remote command: get uptime"); | ||||
|     int size = sizeof(uptimecounter); | ||||
|     unsigned char *sendData = new unsigned char[size]; | ||||
|     memcpy(sendData, (unsigned char*)&uptimecounter , size); | ||||
|     LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port
 | ||||
|     delete sendData; // free memory
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); | ||||
|     LMIC_setTxData2(RCMDPORT, (byte*)&uptimecounter, size, 0); // send data unconfirmed on RCMD Port
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size); | ||||
| }; | ||||
| 
 | ||||
| void get_cputemp (uint8_t val) { | ||||
|     ESP_LOGI(TAG, "Remote command: get cpu temperature"); | ||||
|     float temp = temperatureRead(); | ||||
|     int size = sizeof(temp); | ||||
|     unsigned char *sendData = new unsigned char[size]; | ||||
|     memcpy(sendData, (unsigned char*)&temp, size); | ||||
|     LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port
 | ||||
|     delete sendData; // free memory
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); | ||||
|     LMIC_setTxData2(RCMDPORT, (byte*)&temp, size, 0); // send data unconfirmed on RCMD Port
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size); | ||||
| }; | ||||
| 
 | ||||
| void get_voltage (uint8_t val) { | ||||
|     ESP_LOGI(TAG, "Remote command: get battery voltage"); | ||||
|     #ifdef HAS_BATTERY_PROBE | ||||
|         uint32_t voltage = read_voltage(); | ||||
|         uint16_t voltage = read_voltage(); | ||||
|     #else | ||||
|         uint32_t voltage = 0; | ||||
|         uint16_t voltage = 0; | ||||
|     #endif | ||||
|     int size = sizeof(voltage); | ||||
|     unsigned char *sendData = new unsigned char[size]; | ||||
|     memcpy(sendData, (unsigned char*)&voltage, size); | ||||
|     LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port
 | ||||
|     delete sendData; // free memory
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); | ||||
|     LMIC_setTxData2(RCMDPORT, (byte*)&voltage, size, 0); // send data unconfirmed on RCMD Port
 | ||||
|     ESP_LOGI(TAG, "%d bytes queued in send queue", size); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // assign previously defined functions to set of numeric remote commands
 | ||||
| // format: opcode, function, flag (1 = do make settings persistent / 0 = don't)
 | ||||
| // 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user