bruh
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,44 @@
|
||||
[
|
||||
{
|
||||
"file": "src/io.c",
|
||||
"arguments": [
|
||||
"gcc",
|
||||
"-I./include",
|
||||
"-g",
|
||||
"-c",
|
||||
"src/io.c",
|
||||
"-o",
|
||||
".obj/io.o"
|
||||
],
|
||||
"directory": "/home/oniic/Documents/sibsutisiv522s18/1Y-2H/prog",
|
||||
"output": ".obj/io.o"
|
||||
},
|
||||
{
|
||||
"file": "src/main.c",
|
||||
"arguments": [
|
||||
"gcc",
|
||||
"-I./include",
|
||||
"-g",
|
||||
"-c",
|
||||
"src/main.c",
|
||||
"-o",
|
||||
".obj/main.o"
|
||||
],
|
||||
"directory": "/home/oniic/Documents/sibsutisiv522s18/1Y-2H/prog",
|
||||
"output": ".obj/main.o"
|
||||
},
|
||||
{
|
||||
"file": "src/matrix.c",
|
||||
"arguments": [
|
||||
"gcc",
|
||||
"-I./include",
|
||||
"-g",
|
||||
"-c",
|
||||
"src/matrix.c",
|
||||
"-o",
|
||||
".obj/matrix.o"
|
||||
],
|
||||
"directory": "/home/oniic/Documents/sibsutisiv522s18/1Y-2H/prog",
|
||||
"output": ".obj/matrix.o"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef BITSTRUCT_H
|
||||
#define BITSTRUCT_H
|
||||
#include "include.h"
|
||||
#include "typedef.h"
|
||||
|
||||
#define LED_SET(led, field, value) \
|
||||
(led)->l = ((led)->l & LED_MASK_##field) | \
|
||||
(((uint64_t)(value) & ((1ULL << LED_SIZE_##field) - 1)) << LED_PADD_##field)
|
||||
|
||||
RGB_LED* create_led(uint16_t temp,uint8_t brg,uint8_t r,uint8_t g,uint8_t b);
|
||||
char modify_led(RGB_LED* led,LED_WICH wh,uint16_t num);
|
||||
void set_leds(MATRIX* m,LED_WICH wh, uint16_t num);
|
||||
void del_leds(MATRIX* m);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef CASE
|
||||
#define CASE
|
||||
|
||||
typedef struct{
|
||||
int* ptrFirst;
|
||||
int* ptrLast;
|
||||
} CASE;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef INCLUDE_H
|
||||
#define INCLUDE_H
|
||||
|
||||
// INCLUDE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdalign.h> //
|
||||
#include <stdint.h>
|
||||
|
||||
// DEFINE
|
||||
#define BUFF_MAX 10 //(char) <= 254
|
||||
#define IN_BUFF_CHARS 10 //(char) <= 254
|
||||
|
||||
//TypeDef
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef IO_H
|
||||
#define IO_H
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
// === io.c ===
|
||||
void del_cmd_list(CMD_GRP_ENUM grp);
|
||||
void create_cmd_list(CMD_GRP_ENUM grp,char* get[],int n);
|
||||
char buff_input(char *inbuff, char *_buff);
|
||||
char cmd_buff(char* _buff,CMD_GRP_ENUM grp);
|
||||
char get_matrix_num(void);
|
||||
int get_num(void);
|
||||
|
||||
void declarete_cmd_main();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef MATRIXSTRUCT_H
|
||||
#define MATRIXSTRUCT_H
|
||||
|
||||
#define MAX_MATRIX_ALIVE 21
|
||||
#include "typedef.h"
|
||||
|
||||
void create_matrix(int rows, int cols);
|
||||
void input(LED_WICH grp, unsigned char n);
|
||||
void input_matrix(unsigned char n);
|
||||
void free_matrix(unsigned char n);
|
||||
void get_matrix(unsigned char n);
|
||||
void logic_matrix(unsigned char n1, unsigned char n2);
|
||||
void edit_matrix(unsigned char n);
|
||||
void rand_matrix(unsigned char n);
|
||||
void copy_matrix(unsigned char n1, unsigned char n2);
|
||||
unsigned char is_Matrix_Exist(unsigned char n);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef TYPEDEF_H
|
||||
#define TYPEDEF_H
|
||||
#include "include.h"
|
||||
|
||||
|
||||
typedef struct __attribute__((aligned(4))){
|
||||
uint64_t l; // 14tmp 8brg 8r 8g 8b 4type 2mode
|
||||
} RGB_LED;
|
||||
|
||||
|
||||
typedef struct{
|
||||
RGB_LED** leds;
|
||||
unsigned int n;
|
||||
} LED_STRIP;
|
||||
|
||||
typedef enum{
|
||||
CMD_MAIN,
|
||||
CMD_LOGIC,
|
||||
CMD_EDIT,
|
||||
CMD_LED,
|
||||
|
||||
CMD_GRP_COUNT
|
||||
}CMD_GRP_ENUM;
|
||||
|
||||
typedef enum{
|
||||
CMD_MAIN_CREATE,
|
||||
CMD_MAIN_INPUT,
|
||||
CMD_MAIN_DEL,
|
||||
CMD_MAIN_SHOW,
|
||||
CMD_MAIN_LOGIC,
|
||||
CMD_MAIN_EDIT,
|
||||
CMD_MAIN_RAND,
|
||||
CMD_MAIN_COPY,
|
||||
CMD_MAIN_EXIT,
|
||||
CMD_MAIN_TEST,
|
||||
|
||||
CMD_MAIN_COUNT
|
||||
}CMD_MAIN_ENUM;
|
||||
|
||||
#define MASK_EXTRACT(start, bits) (((1ULL << (bits)) - 1) << (start))
|
||||
|
||||
typedef enum{
|
||||
LED_PADD_TEMP = 50,
|
||||
LED_SIZE_TEMP = 14,
|
||||
LED_MASK_TEMP = ~MASK_EXTRACT(LED_PADD_TEMP,LED_SIZE_TEMP),
|
||||
|
||||
LED_PADD_BR = 42,
|
||||
LED_SIZE_BR = 8,
|
||||
LED_MASK_BR = ~MASK_EXTRACT(LED_PADD_BR,LED_SIZE_BR),
|
||||
|
||||
LED_PADD_R = 34,
|
||||
LED_SIZE_R = 8,
|
||||
LED_MASK_R = ~MASK_EXTRACT(LED_PADD_R,LED_SIZE_R),
|
||||
|
||||
LED_PADD_G = 26,
|
||||
LED_SIZE_G = 8,
|
||||
LED_MASK_G = ~MASK_EXTRACT(LED_PADD_G,LED_SIZE_G),
|
||||
|
||||
LED_PADD_B = 18,
|
||||
LED_SIZE_B = 8,
|
||||
LED_MASK_B = ~MASK_EXTRACT(LED_PADD_B,LED_SIZE_B),
|
||||
|
||||
LED_PADD_TYPE = 14,
|
||||
LED_SIZE_TYPE = 8,
|
||||
LED_MASK_TYPE = ~MASK_EXTRACT(LED_PADD_TYPE,LED_SIZE_TYPE), // тип контроллера?
|
||||
|
||||
LED_PADD_MODE = 10,
|
||||
LED_SIZE_MODE = 4,
|
||||
LED_MASK_MODE = ~MASK_EXTRACT(LED_PADD_MODE,LED_SIZE_MODE), // 16 режимов
|
||||
|
||||
LED_PADD_SPEED = 2,
|
||||
LED_SIZE_SPEED = 8,
|
||||
LED_MASK_SPEED = ~MASK_EXTRACT(LED_PADD_SPEED,LED_SIZE_SPEED), // Скорость анимации режима
|
||||
|
||||
LED_PADD_SSCALE = 0,
|
||||
LED_SIZE_SSCALE = 2,
|
||||
LED_MASK_SSCALE = ~MASK_EXTRACT(LED_PADD_SSCALE,LED_SIZE_SSCALE) // множитель скорости ч.м.с
|
||||
}LED_INFO;
|
||||
|
||||
typedef enum{
|
||||
LED_TEMP,
|
||||
LED_BR,
|
||||
LED_R,LED_G,LED_B,
|
||||
LED_TYPE,
|
||||
LED_MODE,
|
||||
LED_SPEED,LED_SSCALE
|
||||
}LED_WICH;
|
||||
|
||||
typedef struct{
|
||||
unsigned int n;
|
||||
char** str;
|
||||
}CMD_LIST;
|
||||
|
||||
typedef struct{
|
||||
CMD_LIST* list[CMD_GRP_COUNT];
|
||||
}CMD_GRP_LIST;
|
||||
|
||||
typedef struct {
|
||||
int rows;
|
||||
int cols;
|
||||
RGB_LED*** led;
|
||||
} MATRIX;
|
||||
|
||||
typedef struct{
|
||||
unsigned int n;
|
||||
MATRIX** list;
|
||||
}MATRIX_LIST;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
create 3 3
|
||||
input 0
|
||||
1 2 3 4 5 6 7 8 9
|
||||
10 11 12 13 14 15 16 17 18
|
||||
19 20 21 22 23 24 25 26 27
|
||||
28 29 30 31 32 33 34 35 36
|
||||
37 38 39 40 41 42 43 44 45
|
||||
46 47 48 49 50 51 52 53 54
|
||||
55 56 57 58 59 60 61 62 63
|
||||
|
||||
show 0
|
||||
n
|
||||
|
||||
create 3 3
|
||||
rand 1
|
||||
show 1
|
||||
n
|
||||
|
||||
logic 0 1 >=
|
||||
n
|
||||
logic 0 0 ==
|
||||
n
|
||||
|
||||
edit 0
|
||||
point 1:1
|
||||
sub
|
||||
10
|
||||
exit
|
||||
|
||||
show 0
|
||||
n
|
||||
|
||||
copy 0 1
|
||||
show 1
|
||||
n
|
||||
|
||||
del 1
|
||||
exit
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c23",
|
||||
"cppStandard": "gnu++23",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"C_Cpp.errorSquiggles": "disabled"
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,46 @@
|
||||
typedef struct {
|
||||
unsigned int rgbd;
|
||||
_Alignas(unsigned int) unsigned short efg;
|
||||
} rgbled;
|
||||
|
||||
typedef struct {
|
||||
unsigned int rgbd;
|
||||
unsigned int fg;
|
||||
unsigned int e;
|
||||
} rgbled_bad;
|
||||
|
||||
rgbled_bad* create_bad_led();
|
||||
|
||||
// rgbled
|
||||
// | unsigned int rgbd |
|
||||
// dddd dddd rrrr rrrr gggg gggg bbbb bbbb
|
||||
// .... ftte eeee eeee ____ ____ ____ ____
|
||||
// |unsigned short efg| padding |
|
||||
// 8 байт
|
||||
|
||||
// rgbled_bad
|
||||
// | unsigned int rgbd |
|
||||
// dddd dddd rrrr rrrr gggg gggg bbbb bbbb
|
||||
// |unsigned int fg |
|
||||
// .... .... .... .... .... .... .... .ftt
|
||||
// | unsigned int e |
|
||||
// .... .... .... .... .... ...e eeee eeee
|
||||
// 12 байт
|
||||
|
||||
rgbled* create_led(void);
|
||||
|
||||
void set_Temp(rgbled* led, int tempK);
|
||||
void set_R(rgbled* led, int red);
|
||||
void set_G(rgbled* led, int green);
|
||||
void set_B(rgbled* led, int blue);
|
||||
void set_D(rgbled* led, int bright);
|
||||
void set_F(rgbled* led, int type);
|
||||
void set_T(rgbled* led, int work);
|
||||
int get_Temp(rgbled* led);
|
||||
int get_R(rgbled* led);
|
||||
int get_G(rgbled* led);
|
||||
int get_B(rgbled* led);
|
||||
int get_D(rgbled* led);
|
||||
int get_F(rgbled* led);
|
||||
int get_T(rgbled* led);
|
||||
void print_colorHEX(rgbled* led);
|
||||
@@ -0,0 +1,18 @@
|
||||
typedef struct {
|
||||
matrix2d** data;
|
||||
int size;
|
||||
int capacity;
|
||||
} tdQueue;
|
||||
|
||||
#define ERRALLOC do{ \
|
||||
fputs("Ошибка выделения памяти\n", \
|
||||
stderr); exit(EXIT_FAILURE); } while(0)
|
||||
|
||||
tdQueue* queue_create(void);
|
||||
void queue_decontruct(tdQueue* queue);
|
||||
bool queue_is_empty(tdQueue* queue);
|
||||
int queue_size(tdQueue* queue);
|
||||
void queue_enqueue(tdQueue* queue, matrix2d* data);
|
||||
matrix2d* queue_dequeue(tdQueue* queue);
|
||||
matrix2d* queue_peek(tdQueue* queue);
|
||||
void queue_clear(tdQueue* queue);
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "bitrgbled.h"
|
||||
#include "matrix2d.h"
|
||||
#include "contstruct.h"
|
||||
@@ -0,0 +1,16 @@
|
||||
typedef struct {
|
||||
const unsigned int x;
|
||||
const unsigned int y;
|
||||
void*** ptr;
|
||||
} matrix2d;
|
||||
|
||||
matrix2d* create_matrix2d(unsigned int x, unsigned int y);
|
||||
void deconstruct_matrix2d(matrix2d* mat);
|
||||
void print_matrix2d(matrix2d* mat);
|
||||
void fill_rand_matrix2d(matrix2d* mat);
|
||||
void set_elem_matrix2d(matrix2d* mat, void* elem, unsigned int x, unsigned int y);
|
||||
bool not_equal_mtrx(matrix2d* matA, matrix2d* matB);
|
||||
bool equal_mtrx(matrix2d* matA, matrix2d* matB);
|
||||
matrix2d* get_row_matrix2d(matrix2d* mat, int y);
|
||||
matrix2d* get_column_matrix2d(matrix2d* mat, int x);
|
||||
matrix2d* transpond_mtrx(matrix2d* mat);
|
||||
@@ -0,0 +1,39 @@
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -I./include -g
|
||||
LDFLAGS = -lm -g -lmenu
|
||||
|
||||
TARGET = matrix
|
||||
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = .obj
|
||||
|
||||
SRC = $(wildcard $(SRC_DIR)/*.c)
|
||||
OBJ = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CC) $(OBJ) -o $(TARGET) $(LDFLAGS)
|
||||
|
||||
# Компиляция .c -> .o в .obj/
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Создание папки для объектов
|
||||
$(OBJ_DIR):
|
||||
mkdir -p $(OBJ_DIR)
|
||||
|
||||
run:
|
||||
./matrix < input > output
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR) $(TARGET) output
|
||||
|
||||
.cc: $(OBJ)
|
||||
mkdir -p $(OBJ_DIR)
|
||||
@for src in $(SRC); do \
|
||||
obj=$(OBJ_DIR)/$$(basename $$src .c).o; \
|
||||
bear -- $(CC) $(CFLAGS) -c $$src -o $$obj; \
|
||||
done
|
||||
mv ./compile_commands.json .build/ || true
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,132 @@
|
||||
#include "includes.h"
|
||||
|
||||
static const char* control_type[] = {"Voltage", "PWM"};
|
||||
static const char* work_types[] = {"Glowing", "Blinking", "Breath"};
|
||||
|
||||
#define MASK_D 0xff000000
|
||||
#define MASK_R 0x00ff0000
|
||||
#define MASK_G 0x0000ff00
|
||||
#define MASK_B 0x000000ff
|
||||
#define SHIFT_D 24
|
||||
#define SHIFT_R 16
|
||||
#define SHIFT_G 8
|
||||
|
||||
#define MASK_F 0x0800
|
||||
#define MASK_T 0x0600
|
||||
#define MASK_E 0x01ff
|
||||
#define SHIFT_F 11
|
||||
#define SHIFT_T 9
|
||||
|
||||
rgbled* create_led() {
|
||||
rgbled* led = (rgbled*)malloc(sizeof(rgbled));
|
||||
set_Temp(led, 0);
|
||||
set_R(led, 0);
|
||||
set_D(led, 255);
|
||||
set_T(led, 0);
|
||||
set_F(led, 0);
|
||||
return led;
|
||||
}
|
||||
|
||||
rgbled_bad* create_bad_led() {
|
||||
rgbled_bad* led = (rgbled_bad*)malloc(sizeof(rgbled_bad));
|
||||
return led;
|
||||
}
|
||||
|
||||
void set_Temp(rgbled* led, int tempK) {
|
||||
if (tempK < 0 || tempK > 51200) return;
|
||||
tempK /= 100;
|
||||
int red, green, blue;
|
||||
if (tempK <= 66) {
|
||||
green = 99.4708025861 * log(tempK) - 161.1195681661;
|
||||
red = 255;
|
||||
if (tempK <= 19) {
|
||||
blue = 0;
|
||||
} else {
|
||||
blue = 138.5177312231 * log((tempK)-10) - 305.0447927307;
|
||||
}
|
||||
} else {
|
||||
red = 329.698727446 * powf((tempK-60), -0.1332047592);
|
||||
green = 288.1221695283 * powf((tempK - 60), -0.0755148492);
|
||||
blue = 255;
|
||||
}
|
||||
set_R(led, red);
|
||||
set_G(led, green);
|
||||
set_B(led, blue);
|
||||
led->efg = (led->efg & ~MASK_E) | ((tempK << 0) & MASK_E);
|
||||
}
|
||||
|
||||
void set_R(rgbled* led, int red) {
|
||||
if (red < 0 || red > 255) return;
|
||||
led->rgbd = (led->rgbd & ~MASK_R) | ((red << SHIFT_R) & MASK_R);
|
||||
led->efg = (led->efg & ~MASK_E) | ((0) & MASK_E);
|
||||
}
|
||||
|
||||
void set_G(rgbled* led, int green) {
|
||||
if (green < 0 || green > 255) return;
|
||||
led->rgbd = (led->rgbd & ~MASK_G) | ((green << SHIFT_G) & MASK_G);
|
||||
led->efg = (led->efg & ~MASK_E) | ((0) & MASK_E);
|
||||
}
|
||||
|
||||
void set_B(rgbled* led, int blue) {
|
||||
if (blue < 0 || blue > 255) return;
|
||||
led->rgbd = (led->rgbd & ~MASK_B) | ((blue << 0) & MASK_B);
|
||||
led->efg = (led->efg & ~MASK_E) | ((0) & MASK_E);
|
||||
}
|
||||
|
||||
void set_D(rgbled* led, int bright) {
|
||||
if (bright < 0 || bright > 255) return;
|
||||
led->rgbd = (led->rgbd & ~MASK_D) | ((bright << SHIFT_D) & MASK_D);
|
||||
}
|
||||
|
||||
void set_T(rgbled* led, int work) {
|
||||
if (work < 0 || work > 3) return;
|
||||
led->efg = (led->efg & ~MASK_T) | ((work << SHIFT_T) & MASK_T);
|
||||
}
|
||||
|
||||
void set_F(rgbled* led, int type) {
|
||||
if (type < 0 || type > 1) return;
|
||||
led->efg = (led->efg & ~MASK_F) | ((type << SHIFT_F) & MASK_F);
|
||||
}
|
||||
|
||||
int get_Temp(rgbled* led) {
|
||||
return (led->efg & MASK_E)*100;
|
||||
}
|
||||
|
||||
int get_R(rgbled* led) {
|
||||
return (led->rgbd & MASK_R) >> SHIFT_R;
|
||||
}
|
||||
|
||||
int get_G(rgbled* led) {
|
||||
return (led->rgbd & MASK_G) >> SHIFT_G;
|
||||
}
|
||||
|
||||
int get_B(rgbled* led) {
|
||||
return (led->rgbd & MASK_B);
|
||||
}
|
||||
|
||||
int get_D(rgbled* led) {
|
||||
return (led->rgbd & MASK_D) >> SHIFT_D;
|
||||
}
|
||||
|
||||
int get_F(rgbled* led) {
|
||||
return (led->efg & MASK_F) >> SHIFT_F;
|
||||
}
|
||||
|
||||
int get_T(rgbled* led) {
|
||||
return (led->efg & MASK_T) >> SHIFT_T;
|
||||
}
|
||||
|
||||
void hex_color(int num) {
|
||||
printf("%c%c", ((num/16) > 9) ? 'a'+(num / 16)-10 : '0'+(num/16), ((num%16) > 9) ? 'a'+(num%16)-10 : '0'+(num%16));
|
||||
}
|
||||
|
||||
void print_colorHEX(rgbled* led) {
|
||||
int r = get_R(led)*(get_D(led)/255);
|
||||
int g = get_G(led)*(get_D(led)/255);
|
||||
int b = get_B(led)*(get_D(led)/255);
|
||||
//printf("(%d, %d, %d) ", r, g, b);
|
||||
putchar('#');
|
||||
hex_color(r);
|
||||
hex_color(g);
|
||||
hex_color(b);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "includes.h"
|
||||
|
||||
tdQueue* queue_create() {
|
||||
tdQueue* queue = (tdQueue*)malloc(sizeof(tdQueue));
|
||||
queue->data = NULL;
|
||||
queue->size = 0;
|
||||
queue->capacity = 0;
|
||||
return queue;
|
||||
}
|
||||
|
||||
void queue_decontruct(tdQueue* queue)
|
||||
{
|
||||
int i = 0;
|
||||
while ((i < queue->size) && (queue->data[i] != NULL)) {
|
||||
deconstruct_matrix2d(queue->data[i]);
|
||||
i++;
|
||||
}
|
||||
free(queue);
|
||||
}
|
||||
|
||||
bool queue_is_empty(tdQueue* queue)
|
||||
{
|
||||
return queue->size == 0;
|
||||
}
|
||||
|
||||
int queue_size(tdQueue* queue)
|
||||
{
|
||||
return queue->size;
|
||||
}
|
||||
|
||||
void queue_enqueue(tdQueue* queue, matrix2d* data)
|
||||
{
|
||||
if (queue->capacity == queue->size) {
|
||||
if (queue->capacity) {
|
||||
queue->capacity = ceil(queue->capacity*sqrt(2));
|
||||
queue->data = (matrix2d**)realloc(queue->data, sizeof(matrix2d*)*(queue->capacity));
|
||||
} else {
|
||||
queue->capacity = ceil(sqrt(2));
|
||||
queue->data = (matrix2d**)malloc(sizeof(matrix2d*)*(queue->capacity));
|
||||
}
|
||||
}
|
||||
queue->data[queue->size++] = data;
|
||||
}
|
||||
|
||||
matrix2d* queue_dequeue(tdQueue* queue)
|
||||
{
|
||||
if (queue->data == NULL) return NULL;
|
||||
matrix2d* data = queue->data[0];
|
||||
for (int i = 1; i < queue->size; i++) {
|
||||
queue->data[i-1] = queue->data[i];
|
||||
}
|
||||
queue->size -= 1;
|
||||
return data;
|
||||
}
|
||||
|
||||
matrix2d* queue_peek(tdQueue* queue)
|
||||
{
|
||||
if (queue->data == NULL) return NULL;
|
||||
matrix2d* data = queue->data[0];
|
||||
return data;
|
||||
}
|
||||
|
||||
void queue_clear(tdQueue* queue)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < queue->capacity && queue->data[i] != NULL)
|
||||
deconstruct_matrix2d((matrix2d*) (queue->data)[i++]);
|
||||
queue->size = 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "includes.h"
|
||||
|
||||
int main(void) {
|
||||
tdQueue* queue = queue_create();
|
||||
printf("queue is empty? %i\n", queue_is_empty(queue));
|
||||
printf("ptr - %p %p\n", queue_peek(queue), queue_dequeue(queue));
|
||||
matrix2d* mat = create_matrix2d(2, 2);
|
||||
int temp = -1;
|
||||
rgbled* led = create_led();
|
||||
for (int y = 0; y < mat->y; y++)
|
||||
for (int x = 0; x < mat->x; x++) {
|
||||
led = create_led();
|
||||
while(scanf("%d", &temp) != 1 || temp < 0 || temp >= 511000) continue;
|
||||
set_Temp(led, temp);
|
||||
set_elem_matrix2d(mat, (void*)led, x, y);
|
||||
temp = -1;
|
||||
}
|
||||
queue_enqueue(queue, mat);
|
||||
printf("queue is empty? %i\n", queue_is_empty(queue));
|
||||
printf("Size queue? %i (%i)\n", queue_size(queue), queue->capacity);
|
||||
print_matrix2d(queue_peek(queue));
|
||||
for (int i = 0; i < 500000; i++) {
|
||||
mat = create_matrix2d(10, 10);
|
||||
fill_rand_matrix2d(mat);
|
||||
queue_enqueue(queue, mat);
|
||||
}
|
||||
printf("Size queue? %i (%i)\n", queue_size(queue), queue->capacity);
|
||||
mat = queue_dequeue(queue);
|
||||
print_matrix2d(mat);
|
||||
deconstruct_matrix2d(mat);
|
||||
printf("Size queue? %i (%i)\n", queue_size(queue), queue->capacity);
|
||||
tdQueue* queue_b = queue_create();
|
||||
for (int i = 0; i < 500000; i++) {
|
||||
mat = create_matrix2d(10, 10);
|
||||
fill_rand_matrix2d(mat);
|
||||
queue_enqueue(queue_b, mat);
|
||||
}
|
||||
printf("Size queue_b? %i (%i)\n", queue_size(queue_b), queue_b->capacity);
|
||||
queue_decontruct(queue);
|
||||
queue_decontruct(queue_b);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "includes.h"
|
||||
|
||||
int getrand(int min, int max)
|
||||
{
|
||||
return (int)rand() / (RAND_MAX + 1.0) * (max - min) + min;
|
||||
}
|
||||
|
||||
matrix2d* create_matrix2d(unsigned int x, unsigned int y)
|
||||
{
|
||||
matrix2d* mat = (matrix2d*)malloc(sizeof(matrix2d));
|
||||
mat->ptr = (void***)malloc(sizeof(void**) * x);
|
||||
for (int i = 0; i < x; i++)
|
||||
mat->ptr[i] = (void**)malloc(sizeof(void*) * y);
|
||||
for (int i = 0; i < x; i++)
|
||||
for (int j = 0; j < y; j++)
|
||||
mat->ptr[i][j] = (void*)create_led();
|
||||
*((unsigned int*)&(mat->x)) = x;
|
||||
*((unsigned int*)&(mat->y)) = y;
|
||||
return mat;
|
||||
}
|
||||
|
||||
void deconstruct_matrix2d( matrix2d* mat)
|
||||
{
|
||||
for (int i = 0; i < mat->x; i++){
|
||||
for (int j = 0; j < mat->y; j++)
|
||||
free(mat->ptr[i][j]);
|
||||
free(mat->ptr[i]);
|
||||
}
|
||||
free(mat->ptr);
|
||||
free(mat);
|
||||
}
|
||||
|
||||
matrix2d* get_row_matrix2d(matrix2d* mat, int y)
|
||||
{
|
||||
if (y >= mat->y)
|
||||
return NULL;
|
||||
matrix2d* res = create_matrix2d( mat->x, 1);
|
||||
for (int x = 0; x < mat->x; x++)
|
||||
memcpy(res->ptr[x][0], mat->ptr[x][y], sizeof(rgbled));
|
||||
return res;
|
||||
}
|
||||
|
||||
matrix2d* get_column_matrix2d(matrix2d* mat, int x)
|
||||
{
|
||||
if (x >= mat->x)
|
||||
return NULL;
|
||||
matrix2d* res = create_matrix2d(1, mat->y);
|
||||
for (int y = 0; y < mat->y; y++)
|
||||
memcpy(res->ptr[0][y], mat->ptr[x][y], sizeof(rgbled));
|
||||
return res;
|
||||
}
|
||||
|
||||
void print_matrix2d(matrix2d* mat)
|
||||
{
|
||||
for (int y = 0; y < mat->y; y++) {
|
||||
for (int x = 0; x < mat->x; x++) {
|
||||
print_colorHEX((rgbled*)mat->ptr[x][y]);
|
||||
putchar(' ');
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void fill_rand_matrix2d(matrix2d* mat)
|
||||
{
|
||||
for (int y = 0; y < mat->y; y++)
|
||||
for (int x = 0; x < mat->x; x++) {
|
||||
set_R(mat->ptr[x][y], getrand(0, 255));
|
||||
set_G(mat->ptr[x][y], getrand(0, 255));
|
||||
set_B(mat->ptr[x][y], getrand(0, 255));
|
||||
}
|
||||
}
|
||||
|
||||
matrix2d* transpond_mtrx(matrix2d* mat)
|
||||
{
|
||||
matrix2d* res = create_matrix2d(mat->y, mat->x);
|
||||
for (int y = 0; y < mat->y; y++)
|
||||
for (int x = 0; x < mat->x; x++)
|
||||
memcpy(res->ptr[y][x], mat->ptr[x][y], sizeof(rgbled));
|
||||
return res;
|
||||
}
|
||||
|
||||
bool equal_mtrx(matrix2d* matA, matrix2d* matB)
|
||||
{
|
||||
if (matA->x != matB->x || matA->y != matB->y)
|
||||
return false;
|
||||
for (int x = 0; x < matA->x; x++)
|
||||
for (int y = 0; y < matA->y; y++) {
|
||||
rgbled* ledA = (rgbled*)matA->ptr[x][y];
|
||||
rgbled* ledB = (rgbled*)matB->ptr[x][y];
|
||||
if ((ledA->rgbd != ledB->rgbd) || (ledA->efg != ledB->efg))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool not_equal_mtrx(matrix2d* matA, matrix2d* matB)
|
||||
{
|
||||
if (matA->x != matB->x || matA->y != matB->y)
|
||||
return true;
|
||||
for (int x = 0; x < matA->x; x++)
|
||||
for (int y = 0; y < matA->y; y++) {
|
||||
rgbled* ledA = (rgbled*)matA->ptr[x][y];
|
||||
rgbled* ledB = (rgbled*)matB->ptr[x][y];
|
||||
if ((ledA->rgbd == ledB->rgbd) && (ledA->efg == ledB->efg))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void set_elem_matrix2d(matrix2d* mat, void* elem, unsigned int x, unsigned int y)
|
||||
{
|
||||
free(mat->ptr[x][y]);
|
||||
mat->ptr[x][y] = elem;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
10000 8000
|
||||
2500 6500
|
||||
@@ -0,0 +1,40 @@
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -I./include -g
|
||||
LDFLAGS = -lncursesw -lpanel -lmenu
|
||||
|
||||
TARGET = matrix
|
||||
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = .obj
|
||||
|
||||
SRC = $(wildcard $(SRC_DIR)/*.c)
|
||||
OBJ = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CC) $(OBJ) -o $(TARGET) $(LDFLAGS)
|
||||
|
||||
# Компиляция .c -> .o в .obj/
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Создание папки для объектов
|
||||
$(OBJ_DIR):
|
||||
mkdir -p $(OBJ_DIR)
|
||||
|
||||
run:
|
||||
./matrix < input > output
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR) $(TARGET) output
|
||||
|
||||
.cc: $(OBJ)
|
||||
mkdir -p $(OBJ_DIR)
|
||||
@for src in $(SRC); do \
|
||||
obj=$(OBJ_DIR)/$$(basename $$src .c).o; \
|
||||
bear -- $(CC) $(CFLAGS) -c $$src -o $$obj; \
|
||||
done
|
||||
mv ./compile_commands.json .build/ || true
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,89 @@
|
||||
/* === === === bitstruct.c === === === */
|
||||
|
||||
#include "include.h"
|
||||
#include "typedef.h"
|
||||
#include "bitstruct.h"
|
||||
//extern LED_STRIP strip;
|
||||
|
||||
/*void declarate_led_strip(){
|
||||
strip.led=NULL;
|
||||
strip.n=0;
|
||||
} */
|
||||
|
||||
|
||||
RGB_LED* create_led(uint16_t temp,uint8_t brg,uint8_t r,uint8_t g,uint8_t b)
|
||||
{
|
||||
RGB_LED* led = malloc(sizeof(RGB_LED));
|
||||
if (!led) return NULL;
|
||||
|
||||
{
|
||||
led->l = 0;
|
||||
LED_SET(led, TEMP, temp);
|
||||
LED_SET(led, BR, brg);
|
||||
LED_SET(led, R, r);
|
||||
LED_SET(led, G, g);
|
||||
LED_SET(led, B, b);
|
||||
}
|
||||
|
||||
// strip.led = (RGB_LED**)realloc(strip.led,strip.n+1*sizeof(RGB_LED*));
|
||||
// strip.led[strip.n] = led;
|
||||
// strip.n++;
|
||||
return led;
|
||||
}
|
||||
|
||||
char modify_led(RGB_LED* led,LED_WICH wh,uint16_t num){
|
||||
switch(wh){
|
||||
case LED_TEMP:
|
||||
LED_SET(led, TEMP, num);
|
||||
break;
|
||||
case LED_BR:
|
||||
LED_SET(led, BR, num);
|
||||
break;
|
||||
case LED_R:
|
||||
LED_SET(led, R, num);
|
||||
break;
|
||||
case LED_G:
|
||||
LED_SET(led, G, num);
|
||||
break;
|
||||
case LED_B:
|
||||
LED_SET(led, B, num);
|
||||
break;
|
||||
case LED_TYPE:
|
||||
LED_SET(led, TYPE, num);
|
||||
break;
|
||||
case LED_MODE:
|
||||
LED_SET(led, MODE, num);
|
||||
break;
|
||||
case LED_SPEED:
|
||||
LED_SET(led, SPEED, num);
|
||||
break;
|
||||
case LED_SSCALE:
|
||||
LED_SET(led, SSCALE, num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_leds(MATRIX* m,LED_WICH wh, uint16_t num){
|
||||
for (int i = 0; i < m->rows; i++){
|
||||
for (int j = 0; j < m->cols; j++){
|
||||
modify_led(m->led[i][j], wh, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void del_leds(MATRIX* m){
|
||||
for (int i = 0; i < m->rows; i++){
|
||||
for (int j = 0; j < m->cols; j++){
|
||||
free(m->led[i][j]);
|
||||
}
|
||||
free(m->led[i]);
|
||||
}
|
||||
free(m->led);
|
||||
}
|
||||
|
||||
/*void del_strip(){
|
||||
for(int i = strip.n-1;i>=0;i--)
|
||||
del_led(i);
|
||||
}*/
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/* === === === io.c === === === */
|
||||
|
||||
#include "include.h"
|
||||
#include "typedef.h"
|
||||
#include "io.h"
|
||||
|
||||
CMD_GRP_LIST cmd_list;
|
||||
|
||||
void create_cmd_list(CMD_GRP_ENUM grp,char* get[],int n){
|
||||
if(grp == CMD_GRP_COUNT)return;
|
||||
|
||||
CMD_LIST* newlist = (CMD_LIST*)malloc(sizeof(CMD_LIST));
|
||||
newlist->str = (char**)malloc(n*sizeof(char*));
|
||||
for(int i = 0;i<n;i++){
|
||||
newlist->str[i] = (char*)malloc((strlen(get[i])+1)*sizeof(char));
|
||||
strcpy(newlist->str[i],get[i]);
|
||||
}
|
||||
|
||||
del_cmd_list(grp);
|
||||
cmd_list.list[grp] = newlist;
|
||||
cmd_list.list[grp]->n=n;
|
||||
}
|
||||
|
||||
void del_cmd_list(CMD_GRP_ENUM grp){
|
||||
CMD_LIST** list = &cmd_list.list[grp];
|
||||
if((*list)==NULL) return;
|
||||
for(int i = 0; i < (*list)->n; i++)
|
||||
free((*list)->str[i]);
|
||||
free((*list)->str);
|
||||
free(*list);
|
||||
}
|
||||
|
||||
void declarete_cmd_main(){
|
||||
create_cmd_list(CMD_MAIN,(char*[])
|
||||
{"create","input","del","show",
|
||||
"logic","edit","rand","copy",
|
||||
"exit","test"},10);
|
||||
}
|
||||
|
||||
char buff_input(char *inbuff, char *_buff){
|
||||
|
||||
*inbuff = 0;
|
||||
{ // INPUT
|
||||
char ch;
|
||||
memset(_buff, 0, BUFF_MAX);
|
||||
while((ch=getchar())>' '&&*inbuff<BUFF_MAX){
|
||||
*(_buff+*inbuff)=(int)ch;
|
||||
(*inbuff)++;
|
||||
}
|
||||
if(ch<= 4)return -1;
|
||||
_buff[*inbuff] = '\0';
|
||||
}
|
||||
|
||||
|
||||
if (_buff[0]>='a' && _buff[0] <= 'z'){
|
||||
char cmd = cmd_buff(_buff,CMD_MAIN);
|
||||
if(cmd==15)return -1;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char cmd_buff(char* _buff,CMD_GRP_ENUM grp){
|
||||
unsigned int n = cmd_list.list[grp]->n;
|
||||
char** list = cmd_list.list[grp]->str;
|
||||
|
||||
for (int i = 0;i<n;i++){
|
||||
char flag = 1;
|
||||
for(int j = 0;*(list[i]+j)!='\0';j++){
|
||||
if (_buff[j]!=*(list[i]+j)){
|
||||
flag = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag) return i+1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char get_matrix_num(void){
|
||||
extern MATRIX_LIST matrix_l;
|
||||
char inbuff;
|
||||
char _buff[BUFF_MAX];
|
||||
while(buff_input(&inbuff,_buff)>0&&*_buff>' ');
|
||||
|
||||
long int num = 0;
|
||||
char flagIsDec = 1;
|
||||
{ // GetNum
|
||||
int i = 0;
|
||||
if(_buff[0]=='-'){i++;flagIsDec = -1;}
|
||||
|
||||
for(; i<inbuff;i++)
|
||||
if(_buff[i]>= '0' && _buff[i] <= '9')
|
||||
num = (num*10) + (_buff[i]-'0');
|
||||
num *= flagIsDec;
|
||||
}
|
||||
if (num>=matrix_l.n)num = matrix_l.n;
|
||||
if (num<0)num = 0;
|
||||
return num;
|
||||
}
|
||||
|
||||
int get_num(void){
|
||||
char inbuff;
|
||||
char _buff[BUFF_MAX];
|
||||
while(buff_input(&inbuff,_buff)>0&&*_buff>' ');
|
||||
|
||||
long int num = 0;
|
||||
char flagIsDec = 1;
|
||||
{ // GetNum
|
||||
int i = 0;
|
||||
if(_buff[0]=='-'){i++;flagIsDec = -1;}
|
||||
|
||||
for(; i<inbuff;i++)
|
||||
if(_buff[i]>= '0' && _buff[i] <= '9')
|
||||
num = (num*10) + (_buff[i]-'0');
|
||||
num *= flagIsDec;
|
||||
}
|
||||
if (num>INT_MAX)num = INT_MAX;
|
||||
if (num<INT_MIN)num = INT_MIN;
|
||||
return (int)num;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/* === === === main.c === === === */
|
||||
|
||||
#include "include.h"
|
||||
#include "matrixstruct.h"
|
||||
#include "io.h"
|
||||
|
||||
LED_STRIP strip;
|
||||
MATRIX_LIST matrix_l = {0};
|
||||
|
||||
int main(void) {
|
||||
declarete_cmd_main();
|
||||
|
||||
char mode;
|
||||
|
||||
do {
|
||||
char inbuff;
|
||||
char _buff[BUFF_MAX];
|
||||
unsigned char n1, n2;
|
||||
|
||||
mode = buff_input(&inbuff, _buff);
|
||||
|
||||
switch (mode) {
|
||||
case CMD_MAIN_CREATE:
|
||||
n1 = get_num();
|
||||
n2 = get_num();
|
||||
create_matrix(n1, n2);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_INPUT:
|
||||
n1 = get_matrix_num();
|
||||
n1 = is_Matrix_Exist(n1);
|
||||
input_matrix(n1);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_DEL:
|
||||
n1 = get_matrix_num();
|
||||
n1 = is_Matrix_Exist(n1);
|
||||
free_matrix(n1);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_SHOW:
|
||||
n1 = get_matrix_num();
|
||||
n1 = is_Matrix_Exist(n1);
|
||||
get_matrix(n1);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_LOGIC:
|
||||
n1 = get_matrix_num();
|
||||
n1 = is_Matrix_Exist(n1);
|
||||
n2 = get_matrix_num();
|
||||
n2 = is_Matrix_Exist(n2);
|
||||
logic_matrix(n1, n2);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_EDIT:
|
||||
n1 = get_matrix_num();
|
||||
n1 = is_Matrix_Exist(n1);
|
||||
edit_matrix(n1);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_RAND:
|
||||
n1 = get_matrix_num();
|
||||
n1 = is_Matrix_Exist(n1);
|
||||
rand_matrix(n1);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_COPY:
|
||||
n1 = get_matrix_num();
|
||||
n1 = is_Matrix_Exist(n1);
|
||||
n2 = get_matrix_num();
|
||||
n2 = is_Matrix_Exist(n2);
|
||||
copy_matrix(n1, n2);
|
||||
break;
|
||||
|
||||
case CMD_MAIN_EXIT:
|
||||
mode = -1;
|
||||
break;
|
||||
|
||||
case CMD_MAIN_TEST: {
|
||||
alignas(16)RGB_LED alignLed;
|
||||
RGB_LED nalignLed;
|
||||
printf("SizeOf aligned struct: %lu\nSizeOf notAligned struct: %lu",
|
||||
alignof(alignLed), alignof(nalignLed));
|
||||
break;
|
||||
}
|
||||
|
||||
case -1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
} while (mode >= 0);
|
||||
|
||||
del_cmd_list(CMD_MAIN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
/* === === === matrix.c === === === */
|
||||
|
||||
#include "include.h"
|
||||
#include "matrixstruct.h"
|
||||
#include "bitstruct.h"
|
||||
#include "io.h"
|
||||
|
||||
extern MATRIX_LIST matrix_l;
|
||||
|
||||
void create_matrix(int rows,int cols) {
|
||||
MATRIX* m = (MATRIX*)malloc(sizeof(MATRIX));
|
||||
m->rows = rows;
|
||||
m->cols = cols;
|
||||
m->led = (RGB_LED***)malloc(rows * sizeof(RGB_LED**));
|
||||
|
||||
for (int i = 0; i < rows; i++){
|
||||
m->led[i] = (RGB_LED**)malloc(cols * sizeof(RGB_LED*));
|
||||
for (int j = 0; j < cols; j++)
|
||||
m->led[i][j] = create_led(0,0,0,0,0);
|
||||
}
|
||||
|
||||
matrix_l.list = (MATRIX**)realloc(matrix_l.list,(matrix_l.n+1)*sizeof(MATRIX*));
|
||||
matrix_l.list[matrix_l.n] = m;
|
||||
matrix_l.n++;
|
||||
}
|
||||
|
||||
void input(LED_WICH grp,unsigned char n){
|
||||
int maxrow = matrix_l.list[n]->rows;
|
||||
int maxcol = matrix_l.list[n]->cols;
|
||||
RGB_LED*** led = matrix_l.list[n]->led;
|
||||
|
||||
for(int r = 0;r<maxrow;r++){
|
||||
for(int c = 0; c < maxcol;c++){
|
||||
int num = get_num();
|
||||
modify_led(led[r][c], grp, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void input_matrix(unsigned char n){
|
||||
input(LED_R ,n);
|
||||
input(LED_G ,n);
|
||||
input(LED_B ,n);
|
||||
input(LED_TEMP ,n);
|
||||
input(LED_BR ,n);
|
||||
input(LED_TYPE ,n);
|
||||
input(LED_MODE ,n);
|
||||
}
|
||||
|
||||
void free_matrix(unsigned char n){
|
||||
if(n >= matrix_l.n) return;
|
||||
MATRIX* m = matrix_l.list[n];
|
||||
for (int i = 0; i < m->rows; i++){
|
||||
for (int j = 0; j < m->cols; j++)
|
||||
free(m->led[i][j]);
|
||||
free(m->led[i]);
|
||||
}
|
||||
free(m->led);
|
||||
free(matrix_l.list[n]);
|
||||
|
||||
for(int i = n; i < matrix_l.n-1; i++)
|
||||
matrix_l.list[i] = matrix_l.list[i+1];
|
||||
|
||||
matrix_l.n--;
|
||||
if (matrix_l.n == 0) {
|
||||
free(matrix_l.list);
|
||||
matrix_l.list = NULL;
|
||||
} else {
|
||||
matrix_l.list = realloc(matrix_l.list, matrix_l.n * sizeof(MATRIX*));
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t extract(uint64_t l, int padd, int size){
|
||||
return (l >> padd) & ((1ULL << size) - 1);
|
||||
}
|
||||
|
||||
void get_matrix(unsigned char n){
|
||||
int rows = matrix_l.list[n]->rows;
|
||||
int cols = matrix_l.list[n]->cols;
|
||||
RGB_LED*** led = matrix_l.list[n]->led;
|
||||
|
||||
for(int r = 0;r<rows;r++){
|
||||
for(int c = 0;c<cols;c++){
|
||||
RGB_LED* l=led[r][c];
|
||||
printf("%03llu,%03llu ",
|
||||
extract(l->l, LED_PADD_R, LED_SIZE_R),
|
||||
extract(l->l, LED_PADD_TEMP, LED_SIZE_TEMP));
|
||||
}
|
||||
putchar('\n');
|
||||
|
||||
for(int c = 0;c<cols;c++){
|
||||
RGB_LED* l=led[r][c];
|
||||
printf("%03llu,%03llu ",
|
||||
extract(l->l, LED_PADD_G, LED_SIZE_G),
|
||||
extract(l->l, LED_PADD_BR, LED_SIZE_BR));
|
||||
}
|
||||
putchar('\n');
|
||||
|
||||
for(int c = 0;c<cols;c++){
|
||||
RGB_LED* l=led[r][c];
|
||||
printf("%03llu,%02llu%llu ",
|
||||
extract(l->l, LED_PADD_B, LED_SIZE_B),
|
||||
extract(l->l, LED_PADD_TYPE, LED_SIZE_TYPE),
|
||||
extract(l->l, LED_PADD_MODE, LED_SIZE_MODE));
|
||||
}
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
char edit_is_cmd(char _buff[BUFF_MAX],char inbuff,unsigned char n,int* r,int* c,char* mode,char *wich){
|
||||
int rows = matrix_l.list[n]->rows;
|
||||
int cols = matrix_l.list[n]->cols;
|
||||
|
||||
create_cmd_list(CMD_EDIT,(char*[]){"point","add","sub","exit"},4);
|
||||
char loc_cmd = cmd_buff(_buff,CMD_EDIT);
|
||||
|
||||
if (loc_cmd == 1) {
|
||||
buff_input(&inbuff, _buff);
|
||||
long pr = 0, pc = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < inbuff && (_buff[i] != ':' && _buff[i] != ',' && _buff[i] != '.'); i++)
|
||||
if (_buff[i] >= '0' && _buff[i] <= '9')
|
||||
pr = pr * 10 + (_buff[i] - '0');
|
||||
|
||||
for (i++; i < inbuff; i++)
|
||||
if (_buff[i] >= '0' && _buff[i] <= '9')
|
||||
pc = pc * 10 + (_buff[i] - '0');
|
||||
|
||||
if (pr < rows && pc < cols) {
|
||||
*r = (int)pr;
|
||||
*c = (int)pc;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (loc_cmd == 2) { *mode = *mode==1?0:1; return 1; }
|
||||
if (loc_cmd == 3) { *mode = *mode==2?0:2; return 1; }
|
||||
if (loc_cmd == 4) { *mode = *mode==3?0:3; return 1; }
|
||||
|
||||
create_cmd_list(CMD_LED,(char*[]){"temp","brg","r","g","b","type","mode","speed","sscale"},9);
|
||||
char wich_cmd = cmd_buff(_buff,CMD_LED) - 1;
|
||||
|
||||
if (wich_cmd >= 0)
|
||||
*wich = (*wich != wich_cmd && wich_cmd+1) ? wich_cmd : *wich;
|
||||
|
||||
return 0;
|
||||
}
|
||||
void edit_matrix(unsigned char n) {
|
||||
int rows = matrix_l.list[n]->rows;
|
||||
int cols = matrix_l.list[n]->cols;
|
||||
char inbuff;
|
||||
char _buff[BUFF_MAX];
|
||||
|
||||
RGB_LED*** led = matrix_l.list[n]->led;
|
||||
|
||||
int r = 0, c = 0;
|
||||
char mode = 0;
|
||||
char wich = 0;
|
||||
|
||||
while (r < rows) {
|
||||
char input = buff_input(&inbuff,_buff);
|
||||
if (mode == 3) break;
|
||||
if (input == -1) break;
|
||||
|
||||
if(edit_is_cmd(_buff,inbuff,n,&r,&c,&mode,&wich)) continue;
|
||||
|
||||
long num = 0;
|
||||
int i = 0, sign = 1;
|
||||
|
||||
if (inbuff > 0 && _buff[0] == '-') { sign = -1; i++; }
|
||||
for (; i < inbuff; i++) {
|
||||
if (_buff[i] >= '0' && _buff[i] <= '9')
|
||||
num = num * 10 + (_buff[i] - '0');
|
||||
}
|
||||
num *= sign;
|
||||
|
||||
uint64_t old = 0;
|
||||
switch(wich){
|
||||
case LED_TEMP:
|
||||
old = (led[r][c]->l >> LED_PADD_TEMP) &
|
||||
((1ULL<<LED_SIZE_TEMP)-1); break;
|
||||
case LED_BR:
|
||||
old = (led[r][c]->l >> LED_PADD_BR) &
|
||||
((1ULL<<LED_SIZE_BR)-1); break;
|
||||
case LED_R:
|
||||
old = (led[r][c]->l >> LED_PADD_R) &
|
||||
((1ULL<<LED_SIZE_R)-1); break;
|
||||
case LED_G:
|
||||
old = (led[r][c]->l >> LED_PADD_G) &
|
||||
((1ULL<<LED_SIZE_G)-1); break;
|
||||
case LED_B:
|
||||
old = (led[r][c]->l >> LED_PADD_B) &
|
||||
((1ULL<<LED_SIZE_B)-1); break;
|
||||
case LED_TYPE:
|
||||
old = (led[r][c]->l >> LED_PADD_TYPE) &
|
||||
((1ULL<<LED_SIZE_TYPE)-1); break;
|
||||
case LED_MODE:
|
||||
old = (led[r][c]->l >> LED_PADD_MODE) &
|
||||
((1ULL<<LED_SIZE_MODE)-1); break;
|
||||
case LED_SPEED:
|
||||
old = (led[r][c]->l >> LED_PADD_SPEED)&
|
||||
((1ULL<<LED_SIZE_SPEED)-1); break;
|
||||
case LED_SSCALE:
|
||||
old = (led[r][c]->l >> LED_PADD_SSCALE)&
|
||||
((1ULL<<LED_SIZE_SSCALE)-1); break;
|
||||
}
|
||||
|
||||
long val = old;
|
||||
|
||||
switch(mode){
|
||||
case 0: val = num; break;
|
||||
case 1: val += num; break;
|
||||
case 2: val -= num; break;
|
||||
}
|
||||
|
||||
modify_led(led[r][c], wich, val);
|
||||
|
||||
if (++c >= cols) {
|
||||
c = 0;
|
||||
r++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long long int get_matrix_cost(unsigned char n){
|
||||
int rows = matrix_l.list[n]->rows;
|
||||
int cols = matrix_l.list[n]->cols;
|
||||
RGB_LED*** led = matrix_l.list[n]->led;
|
||||
|
||||
long long int cost=0;
|
||||
|
||||
for(int r = 0;r<rows;r++){
|
||||
for(int c = 0;c<cols;c++){
|
||||
RGB_LED* l = led[r][c];
|
||||
|
||||
uint64_t R = extract(l->l, LED_PADD_R, LED_SIZE_R);
|
||||
uint64_t G = extract(l->l, LED_PADD_G, LED_SIZE_G);
|
||||
uint64_t B = extract(l->l, LED_PADD_B, LED_SIZE_B);
|
||||
uint64_t TEMP = extract(l->l, LED_PADD_TEMP, LED_SIZE_TEMP);
|
||||
uint64_t BR = extract(l->l, LED_PADD_BR, LED_SIZE_BR);
|
||||
uint64_t MODE = extract(l->l, LED_PADD_MODE, LED_SIZE_MODE);
|
||||
|
||||
cost += ((R + G + B)
|
||||
- (TEMP * (((long double)BR)/50)))
|
||||
* MODE;
|
||||
}
|
||||
}
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
||||
void logic_matrix(unsigned char n1,unsigned char n2){
|
||||
char inbuff;
|
||||
char _buff[BUFF_MAX];
|
||||
|
||||
char cmd = 0;
|
||||
{
|
||||
buff_input(&inbuff,_buff);
|
||||
char* cmds[] = {"==","!=",">=","<=",">","<"};
|
||||
create_cmd_list(CMD_LOGIC,cmds,6);
|
||||
|
||||
cmd = cmd_buff(_buff,CMD_LOGIC);
|
||||
del_cmd_list(CMD_LOGIC);
|
||||
}
|
||||
|
||||
long long int cost1 = get_matrix_cost(n1);
|
||||
long long int cost2 = get_matrix_cost(n2);
|
||||
|
||||
switch(cmd){
|
||||
case 0: putchar('-');putchar('1'); break;
|
||||
case 1: putchar(cost1==cost2?'1':'0'); break;
|
||||
case 2: putchar(cost1!=cost2?'1':'0'); break;
|
||||
case 3: putchar(cost1>=cost2?'1':'0'); break;
|
||||
case 4: putchar(cost1<=cost2?'1':'0'); break;
|
||||
case 5: putchar(cost1>cost2?'1':'0'); break;
|
||||
case 6: putchar(cost1<cost2?'1':'0'); break;
|
||||
}
|
||||
}
|
||||
|
||||
int get_rand(int min, int max) {
|
||||
return (double)rand() / (RAND_MAX + 1.0) * (max - min) + min;
|
||||
}
|
||||
|
||||
void rand_matrix(unsigned char n){
|
||||
unsigned int lo, hi;
|
||||
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
|
||||
srand(((unsigned long long)hi << 32) | lo);
|
||||
|
||||
int rows = matrix_l.list[n]->rows;
|
||||
int cols = matrix_l.list[n]->cols;
|
||||
RGB_LED*** led = matrix_l.list[n]->led;
|
||||
|
||||
for (int r = 0; r < rows; r++){
|
||||
for(int c = 0; c < cols; c++){
|
||||
modify_led(led[r][c], LED_R, get_rand(0,255));
|
||||
modify_led(led[r][c], LED_G, get_rand(0,255));
|
||||
modify_led(led[r][c], LED_B, get_rand(0,255));
|
||||
modify_led(led[r][c], LED_TEMP, get_rand(2000,6000));
|
||||
modify_led(led[r][c], LED_BR, get_rand(0,255));
|
||||
modify_led(led[r][c], LED_TYPE, get_rand(0,63));
|
||||
modify_led(led[r][c], LED_MODE, get_rand(0,3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void copy_matrix(unsigned char n1, unsigned char n2){
|
||||
int rows = matrix_l.list[n1]->rows;
|
||||
int cols = matrix_l.list[n1]->cols;
|
||||
RGB_LED*** led = matrix_l.list[n1]->led;
|
||||
|
||||
create_matrix(rows,cols);
|
||||
|
||||
RGB_LED*** led2 = matrix_l.list[matrix_l.n-1]->led;
|
||||
|
||||
for(int r = 0; r<rows;r++){
|
||||
for(int c = 0; c<cols;c++){
|
||||
led2[r][c]->l = led[r][c]->l;
|
||||
}
|
||||
}
|
||||
|
||||
if(n2 < matrix_l.n){
|
||||
MATRIX* dst = matrix_l.list[n2];
|
||||
MATRIX* src = matrix_l.list[matrix_l.n-1];
|
||||
|
||||
for(int r=0;r<rows;r++)
|
||||
for(int c=0;c<cols;c++)
|
||||
dst->led[r][c]->l = src->led[r][c]->l;
|
||||
|
||||
free_matrix(matrix_l.n-1);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char is_Matrix_Exist(unsigned char n){
|
||||
|
||||
if(matrix_l.n == 0){
|
||||
create_matrix(4,4);
|
||||
rand_matrix(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(n >= matrix_l.n){
|
||||
return matrix_l.n - 1;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user