/*
* imageproc.c
*
* Created on: May 30, 2016
* Author: rhuber
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
// Lots of dependencies, so we need to include all of these files
#include "flexio_ov7670.h"
#include "board.h"
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device_stack_interface.h"
#include "usb_descriptor.h"
#include "camera.h"
#define ROI_W 72
#define ROI_H 80
#define ROI_X ((160 - ROI_W) / 2)
#define ROI_Y ((120 - ROI_H) / 2)
#define ROI_X2 (ROI_X + ROI_W)
#define ROI_Y2 (ROI_Y + ROI_H)
uint16_t image1[ROI_H][ROI_W];
uint8_t edge_image[ROI_H][ROI_W];
uint8_t edge_ar[ROI_H][ROI_W];
void capture_image(int imagenum, volatile uint16_t ar[120][160] )
{
uint32_t x, y;
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
image1[y][x] = ar[ROI_Y + y][ROI_X + x];
}
}
}
#define RED(a) ((((a) & 0xf800) >> 11) << 3)
#define GREEN(a) ((((a) & 0x07e0) >> 5) << 2)
#define BLUE(a) (((a) & 0x001f) << 3)
uint16_t conv_bw_rgb565(uint16_t src) {
int r = RED(src); // 5 bits
int g = GREEN(src); // 6 bits
int b = BLUE(src); // 5 bits
int gray = (r + g + b) / 3;
uint16_t output = ((gray >> 3) & 0x1F) << 11 | ((gray >> 2) & 0x3f) << 5 | ((gray >> 3) & 0x1F);
return output;
}
/// ( ((a&0xf800)>>11) + ((a&0x03e0)>>5) + (a&0x1f) ) // RGB565
uint16_t diff_rgb565(uint16_t src, uint16_t dest) {
int rSrc = (src & 0xf800) >> 11; // 5 bits
int gSrc = (src & 0x07e0) >> 5; // 6 bits
int bSrc = (src & 0x001f); // 5 bits
int rDst = (dest & 0xf800) >> 11;
int gDst = (dest & 0x07e0) >> 5;
int bDst = (dest & 0x001f);
rDst -= rSrc;
if(rDst > 31)
rDst = 31;
else if(rDst < 0)
rDst = 0;
gDst -= gSrc;
if(gDst > 63)
gDst = 63;
else if(gDst < 0)
gDst = 0;
bDst -= bSrc;
if(bDst > 31)
bDst = 31;
else if(bDst < 0)
bDst = 0;
uint16_t output = (rDst & 0x1F) << 11 | (gDst & 0x3f) << 5 | (bDst & 0x1F);
return output;
}
void diff_image(int imagenum, volatile uint16_t ar[120][160] )
{
uint32_t x, y;
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
ar[ROI_Y + y][ROI_X + x] = diff_rgb565(image1[y][x], ar[ROI_Y + y][ROI_X + x]);
}
}
}
int totalDiff = 0;
//#define RED(a) ((((a) & 0xf800) >> 11) << 3)
//#define GREEN(a) ((((a) & 0x07e0) >> 5) << 2)
//#define BLUE(a) (((a) & 0x001f) << 3)
uint16_t diffshow_rgb565(uint16_t src, uint16_t dest) {
int r = RED(src);
int g = GREEN(src);
int b = BLUE(src);
int graySrc = (r + g + b) / 3;
r = RED(dest);
g = GREEN(dest);
b = BLUE(dest);
int grayDest = (r + g + b) / 3;
int grayDiff = graySrc - grayDest;
if(grayDiff < 0)
grayDiff = -grayDiff;
totalDiff += grayDiff;
int redDest = grayDest;
if(grayDiff > 0x08) {
redDest = grayDest + (grayDiff );
if(redDest > 255)
redDest = 255;
}
uint16_t output = ((redDest >> 3) & 0x1F) << 11 | ((grayDest >> 2) & 0x3f) << 5 | ((grayDest >> 3) & 0x1F);
return output;
}
#define RGB(r, g, b) ((r >> 3) & 0x1F) << 11 | ((g >> 2) & 0x3f) << 5 | ((b >> 3) & 0x1F)
void diffshow_image(int imagenum, volatile uint16_t ar[120][160] )
{
totalDiff = 0; // reset our diff counter
uint32_t x, y;
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
ar[ROI_Y + y][ROI_X + x] = diffshow_rgb565(image1[y][x], ar[ROI_Y + y][ROI_X + x]);
}
}
// totalDiff level: 347000 bad match, 15000 good match
int level = (totalDiff * ROI_W) / 347000;
if(level > ROI_W)
level = ROI_W;
// First color bar is red
uint16_t color16 = RGB(255, 0, 0);
for(x = 0 ; x < level ; x++) {
ar[ROI_Y-2][ROI_X + x] = color16;
ar[ROI_Y-1][ROI_X + x] = color16;
}
// 2nd bar is green
color16 = RGB(0, 255, 0);
for( ; x < ROI_W ; x++) {
ar[ROI_Y-2][ROI_X + x] = color16;
ar[ROI_Y-1][ROI_X + x] = color16;
}
}
void conv_bw_image(int imagenum, volatile uint16_t ar[120][160] )
{
uint32_t x, y;
for(y = ROI_Y ; y < ROI_Y2 ; y++) {
for(x = ROI_X ; x < ROI_X2 ; x++) {
ar[y][x] = conv_bw_rgb565(ar[y][x]);
}
}
}
void show_saved_image(int imagenum, volatile uint16_t ar[120][160] )
{
uint32_t x, y;
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
ar[ROI_Y + y][ROI_X + x] = conv_bw_rgb565(image1[y][x]);
}
}
}
uint32_t hist[256];
void histogram_image(int flags, uint16_t color16, volatile uint16_t ar[120][160], uint8_t edge_input1[ROI_H][ROI_W] )
{
int x, y;
totalDiff = 0;
for(x = 0 ; x < 256 ; x++) {
hist[x] = 0;
}
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
int edge1 = edge_input1[y][x];
hist[edge1]++;
}
}
// uint16_t color16 = RGB(255, 0, 0); // Show hist in red
// Total counts: 60*80 = 4800 (~0x1000)
for(x = 0 ; x < 128 ; x++) {
y = (hist[x << 1] + hist[(x << 1) + 1]) >> 2;
if(y > 119)
y = 119;
else if(y < 0)
y = 0;
ar[119 - y][x] = color16;
}
}
void scan_edges_image(int imagenum, volatile uint16_t ar[120][160], uint8_t edge_output[ROI_H][ROI_W])
{
//edge_image[ROI_H][ROI_W];
// iterators
unsigned int x, y;
// initialize our top/bottom and left/right borders
for(x = 0; x < ROI_W; x++){
edge_output[0][x] = 0;
edge_output[ROI_H - 1][x] = 0;
}
for(y = 0; y < ROI_H; y++){
edge_output[y][0] = 0;
edge_output[y][ROI_W - 1] = 0;
}
for(x = 1; x < ROI_W - 1; x++){
for(y = 1; y < ROI_H - 1; y++){
// initialize Gx and Gy to 0
int Gx = 0;
int Gy = 0;
unsigned int intensity = 0;
uint16_t pixel;
// Left column
pixel = ar[ROI_Y + y - 1][ROI_X + x - 1];
int r = RED(pixel);
int g = GREEN(pixel);
int b = BLUE(pixel);
intensity = (r + g + b);
Gx += -intensity;
Gy += -intensity;
pixel = ar[ROI_Y + y][ROI_X + x - 1];
r = RED(pixel);
g = GREEN(pixel);
b = BLUE(pixel);
intensity = (r + g + b);
Gx += -2 * intensity;
pixel = ar[ROI_Y + y + 1][ROI_X + x - 1];
r = RED(pixel);
g = GREEN(pixel);
b = BLUE(pixel);
intensity = (r + g + b);
Gx += -intensity;
Gy += +intensity;
// middle column
pixel = ar[ROI_Y + y - 1][ROI_X + x];
r = RED(pixel);
g = GREEN(pixel);
b = BLUE(pixel);
intensity = (r + g + b);
Gy += -2 * intensity;
pixel = ar[ROI_Y + y + 1][ROI_X + x];
r = RED(pixel);
g = GREEN(pixel);
b = BLUE(pixel);
intensity = (r + g + b);
Gy += +2 * intensity;
// right column
pixel = ar[ROI_Y + y - 1][ROI_X + x + 1];
r = RED(pixel);
g = GREEN(pixel);
b = BLUE(pixel);
intensity = (r + g + b);
Gx += +intensity;
Gy += -intensity;
pixel = ar[ROI_Y + y][ROI_X + x + 1];
r = RED(pixel);
g = GREEN(pixel);
b = BLUE(pixel);
intensity = (r + g + b);
Gx += +2 * intensity;
pixel = ar[ROI_Y + y + 1][ROI_X + x + 1];
r = RED(pixel);
g = GREEN(pixel);
b = BLUE(pixel);
intensity = (r + g + b);
Gx += +intensity;
Gy += +intensity;
// calculate the gradient length
unsigned int length = (unsigned int)sqrt( (float)(Gx * Gx) + (float)(Gy * Gy) );
// normalize the length to 0 to 255
length = length / 17;
// draw the pixel on the edge image
length *= 3;
if(length > 255)
length = 255;
edge_output[y][x] = length;
}
}
}
void overlay_edge_image(int flags, volatile uint16_t ar[120][160], uint8_t edge_input[ROI_H][ROI_W] )
{
uint32_t x, y;
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
uint16_t pixel = ar[ROI_Y + y][ROI_X + x];
uint32_t edge = edge_input[y][x];
int r = RED(pixel);
int g = GREEN(pixel);
int b = BLUE(pixel);
int gray = ((r + g + b) / 3);
edge += gray;
if(edge > 255)
edge = 255;
uint16_t color16 = RGB(gray, gray, edge); // Show edges in blue
ar[ROI_Y + y][ROI_X + x] = color16;
}
}
}
void show_edge_image(int flags, volatile uint16_t ar[120][160], uint8_t edge_input1[ROI_H][ROI_W])
{
uint32_t x, y;
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
uint8_t edge = edge_input1[y][x];
uint16_t color16 = RGB(edge, edge, edge); // Show edges in green
ar[ROI_Y + y][ROI_X + x] = color16;
}
}
}
void show_edge_image2(int flags, volatile uint16_t ar[120][160], uint8_t edge_input1[ROI_H][ROI_W], uint8_t edge_input2[ROI_H][ROI_W] )
{
uint32_t x, y;
totalDiff = 0;
for(y = 0 ; y < ROI_H ; y++) {
for(x = 0 ; x < ROI_W ; x++) {
int edge1 = edge_input1[y][x];
int edge2 = edge_input2[y][x];
int grayDiff = edge1 - edge2;
if(grayDiff < 0)
grayDiff = -grayDiff;
totalDiff += grayDiff;
uint16_t color16 = RGB(edge1, edge2, 0); // Show edges in green
ar[ROI_Y + y][ROI_X + x] = color16;
}
}
// totalDiff level: 347000 bad match, 15000 good match
int level = (totalDiff * ROI_W) / 347000;
if(level > ROI_W)
level = ROI_W;
// First color bar is red
uint16_t color16 = RGB(255, 0, 0);
for(x = 0 ; x < level ; x++) {
ar[ROI_Y-2][ROI_X + x] = color16;
ar[ROI_Y-1][ROI_X + x] = color16;
}
// 2nd bar is green
color16 = RGB(0, 255, 0);
for( ; x < ROI_W ; x++) {
ar[ROI_Y-2][ROI_X + x] = color16;
ar[ROI_Y-1][ROI_X + x] = color16;
}
}
#define SEARCH_W 12
#define SEARCH_H 12
#define SEARCH_X (SEARCH_W / 2)
#define SEARCH_Y (SEARCH_H / 2)
#define SEARCH_STEP_X 2
#define SEARCH_STEP_Y 2
void search_edge_image2(int flags, volatile uint16_t ar[120][160], uint8_t edge_live1[ROI_H][ROI_W], uint8_t edge_input2[ROI_H][ROI_W] )
{
int x, y;
int offX, offY;
long minDiff = 80 * 60 * 255;
int minX;
int minY;
for(offY = 0 ; offY < SEARCH_H ; offY+=SEARCH_STEP_Y) {
for(offX = 0 ; offX < SEARCH_W ; offX+=SEARCH_STEP_X) {
totalDiff = 0;
for(y = 0 ; y < ROI_H-SEARCH_H ; y++) {
for(x = 0 ; x < ROI_W-SEARCH_W ; x++) {
int edge1 = edge_live1[y + SEARCH_Y][x + SEARCH_X];
int edge2 = edge_input2[y + offY+ SEARCH_Y][x + offX + SEARCH_X];
int grayDiff = edge1 - edge2;
if(grayDiff < 0)
grayDiff = -grayDiff;
totalDiff += grayDiff;
}
}
if(totalDiff < minDiff) {
minDiff = totalDiff;
minX = offX;
minY = offY;
}
}
}
totalDiff = 0;
for(y = 0 ; y < ROI_H-SEARCH_H ; y++) {
for(x = 0 ; x < ROI_W-SEARCH_W ; x++) {
int edge1 = edge_live1[y + SEARCH_Y][x + SEARCH_X];
int edge2 = edge_input2[y+minY + SEARCH_Y][x+minX + SEARCH_X];
int grayDiff = edge1 - edge2;
if(grayDiff < 0)
grayDiff = -grayDiff;
totalDiff += grayDiff;
uint16_t color16 = RGB(edge1, edge2, 0); // Show edges in green
ar[ROI_Y + y + SEARCH_Y][ROI_X + x + SEARCH_X] = color16;
}
}
// totalDiff level: 347000 bad match, 15000 good match
int level = (totalDiff * ROI_W) / 347000;
if(level > ROI_W)
level = ROI_W;
// First color bar is red
uint16_t color16 = RGB(255, 0, 0);
for(x = 0 ; x < level ; x++) {
ar[ROI_Y+ROI_H][ROI_X + x] = color16;
ar[ROI_Y+ROI_H+1][ROI_X + x] = color16;
}
// 2nd bar is green
color16 = RGB(0, 255, 0);
for( ; x < ROI_W ; x++) {
ar[ROI_Y+ROI_H][ROI_X + x] = color16;
ar[ROI_Y+ROI_H+1][ROI_X + x] = color16;
}
}
/*
* Array indexing ar[row][col] also known as ar[y][x]
*
*/
#define add_color(a) ( ((a&0xf800)>>11) + ((a&0x03e0)>>5) + (a&0x1f) )
enum _gpio_pins_pinNames2{
kGpioLED_A = GPIO_MAKE_PIN(GPIOA_IDX, 15U),
kGpioLED_B = GPIO_MAKE_PIN(GPIOA_IDX, 16U),
};
const gpio_output_pin_user_config_t ledPins2[] = {
{
.pinName = kGpioLED_A,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = kGpioLED_B,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = GPIO_PINS_OUT_OF_RANGE,
}
};
gpio_input_pin_user_config_t inputPinSW_A =
{
.pinName = kGpioSW2,
.config.isPullEnable = true,
.config.pullSelect = kPortPullUp,
.config.isPassiveFilterEnabled = false,
.config.isDigitalFilterEnabled = false,
.config.interrupt = kPortIntDisabled
};
// OV7680 GPIO
// PTA1
// PTA2
// PTB0
// PTB2
// PTB3
// PTC3
// PTC8
// PTC9
// PTB10
// PTB11
// PTB18
// PTB19
// PTB21
// PTB20
// PTB22
// PTB23
//
void setGPIO(uint32_t pinName, int enabled) {
GPIO_DRV_WritePinOutput(pinName, enabled ? 1 : 0);
}
void config_gpio_pins2() {
/* Affects PORTA_PCR4 register */
PORT_HAL_SetMuxMode(PORTA,15UL,kPortMuxAsGpio);
GPIO_DRV_SetPinDir(kGpioLED_A, kGpioDigitalOutput);
PORT_HAL_SetMuxMode(PORTA,16UL,kPortMuxAsGpio);
GPIO_DRV_SetPinDir(kGpioLED_B, kGpioDigitalOutput);
// PORT_HAL_SetPullMode(PORTA,4UL,kPortPullUp);
// PORT_HAL_SetPullCmd(PORTA,4UL,true);
}
enum displayState_e {
DISP_Normal,
DISP_Saved,
DISP_BW,
Disp_Diff,
Disp_Edge_Overlay,
Disp_Edge,
Disp_Edge_Diff,
Disp_Edge_Search,
Disp_MAX,
};
void ImageProc_Init()
{
}
void ImageProc_Task(void)
{
int buf;
// int i,j;
int pending_request_flag = 0;
int pending_request_buf = 0;
// int last_button = 0;
int button1 = 0;
int lastbutton1 = 0;
int button2 = 0;
int lastbutton2 = 0;
int capturePending = 0;
// int showDiff = 0;
// int showBW = 0;
int diffMax = 0;
int diffMin = 0x10000000;
int displayState = DISP_Normal;
int led_on_time = 0;
int led_off_time = 0;
int blinks=0;
unsigned int b2counts = 0;
unsigned int capCountdown = 0;
//SW_EN;
PORT_HAL_SetMuxMode(PORTA, 4, kPortMuxAsGpio);
PORT_HAL_SetMuxMode(PORTC, 6, kPortMuxAsGpio);
config_gpio_pins2();
// GPIO_DRV_InputPinInit(&inputPinSW2);
button1 = GPIO_DRV_ReadPinInput(kGpioSW1);
lastbutton1 = button1;
button2 = GPIO_DRV_ReadPinInput(kGpioSW2);
lastbutton2 = button2;
printf("Button1 = %d, Button2 = %d\r\n", button1, button2);
while(1)
{
/*
* The 'portb_callback' function of the camera is where we think the camera indicates that an image
* capture has completed. It let's us know this information through the global variable 'buf_indicator'.
* '1' indicates buffer 0 is ready, '2' indicates buffer 1 is ready, and '0' means nothing happening.
*
* When a PC's program is grabbing video (is_sending flag TRUE), the USB initiates image capture.
* If not (is_sending flag FALSE), we initiate image capture.
*/
if ( buf_indicator )
{
// buf_indicator flips between 1 and 2. Adjust value to line up with 0 referenced buffer
buf=buf_indicator-1;
// USB capture indicated by '.', capture initiated by our routine is ':'
if ( pending_request_flag ) printf(":"); else printf(".");
buf_indicator=0;
pending_request_flag= 0;
uint16_t color = RGB(255, 0, 0);
if(capturePending) {
capture_image(1, (void *)&(u8CameraFrameBuffer[buf][32]) );
scan_edges_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_image );
capturePending = 0;
// showDiff = 1;
} else {
switch(displayState) {
case DISP_Normal:
break;
case DISP_Saved:
show_saved_image(1, (void *)&(u8CameraFrameBuffer[buf][32]) );
overlay_edge_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_image );
color = RGB(255, 0, 0);
histogram_image(0, color, (void *)&(u8CameraFrameBuffer[buf][32]), edge_image);
break;
case DISP_BW:
conv_bw_image(1, (void *)&(u8CameraFrameBuffer[buf][32]) );
overlay_edge_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar );
break;
case Disp_Diff:
diffshow_image(1, (void *)&(u8CameraFrameBuffer[buf][32]) );
if(totalDiff < diffMin)
diffMin = totalDiff;
if(totalDiff > diffMax)
diffMax = totalDiff;
break;
case Disp_Edge_Overlay:
scan_edges_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar );
overlay_edge_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar );
break;
case Disp_Edge:
scan_edges_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar );
show_edge_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar );
color = RGB(0, 255, 0);
histogram_image(0, color, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar);
break;
case Disp_Edge_Diff:
scan_edges_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar );
show_edge_image2(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar, edge_image );
color = RGB(255, 0, 0);
histogram_image(0, color, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar);
if(totalDiff < diffMin)
diffMin = totalDiff;
if(totalDiff > diffMax)
diffMax = totalDiff;
break;
case Disp_Edge_Search:
scan_edges_image(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar );
search_edge_image2(1, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar, edge_image );
color = RGB(255, 0, 0);
// histogram_image(0, color, (void *)&(u8CameraFrameBuffer[buf][32]), edge_ar);
if(totalDiff < diffMin)
diffMin = totalDiff;
if(totalDiff > diffMax)
diffMax = totalDiff;
break;
default:
displayState = DISP_Normal;
break;
}
}
}
else
{
if (!virtual_camera.is_sending && !pending_request_flag )
{
// since USB is not requesting image capture, let's do it ourselves
// pending_request_flag = 1;
// flexio_ov7670_start_capture( pending_request_buf+1 );
// pending_request_buf = 1-pending_request_buf;
//LED3_TOGGLE;
// OSA_TimeDelay(5); /* 5ms */
}
else
{
OSA_TimeDelay(5); /* 5ms */
}
}
button1 = GPIO_DRV_ReadPinInput(kGpioSW1);
button2 = GPIO_DRV_ReadPinInput(kGpioSW2);
if(button2 == 0) {
b2counts++;
if(capCountdown != 0) {
printf(" - Capture CANCELLED, countDown=%x\r\n", capCountdown);
capCountdown = 0; // Cancel capture
}
}
if(capCountdown > 0) {
--capCountdown;
if((capCountdown & 0x1FF) == 0x100) {
LED3_ON;
setGPIO(kGpioLED_B, 0); // Light Green LED
setGPIO(kGpioLED_A, 0); // Light Orange LED
printf(" - On, countDown=%x\r\n", capCountdown);
} else if((capCountdown & 0x1FF) == 0x000) {
LED3_OFF;
setGPIO(kGpioLED_B, 1); // clear green LED
setGPIO(kGpioLED_A, 1); // clear orange LED
if(capCountdown == 0) {
capturePending = 1;
displayState = Disp_Edge_Search;
printf(" - Capture started, countDown=%x\r\n", capCountdown);
} else {
printf(" - Off, countDown=%x\r\n", capCountdown);
}
}
}
if(lastbutton1 != button1 || lastbutton2 != button2 ) {
printf("Button1 = %d, Button2 = %d, diffMin=%d, diffMax=%d, state=%d\r\n", button1, button2, diffMin, diffMax, displayState);
// setGPIO(kGpioLED_A, button1);
// setGPIO(kGpioLED_B, button2);
if(button1 == 0 && button2 == 0) {
capturePending = 1;
// capture_image(1, (void *)&(u8CameraFrameBuffer[buf][32]) );
} else if(button2 == 0) {
// showDiff = !showDiff;
diffMax = 0;
diffMin = 0x1000000;
displayState = Disp_Edge;
} else if(button1 == 0) {
if(++displayState >= Disp_MAX)
displayState = 0;
blinks = displayState;
led_on_time = 10;
LED3_ON;
} else {
// All buttons released
if(lastbutton2 == 0) {
if(b2counts > 300) {
capCountdown = 0x1000;
displayState = Disp_Edge;
} else {
displayState = Disp_Edge_Search;
}
printf("\r\nCapture=%d: b2counts=%u\r\n", capturePending, b2counts);
b2counts = 0;
}
}
lastbutton1 = button1;
lastbutton2 = button2;
}
if(led_on_time > 0) {
if(--led_on_time <= 0) {
LED3_OFF;
led_on_time = 0;
if(blinks > 0) {
led_off_time = 40;
--blinks;
}
}
} else if(led_off_time > 0) {
if(--led_off_time <= 0) {
LED3_ON;
led_on_time = 10;
}
} else if(displayState == Disp_Diff || displayState == Disp_Edge_Diff || displayState == Disp_Edge_Search) {
if(totalDiff < 50000) {
setGPIO(kGpioLED_B, 0); // Light Green LED
setGPIO(kGpioLED_A, 1); // clear orange LED
// led_on_time = 1;
// led_off_time = 20;
// LED3_ON;
} else if(totalDiff < 100000) {
setGPIO(kGpioLED_B, 0); // Light Green LED
setGPIO(kGpioLED_A, 0); // Light Orange LED
// led_on_time = 1;
// led_off_time = 100;
// LED3_ON;
} else if(totalDiff < 150000) {
setGPIO(kGpioLED_A, 0); // Light Orange LED
setGPIO(kGpioLED_B, 1); // clear green LED
// led_on_time = 1;
// led_off_time = 200;
// LED3_ON;
} else {
setGPIO(kGpioLED_B, 1); // clear green LED
setGPIO(kGpioLED_A, 1); // clear orange LED
}
}
}
// OSA_TimeDelay(2000U);
// LED3_TOGGLE;
}
Comments