A program for listening to rates via i2c
Embed:
(wiki syntax)
Show/hide line numbers
SN_SnRateListener.cpp
00001 #include "SN_SnRateListener.h" 00002 #include "SnBitUtils.h" 00003 00004 float SnRateListener::getRate() 00005 { 00006 char results[2]; 00007 //Pins 9 and 10 on the LPC1768 correspond to one of two i2c buses. 00008 I2C linkToFpga(p9,p10); //declaring this locally? 00009 for(uint8_t tries=0;(tries<kMaxRateReadTries)&&(getLastAck()==false);++tries) 00010 { 00011 I2C i2c(p9,p10); 00012 setLastAck(!i2c.read(getMMFCAddress(),results,2)); //think about sizeof(uint8_t)*2 here 00013 } 00014 setMSBs(results[0]); 00015 setLSBs(results[1]); 00016 //MSB>128 00017 if (((float)results[0]) > 128.0) 00018 { 00019 return 5.0625*32767.0/((float)(results[0]<<8) - 32768 + (float)(results[1])); 00020 } 00021 else 00022 { 00023 if (((float)results[0]) == 128.0) 00024 { 00025 return (float)(32767.0/((float)results[1]))*5.0625; 00026 } 00027 else 00028 { 00029 return (((float)(results[0]<<8) + (float)(results[1]))/32767.0*5.0625); 00030 } 00031 } 00032 //return 0.0; //add interpretation here tomorrow, June 5th, 2019 (JCH) 00033 } 00034 void SnRateListener::setMSBs(uint8_t a) 00035 { 00036 rateMSBs = a; 00037 } 00038 void SnRateListener::setLSBs(uint8_t a) 00039 { 00040 rateLSBs = a; 00041 } 00042 uint8_t SnRateListener::getMMFCAddress() 00043 { 00044 return MMFC_address; 00045 } 00046 void SnRateListener::setLastAck(bool a) 00047 { 00048 lastAcknowledge = a; 00049 } 00050 bool SnRateListener::getLastAck() 00051 { 00052 return lastAcknowledge; 00053 }
Generated on Mon Nov 7 2022 06:28:23 by
1.7.2