Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ChaNFSSD mbed BMP085 SHT2x
libT/mbed/libT_getAcc.c@1:83960ee4d9a2, 2012-01-13 (annotated)
- Committer:
- tosihisa
- Date:
- Fri Jan 13 10:15:08 2012 +0000
- Revision:
- 1:83960ee4d9a2
- Parent:
- 0:6089ae824f06
add 5-sec wait before using CO2-sensor
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tosihisa | 1:83960ee4d9a2 | 1 | /* |
| tosihisa | 1:83960ee4d9a2 | 2 | * Copyright (c) 2011 Toshihisa T |
| tosihisa | 1:83960ee4d9a2 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
| tosihisa | 1:83960ee4d9a2 | 4 | */ |
| tosihisa | 0:6089ae824f06 | 5 | |
| tosihisa | 0:6089ae824f06 | 6 | extern "C" { |
| tosihisa | 0:6089ae824f06 | 7 | static int libT_getAccTOmV(unsigned long Val,long *mV); |
| tosihisa | 0:6089ae824f06 | 8 | int libT_getAcc1dot5G(unsigned long ADval,long *g); |
| tosihisa | 0:6089ae824f06 | 9 | int libT_getAcc6G(unsigned long ADval,long *g); |
| tosihisa | 0:6089ae824f06 | 10 | } |
| tosihisa | 0:6089ae824f06 | 11 | |
| tosihisa | 0:6089ae824f06 | 12 | |
| tosihisa | 0:6089ae824f06 | 13 | static int libT_getAccTOmV(unsigned long Val,long *mV) |
| tosihisa | 0:6089ae824f06 | 14 | { |
| tosihisa | 0:6089ae824f06 | 15 | *mV = 0; |
| tosihisa | 0:6089ae824f06 | 16 | |
| tosihisa | 0:6089ae824f06 | 17 | /* AnalogIn = 1mV = 19.85939393939394 */ |
| tosihisa | 0:6089ae824f06 | 18 | if(Val >= 32767UL){ |
| tosihisa | 0:6089ae824f06 | 19 | *mV = ((Val - 32767UL) * 100UL) / 1985UL; |
| tosihisa | 0:6089ae824f06 | 20 | *mV = 0 - *mV; |
| tosihisa | 0:6089ae824f06 | 21 | } else { |
| tosihisa | 0:6089ae824f06 | 22 | *mV = ((32767UL - Val) * 100UL) / 1985UL; |
| tosihisa | 0:6089ae824f06 | 23 | } |
| tosihisa | 0:6089ae824f06 | 24 | return 0; |
| tosihisa | 0:6089ae824f06 | 25 | } |
| tosihisa | 0:6089ae824f06 | 26 | |
| tosihisa | 0:6089ae824f06 | 27 | int libT_getAcc1dot5G(unsigned long ADval,long *g) |
| tosihisa | 0:6089ae824f06 | 28 | { |
| tosihisa | 0:6089ae824f06 | 29 | long mV = 0; |
| tosihisa | 0:6089ae824f06 | 30 | libT_getAccTOmV(ADval,&mV); /* A/D value to mV */ |
| tosihisa | 0:6089ae824f06 | 31 | *g = (long)(mV / 8); /* 0.01g units */ |
| tosihisa | 0:6089ae824f06 | 32 | return 0; |
| tosihisa | 0:6089ae824f06 | 33 | } |
| tosihisa | 0:6089ae824f06 | 34 | |
| tosihisa | 0:6089ae824f06 | 35 | int libT_getAcc6G(unsigned long ADval,long *g) |
| tosihisa | 0:6089ae824f06 | 36 | { |
| tosihisa | 0:6089ae824f06 | 37 | long mV = 0; |
| tosihisa | 0:6089ae824f06 | 38 | libT_getAccTOmV(ADval,&mV); /* A/D value to mV */ |
| tosihisa | 0:6089ae824f06 | 39 | *g = (long)(mV / 2); /* 0.01g units */ |
| tosihisa | 0:6089ae824f06 | 40 | return 0; |
| tosihisa | 0:6089ae824f06 | 41 | } |
| tosihisa | 0:6089ae824f06 | 42 | |
| tosihisa | 0:6089ae824f06 | 43 | #if 0 |
| tosihisa | 0:6089ae824f06 | 44 | int main(void) |
| tosihisa | 0:6089ae824f06 | 45 | { |
| tosihisa | 0:6089ae824f06 | 46 | long g; |
| tosihisa | 0:6089ae824f06 | 47 | |
| tosihisa | 0:6089ae824f06 | 48 | libT_getAcc1dot5G(22767UL,&g); |
| tosihisa | 0:6089ae824f06 | 49 | if(g >= 0){ |
| tosihisa | 0:6089ae824f06 | 50 | printf("1.5g g(DOWN)=%ld.%02ld\n",g/100,g%100); |
| tosihisa | 0:6089ae824f06 | 51 | } else { |
| tosihisa | 0:6089ae824f06 | 52 | g = g * -1; |
| tosihisa | 0:6089ae824f06 | 53 | printf("1.5g g(UP)=%ld.%02ld\n",g/100,g%100); |
| tosihisa | 0:6089ae824f06 | 54 | } |
| tosihisa | 0:6089ae824f06 | 55 | libT_getAcc6G(22767UL,&g); |
| tosihisa | 0:6089ae824f06 | 56 | if(g >= 0){ |
| tosihisa | 0:6089ae824f06 | 57 | printf("6g g(DOWN)=%ld.%02ld\n",g/100,g%100); |
| tosihisa | 0:6089ae824f06 | 58 | } else { |
| tosihisa | 0:6089ae824f06 | 59 | g = g * -1; |
| tosihisa | 0:6089ae824f06 | 60 | printf("6g g(UP)=%ld.%02ld\n",g/100,g%100); |
| tosihisa | 0:6089ae824f06 | 61 | } |
| tosihisa | 0:6089ae824f06 | 62 | return 0; |
| tosihisa | 0:6089ae824f06 | 63 | } |
| tosihisa | 0:6089ae824f06 | 64 | #endif |