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