Commit d30c7ddd authored by Vít Ramba's avatar Vít Ramba
Browse files

Changes based on feedback + new code

parent d2403640
//defining all the adressses
// Defining all the adressses
#define SERIAL_PORT_BASE 0xffffc000
#define SERP_RX_ST_REG_o 0x00
......@@ -28,31 +28,20 @@
#define LCD_FB_START 0xffe00000
#define LCD_FB_END 0xffe4afff
//display properities
#define LCD_WIDTH 480
#define LCD_HEIGHT 320
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define LCD_WIDTH 480 // Display width
#define LCD_HEIGHT 320 // Display height
#include "my_terminal.h"
#include "my_lcd_text.h"
#include "font_types.h"
/* Getting extern structs */
rgb_color_16b_t Gcolor16b;
font_descriptor_t font_winFreeSystem14x16;
/* Struct for knobs */
typedef struct {
typedef struct { // Struct for knobs
uint8_t R;
uint8_t G;
uint8_t B;
} knobs_t;
/* Pointer for drawing */
typedef struct {
typedef struct { // Pointer for drawing
uint16_t x;
uint16_t y;
} point_t;
......@@ -64,58 +53,62 @@ void show_color_on_led(uint64_t color);
void drawPoint(point_t *oldPoint, point_t *newPoint,
volatile uint16_t *lcd, uint16_t color_16b);
int setDrawColor(uint16_t *color16b, uint64_t *color64b, int wait_time);
void setDrawColor_knob(uint16_t *color16b, uint64_t *color64b,
volatile knobs_t *knobs);
/* The main function */
int main(void) {
//inicialization
//Inicialization
int small_font = 1;
int wait_time = 100; //number of cycles to wait
int inf_time = -1;
volatile uint16_t *lcd_t = (typeof(lcd_t))LCD_FB_START;
volatile knobs_t *knobs;
volatile knobs_t knobs = {0, 0, 0};
uint16_t color16b;
uint64_t color64b;
//Init position
loadKnobs(knobs);
// Init position
loadKnobs(&knobs);
point_t oldPoint;
setPoint(&oldPoint, knobs->R, knobs->G);
setPoint(&oldPoint, knobs.R, knobs.G);
point_t newPoint;
setPoint(&newPoint, knobs->R, knobs->G);
setPoint(&newPoint, knobs.R, knobs.G);
//LCD draw
// LCD draw
init_lcd_message(small_font, Gcolor16b.yellow, &font_winFreeSystem14x16);
setDrawColor(&color16b, &color64b, inf_time);
//the main code cycle
// The main code cycle
int print_c = 0;
int i_break = 0;
while (1)
{
loadKnobs(knobs);
setPoint(&newPoint, knobs->R, knobs->G);
uint8_t last_col = 0;
while (1) {
loadKnobs(&knobs);
setPoint(&newPoint, knobs.R, knobs.G);
drawPoint(&oldPoint, &newPoint, lcd_t, color16b);
i_break = setDrawColor(&color16b, &color64b, wait_time);
//end of code
if(i_break == 1)
{
i_break = setDrawColor(&color16b, &color64b, wait_time);
if(knobs.B != last_col) { // Changing color with knob
setDrawColor_knob(&color16b, &color64b, &knobs);
last_col = knobs.B;
}
if(i_break == 1) { // End of program
print_str_on_terminal("YOU QUITED THE GAME\n");
print_str_on_terminal("BYE BYE\n");
break;
}
//print of coordinates and info
if (print_c % 100 == 0)
{
if (print_c % 100 == 0) { // Print coordinates and info
print_coordinates(newPoint.x, newPoint.y);
print_str_on_terminal("HOLD BUTTON TO CHANGE COLOR\n");
print_c = 0;
}
++print_c;
}
while(1) {} // Infinite loop
return 0;
}
......@@ -152,12 +145,10 @@ void drawPoint(point_t *oldPoint, point_t *newPoint,
int ji = newPoint->y > oldPoint->y ? 1 : -1;
int i = 0;
int j = 0;
if (oldPoint->x + i != newPoint->x)
{
if (oldPoint->x + i != newPoint->x) {
i += ii;
}
if (oldPoint->y + j != newPoint->y)
{
if (oldPoint->y + j != newPoint->y) {
j += ji;
}
lcd[(oldPoint->y + j) * LCD_WIDTH + (oldPoint->x + i)] = color_16b;
......@@ -171,11 +162,38 @@ int setDrawColor(uint16_t *color16b, uint64_t *color64b, int wait_time) {
int ret = 0;
ret = pick_color_trm(color16b, color64b, wait_time);
if (ret == 'q')
{
if (ret == 'q') {
return 1;
}
show_color_on_led(*color64b);
return 0;
}
/* Changes draw color and led color based on B knob data */
void setDrawColor_knob(uint16_t *color16b, uint64_t *color64b,
volatile knobs_t *knobs) {
if(knobs->B < 51) {
print_str_on_terminal("PICKED: RED\n");
*color16b = Gcolor16b.red;
*color64b = Gcolor64b.red;
} else if(knobs->B < 102) {
print_str_on_terminal("PICKED: GREEN\n");
*color16b = Gcolor16b.green;
*color64b = Gcolor64b.green;
} else if(knobs->B < 153) {
print_str_on_terminal("PICKED: BLUE\n");
*color16b = Gcolor16b.blue;
*color64b = Gcolor64b.blue;
} else if(knobs->B < 204) {
print_str_on_terminal("PICKED: YELLOW\n");
*color16b = Gcolor16b.yellow;
*color64b = Gcolor64b.yellow;
} else if(knobs->B <= 255) {
print_str_on_terminal("PICKED: WHITE\n");
*color16b = Gcolor16b.white;
*color64b = Gcolor64b.white;
}
show_color_on_led(*color64b);
}
#ifndef __MY_LCD_TEXT__
#define __MY_LCD_TEXT__
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "font_types.h"
#include "my_terminal.h"
......@@ -72,4 +76,4 @@ void black_the_draw_frame(void);
//fcn to make the draw frame
void make_draw_frame(uint16_t pix_color);
#endif
\ No newline at end of file
#endif
......@@ -12,8 +12,6 @@
#define SERP_TX_DATA_REG_o 0x0c
#include <stdint.h>
#include <stdio.h>
#include "my_terminal.h"
#include "my_lcd_text.h"
......@@ -201,4 +199,4 @@ volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_tim
break;
}
return ret;
}
\ No newline at end of file
}
#ifndef __MY_TERMINAL__
#define __MY_TERMINAL__
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
//Gets one character from terminal input
volatile int terminalIn();
......@@ -28,4 +32,4 @@ void print_num_terminal(int num);
//Gets color choice from terminal input with and without timeout
volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_time);
#endif
\ No newline at end of file
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment