Library for MAXREFDES131 OneWire GridEYE sensor interface
Dependents: MAXREFDES131_Qt_Demo MAXREFDES130_131_Demo
API_Level_1/grideye_api_lv1.c@3:5b025369ad96, 2016-06-14 (annotated)
- Committer:
- j3
- Date:
- Tue Jun 14 20:32:49 2016 +0000
- Revision:
- 3:5b025369ad96
- Parent:
- 1:9e457e35e2e3
- Child:
- 8:fa89d4cd41cd
updated library to use RomIterator for OW slaves
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 1:9e457e35e2e3 | 1 | /******************************************************************************* |
j3 | 1:9e457e35e2e3 | 2 | include file |
j3 | 1:9e457e35e2e3 | 3 | *******************************************************************************/ |
j3 | 1:9e457e35e2e3 | 4 | #include "grideye_api_common.h" |
j3 | 3:5b025369ad96 | 5 | #include "grideye_api_lv1.h" |
j3 | 1:9e457e35e2e3 | 6 | |
j3 | 1:9e457e35e2e3 | 7 | |
j3 | 1:9e457e35e2e3 | 8 | /******************************************************************************* |
j3 | 1:9e457e35e2e3 | 9 | macro definition |
j3 | 1:9e457e35e2e3 | 10 | *******************************************************************************/ |
j3 | 1:9e457e35e2e3 | 11 | |
j3 | 1:9e457e35e2e3 | 12 | /* Grid-EYE's number of pixels */ |
j3 | 1:9e457e35e2e3 | 13 | #define SNR_SZ_X (8) |
j3 | 1:9e457e35e2e3 | 14 | #define SNR_SZ_Y (8) |
j3 | 1:9e457e35e2e3 | 15 | #define SNR_SZ (SNR_SZ_X * SNR_SZ_Y) |
j3 | 1:9e457e35e2e3 | 16 | |
j3 | 1:9e457e35e2e3 | 17 | |
j3 | 1:9e457e35e2e3 | 18 | /******************************************************************************* |
j3 | 1:9e457e35e2e3 | 19 | public method |
j3 | 1:9e457e35e2e3 | 20 | ******************************************************************************/ |
j3 | 1:9e457e35e2e3 | 21 | |
j3 | 1:9e457e35e2e3 | 22 | /*------------------------------------------------------------------------------ |
j3 | 1:9e457e35e2e3 | 23 | Read data form I2C bus. |
j3 | 1:9e457e35e2e3 | 24 | ------------------------------------------------------------------------------*/ |
j3 | 1:9e457e35e2e3 | 25 | BOOL bAMG_PUB_I2C_Read( UCHAR ucI2cAddr, UCHAR ucRegAddr, UCHAR ucSize, UCHAR* ucDstAddr ) |
j3 | 1:9e457e35e2e3 | 26 | { |
j3 | 1:9e457e35e2e3 | 27 | #if defined(MCU_TEST) |
j3 | 1:9e457e35e2e3 | 28 | { |
j3 | 1:9e457e35e2e3 | 29 | extern UCHAR I2C_Read( UCHAR, UCHAR, UCHAR*, UCHAR ); |
j3 | 1:9e457e35e2e3 | 30 | return( I2C_Read( ucI2cAddr, ucRegAddr, ucDstAddr, ucSize ) ); |
j3 | 1:9e457e35e2e3 | 31 | } |
j3 | 1:9e457e35e2e3 | 32 | #else /* !defined(MCU_TEST) */ |
j3 | 1:9e457e35e2e3 | 33 | { |
j3 | 1:9e457e35e2e3 | 34 | return( 1 ); |
j3 | 1:9e457e35e2e3 | 35 | } |
j3 | 1:9e457e35e2e3 | 36 | #endif /* defined(MCU_TEST) */ |
j3 | 1:9e457e35e2e3 | 37 | } |
j3 | 1:9e457e35e2e3 | 38 | |
j3 | 1:9e457e35e2e3 | 39 | /*------------------------------------------------------------------------------ |
j3 | 1:9e457e35e2e3 | 40 | Convert thermistor register value. |
j3 | 1:9e457e35e2e3 | 41 | ------------------------------------------------------------------------------*/ |
j3 | 1:9e457e35e2e3 | 42 | short shAMG_PUB_TMP_ConvThermistor( UCHAR aucRegVal[2] ) |
j3 | 1:9e457e35e2e3 | 43 | { |
j3 | 1:9e457e35e2e3 | 44 | short shVal = ((short)(aucRegVal[1] & 0x07) << 8) | aucRegVal[0]; |
j3 | 1:9e457e35e2e3 | 45 | |
j3 | 1:9e457e35e2e3 | 46 | if( 0 != (0x08 & aucRegVal[1]) ) |
j3 | 1:9e457e35e2e3 | 47 | { |
j3 | 1:9e457e35e2e3 | 48 | shVal *= -1; |
j3 | 1:9e457e35e2e3 | 49 | } |
j3 | 1:9e457e35e2e3 | 50 | |
j3 | 1:9e457e35e2e3 | 51 | shVal *= 16; |
j3 | 1:9e457e35e2e3 | 52 | |
j3 | 1:9e457e35e2e3 | 53 | return( shVal ); |
j3 | 1:9e457e35e2e3 | 54 | } |
j3 | 1:9e457e35e2e3 | 55 | |
j3 | 1:9e457e35e2e3 | 56 | /*------------------------------------------------------------------------------ |
j3 | 1:9e457e35e2e3 | 57 | Convert temperature register value for 1 pixel. |
j3 | 1:9e457e35e2e3 | 58 | ------------------------------------------------------------------------------*/ |
j3 | 1:9e457e35e2e3 | 59 | short shAMG_PUB_TMP_ConvTemperature( UCHAR aucRegVal[2] ) |
j3 | 1:9e457e35e2e3 | 60 | { |
j3 | 1:9e457e35e2e3 | 61 | short shVal = ((short)(aucRegVal[1] & 0x07) << 8) | aucRegVal[0]; |
j3 | 1:9e457e35e2e3 | 62 | |
j3 | 1:9e457e35e2e3 | 63 | if( 0 != (0x08 & aucRegVal[1]) ) |
j3 | 1:9e457e35e2e3 | 64 | { |
j3 | 1:9e457e35e2e3 | 65 | shVal -= 2048; |
j3 | 1:9e457e35e2e3 | 66 | } |
j3 | 1:9e457e35e2e3 | 67 | |
j3 | 1:9e457e35e2e3 | 68 | shVal *= 64; |
j3 | 1:9e457e35e2e3 | 69 | |
j3 | 1:9e457e35e2e3 | 70 | return( shVal ); |
j3 | 1:9e457e35e2e3 | 71 | } |
j3 | 1:9e457e35e2e3 | 72 | |
j3 | 1:9e457e35e2e3 | 73 | /*------------------------------------------------------------------------------ |
j3 | 1:9e457e35e2e3 | 74 | Convert temperature register value for 64 pixel. |
j3 | 1:9e457e35e2e3 | 75 | ------------------------------------------------------------------------------*/ |
j3 | 1:9e457e35e2e3 | 76 | void vAMG_PUB_TMP_ConvTemperature64( UCHAR* pucRegVal, short* pshVal ) |
j3 | 1:9e457e35e2e3 | 77 | { |
j3 | 1:9e457e35e2e3 | 78 | UCHAR ucCnt = 0; |
j3 | 1:9e457e35e2e3 | 79 | |
j3 | 1:9e457e35e2e3 | 80 | for( ucCnt = 0; ucCnt < SNR_SZ; ucCnt++ ) |
j3 | 1:9e457e35e2e3 | 81 | { |
j3 | 1:9e457e35e2e3 | 82 | pshVal[ucCnt] = shAMG_PUB_TMP_ConvTemperature( pucRegVal + ucCnt * 2 ); |
j3 | 1:9e457e35e2e3 | 83 | } |
j3 | 1:9e457e35e2e3 | 84 | } |
j3 | 1:9e457e35e2e3 | 85 | |
j3 | 1:9e457e35e2e3 | 86 | /*------------------------------------------------------------------------------ |
j3 | 1:9e457e35e2e3 | 87 | Convert value. |
j3 | 1:9e457e35e2e3 | 88 | ------------------------------------------------------------------------------*/ |
j3 | 1:9e457e35e2e3 | 89 | short shAMG_PUB_CMN_ConvFtoS( float fVal ) |
j3 | 1:9e457e35e2e3 | 90 | { |
j3 | 1:9e457e35e2e3 | 91 | return( ( fVal > 0 ) ? (short)(fVal * 256 + 0.5) : (short)(fVal * 256 - 0.5) ); |
j3 | 1:9e457e35e2e3 | 92 | } |
j3 | 1:9e457e35e2e3 | 93 | |
j3 | 1:9e457e35e2e3 | 94 | /*------------------------------------------------------------------------------ |
j3 | 1:9e457e35e2e3 | 95 | Convert value. |
j3 | 1:9e457e35e2e3 | 96 | ------------------------------------------------------------------------------*/ |
j3 | 1:9e457e35e2e3 | 97 | float fAMG_PUB_CMN_ConvStoF( short shVal ) |
j3 | 1:9e457e35e2e3 | 98 | { |
j3 | 1:9e457e35e2e3 | 99 | return( (float)shVal / 256 ); |
j3 | 1:9e457e35e2e3 | 100 | } |
j3 | 1:9e457e35e2e3 | 101 |