/*
 * PixelGraphics.h
 *
 */

#ifndef INC_PIXEL_GRAPHICS_H_
#define INC_PIXEL_GRAPHICS_H_

/* инклюды */
#include "main.h"
#include "string.h"
#include "stdio.h"

#define GFX_BufferWidth 	128		//ширина дисплея в пикселях
#define GFX_BufferHeight 	32		//высота дисплея в пикселях

#define GFX_pxView_On	1		//закраска пикселя On
#define GFX_pxView_Off	0		//закраска пикселя Off

#define GFX_ChInvers	1		//инверсия символа шрифта On
#define GFX_ChUnInvers	0		//инверсия символа шрифта Off



typedef struct
{
  uint8_t xPos_Start; 
  uint8_t yPos_Start; 
  uint8_t xPos_End; 
  uint8_t yPos_End;
  uint8_t pxColor;
}GFX_LineHandleTypeDef;
typedef struct
{
  uint8_t xPos_Start; 
  uint8_t yPos_Start; 
  uint8_t rectangle_Width; 
  uint8_t rectangle_Height;
  uint8_t pxColor;
  uint8_t Filled;
}GFX_RectangleHandleTypeDef;

typedef struct
{
  uint8_t xPos; 
  uint8_t yPos; 
  uint8_t circle_Radius;
  uint8_t pxColor;
  uint8_t Filled;
}GFX_CircleHandleTypeDef;
typedef struct
{
  uint8_t xPos1; 
  uint8_t yPos1; 
  uint8_t xPos2; 
  uint8_t yPos2; 
  uint8_t xPos3; 
  uint8_t yPos3; 
  uint8_t pxColor;
  uint8_t Filled;
}GFX_TriangleHandleTypeDef;

typedef struct
{
  uint8_t   xPos; 
  uint8_t   yPos; 
  uint8_t   size;
  uint16_t  angle;
  uint8_t   pxColor;
  uint8_t   Filled;
}GFX_ArrowHandleTypeDef;

typedef struct
{
  uint8_t   xPos;
  uint8_t   yPos;
  uint8_t   radius;
  uint16_t  startAngle;
  uint16_t  endAngle;
  uint8_t   pxColor;
  uint8_t   Filled;
}GFX_ArcHandleTypeDef;

typedef struct
{
  uint8_t   xPos; 
  uint8_t   yPos;
  uint8_t   plotHeight;
  uint8_t   plotWidth;
  
  int16_t   dataX;
  int32_t   dataY;
  float     dataInd;
  int32_t   dataPrevY;
  
  int16_t   plotXShift;
  int16_t   plotYShift;
  
  struct
  {
    unsigned  dataSigned:1;
    unsigned  plotFrame:1;
    unsigned  plotXAxis:1;
    unsigned  plotYAxis:1;
    unsigned  initialized:1;
  }f;
}GFX_PlotterHandleTypeDef;



/* прототипы функций */
void GFX_Clean_Buffer_Frame(uint8_t *Buffer_Frame);
void GFX_Clean_Area(uint8_t *Buffer_Frame, uint16_t xPos_Start, uint16_t yPos_Start, uint16_t width, uint16_t height);
void GFX_Draw_Pixel(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t pxColor);
void GFX_Invertion_Area(uint8_t *Buffer_Frame, uint16_t xPos_Start, uint16_t yPos_Start, uint16_t width, uint16_t height);
void GFX_Invertion_Display(uint8_t *Buffer_Frame);

void GFX_Draw_Char_1_Byte(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, char Symbol, uint8_t Inversion);
void GFX_Draw_Char_2_Byte(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t Symbol, uint8_t inversion);
void GFX_Output_String(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, char *String, uint8_t setChSpacing, uint8_t Inversion);

void GFX_Draw_Line(uint8_t *Buffer_Frame, GFX_LineHandleTypeDef *hLine);
void GFX_Draw_Rectangle(uint8_t *Buffer_Frame, GFX_RectangleHandleTypeDef *hRectangle);
void GFX_Draw_Circle(uint8_t *Buffer_Frame, GFX_CircleHandleTypeDef *hCircle);
void GFX_Draw_Triangle(uint8_t *Buffer_Frame, GFX_TriangleHandleTypeDef *hTriangle);
void GFX_Draw_Arrow(uint8_t *Buffer_Frame, GFX_ArrowHandleTypeDef *hArrow);
void GFX_Draw_Arc(uint8_t *Buffer_Frame, GFX_ArcHandleTypeDef *hArc);
void GFX_Plotter_uint8_t(uint8_t *Buffer_Frame, GFX_PlotterHandleTypeDef *hPlot, uint8_t *data, uint32_t data_size, float data_step, uint8_t data_max);
void GFX_Plotter_uint16_t(uint8_t *Buffer_Frame, GFX_PlotterHandleTypeDef *hPlot, uint16_t *data, uint32_t data_size, float data_step, uint16_t data_max);
void GFX_Plotter_int(uint8_t *Buffer_Frame, GFX_PlotterHandleTypeDef *hPlot, int *data, uint32_t data_size, float data_step, int data_max);
void GFX_Plotter_float(uint8_t *Buffer_Frame, GFX_PlotterHandleTypeDef *hPlot, float *data, uint32_t data_size, float data_step, float data_max);



void __GFX_Draw_Line(uint8_t *Buffer_Frame, uint8_t xPos_Start, uint8_t yPos_Start, uint8_t xPos_End, uint8_t yPos_End, uint8_t pxColor);
void __GFX_Draw_Rectangle(uint8_t *Buffer_Frame, uint8_t xPos_Start, uint8_t yPos_Start, uint8_t rectangle_Width, uint8_t rectangle_Height, uint8_t pxColor);
void __GFX_Draw_Rectangle_Filled(uint8_t *Buffer_Frame, uint8_t xPos_Start, uint8_t yPos_Start, uint8_t rectangle_Width, uint8_t rectangle_Height, uint8_t pxColor);
void __GFX_Draw_Circle(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t circle_Radius, uint8_t pxColor);
void __GFX_Draw_Circle_Filled(uint8_t *Buffer_Frame, int8_t xPos, int8_t yPos, int8_t circle_Radius, uint8_t pxColor);
void __GFX_Draw_Triangle(uint8_t *Buffer_Frame, 
                         uint8_t xPos1, uint8_t yPos1, 
                         uint8_t xPos2, uint8_t yPos2, 
                         uint8_t xPos3, uint8_t yPos3, 
                         uint8_t pxColor);
void __GFX_Draw_Arrow(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t size, uint16_t angle, uint8_t pxColor);
void __GFX_Draw_Arrow_Ortho(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t size, uint16_t angle, uint8_t pxColor);
void __GFX_Draw_Arc(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t radius, uint16_t startAngle, uint16_t endAngle, uint8_t pxColor);
HAL_StatusTypeDef __GFX_StartPlot(uint8_t *Buffer_Frame, GFX_PlotterHandleTypeDef *hPlot);
void __GFX_Draw_Plotter_Value(uint8_t *Buffer_Frame, GFX_PlotterHandleTypeDef *hPlot);
#endif /* INC_PIXEL_GRAPHICS_H_ */
