SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

Committer:
hazheng
Date:
Wed Apr 19 19:43:15 2017 +0000
Revision:
96:ec89c4d1383d
Parent:
93:8e1bd3602d53
Child:
97:0ed9ede9a995
Child:
98:fc92bb37ee17
Removed commented code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 28:271fc8445e89 1 #include "ArduCAM.h"
hazheng 28:271fc8445e89 2
hazheng 57:0d8a155d511d 3 //#define SW_DEBUG
hazheng 29:f87d8790f57d 4 #include "GlobalVariable.h"
hazheng 56:7d3395ae022d 5 #include "SWCommon.h"
hazheng 56:7d3395ae022d 6
hazheng 29:f87d8790f57d 7
hazheng 32:5badeff825dc 8 #include "CamRegBuf.h"
hazheng 32:5badeff825dc 9
hazheng 41:7b21c5e3599e 10 #include "ArduUTFT.h"
hazheng 41:7b21c5e3599e 11
hazheng 32:5badeff825dc 12 #include <string>
hazheng 32:5badeff825dc 13
hazheng 57:0d8a155d511d 14 #define CAM_BLK_CAL_ACTIVE
hazheng 44:15de535c4005 15
hazheng 46:a5eb9bd3bb55 16 //#define CAM_DISP_DEBUG
hazheng 81:32bd7a25a699 17 //#define CAM_DISP_DEBUG_CENTER
hazheng 81:32bd7a25a699 18 //#define CAM_DISP_IMG
hazheng 46:a5eb9bd3bb55 19
hazheng 57:0d8a155d511d 20 #define IMG_PROC_SIGNAL 0xBB
hazheng 57:0d8a155d511d 21
hazheng 46:a5eb9bd3bb55 22 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 23 extern "C" {
hazheng 46:a5eb9bd3bb55 24 #endif
hazheng 44:15de535c4005 25
hazheng 57:0d8a155d511d 26 const static uint8_t CAM_BLK_CAL_LEFT = ((RESOLUTION_WIDTH / 2) - 1);
hazheng 57:0d8a155d511d 27 const static uint8_t CAM_BLK_CAL_RIGHT = ((RESOLUTION_WIDTH / 2) + 1);
hazheng 70:311d32a596db 28 const static uint8_t TERMINATE_WIDTH = static_cast<uint8_t>(RESOLUTION_WIDTH * 0.28f);
hazheng 57:0d8a155d511d 29
hazheng 46:a5eb9bd3bb55 30 static DigitalOut cam_cs(PIN_ACC_CS, 1);
hazheng 29:f87d8790f57d 31
hazheng 46:a5eb9bd3bb55 32 static uint8_t temp_mid_pos = RESOLUTION_WIDTH / 2;
hazheng 46:a5eb9bd3bb55 33 static uint8_t black_calibrate = 70;
hazheng 65:295c222fdf88 34 static volatile uint8_t centerLine[CAM_ROI_UPPER_LIMIT * 2];
hazheng 64:43ab429a37e0 35 static volatile uint8_t is_encounter_terminate = 0;
hazheng 79:bdbac82c979b 36 static volatile uint8_t is_border_find = BOTH_NOT_FOUND;
hazheng 44:15de535c4005 37
hazheng 44:15de535c4005 38 void cal_black_calibrate();
hazheng 34:f79db3bc2f86 39
hazheng 34:f79db3bc2f86 40 inline void ardu_cam_spi_write_8(int address, int value)
hazheng 29:f87d8790f57d 41 {
hazheng 34:f79db3bc2f86 42 // take the SS pin low to select the chip:
hazheng 56:7d3395ae022d 43 #ifdef SW_DEBUG
hazheng 56:7d3395ae022d 44 g_sw_spi_lock.lock();
hazheng 56:7d3395ae022d 45 #endif
hazheng 34:f79db3bc2f86 46 cam_cs = 0;
hazheng 34:f79db3bc2f86 47 // send in the address and value via SPI:
hazheng 34:f79db3bc2f86 48 g_spi_port.write(address | 0x80);
hazheng 34:f79db3bc2f86 49 g_spi_port.write(value);
hazheng 34:f79db3bc2f86 50 // take the SS pin high to de-select the chip:
hazheng 34:f79db3bc2f86 51 cam_cs = 1;
hazheng 56:7d3395ae022d 52 #ifdef SW_DEBUG
hazheng 56:7d3395ae022d 53 g_sw_spi_lock.unlock();
hazheng 56:7d3395ae022d 54 #endif
hazheng 34:f79db3bc2f86 55 }
hazheng 34:f79db3bc2f86 56
hazheng 34:f79db3bc2f86 57 inline uint8_t ardu_cam_spi_read_8(int address)
hazheng 34:f79db3bc2f86 58 {
hazheng 34:f79db3bc2f86 59 // take the SS pin low to select the chip:
hazheng 56:7d3395ae022d 60 #ifdef SW_DEBUG
hazheng 56:7d3395ae022d 61 g_sw_spi_lock.lock();
hazheng 56:7d3395ae022d 62 #endif
hazheng 29:f87d8790f57d 63 cam_cs = 0;
hazheng 34:f79db3bc2f86 64 // send in the address and value via SPI:
hazheng 34:f79db3bc2f86 65 g_spi_port.write(address & 0x7F);
hazheng 34:f79db3bc2f86 66 uint8_t value = static_cast<uint8_t>(g_spi_port.write(0x00));
hazheng 34:f79db3bc2f86 67 // take the SS pin high to de-select the chip:
hazheng 29:f87d8790f57d 68 cam_cs = 1;
hazheng 56:7d3395ae022d 69 #ifdef SW_DEBUG
hazheng 56:7d3395ae022d 70 g_sw_spi_lock.unlock();
hazheng 56:7d3395ae022d 71 #endif
hazheng 34:f79db3bc2f86 72 return value;
hazheng 34:f79db3bc2f86 73 }
hazheng 29:f87d8790f57d 74
hazheng 28:271fc8445e89 75 bool ardu_cam_init()
hazheng 28:271fc8445e89 76 {
hazheng 87:15fcf7891bf9 77 CamRegBuf * camReg = new CamRegBuf(CAM_SCCB_WRITE, CAM_SCCB_READ);
hazheng 36:7e747e19f660 78
hazheng 36:7e747e19f660 79 camReg->WriteRegSet(ResetProg);
hazheng 46:a5eb9bd3bb55 80 wait_ms(10);
hazheng 37:7074a6118d03 81 camReg->WriteRegSet(QVGA);
hazheng 44:15de535c4005 82 wait_ms(10);
hazheng 32:5badeff825dc 83
hazheng 36:7e747e19f660 84 #if defined(ARDUCAM_OV2640)
hazheng 32:5badeff825dc 85 camReg->SCCBWrite(0xff, 0x01);
hazheng 36:7e747e19f660 86 #endif
hazheng 32:5badeff825dc 87
hazheng 32:5badeff825dc 88 delete camReg;
hazheng 32:5badeff825dc 89 camReg = NULL;
hazheng 32:5badeff825dc 90
hazheng 34:f79db3bc2f86 91 uint8_t VerNum = ardu_cam_spi_read_8(0x40);
hazheng 34:f79db3bc2f86 92 VerNum = ardu_cam_spi_read_8(0x40);
hazheng 29:f87d8790f57d 93
hazheng 34:f79db3bc2f86 94 ardu_cam_spi_write_8(ARDUCHIP_TEST1, ARDUCHIP_TEST_MSG);
hazheng 34:f79db3bc2f86 95 uint8_t testV = ardu_cam_spi_read_8(ARDUCHIP_TEST1);
hazheng 35:ac4fcca21560 96 if(VerNum != ARDUCHIP_VER_NUM || testV != ARDUCHIP_TEST_MSG)
hazheng 29:f87d8790f57d 97 {
hazheng 29:f87d8790f57d 98 return false;
hazheng 29:f87d8790f57d 99 }
hazheng 28:271fc8445e89 100
hazheng 96:ec89c4d1383d 101 ardu_cam_spi_write_8(ARDUCHIP_CAP_CTRL, 0x00);
hazheng 29:f87d8790f57d 102
hazheng 44:15de535c4005 103 cal_black_calibrate();
hazheng 29:f87d8790f57d 104
hazheng 29:f87d8790f57d 105 return true;
hazheng 29:f87d8790f57d 106 }
hazheng 29:f87d8790f57d 107
hazheng 29:f87d8790f57d 108 void ardu_cam_start_capture()
hazheng 29:f87d8790f57d 109 {
hazheng 34:f79db3bc2f86 110 ardu_cam_spi_write_8(ARDUCHIP_FIFO, FIFO_CLEAR_MASK);
hazheng 48:f76b5e252444 111
hazheng 34:f79db3bc2f86 112 ardu_cam_spi_write_8(ARDUCHIP_FIFO, FIFO_START_MASK);
hazheng 29:f87d8790f57d 113 }
hazheng 29:f87d8790f57d 114
hazheng 32:5badeff825dc 115 uint32_t ardu_cam_get_fifo_length()
hazheng 32:5badeff825dc 116 {
hazheng 32:5badeff825dc 117 uint32_t len1,len2,len3,length=0;
hazheng 34:f79db3bc2f86 118 len1 = ardu_cam_spi_read_8(FIFO_SIZE1);
hazheng 34:f79db3bc2f86 119 len2 = ardu_cam_spi_read_8(FIFO_SIZE2);
hazheng 34:f79db3bc2f86 120 len3 = ardu_cam_spi_read_8(FIFO_SIZE3) & 0x07;
hazheng 32:5badeff825dc 121 length = ((len3 << 16) | (len2 << 8) | len1) & 0x07ffff;
hazheng 32:5badeff825dc 122 return length;
hazheng 32:5badeff825dc 123 }
hazheng 32:5badeff825dc 124
hazheng 32:5badeff825dc 125 uint8_t ardu_cam_get_pixel()
hazheng 32:5badeff825dc 126 {
hazheng 34:f79db3bc2f86 127 uint16_t VH = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 34:f79db3bc2f86 128 uint16_t VL = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 34:f79db3bc2f86 129 //uint16_t VL = ardu_cam_spi_burst_read_16();
hazheng 32:5badeff825dc 130
hazheng 32:5badeff825dc 131 VL = (VL & 0x00FF) | ((VH << 8) & 0xFF00);
hazheng 33:e3fcc4d6bb9b 132 uint8_t ch = ((VL & 0xF800) >> 9);// << 2;
hazheng 33:e3fcc4d6bb9b 133 float pixel = (static_cast<float>(ch) * 0.21);
hazheng 32:5badeff825dc 134
hazheng 33:e3fcc4d6bb9b 135 ch = ((VL & 0x07E0) >> 3);// << 2;
hazheng 33:e3fcc4d6bb9b 136 pixel += (static_cast<float>(ch) * 0.72);
hazheng 32:5badeff825dc 137
hazheng 33:e3fcc4d6bb9b 138 ch = (VL & 0x001F) << 2;
hazheng 33:e3fcc4d6bb9b 139 pixel += (static_cast<float>(ch) * 0.07);
hazheng 32:5badeff825dc 140
hazheng 32:5badeff825dc 141 return static_cast<uint8_t>(pixel);
hazheng 32:5badeff825dc 142 }
hazheng 41:7b21c5e3599e 143
hazheng 44:15de535c4005 144 uint8_t ardu_cam_is_capture_finished()
hazheng 44:15de535c4005 145 {
hazheng 44:15de535c4005 146 return (ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK);
hazheng 44:15de535c4005 147 }
hazheng 44:15de535c4005 148
hazheng 44:15de535c4005 149 void cal_black_calibrate()
hazheng 44:15de535c4005 150 {
hazheng 44:15de535c4005 151 ardu_cam_start_capture();
hazheng 44:15de535c4005 152
hazheng 44:15de535c4005 153 while (!(ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK));
hazheng 44:15de535c4005 154
hazheng 44:15de535c4005 155 float temp = 0.0f;
hazheng 44:15de535c4005 156 static uint16_t pixel = 0x00;
hazheng 44:15de535c4005 157 for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 44:15de535c4005 158 {
hazheng 44:15de535c4005 159 pixel = static_cast<uint16_t>(ardu_cam_spi_read_8(SINGLE_FIFO_READ)) << 8;
hazheng 44:15de535c4005 160 pixel = pixel | ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 161
hazheng 44:15de535c4005 162 if(CAM_BLK_CAL_LEFT < j && j <= CAM_BLK_CAL_RIGHT)
hazheng 44:15de535c4005 163 {
hazheng 44:15de535c4005 164 temp += static_cast<uint8_t>((pixel >> 3) & 0x00FF);
hazheng 44:15de535c4005 165 }
hazheng 44:15de535c4005 166 }
hazheng 44:15de535c4005 167 temp = temp / (CAM_BLK_CAL_RIGHT - CAM_BLK_CAL_LEFT);
hazheng 44:15de535c4005 168 black_calibrate = temp * 0.7f;
hazheng 44:15de535c4005 169 }
hazheng 44:15de535c4005 170
hazheng 65:295c222fdf88 171 inline void get_img_row_info(const uint8_t display, const uint8_t rowI, uint8_t * left, uint8_t * right, uint8_t* isBorderFound)
hazheng 44:15de535c4005 172 {
hazheng 44:15de535c4005 173 *left = 0;
hazheng 44:15de535c4005 174 *right = RESOLUTION_WIDTH;
hazheng 65:295c222fdf88 175 *isBorderFound = BOTH_NOT_FOUND;
hazheng 44:15de535c4005 176 uint8_t isRightFound = 0;
hazheng 44:15de535c4005 177 static uint16_t pixel = 0x0000;
hazheng 44:15de535c4005 178 static uint8_t pGreen = 0x00;
hazheng 44:15de535c4005 179
hazheng 44:15de535c4005 180 for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 44:15de535c4005 181 {
hazheng 44:15de535c4005 182 pixel = static_cast<uint16_t>(ardu_cam_spi_read_8(SINGLE_FIFO_READ)) << 8;
hazheng 44:15de535c4005 183 pixel = pixel | ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 184
hazheng 57:0d8a155d511d 185 pGreen = static_cast<uint8_t>((pixel & 0x07E0) >> 3);
hazheng 44:15de535c4005 186 if((pGreen < black_calibrate))
hazheng 44:15de535c4005 187 {
hazheng 44:15de535c4005 188 if(j < temp_mid_pos)
hazheng 44:15de535c4005 189 {
hazheng 65:295c222fdf88 190 *isBorderFound = LEFT_FOUND;
hazheng 44:15de535c4005 191 *left = j;
hazheng 46:a5eb9bd3bb55 192 #ifdef CAM_DISP_DEBUG
hazheng 46:a5eb9bd3bb55 193 ardu_utft_write_DATA(0xF8, 0x00);
hazheng 46:a5eb9bd3bb55 194 #endif
hazheng 44:15de535c4005 195 }
hazheng 44:15de535c4005 196 else if(!isRightFound)
hazheng 44:15de535c4005 197 {
hazheng 44:15de535c4005 198 *right = j;
hazheng 44:15de535c4005 199 isRightFound = 1;
hazheng 46:a5eb9bd3bb55 200 #ifdef CAM_DISP_DEBUG
hazheng 46:a5eb9bd3bb55 201 ardu_utft_write_DATA(0xF8, 0x00);
hazheng 46:a5eb9bd3bb55 202 #endif
hazheng 44:15de535c4005 203 }
hazheng 73:1dcf56e9f1d4 204 #ifdef CAM_DISP_DEBUG
hazheng 73:1dcf56e9f1d4 205 else
hazheng 73:1dcf56e9f1d4 206 {
hazheng 73:1dcf56e9f1d4 207 ardu_utft_write_DATA(static_cast<uint8_t>(pixel >> 8), static_cast<uint8_t>(pixel));
hazheng 73:1dcf56e9f1d4 208 }
hazheng 73:1dcf56e9f1d4 209 #endif
hazheng 44:15de535c4005 210 }
hazheng 46:a5eb9bd3bb55 211 #ifdef CAM_DISP_DEBUG
hazheng 46:a5eb9bd3bb55 212 else
hazheng 46:a5eb9bd3bb55 213 {
hazheng 46:a5eb9bd3bb55 214 ardu_utft_write_DATA(static_cast<uint8_t>(pixel >> 8), static_cast<uint8_t>(pixel));
hazheng 46:a5eb9bd3bb55 215 }
hazheng 50:c387c88141fb 216
hazheng 46:a5eb9bd3bb55 217 #elif defined(CAM_DISP_IMG)
hazheng 46:a5eb9bd3bb55 218 ardu_utft_write_DATA(static_cast<uint8_t>(pixel >> 8), static_cast<uint8_t>(pixel));
hazheng 46:a5eb9bd3bb55 219 #endif
hazheng 44:15de535c4005 220 }
hazheng 65:295c222fdf88 221
hazheng 65:295c222fdf88 222 if(*isBorderFound == LEFT_FOUND && isRightFound)
hazheng 65:295c222fdf88 223 {
hazheng 65:295c222fdf88 224 *isBorderFound = BOTH_FOUND;
hazheng 65:295c222fdf88 225 }
hazheng 65:295c222fdf88 226 else if(isRightFound)
hazheng 65:295c222fdf88 227 {
hazheng 65:295c222fdf88 228 *isBorderFound = RIGHT_FOUND;
hazheng 65:295c222fdf88 229 }
hazheng 65:295c222fdf88 230
hazheng 44:15de535c4005 231 }
hazheng 44:15de535c4005 232
hazheng 44:15de535c4005 233 volatile const uint8_t* ardu_cam_get_center_array()
hazheng 44:15de535c4005 234 {
hazheng 44:15de535c4005 235 return centerLine;
hazheng 44:15de535c4005 236 }
hazheng 44:15de535c4005 237
hazheng 44:15de535c4005 238 void image_processing()
hazheng 44:15de535c4005 239 {
hazheng 63:d9a81b3d69f5 240
hazheng 57:0d8a155d511d 241 //while(true)
hazheng 44:15de535c4005 242 {
hazheng 44:15de535c4005 243 ardu_cam_start_capture();
hazheng 44:15de535c4005 244
hazheng 44:15de535c4005 245 while (!(ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK));
hazheng 44:15de535c4005 246
hazheng 44:15de535c4005 247 temp_mid_pos = RESOLUTION_WIDTH / 2;
hazheng 79:bdbac82c979b 248 is_border_find = BOTH_NOT_FOUND;
hazheng 57:0d8a155d511d 249 #ifdef CAM_BLK_CAL_ACTIVE
hazheng 57:0d8a155d511d 250 static float calTemp = 0.0f;
hazheng 57:0d8a155d511d 251 calTemp = 0.0f;
hazheng 57:0d8a155d511d 252 static uint16_t greenPixel = 0x00;
hazheng 64:43ab429a37e0 253 uint8_t isValid = 1;
hazheng 57:0d8a155d511d 254 for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 57:0d8a155d511d 255 {
hazheng 57:0d8a155d511d 256 if(CAM_BLK_CAL_LEFT < j && j <= CAM_BLK_CAL_RIGHT)
hazheng 57:0d8a155d511d 257 {
hazheng 57:0d8a155d511d 258 greenPixel = static_cast<uint16_t>(ardu_cam_spi_read_8(SINGLE_FIFO_READ)) << 8;
hazheng 57:0d8a155d511d 259 greenPixel = greenPixel | ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 57:0d8a155d511d 260 greenPixel = (greenPixel & 0x07E0) >> 3;
hazheng 64:43ab429a37e0 261 if(static_cast<uint8_t>(greenPixel) < black_calibrate)
hazheng 64:43ab429a37e0 262 {
hazheng 64:43ab429a37e0 263 isValid = 0;
hazheng 64:43ab429a37e0 264 }
hazheng 57:0d8a155d511d 265 calTemp += static_cast<uint8_t>(greenPixel);
hazheng 57:0d8a155d511d 266 }
hazheng 57:0d8a155d511d 267 else
hazheng 57:0d8a155d511d 268 {
hazheng 57:0d8a155d511d 269 ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 57:0d8a155d511d 270 ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 57:0d8a155d511d 271 }
hazheng 57:0d8a155d511d 272 }
hazheng 64:43ab429a37e0 273
hazheng 64:43ab429a37e0 274 if(isValid)
hazheng 64:43ab429a37e0 275 {
hazheng 64:43ab429a37e0 276 calTemp = calTemp / static_cast<float>(CAM_BLK_CAL_RIGHT - CAM_BLK_CAL_LEFT);
hazheng 64:43ab429a37e0 277 black_calibrate = static_cast<uint8_t>(calTemp * 0.7f);
hazheng 64:43ab429a37e0 278 }
hazheng 57:0d8a155d511d 279 #endif
hazheng 44:15de535c4005 280 //cal_black_calibrate();
hazheng 44:15de535c4005 281 uint8_t leftPos = 0;
hazheng 44:15de535c4005 282 uint8_t rightPos = 0;
hazheng 65:295c222fdf88 283 uint8_t isBorderFound = BOTH_NOT_FOUND;
hazheng 82:992ba6f31e24 284 is_encounter_terminate = 0;
hazheng 44:15de535c4005 285 for (uint8_t i = 0; i < CAM_ROI_UPPER_LIMIT; ++i)
hazheng 44:15de535c4005 286 {
hazheng 46:a5eb9bd3bb55 287 #if defined(CAM_DISP_IMG) or defined(CAM_DISP_DEBUG)
hazheng 46:a5eb9bd3bb55 288 ardu_utft_set_camimg_row(CAM_ROI_UPPER_LIMIT - i);
hazheng 46:a5eb9bd3bb55 289 #endif
hazheng 65:295c222fdf88 290 get_img_row_info(0, i, &leftPos, &rightPos, &isBorderFound);
hazheng 44:15de535c4005 291 temp_mid_pos = (leftPos + rightPos) / 2;
hazheng 64:43ab429a37e0 292 uint8_t dis_btw_left_right = rightPos - leftPos - 1;
hazheng 64:43ab429a37e0 293 if(dis_btw_left_right < TERMINATE_WIDTH)
hazheng 64:43ab429a37e0 294 {
hazheng 64:43ab429a37e0 295 is_encounter_terminate = 1;
hazheng 64:43ab429a37e0 296 }
hazheng 46:a5eb9bd3bb55 297
hazheng 46:a5eb9bd3bb55 298 #ifdef CAM_DISP_DEBUG_CENTER
hazheng 44:15de535c4005 299 ardu_utft_set_camimg_rowcol(CAM_ROI_UPPER_LIMIT - i, temp_mid_pos);
hazheng 44:15de535c4005 300 ardu_utft_write_DATA(0xF8, 0x00);
hazheng 44:15de535c4005 301 #endif
hazheng 46:a5eb9bd3bb55 302
hazheng 44:15de535c4005 303 centerLine[CAM_ROI_UPPER_LIMIT - i - 1] = temp_mid_pos;
hazheng 65:295c222fdf88 304 centerLine[(2 * CAM_ROI_UPPER_LIMIT) - i - 1] = isBorderFound;
hazheng 79:bdbac82c979b 305 switch(is_border_find)
hazheng 79:bdbac82c979b 306 {
hazheng 79:bdbac82c979b 307 case BOTH_NOT_FOUND:
hazheng 79:bdbac82c979b 308 switch(isBorderFound)
hazheng 79:bdbac82c979b 309 {
hazheng 79:bdbac82c979b 310 case LEFT_FOUND:
hazheng 79:bdbac82c979b 311 is_border_find = LEFT_FOUND;
hazheng 79:bdbac82c979b 312 break;
hazheng 79:bdbac82c979b 313 case RIGHT_FOUND:
hazheng 79:bdbac82c979b 314 is_border_find = RIGHT_FOUND;
hazheng 79:bdbac82c979b 315 break;
hazheng 79:bdbac82c979b 316 case BOTH_FOUND:
hazheng 79:bdbac82c979b 317 is_border_find = BOTH_FOUND;
hazheng 79:bdbac82c979b 318 break;
hazheng 79:bdbac82c979b 319 default:
hazheng 79:bdbac82c979b 320 break;
hazheng 79:bdbac82c979b 321 }
hazheng 79:bdbac82c979b 322 break;
hazheng 79:bdbac82c979b 323 case LEFT_FOUND:
hazheng 79:bdbac82c979b 324 switch(isBorderFound)
hazheng 79:bdbac82c979b 325 {
hazheng 79:bdbac82c979b 326 case RIGHT_FOUND:
hazheng 79:bdbac82c979b 327 case BOTH_FOUND:
hazheng 79:bdbac82c979b 328 is_border_find = BOTH_FOUND;
hazheng 79:bdbac82c979b 329 break;
hazheng 79:bdbac82c979b 330 default:
hazheng 79:bdbac82c979b 331 break;
hazheng 79:bdbac82c979b 332 }
hazheng 79:bdbac82c979b 333 break;
hazheng 79:bdbac82c979b 334 case RIGHT_FOUND:
hazheng 79:bdbac82c979b 335 switch(isBorderFound)
hazheng 79:bdbac82c979b 336 {
hazheng 79:bdbac82c979b 337 case LEFT_FOUND:
hazheng 79:bdbac82c979b 338 case BOTH_FOUND:
hazheng 79:bdbac82c979b 339 is_border_find = BOTH_FOUND;
hazheng 79:bdbac82c979b 340 break;
hazheng 79:bdbac82c979b 341 default:
hazheng 79:bdbac82c979b 342 break;
hazheng 79:bdbac82c979b 343 }
hazheng 79:bdbac82c979b 344 break;
hazheng 79:bdbac82c979b 345 case BOTH_FOUND:
hazheng 79:bdbac82c979b 346 default:
hazheng 79:bdbac82c979b 347 break;
hazheng 79:bdbac82c979b 348 }
hazheng 44:15de535c4005 349 }
hazheng 44:15de535c4005 350 }
hazheng 44:15de535c4005 351 }
hazheng 46:a5eb9bd3bb55 352
hazheng 46:a5eb9bd3bb55 353
hazheng 43:0d1886f4848a 354 void ardu_cam_display_img_utft()
hazheng 43:0d1886f4848a 355 {
hazheng 43:0d1886f4848a 356 ardu_cam_start_capture();
hazheng 44:15de535c4005 357
hazheng 44:15de535c4005 358 while (!(ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK));
hazheng 44:15de535c4005 359
hazheng 44:15de535c4005 360 temp_mid_pos = RESOLUTION_WIDTH / 2;
hazheng 46:a5eb9bd3bb55 361
hazheng 44:15de535c4005 362 for (uint8_t i = 0; i < CAM_ROI_UPPER_LIMIT; ++i)
hazheng 43:0d1886f4848a 363 {
hazheng 46:a5eb9bd3bb55 364 ardu_utft_set_camimg_row(CAM_ROI_UPPER_LIMIT - i);
hazheng 46:a5eb9bd3bb55 365 for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 46:a5eb9bd3bb55 366 {
hazheng 46:a5eb9bd3bb55 367 uint8_t VH = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 368 uint8_t VL = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 369
hazheng 46:a5eb9bd3bb55 370 ardu_utft_write_DATA(VH, VL);
hazheng 46:a5eb9bd3bb55 371 }
hazheng 44:15de535c4005 372
hazheng 43:0d1886f4848a 373 }
hazheng 44:15de535c4005 374 }
hazheng 64:43ab429a37e0 375
hazheng 64:43ab429a37e0 376 uint8_t ardu_cam_get_is_encounter_terminate()
hazheng 64:43ab429a37e0 377 {
hazheng 64:43ab429a37e0 378 return is_encounter_terminate;
hazheng 64:43ab429a37e0 379 }
hazheng 79:bdbac82c979b 380
hazheng 79:bdbac82c979b 381 uint8_t ardu_cam_get_is_border_found()
hazheng 79:bdbac82c979b 382 {
hazheng 79:bdbac82c979b 383 return is_border_find;
hazheng 79:bdbac82c979b 384 }
hazheng 96:ec89c4d1383d 385
hazheng 46:a5eb9bd3bb55 386 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 387 }
hazheng 46:a5eb9bd3bb55 388 #endif
hazheng 46:a5eb9bd3bb55 389
hazheng 46:a5eb9bd3bb55 390
hazheng 46:a5eb9bd3bb55 391