Malexis 90640 sensor
Dependencies: mbed
main.cpp@4:b9ae79d80127, 2018-04-20 (annotated)
- Committer:
- withboobs
- Date:
- Fri Apr 20 17:26:01 2018 +0000
- Revision:
- 4:b9ae79d80127
- Parent:
- 3:d2e64ef64905
nothing to say;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
withboobs | 0:99e98f131071 | 1 | #include "mbed.h" |
withboobs | 0:99e98f131071 | 2 | #include <MLX90640_I2C_Driver.h> |
withboobs | 0:99e98f131071 | 3 | #include <MLX90640_API.h> |
withboobs | 0:99e98f131071 | 4 | |
withboobs | 1:3f763d28c1be | 5 | #define FRAMES_NUM 15 |
withboobs | 0:99e98f131071 | 6 | #define TA_SHIFT 8 |
withboobs | 0:99e98f131071 | 7 | |
withboobs | 3:d2e64ef64905 | 8 | #define FIRMWARE "eye_r_eye-mlx90640_32x24-v_1_5" |
withboobs | 1:3f763d28c1be | 9 | Serial pc(USBTX, USBRX); // tx, rx, Virtual serial port over USB |
withboobs | 1:3f763d28c1be | 10 | void PrintEEPROM(uint16_t *p); |
withboobs | 1:3f763d28c1be | 11 | void PrintRawData(uint16_t *p); |
withboobs | 1:3f763d28c1be | 12 | void PrintToF(float *p); |
withboobs | 1:3f763d28c1be | 13 | void PrintToU(float *p); |
withboobs | 0:99e98f131071 | 14 | |
withboobs | 1:3f763d28c1be | 15 | DigitalOut led_green(LED2); |
withboobs | 0:99e98f131071 | 16 | |
withboobs | 2:44869d695501 | 17 | char buffer[3076]={'S'}; |
withboobs | 2:44869d695501 | 18 | |
withboobs | 0:99e98f131071 | 19 | int main() |
withboobs | 0:99e98f131071 | 20 | { |
withboobs | 3:d2e64ef64905 | 21 | uint8_t printme=1; |
withboobs | 0:99e98f131071 | 22 | MLX90640_I2CFreqSet(1000); |
withboobs | 1:3f763d28c1be | 23 | pc.baud(230400); |
withboobs | 1:3f763d28c1be | 24 | paramsMLX90640 mlx90640; |
withboobs | 1:3f763d28c1be | 25 | uint8_t slaveAddress = 0x33; |
withboobs | 0:99e98f131071 | 26 | uint16_t *pEE; |
withboobs | 0:99e98f131071 | 27 | uint16_t *pFrame; |
withboobs | 0:99e98f131071 | 28 | static uint16_t eeMLX90640[832]; |
withboobs | 0:99e98f131071 | 29 | static uint16_t mlx90640Frame[834]; |
withboobs | 0:99e98f131071 | 30 | static float mlx90640To[768]; |
withboobs | 0:99e98f131071 | 31 | float emissivity = 1; |
withboobs | 0:99e98f131071 | 32 | float eTa; //Ta for emissivity compensation |
withboobs | 1:3f763d28c1be | 33 | |
withboobs | 0:99e98f131071 | 34 | pEE = eeMLX90640; |
withboobs | 0:99e98f131071 | 35 | pFrame = mlx90640Frame; |
withboobs | 3:d2e64ef64905 | 36 | MLX90640_SetRefreshRate(slaveAddress,1); |
withboobs | 3:d2e64ef64905 | 37 | //MLX90640_SetResolution(slaveAddress,0x03); |
withboobs | 3:d2e64ef64905 | 38 | MLX90640_SetInterleavedMode(slaveAddress); |
withboobs | 1:3f763d28c1be | 39 | MLX90640_I2CFreqSet(400); |
withboobs | 2:44869d695501 | 40 | MLX90640_DumpEE(slaveAddress, pEE); |
withboobs | 1:3f763d28c1be | 41 | MLX90640_I2CFreqSet(1000); |
withboobs | 2:44869d695501 | 42 | MLX90640_ExtractParameters(pEE, &mlx90640 ); |
withboobs | 0:99e98f131071 | 43 | |
withboobs | 1:3f763d28c1be | 44 | while (1) |
withboobs | 0:99e98f131071 | 45 | { |
withboobs | 2:44869d695501 | 46 | if (pc.readable()) |
withboobs | 2:44869d695501 | 47 | { |
withboobs | 2:44869d695501 | 48 | char c = pc.getc(); |
withboobs | 2:44869d695501 | 49 | if (printme) |
withboobs | 2:44869d695501 | 50 | { |
withboobs | 2:44869d695501 | 51 | switch (c) |
withboobs | 2:44869d695501 | 52 | { |
withboobs | 2:44869d695501 | 53 | case 'q': |
withboobs | 2:44869d695501 | 54 | printme=0; |
withboobs | 2:44869d695501 | 55 | break; |
withboobs | 2:44869d695501 | 56 | } |
withboobs | 2:44869d695501 | 57 | continue; |
withboobs | 2:44869d695501 | 58 | } |
withboobs | 2:44869d695501 | 59 | |
withboobs | 2:44869d695501 | 60 | switch (c) |
withboobs | 2:44869d695501 | 61 | { |
withboobs | 2:44869d695501 | 62 | case '1': |
withboobs | 2:44869d695501 | 63 | MLX90640_SetRefreshRate(slaveAddress,1); |
withboobs | 2:44869d695501 | 64 | break; |
withboobs | 2:44869d695501 | 65 | |
withboobs | 2:44869d695501 | 66 | case '2': |
withboobs | 2:44869d695501 | 67 | MLX90640_SetRefreshRate(slaveAddress,2); |
withboobs | 2:44869d695501 | 68 | break; |
withboobs | 2:44869d695501 | 69 | |
withboobs | 2:44869d695501 | 70 | case '4': |
withboobs | 2:44869d695501 | 71 | MLX90640_SetRefreshRate(slaveAddress,4); |
withboobs | 2:44869d695501 | 72 | break; |
withboobs | 3:d2e64ef64905 | 73 | |
withboobs | 3:d2e64ef64905 | 74 | case '5': |
withboobs | 3:d2e64ef64905 | 75 | MLX90640_SetRefreshRate(slaveAddress,5); |
withboobs | 3:d2e64ef64905 | 76 | break; |
withboobs | 3:d2e64ef64905 | 77 | |
withboobs | 3:d2e64ef64905 | 78 | case 'c': |
withboobs | 3:d2e64ef64905 | 79 | MLX90640_SetChessMode(slaveAddress); |
withboobs | 3:d2e64ef64905 | 80 | break; |
withboobs | 3:d2e64ef64905 | 81 | |
withboobs | 3:d2e64ef64905 | 82 | case 'i': |
withboobs | 3:d2e64ef64905 | 83 | MLX90640_SetInterleavedMode(slaveAddress); |
withboobs | 3:d2e64ef64905 | 84 | break; |
withboobs | 2:44869d695501 | 85 | |
withboobs | 2:44869d695501 | 86 | case '?': |
withboobs | 2:44869d695501 | 87 | pc.printf(FIRMWARE "\n"); |
withboobs | 2:44869d695501 | 88 | break; |
withboobs | 2:44869d695501 | 89 | |
withboobs | 2:44869d695501 | 90 | case 'p': |
withboobs | 2:44869d695501 | 91 | printme=1; |
withboobs | 3:d2e64ef64905 | 92 | break; |
withboobs | 2:44869d695501 | 93 | |
withboobs | 3:d2e64ef64905 | 94 | default: |
withboobs | 3:d2e64ef64905 | 95 | pc.printf("?\n"); |
withboobs | 3:d2e64ef64905 | 96 | break; |
withboobs | 3:d2e64ef64905 | 97 | |
withboobs | 2:44869d695501 | 98 | } // switch |
withboobs | 2:44869d695501 | 99 | } |
withboobs | 2:44869d695501 | 100 | |
withboobs | 1:3f763d28c1be | 101 | led_green = 1; // turn on LED until initialization is complete |
withboobs | 2:44869d695501 | 102 | MLX90640_GetFrameData(slaveAddress, pFrame); |
withboobs | 1:3f763d28c1be | 103 | led_green = 0; // turn on LED until initialization is complete |
withboobs | 1:3f763d28c1be | 104 | eTa = MLX90640_GetTa(pFrame, &mlx90640) - TA_SHIFT; |
withboobs | 1:3f763d28c1be | 105 | MLX90640_CalculateTo(pFrame, &mlx90640, emissivity, eTa, mlx90640To); |
withboobs | 2:44869d695501 | 106 | if (printme) |
withboobs | 2:44869d695501 | 107 | { |
withboobs | 2:44869d695501 | 108 | PrintToU(mlx90640To); |
withboobs | 2:44869d695501 | 109 | } |
withboobs | 0:99e98f131071 | 110 | } |
withboobs | 0:99e98f131071 | 111 | |
withboobs | 0:99e98f131071 | 112 | } |
withboobs | 1:3f763d28c1be | 113 | |
withboobs | 1:3f763d28c1be | 114 | void PrintToU(float *p) |
withboobs | 1:3f763d28c1be | 115 | { |
withboobs | 2:44869d695501 | 116 | uint16_t idx=1,i; |
withboobs | 2:44869d695501 | 117 | uint16_t d; |
withboobs | 2:44869d695501 | 118 | for(i=0; i<768; i++) |
withboobs | 1:3f763d28c1be | 119 | { |
withboobs | 1:3f763d28c1be | 120 | d = 10 * *p++; |
withboobs | 2:44869d695501 | 121 | sprintf(buffer+idx,"%04x",d); |
withboobs | 2:44869d695501 | 122 | idx+=4; |
withboobs | 1:3f763d28c1be | 123 | } |
withboobs | 2:44869d695501 | 124 | buffer[idx++] = 'E'; |
withboobs | 2:44869d695501 | 125 | buffer[idx++] = '\n'; |
withboobs | 2:44869d695501 | 126 | buffer[idx++] = 0; |
withboobs | 2:44869d695501 | 127 | pc.printf(buffer); |
withboobs | 1:3f763d28c1be | 128 | } |
withboobs | 1:3f763d28c1be | 129 | |
withboobs | 1:3f763d28c1be | 130 | void PrintToF(float *p) |
withboobs | 1:3f763d28c1be | 131 | { |
withboobs | 1:3f763d28c1be | 132 | for(int i=0; i<768; i++) |
withboobs | 1:3f763d28c1be | 133 | { |
withboobs | 1:3f763d28c1be | 134 | pc.printf("%0.3f,",*p++); |
withboobs | 1:3f763d28c1be | 135 | } |
withboobs | 1:3f763d28c1be | 136 | pc.printf("\n"); |
withboobs | 1:3f763d28c1be | 137 | |
withboobs | 1:3f763d28c1be | 138 | } |
withboobs | 1:3f763d28c1be | 139 | |
withboobs | 1:3f763d28c1be | 140 | void PrintRawData(uint16_t *p) |
withboobs | 1:3f763d28c1be | 141 | { |
withboobs | 1:3f763d28c1be | 142 | for(int i=0; i<832; i++) { |
withboobs | 1:3f763d28c1be | 143 | pc.printf("%04X,",*p++); |
withboobs | 1:3f763d28c1be | 144 | } |
withboobs | 1:3f763d28c1be | 145 | pc.printf("\r\n"); |
withboobs | 1:3f763d28c1be | 146 | } |