// File: mrlordkaj[P]i2cdevlib-pi/MS5803/MS5803.cpp
// Function: MS5803::_getADCconversion(measurement, precision)
int32_t MS5803::_getADCconversion(measurement _measurement, precision _precision){
	// Retrieve ADC measurement from the device.
	// Select measurement type and precision
	uint32_t result;
	uint8_t reg_address = CMD_ADC_CONV + _measurement + _precision;
	uint8_t write_length = 0;
	uint8_t read_length = 3;
	uint16_t read_timeout = 2000;
	//sendCommand(CMD_ADC_CONV + _measurement + _precision);
	I2Cdev::writeBytes(_dev_address,reg_address,write_length,_buffer); // buffer is ignored when write_length is 0
		
	// Wait for conversion to complete
	delay(1); //general delay
	switch( _precision )
	{
		case ADC_256 : delay(1); break;
		case ADC_512 : delay(3 >> CLKPR); break;
		case ADC_1024: delay(4 >> CLKPR); break;
		case ADC_2048: delay(6 >> CLKPR); break;
		case ADC_4096: delay(10 >> CLKPR); break;
	}
	I2Cdev::readBytes(_dev_address,MS5803_ADC_READ,read_length,_buffer,read_timeout);
	result = ((uint32_t)_buffer[0] << 16) + ((uint32_t)_buffer[1] << 8) + _buffer[2];
	if (_debug) {
		Serial.print("Reading MS5803 ADC");
		switch (_measurement) {
			case PRESSURE:    Serial.println(" Pressure: "   ); break;
			case TEMPERATURE: Serial.println(" Temperature: "); break;
		}
		Serial.print("    buffer[0] = "); Serial.println(_buffer[0]);
		Serial.print("    buffer[1] = "); Serial.println(_buffer[1]);
		Serial.print("    buffer[2] = "); Serial.println(_buffer[2]);
	}
	return result;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movl %edx, 0x28(%rsp)
movq 0x30(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movl 0x2c(%rsp), %eax
movl 0x28(%rsp), %edx
addl %edx, %eax
addb $0x40, %al
movb %al, 0x23(%rsp)
movb $0x0, 0x22(%rsp)
movb $0x3, 0x21(%rsp)
movw $0x7d0, 0x1e(%rsp)      # imm = 0x7D0
movzbl 0xe(%rcx), %edi
movzbl 0x23(%rsp), %esi
movzbl 0x22(%rsp), %edx
callq 0x22290
movl $0x1, %edi
callq 0x228c0
movl 0x28(%rsp), %eax
movq %rax, 0x10(%rsp)
subq $0x8, %rax
ja 0x492b7
movq 0x10(%rsp), %rax
leaq 0x2cd4(%rip), %rcx      # 0x4bf48
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, %edi
callq 0x228c0
jmp 0x492b7
movl $0x3, %edi
callq 0x228c0
jmp 0x492b7
movl $0x4, %edi
callq 0x228c0
jmp 0x492b7
movl $0x6, %edi
callq 0x228c0
jmp 0x492b7
movl $0xa, %edi
callq 0x228c0
movq 0x8(%rsp), %rcx
movb 0xe(%rcx), %dl
movb 0x21(%rsp), %al
xorl %esi, %esi
movzbl %dl, %edi
movzbl %al, %edx
movzwl 0x1e(%rsp), %r8d
callq 0x22b50
movq 0x8(%rsp), %rax
movzbl (%rax), %ecx
shll $0x10, %ecx
movzbl 0x1(%rax), %edx
shll $0x8, %edx
addl %edx, %ecx
movzbl 0x2(%rax), %edx
addl %edx, %ecx
movl %ecx, 0x24(%rsp)
testb $0x1, 0x15(%rax)
je 0x493c9
movq 0x12c5b(%rip), %rdi     # 0x5bf60
leaq 0x2e18(%rip), %rsi      # 0x4c124
callq 0x22e80
movl 0x2c(%rsp), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x4932a
jmp 0x4931f
movl 0x4(%rsp), %eax
subl $0x10, %eax
je 0x4933f
jmp 0x49352
movq 0x12c2f(%rip), %rdi     # 0x5bf60
leaq 0x2dff(%rip), %rsi      # 0x4c137
callq 0x22de0
jmp 0x49352
movq 0x12c1a(%rip), %rdi     # 0x5bf60
leaq 0x2df6(%rip), %rsi      # 0x4c143
callq 0x22de0
movq 0x12c07(%rip), %rdi     # 0x5bf60
leaq 0x2df2(%rip), %rsi      # 0x4c152
callq 0x22e80
movq 0x8(%rsp), %rax
movq 0x12bef(%rip), %rdi     # 0x5bf60
movzbl (%rax), %esi
callq 0x22df0
movq 0x12be0(%rip), %rdi     # 0x5bf60
leaq 0x2ddc(%rip), %rsi      # 0x4c163
callq 0x22e80
movq 0x8(%rsp), %rax
movq 0x12bc8(%rip), %rdi     # 0x5bf60
movzbl 0x1(%rax), %esi
callq 0x22df0
movq 0x12bb8(%rip), %rdi     # 0x5bf60
leaq 0x2dc5(%rip), %rsi      # 0x4c174
callq 0x22e80
movq 0x8(%rsp), %rax
movq 0x12ba0(%rip), %rdi     # 0x5bf60
movzbl 0x2(%rax), %esi
callq 0x22df0
movl 0x24(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)