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:
Thu Apr 20 21:04:10 2017 +0000
Revision:
100:ffbeefc9e218
Parent:
97:0ed9ede9a995
Better version of Intersection detection.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 82:992ba6f31e24 1 #include "TestingState.h"
Bobymicjohn 97:0ed9ede9a995 2 #include "ArduCAM.h"
Bobymicjohn 97:0ed9ede9a995 3 #include "ArduUTFT.h"
Bobymicjohn 97:0ed9ede9a995 4 #include "CamRegBuf.h"
Bobymicjohn 97:0ed9ede9a995 5 #include "StateManager.h"
hazheng 82:992ba6f31e24 6
Bobymicjohn 97:0ed9ede9a995 7 TestingState::TestingState() :
Bobymicjohn 97:0ed9ede9a995 8 m_shouldTerminate(0)
hazheng 82:992ba6f31e24 9 {}
hazheng 82:992ba6f31e24 10
hazheng 82:992ba6f31e24 11 TestingState::~TestingState()
hazheng 82:992ba6f31e24 12 {}
hazheng 82:992ba6f31e24 13
hazheng 82:992ba6f31e24 14 void TestingState::DrawUserInterface()
hazheng 82:992ba6f31e24 15 {
Bobymicjohn 97:0ed9ede9a995 16 ardu_utft_clr_scr();
Bobymicjohn 97:0ed9ede9a995 17 ardu_utft_print("Camera Version: ", 300, 80);
hazheng 82:992ba6f31e24 18
Bobymicjohn 97:0ed9ede9a995 19 ardu_utft_print("Camera PID: ", 300, 100);
Bobymicjohn 97:0ed9ede9a995 20
Bobymicjohn 97:0ed9ede9a995 21 ardu_utft_print("ArduCam Version: ", 300, 120);
Bobymicjohn 97:0ed9ede9a995 22
Bobymicjohn 97:0ed9ede9a995 23 ardu_utft_print("Screen Version: ", 300, 140);
Bobymicjohn 97:0ed9ede9a995 24
Bobymicjohn 97:0ed9ede9a995 25 ardu_utft_print("Touch the screen anywhere to go back.", 300, 200);
hazheng 82:992ba6f31e24 26 }
hazheng 82:992ba6f31e24 27
hazheng 82:992ba6f31e24 28 void TestingState::Update(float deltaTime)
hazheng 82:992ba6f31e24 29 {
Bobymicjohn 97:0ed9ede9a995 30 if(m_shouldTerminate)
Bobymicjohn 97:0ed9ede9a995 31 {
Bobymicjohn 97:0ed9ede9a995 32 m_shouldTerminate = 0;
Bobymicjohn 97:0ed9ede9a995 33 state_manager_switch_state(STANDBY_STATE);
Bobymicjohn 97:0ed9ede9a995 34 return;
Bobymicjohn 97:0ed9ede9a995 35 }
hazheng 82:992ba6f31e24 36
Bobymicjohn 97:0ed9ede9a995 37 ardu_cam_display_img_utft();
Bobymicjohn 97:0ed9ede9a995 38
Bobymicjohn 97:0ed9ede9a995 39 char buf[50];
Bobymicjohn 97:0ed9ede9a995 40 uint8_t temp;
Bobymicjohn 97:0ed9ede9a995 41
Bobymicjohn 97:0ed9ede9a995 42 CamRegBuf * camReg = new CamRegBuf(CAM_SCCB_WRITE, CAM_SCCB_READ);
Bobymicjohn 97:0ed9ede9a995 43
Bobymicjohn 97:0ed9ede9a995 44 #if defined(ARDUCAM_OV2640)
Bobymicjohn 97:0ed9ede9a995 45 camReg->SCCBWrite(0xff, 0x01);
Bobymicjohn 97:0ed9ede9a995 46 #endif
Bobymicjohn 97:0ed9ede9a995 47
Bobymicjohn 97:0ed9ede9a995 48 temp = camReg->SCCBRead(CAM_VER_ADDR);
Bobymicjohn 97:0ed9ede9a995 49 sprintf(buf, "%#x", temp);
Bobymicjohn 97:0ed9ede9a995 50 ardu_utft_set_color(255, 255, 255);
Bobymicjohn 97:0ed9ede9a995 51 ardu_utft_print(buf, 150, 80);
Bobymicjohn 97:0ed9ede9a995 52 if(temp == CAM_VER_VALUE)
Bobymicjohn 97:0ed9ede9a995 53 {
Bobymicjohn 97:0ed9ede9a995 54 ardu_utft_set_color(0, 255, 0);
Bobymicjohn 97:0ed9ede9a995 55 ardu_utft_print("O", 100, 80);
Bobymicjohn 97:0ed9ede9a995 56 }
Bobymicjohn 97:0ed9ede9a995 57 else
Bobymicjohn 97:0ed9ede9a995 58 {
Bobymicjohn 97:0ed9ede9a995 59 ardu_utft_set_color(255, 0, 0);
Bobymicjohn 97:0ed9ede9a995 60 ardu_utft_print("X", 100, 80);
Bobymicjohn 97:0ed9ede9a995 61 }
Bobymicjohn 97:0ed9ede9a995 62
Bobymicjohn 97:0ed9ede9a995 63 temp = camReg->SCCBRead(CAM_PID_ADDR);
Bobymicjohn 97:0ed9ede9a995 64 ardu_utft_set_color(255, 255, 255);
Bobymicjohn 97:0ed9ede9a995 65 sprintf(buf, "%#x", temp);
Bobymicjohn 97:0ed9ede9a995 66 ardu_utft_print(buf, 150, 100);
Bobymicjohn 97:0ed9ede9a995 67 if(temp == CAM_PID_VALUE)
Bobymicjohn 97:0ed9ede9a995 68 {
Bobymicjohn 97:0ed9ede9a995 69 ardu_utft_set_color(0, 255, 0);
Bobymicjohn 97:0ed9ede9a995 70 ardu_utft_print("O", 100, 100);
Bobymicjohn 97:0ed9ede9a995 71 }
Bobymicjohn 97:0ed9ede9a995 72 else
Bobymicjohn 97:0ed9ede9a995 73 {
Bobymicjohn 97:0ed9ede9a995 74 ardu_utft_set_color(255, 0, 0);
Bobymicjohn 97:0ed9ede9a995 75 ardu_utft_print("X", 100, 100);
Bobymicjohn 97:0ed9ede9a995 76 }
Bobymicjohn 97:0ed9ede9a995 77
Bobymicjohn 97:0ed9ede9a995 78 delete camReg;
Bobymicjohn 97:0ed9ede9a995 79 camReg = NULL;
Bobymicjohn 97:0ed9ede9a995 80
Bobymicjohn 97:0ed9ede9a995 81
Bobymicjohn 97:0ed9ede9a995 82
Bobymicjohn 97:0ed9ede9a995 83 temp = ardu_cam_get_ver_num();
Bobymicjohn 97:0ed9ede9a995 84 sprintf(buf, "%#x", temp);
Bobymicjohn 97:0ed9ede9a995 85 ardu_utft_set_color(255, 255, 255);
Bobymicjohn 97:0ed9ede9a995 86 ardu_utft_print(buf, 150, 120);
Bobymicjohn 97:0ed9ede9a995 87 if(temp == ARDUCHIP_VER_NUM)
Bobymicjohn 97:0ed9ede9a995 88 {
Bobymicjohn 97:0ed9ede9a995 89 ardu_utft_set_color(0, 255, 0);
Bobymicjohn 97:0ed9ede9a995 90 ardu_utft_print("O", 100, 120);
Bobymicjohn 97:0ed9ede9a995 91 }
Bobymicjohn 97:0ed9ede9a995 92 else
Bobymicjohn 97:0ed9ede9a995 93 {
Bobymicjohn 97:0ed9ede9a995 94 ardu_utft_set_color(255, 0, 0);
Bobymicjohn 97:0ed9ede9a995 95 ardu_utft_print("X", 100, 120);
Bobymicjohn 97:0ed9ede9a995 96 }
Bobymicjohn 97:0ed9ede9a995 97 temp = 0;
Bobymicjohn 97:0ed9ede9a995 98 temp = ardu_utft_get_ver_num();
Bobymicjohn 97:0ed9ede9a995 99 sprintf(buf, "%#x", temp);
Bobymicjohn 97:0ed9ede9a995 100 ardu_utft_set_color(255, 255, 255);
Bobymicjohn 97:0ed9ede9a995 101 ardu_utft_print(buf, 150, 140);
Bobymicjohn 97:0ed9ede9a995 102 if(temp == ARDUCHIP_VER_NUM_UTFT)
Bobymicjohn 97:0ed9ede9a995 103 {
Bobymicjohn 97:0ed9ede9a995 104 ardu_utft_set_color(0, 255, 0);
Bobymicjohn 97:0ed9ede9a995 105 ardu_utft_print("O", 100, 140);
Bobymicjohn 97:0ed9ede9a995 106 }
Bobymicjohn 97:0ed9ede9a995 107 else
Bobymicjohn 97:0ed9ede9a995 108 {
Bobymicjohn 97:0ed9ede9a995 109 ardu_utft_set_color(255, 0, 0);
Bobymicjohn 97:0ed9ede9a995 110 ardu_utft_print("X", 100, 140);
Bobymicjohn 97:0ed9ede9a995 111 }
hazheng 82:992ba6f31e24 112 }
hazheng 82:992ba6f31e24 113
hazheng 82:992ba6f31e24 114 uint8_t TestingState::HasTouchPosFunction() const
hazheng 82:992ba6f31e24 115 {
hazheng 82:992ba6f31e24 116 return 0;
hazheng 82:992ba6f31e24 117 }
hazheng 82:992ba6f31e24 118
hazheng 82:992ba6f31e24 119 uint8_t TestingState::HasTouchIrqFunction() const
hazheng 82:992ba6f31e24 120 {
hazheng 82:992ba6f31e24 121 return 1;
hazheng 82:992ba6f31e24 122 }
hazheng 82:992ba6f31e24 123
hazheng 82:992ba6f31e24 124 void TestingState::TouchIrqCallback()
hazheng 82:992ba6f31e24 125 {
Bobymicjohn 97:0ed9ede9a995 126 m_shouldTerminate = 1;
hazheng 82:992ba6f31e24 127 }