?? hmi.c
字號:
}
// All conditions are OK, we can start to work
*HMI_CMD_Stream = pointX | X_COORDINATE_MASK;
*(HMI_CMD_Stream + 1)= (pointY / HMI_ROW_WIDTH) | Y_COORDINATE_MASK;
HMI_CMD_Para->DataLen = HMI_LOCATE_CMD_STREAM_SIZE;
HMI_CMD_Para->DataList = HMI_CMD_Stream;
HMI_Draw_Para->color = color;
HMI_Draw_Para->pointX = pointX;
HMI_Draw_Para->pointY = pointY;
foundQueueSlot_CMD->HMI_Func_Para = HMI_CMD_Para;
foundQueueSlot_Data->HMI_Func_Para = HMI_Draw_Para;
return SUCCESS;
}
WorkingStatus HMI_Draw_Line_Data(void *HMI_Draw_Para)
{
uint8_t temp_Row, temp_i, temp_Width, temp_Height, bestSuitDivider,
temp_Mask, temp_Y, temp_X, tempRowRemain_Start, tempRowNUM;
// Robust Check, make sure no out border
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX >= HMI_WIDTH_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX = 0;
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + HMI_ROW_WIDTH;
}
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY >= HMI_HEIGHT_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY = 0;
}
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX >= HMI_WIDTH_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX = 0;
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY + HMI_ROW_WIDTH;
}
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY >= HMI_HEIGHT_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY = 0;
}
GPIO_SetBits(LCD_DC_PORT, LCD_DC_PIN); // Pull up D/_C to enter data mode
temp_Width = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX - ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX + 1;
temp_Height = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY - ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + 1;
// Fuck, I'm not clever enough to find a algorithm to handle or, at least need to seperate it into 2 TYEP:
// 1. Width is largger than height
// 2. Width is smaller than height
// So, straightforward I seperate it in 5 to easy the logic
// Point type is already excluded in HMI_Draw_Line()
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX)
{
// Vertical line
for (temp_i = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY; temp_i <= ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY; temp_i++)
{
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX] &= ~(0x01 << (temp_i % HMI_ROW_WIDTH));
}
else
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX] |= 0x01 << (temp_i % HMI_ROW_WIDTH);
}
}
}
else if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY)
{
// Horizon line
temp_Row = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY / HMI_ROW_WIDTH;
temp_Mask = 0x01 << (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY % HMI_ROW_WIDTH);
for (temp_i = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX; temp_i <= ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX; temp_i++)
{
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_Row][temp_i] &= ~temp_Mask;
}
else
{
sta_LCD_Graphic_BUF[temp_Row][temp_i] |= temp_Mask;
}
}
}
else if (temp_Width == temp_Height)
{
// 45 degree line
for (temp_i = 0; temp_i < temp_Width; temp_i++)
{
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[(((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + temp_i) / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX + temp_i]
&= ~(0x01 << ((((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + temp_i) % HMI_ROW_WIDTH));
}
else
{
sta_LCD_Graphic_BUF[(((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + temp_i) / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX + temp_i]
&= ~(0x01 << ((((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + temp_i) % HMI_ROW_WIDTH));
}
}
}
else if (temp_Width > temp_Height)
{
// Get bestSuitDivider
bestSuitDivider = temp_Width / temp_Height;
// Check if one dot more per Y axis is better
bestSuitDivider = (((bestSuitDivider + 1) * temp_Height - temp_Width) < (temp_Width % temp_Height)) ? (bestSuitDivider + 1) : bestSuitDivider;
// So Y axis will add 1 every X axis add bestSuitDivider
for (temp_i = 0; temp_i < temp_Width; temp_i++)
{
temp_Y = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + temp_i / bestSuitDivider;
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_Y / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX + temp_i]
&= ~(0x01 << (temp_Y % HMI_ROW_WIDTH));
}
else
{
sta_LCD_Graphic_BUF[temp_Y / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX + temp_i]
&= ~(0x01 << (temp_Y % HMI_ROW_WIDTH));
}
}
}
else
{
// Get bestSuitDivider
bestSuitDivider = temp_Height / temp_Width;
// Check if one dot more per Y axis is better
bestSuitDivider = (((bestSuitDivider + 1) * temp_Width - temp_Height) < (temp_Height % temp_Width)) ? (bestSuitDivider + 1) : bestSuitDivider;
// So X axis will add 1 every Y axis add bestSuitDivider
for (temp_i = 0; temp_i < temp_Height; temp_i++)
{
temp_X = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX + temp_i / bestSuitDivider;
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][temp_X] &= ~(0x01 << (temp_i % HMI_ROW_WIDTH));
}
else
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][temp_X] &= ~(0x01 << (temp_i % HMI_ROW_WIDTH));
}
}
}
tempRowRemain_Start = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY % HMI_ROW_WIDTH;
tempRowNUM = (temp_Height - tempRowRemain_Start) / HMI_ROW_WIDTH;
tempRowNUM += (0 == tempRowRemain_Start ? 0 : 1);
tempRowNUM += (0 == ((temp_Height - tempRowRemain_Start) % HMI_ROW_WIDTH) ? 0 : 1);
HMI_Data_TX(sta_LCD_Graphic_BUF[((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY / HMI_ROW_WIDTH] + ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX,
(tempRowNUM - 1) * HMI_WIDTH_PIX + temp_Width);
//(HMI_WIDTH_PIX - ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX) + (tempRowNUM - 2) * HMI_WIDTH_PIX +
//(((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX + ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->width));
return FINISHED;
}
ErrorStatus HMI_Draw_Line(uint8_t startX, uint8_t startY, uint8_t endX, uint8_t endY, HMIDrawColor color)
{
struct_HMI_Queue *foundQueueSlot_CMD = NULL;
struct_HMI_Queue *foundQueueSlot_Data = NULL;
struct_HMI_Draw_Para_Line *HMI_Draw_Para = NULL;
struct_HMI_CMD_Para *HMI_CMD_Para = NULL;
uint8_t *HMI_CMD_Stream = NULL;
// First make sure it's not a point
if ((endX == startX) && (endY == startY))
{
return HMI_Draw_Point(startX, startY, color);
}
// Prepare to get all necessary space
foundQueueSlot_CMD = HMI_Find_Queue_Slot(HMI_TASK_TYPE_BUS);
if ((foundQueueSlot_CMD != NULL))
{
foundQueueSlot_CMD->HMI_Function_Index = ENUM_HMI_CMD_STREAM;
}
else
{
FLAG_HMI_QUEUE_FULL = SET;
return ERROR;
}
foundQueueSlot_Data = HMI_Find_Queue_Slot(HMI_TASK_TYPE_BUS);
if (foundQueueSlot_Data != NULL)
{
foundQueueSlot_Data->HMI_Function_Index = ENUM_HMI_DRAW_LINE_DATA;
}
else
{
foundQueueSlot_CMD->HMI_Function_Index = ENUM_HMI_NULL;
FLAG_HMI_QUEUE_FULL = SET;
return ERROR;
}
// To here queue slots are available and occupied
HMI_CMD_Stream = malloc(HMI_LOCATE_CMD_STREAM_SIZE);
if (NULL == HMI_CMD_Stream)
{
foundQueueSlot_CMD->HMI_Function_Index = ENUM_HMI_NULL;
foundQueueSlot_Data->HMI_Function_Index = ENUM_HMI_NULL;
FLAG_HEAP_FULL = SET;
return ERROR;
}
HMI_CMD_Para = malloc(sizeof(struct_HMI_CMD_Para));
if (NULL == HMI_CMD_Para)
{
foundQueueSlot_CMD->HMI_Function_Index = ENUM_HMI_NULL;
foundQueueSlot_Data->HMI_Function_Index = ENUM_HMI_NULL;
free(HMI_CMD_Stream);
FLAG_HEAP_FULL = SET;
return ERROR;
}
HMI_Draw_Para = malloc(sizeof(struct_HMI_Draw_Para_Line));
if (NULL == HMI_Draw_Para)
{
foundQueueSlot_CMD->HMI_Function_Index = ENUM_HMI_NULL;
foundQueueSlot_Data->HMI_Function_Index = ENUM_HMI_NULL;
free(HMI_CMD_Stream);
free(HMI_CMD_Para);
FLAG_HEAP_FULL = SET;
return ERROR;
}
// All conditions are OK, we can start to work
*HMI_CMD_Stream = startX | X_COORDINATE_MASK;
*(HMI_CMD_Stream + 1)= (startY / HMI_ROW_WIDTH) | Y_COORDINATE_MASK;
HMI_CMD_Para->DataLen = HMI_LOCATE_CMD_STREAM_SIZE;
HMI_CMD_Para->DataList = HMI_CMD_Stream;
HMI_Draw_Para->color = color;
HMI_Draw_Para->startX = startX;
HMI_Draw_Para->startY = startY;
HMI_Draw_Para->endX = endX;
HMI_Draw_Para->endY = endY;
foundQueueSlot_CMD->HMI_Func_Para = HMI_CMD_Para;
foundQueueSlot_Data->HMI_Func_Para = HMI_Draw_Para;
return SUCCESS;
}
WorkingStatus HMI_Draw_Rect_Data(void *HMI_Draw_Para)
{
uint8_t temp_Row, temp_i, tempRowRemain_Start, tempRowNUM, temp_Mask, temp_Width, temp_Height;
// Robust Check, make sure no out border
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX >= HMI_WIDTH_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX = 0;
}
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY >= HMI_HEIGHT_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY = 0;
}
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX >= HMI_WIDTH_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX = HMI_WIDTH_PIX - 1;
}
if (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY >= HMI_HEIGHT_PIX)
{
((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY = HMI_HEIGHT_PIX - 1;
}
temp_Width = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX - ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX + 1;
temp_Height = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY - ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + 1;
// 4 Lines
GPIO_SetBits(LCD_DC_PORT, LCD_DC_PIN); // Pull up D/_C to enter data mode
// 1st Vertical line
for (temp_i = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + 1; temp_i < ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY; temp_i++)
{
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX] &= ~(0x01 << (temp_i % HMI_ROW_WIDTH));
}
else
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX] |= 0x01 << (temp_i % HMI_ROW_WIDTH);
}
}
// 2nd Vertical line
for (temp_i = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY + 1; temp_i < ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY; temp_i++)
{
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX] &= ~(0x01 << (temp_i % HMI_ROW_WIDTH));
}
else
{
sta_LCD_Graphic_BUF[temp_i / HMI_ROW_WIDTH][((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX] |= 0x01 << (temp_i % HMI_ROW_WIDTH);
}
}
// 1st Horizon line
temp_Row = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY / HMI_ROW_WIDTH;
temp_Mask = 0x01 << (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY % HMI_ROW_WIDTH);
for (temp_i = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX; temp_i <= ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX; temp_i++)
{
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_Row][temp_i] &= ~temp_Mask;
}
else
{
sta_LCD_Graphic_BUF[temp_Row][temp_i] |= temp_Mask;
}
}
// 2nd Horizon line
temp_Row = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY / HMI_ROW_WIDTH;
temp_Mask = 0x01 << (((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endY % HMI_ROW_WIDTH);
for (temp_i = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX; temp_i <= ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->endX; temp_i++)
{
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[temp_Row][temp_i] &= ~temp_Mask;
}
else
{
sta_LCD_Graphic_BUF[temp_Row][temp_i] |= temp_Mask;
}
}
tempRowRemain_Start = ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY % HMI_ROW_WIDTH;
tempRowNUM = (temp_Height - tempRowRemain_Start) / HMI_ROW_WIDTH;
tempRowNUM += (0 == tempRowRemain_Start ? 0 : 1);
tempRowNUM += (0 == ((temp_Height - tempRowRemain_Start) % HMI_ROW_WIDTH) ? 0 : 1);
HMI_Data_TX(sta_LCD_Graphic_BUF[((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startY / HMI_ROW_WIDTH] + ((struct_HMI_Draw_Para_Line *)HMI_Draw_Para)->startX,
(tempRowNUM - 1) * HMI_WIDTH_PIX + temp_Width);
//(HMI_WIDTH_PIX - ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX) + (tempRowNUM - 2) * HMI_WIDTH_PIX +
//(((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX + ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->width));
return FINISHED;
}
ErrorStatus HMI_Draw_Rect(uint8_t startX, uint8_t startY, uint8_t endX, uint8_t endY, HMIDrawColor color)
{
struct_HMI_Queue *foundQueueSlot_CMD = NULL;
struct_HMI_Queue *foundQueueSlot_Data = NULL;
struct_HMI_Draw_Para_Rect *HMI_Draw_Para = NULL;
struct_HMI_CMD_Para *HMI_CMD_Para = NULL;
uint8_t *HMI_CMD_Stream = NULL;
// Prepare to get all necessary space
foundQueueSlot_CMD = HMI_Find_Queue_Slot(HMI_TASK_TYPE_BUS);
if ((foundQueueSlot_CMD != NULL))
{
foundQueueSlot_CMD->HMI_Function_Index = ENUM_HMI_CMD_STREAM;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -