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: eye_r_eye-htpa32x32-v_1_8-ticker mbed
Fork of eye_r_eye-htpa32x32-v_1_8-ticker by
main.cpp@2:270ef0ab1a2e, 2018-03-15 (annotated)
- Committer:
- withboobs
- Date:
- Thu Mar 15 13:16:22 2018 +0000
- Revision:
- 2:270ef0ab1a2e
- Parent:
- 1:7fd5cc2052cf
Use eoc between the conversion, rather than an external timer. I2C speed set to 400kHz which seems to work fine. If some blocks don't get downloaded right, decrease that to 100kHz.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
withboobs | 0:851be67e4df5 | 1 | #include "mbed.h" |
withboobs | 0:851be67e4df5 | 2 | |
withboobs | 0:851be67e4df5 | 3 | /** |
withboobs | 0:851be67e4df5 | 4 | * HTPA32x32dL2_1HiSiF5_0: TN=96 |
withboobs | 0:851be67e4df5 | 5 | */ |
withboobs | 0:851be67e4df5 | 6 | #include "heimann32x32.h" |
withboobs | 0:851be67e4df5 | 7 | |
withboobs | 2:270ef0ab1a2e | 8 | #define FIRMWARE "eye_r_eye-v_1_9" |
withboobs | 0:851be67e4df5 | 9 | |
withboobs | 2:270ef0ab1a2e | 10 | //#define BAUDRATE 115200 |
withboobs | 2:270ef0ab1a2e | 11 | #define BAUDRATE 230400 |
withboobs | 1:7fd5cc2052cf | 12 | //#define PROC HTPA_PROC_RAW |
withboobs | 0:851be67e4df5 | 13 | #define PROC (HTPA_PROC_ELOFFS | HTPA_PROC_THOFFS) |
withboobs | 1:7fd5cc2052cf | 14 | //#define PROC HTPA_PROC_ELOFFS |
withboobs | 0:851be67e4df5 | 15 | //#define PROC (HTPA_PROC_ELOFFS | HTPA_PROC_THOFFS | HTPA_PROC_CONVERT) |
withboobs | 0:851be67e4df5 | 16 | |
withboobs | 2:270ef0ab1a2e | 17 | #define HTPA_DT_MS 5 |
withboobs | 0:851be67e4df5 | 18 | |
withboobs | 0:851be67e4df5 | 19 | I2C i2c(I2C_SDA, I2C_SCL), i2ce(I2C_SDA, I2C_SCL); |
withboobs | 0:851be67e4df5 | 20 | |
withboobs | 0:851be67e4df5 | 21 | HTPA32x32 h = HTPA32x32( (I2C *) &i2c, (I2C *) &i2ce); |
withboobs | 0:851be67e4df5 | 22 | |
withboobs | 0:851be67e4df5 | 23 | Serial pc(SERIAL_TX, SERIAL_RX); |
withboobs | 0:851be67e4df5 | 24 | |
withboobs | 0:851be67e4df5 | 25 | DigitalOut led_green(LED2); |
withboobs | 0:851be67e4df5 | 26 | |
withboobs | 0:851be67e4df5 | 27 | int main() |
withboobs | 0:851be67e4df5 | 28 | { |
withboobs | 0:851be67e4df5 | 29 | bool printme=0, print_labels=0; |
withboobs | 0:851be67e4df5 | 30 | uint8_t j; |
withboobs | 0:851be67e4df5 | 31 | int16_t i; |
withboobs | 0:851be67e4df5 | 32 | |
withboobs | 0:851be67e4df5 | 33 | led_green = 1; // turn on LED until initialization is complete |
withboobs | 0:851be67e4df5 | 34 | |
withboobs | 0:851be67e4df5 | 35 | pc.baud(BAUDRATE); |
withboobs | 0:851be67e4df5 | 36 | |
withboobs | 0:851be67e4df5 | 37 | wait_ms(100); |
withboobs | 0:851be67e4df5 | 38 | |
withboobs | 0:851be67e4df5 | 39 | h.init(); |
withboobs | 0:851be67e4df5 | 40 | wait_ms(HTPA_DT_MS); |
withboobs | 0:851be67e4df5 | 41 | h.PU(1); |
withboobs | 0:851be67e4df5 | 42 | |
withboobs | 0:851be67e4df5 | 43 | h.start(); |
withboobs | 0:851be67e4df5 | 44 | h.proc = PROC; |
withboobs | 0:851be67e4df5 | 45 | |
withboobs | 0:851be67e4df5 | 46 | wait_ms(HTPA_DT_MS); |
withboobs | 0:851be67e4df5 | 47 | |
withboobs | 0:851be67e4df5 | 48 | led_green = 0; // initializaiton complete |
withboobs | 2:270ef0ab1a2e | 49 | |
withboobs | 0:851be67e4df5 | 50 | if (h.tn != TABLENUMBER) |
withboobs | 0:851be67e4df5 | 51 | { |
withboobs | 0:851be67e4df5 | 52 | pc.printf("TN=%d does not match the interpolation table %d\n", h.tn, TABLENUMBER); |
withboobs | 2:270ef0ab1a2e | 53 | pc.printf("Cannot continue!\n"); |
withboobs | 2:270ef0ab1a2e | 54 | while (1); |
withboobs | 0:851be67e4df5 | 55 | } |
withboobs | 0:851be67e4df5 | 56 | |
withboobs | 0:851be67e4df5 | 57 | while (1) |
withboobs | 0:851be67e4df5 | 58 | { |
withboobs | 0:851be67e4df5 | 59 | /* talk to me! */ |
withboobs | 0:851be67e4df5 | 60 | if (pc.readable()) |
withboobs | 0:851be67e4df5 | 61 | { |
withboobs | 0:851be67e4df5 | 62 | char c = pc.getc(); |
withboobs | 0:851be67e4df5 | 63 | if (printme) |
withboobs | 0:851be67e4df5 | 64 | { |
withboobs | 0:851be67e4df5 | 65 | switch (c) |
withboobs | 0:851be67e4df5 | 66 | { |
withboobs | 0:851be67e4df5 | 67 | case 'p': |
withboobs | 0:851be67e4df5 | 68 | printme=1; |
withboobs | 0:851be67e4df5 | 69 | break; |
withboobs | 0:851be67e4df5 | 70 | |
withboobs | 0:851be67e4df5 | 71 | case 'q': |
withboobs | 0:851be67e4df5 | 72 | printme=0; |
withboobs | 0:851be67e4df5 | 73 | break; |
withboobs | 0:851be67e4df5 | 74 | } |
withboobs | 0:851be67e4df5 | 75 | continue; |
withboobs | 0:851be67e4df5 | 76 | } |
withboobs | 0:851be67e4df5 | 77 | |
withboobs | 0:851be67e4df5 | 78 | switch (c) |
withboobs | 0:851be67e4df5 | 79 | { |
withboobs | 0:851be67e4df5 | 80 | case '?': |
withboobs | 0:851be67e4df5 | 81 | pc.printf(FIRMWARE "\n"); |
withboobs | 0:851be67e4df5 | 82 | break; |
withboobs | 0:851be67e4df5 | 83 | |
withboobs | 0:851be67e4df5 | 84 | case 'c': |
withboobs | 0:851be67e4df5 | 85 | /* complete conversion to dK */ |
withboobs | 0:851be67e4df5 | 86 | h.proc = HTPA_PROC_CONVERT | HTPA_PROC_ELOFFS | HTPA_PROC_THOFFS; |
withboobs | 0:851be67e4df5 | 87 | break; |
withboobs | 0:851be67e4df5 | 88 | |
withboobs | 0:851be67e4df5 | 89 | case 'o': |
withboobs | 0:851be67e4df5 | 90 | /* raw readings compensated by electric and thermal offsets */ |
withboobs | 0:851be67e4df5 | 91 | h.proc = HTPA_PROC_ELOFFS | HTPA_PROC_THOFFS; |
withboobs | 0:851be67e4df5 | 92 | break; |
withboobs | 0:851be67e4df5 | 93 | |
withboobs | 0:851be67e4df5 | 94 | case 'r': |
withboobs | 0:851be67e4df5 | 95 | /* raw readings */ |
withboobs | 0:851be67e4df5 | 96 | h.proc = HTPA_PROC_RAW; |
withboobs | 0:851be67e4df5 | 97 | break; |
withboobs | 0:851be67e4df5 | 98 | |
withboobs | 0:851be67e4df5 | 99 | case 'd': |
withboobs | 0:851be67e4df5 | 100 | if (print_labels) |
withboobs | 0:851be67e4df5 | 101 | pc.printf("adc=", h.mbit); |
withboobs | 0:851be67e4df5 | 102 | pc.printf("%x,", h.mbit); |
withboobs | 0:851be67e4df5 | 103 | if (print_labels) |
withboobs | 0:851be67e4df5 | 104 | pc.printf("bias="); |
withboobs | 0:851be67e4df5 | 105 | pc.printf("%x,", h.bias); |
withboobs | 0:851be67e4df5 | 106 | if (print_labels) |
withboobs | 0:851be67e4df5 | 107 | pc.printf("clk="); |
withboobs | 0:851be67e4df5 | 108 | pc.printf("%x,", h.clk); |
withboobs | 0:851be67e4df5 | 109 | if (print_labels) |
withboobs | 0:851be67e4df5 | 110 | pc.printf("bpa="); |
withboobs | 0:851be67e4df5 | 111 | pc.printf("%x,", h.bpa); |
withboobs | 0:851be67e4df5 | 112 | if (print_labels) |
withboobs | 0:851be67e4df5 | 113 | pc.printf("pu="); |
withboobs | 0:851be67e4df5 | 114 | pc.printf("%x,", h.pu); |
withboobs | 0:851be67e4df5 | 115 | if (print_labels) |
withboobs | 0:851be67e4df5 | 116 | pc.printf("tn="); |
withboobs | 0:851be67e4df5 | 117 | pc.printf("%x,", h.tn); |
withboobs | 0:851be67e4df5 | 118 | if (print_labels) |
withboobs | 0:851be67e4df5 | 119 | pc.printf("PixCmin="); |
withboobs | 0:851be67e4df5 | 120 | pc.printf("%f,", h.PixCmin); |
withboobs | 0:851be67e4df5 | 121 | if (print_labels) |
withboobs | 0:851be67e4df5 | 122 | pc.printf("PixCmax="); |
withboobs | 0:851be67e4df5 | 123 | pc.printf("%f,", h.PixCmax); |
withboobs | 0:851be67e4df5 | 124 | if (print_labels) |
withboobs | 0:851be67e4df5 | 125 | pc.printf("epsilon="); |
withboobs | 0:851be67e4df5 | 126 | pc.printf("%d,", h.epsilon); |
withboobs | 0:851be67e4df5 | 127 | if (print_labels) |
withboobs | 0:851be67e4df5 | 128 | pc.printf("gradScale="); |
withboobs | 0:851be67e4df5 | 129 | pc.printf("%d,", h.gradScale); |
withboobs | 0:851be67e4df5 | 130 | if (print_labels) |
withboobs | 0:851be67e4df5 | 131 | pc.printf("PTATgrad="); |
withboobs | 0:851be67e4df5 | 132 | pc.printf("%f,", h.PTATgrad); |
withboobs | 0:851be67e4df5 | 133 | if (print_labels) |
withboobs | 0:851be67e4df5 | 134 | pc.printf("PTAToffs="); |
withboobs | 0:851be67e4df5 | 135 | pc.printf("%f\n", h.PTAToffs); |
withboobs | 0:851be67e4df5 | 136 | break; |
withboobs | 0:851be67e4df5 | 137 | |
withboobs | 0:851be67e4df5 | 138 | case 't': |
withboobs | 0:851be67e4df5 | 139 | if (print_labels) |
withboobs | 0:851be67e4df5 | 140 | pc.printf("Ta_dK="); |
withboobs | 0:851be67e4df5 | 141 | pc.printf("%d\n", h.Ta_dK); |
withboobs | 0:851be67e4df5 | 142 | break; |
withboobs | 0:851be67e4df5 | 143 | |
withboobs | 0:851be67e4df5 | 144 | case 'l': |
withboobs | 0:851be67e4df5 | 145 | print_labels=1; |
withboobs | 0:851be67e4df5 | 146 | break; |
withboobs | 0:851be67e4df5 | 147 | |
withboobs | 0:851be67e4df5 | 148 | case 's': |
withboobs | 0:851be67e4df5 | 149 | print_labels=0; |
withboobs | 0:851be67e4df5 | 150 | break; |
withboobs | 0:851be67e4df5 | 151 | |
withboobs | 0:851be67e4df5 | 152 | case 'p': |
withboobs | 0:851be67e4df5 | 153 | printme=1; |
withboobs | 0:851be67e4df5 | 154 | break; |
withboobs | 0:851be67e4df5 | 155 | |
withboobs | 0:851be67e4df5 | 156 | case 'q': |
withboobs | 0:851be67e4df5 | 157 | printme=0; |
withboobs | 0:851be67e4df5 | 158 | break; |
withboobs | 0:851be67e4df5 | 159 | } // switch |
withboobs | 0:851be67e4df5 | 160 | } |
withboobs | 2:270ef0ab1a2e | 161 | |
withboobs | 2:270ef0ab1a2e | 162 | if (h.eoc()) |
withboobs | 0:851be67e4df5 | 163 | { |
withboobs | 0:851be67e4df5 | 164 | led_green = 1; |
withboobs | 0:851be67e4df5 | 165 | h.readb(); |
withboobs | 0:851be67e4df5 | 166 | led_green = 0; |
withboobs | 0:851be67e4df5 | 167 | |
withboobs | 0:851be67e4df5 | 168 | if (h.available) |
withboobs | 0:851be67e4df5 | 169 | { |
withboobs | 0:851be67e4df5 | 170 | h.apply_offsets(); |
withboobs | 0:851be67e4df5 | 171 | |
withboobs | 0:851be67e4df5 | 172 | if (printme) |
withboobs | 0:851be67e4df5 | 173 | { |
withboobs | 0:851be67e4df5 | 174 | if (print_labels) |
withboobs | 0:851be67e4df5 | 175 | pc.printf("data="); |
withboobs | 0:851be67e4df5 | 176 | uint16_t * data_ptr = (uint16_t *) h.Data; |
withboobs | 0:851be67e4df5 | 177 | for (i=0; i<32; i++) |
withboobs | 0:851be67e4df5 | 178 | { |
withboobs | 0:851be67e4df5 | 179 | for (j=0; j<32; j++) |
withboobs | 0:851be67e4df5 | 180 | { |
withboobs | 0:851be67e4df5 | 181 | if (!print_labels) |
withboobs | 0:851be67e4df5 | 182 | { |
withboobs | 0:851be67e4df5 | 183 | if (i==0 && j==0) |
withboobs | 0:851be67e4df5 | 184 | pc.printf("S%04x", data_ptr[32*i + j]); |
withboobs | 0:851be67e4df5 | 185 | else |
withboobs | 0:851be67e4df5 | 186 | pc.printf("%04x", data_ptr[32*i + j]); |
withboobs | 0:851be67e4df5 | 187 | } |
withboobs | 0:851be67e4df5 | 188 | else |
withboobs | 0:851be67e4df5 | 189 | pc.printf("%04x", data_ptr[32*i + j]); |
withboobs | 0:851be67e4df5 | 190 | } |
withboobs | 0:851be67e4df5 | 191 | } |
withboobs | 0:851be67e4df5 | 192 | if (print_labels) |
withboobs | 0:851be67e4df5 | 193 | pc.printf("\n"); |
withboobs | 0:851be67e4df5 | 194 | else |
withboobs | 0:851be67e4df5 | 195 | pc.printf("E\n"); |
withboobs | 0:851be67e4df5 | 196 | |
withboobs | 0:851be67e4df5 | 197 | } // if (printme) |
withboobs | 0:851be67e4df5 | 198 | |
withboobs | 0:851be67e4df5 | 199 | } // if (h.available) |
withboobs | 0:851be67e4df5 | 200 | |
withboobs | 0:851be67e4df5 | 201 | } // if (t.read_ms() ... ) |
withboobs | 0:851be67e4df5 | 202 | |
withboobs | 0:851be67e4df5 | 203 | } // while(1) |
withboobs | 0:851be67e4df5 | 204 | |
withboobs | 0:851be67e4df5 | 205 | } // main |