This commit is contained in:
oniic
2026-04-25 17:23:04 +07:00
parent 7f0f6ab5ba
commit 92b040fb32
129 changed files with 1809 additions and 1112 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "1Y-2H/trpo/gui-quizsolver"]
path = 1Y-2H/trpo/gui-quizsolver
url = https://git.oniic.ru/oniic/quizsolver.git
View File
View File
View File
View File
View File
View File
View File
View File
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
View File
View File
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
+10 -26
View File
@@ -1,30 +1,14 @@
#include <stdio.h>
typedef struct{
char ch;
struct ste{
int x;
int y;
int z;
}st;
}STR;
int main(){
int partFirst = 16; // считаем что романтические отношения начинаются с 16
int partSecond = 16;
STR m1;
putchar('a'); //1
m1.ch = 'A';
putchar('g'); //2
(&m1)->ch = 'B';
putchar('z'); //3
putchar('z'); //4
STR* m2;
putchar('a');//5
m2->st.x = 'A';
putchar('g'); //6
(&(m2)->st)->x = 'B';
putchar('z'); //7
int count = 0, fix = -2;
while (partFirst<80){
if (count == 3+(fix>7?2:0)) {fix++; count = 0;}
partSecond = (partFirst + 4) + fix;
printf("Возраст партнёров %d • %d\n", partFirst, partSecond);
partFirst++; count++;
}
}
Executable → Regular
View File
Executable → Regular
View File
Binary file not shown.
Binary file not shown.
+5 -4
View File
@@ -5,15 +5,16 @@
#include <stdlib.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#define AVG_TIME_LOOPS 1
#define AVG_RAND_MAX 100000
#define MILLION 1000000
void sort_radix(uint32_t* arr,int n);
void sort_heap(uint32_t* arr,int n);
void sort_bubble(uint32_t* arr,int n);
void sort_merge(uint32_t* arr,int left, int right);
void sort_radix(uint32_t* arr,uint32_t n);
void sort_heap(uint32_t* arr,uint32_t n);
void sort_bubble(uint32_t* arr,uint32_t n);
void sort_merge(uint32_t* arr,uint32_t left, uint32_t right);
void run_exp();
+20 -18
View File
@@ -2,7 +2,7 @@
#include <time.h>
double get_time();
void fill_rand(uint32_t *arr, int n);
void fill_rand(uint32_t *arr, uint32_t n);
int main(int argc,char **argv) {
srand(get_time());
@@ -14,42 +14,42 @@ int main(int argc,char **argv) {
break;
case '2': // Test Sorts
{
int n;
uint32_t n;
if(!(argv[1][1]>='a'&&argv[1][1]<='z')){
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
return 0;}
printf("Write n:");
scanf("%d",&n);
scanf("%" SCNu32, &n);
while(getchar()>'\n');
uint32_t *arr = (uint32_t*)malloc(sizeof(uint32_t) * n);
printf("Write n nums:");
for (int i = 0;i<n;i++){
scanf("%d",&arr[i]);
for (uint32_t i = 0;i<n;i++){
scanf("%" SCNu32, &arr[i]);
}
for(int i = 0; i<n;i++)printf("%d ",arr[i]);
for(uint32_t i = 0; i<n;i++)printf("%p %d\n",&arr[i],arr[i]);
putchar('\n');
switch(argv[1][1]){
case 'r': // Radix
sort_radix(arr,n);
for(int i = 0; i<n;i++)printf("%d ",arr[i]);
for(uint32_t i = 0; i<n;i++)printf("%p %d\n",&arr[i],arr[i]);
break;
case 'h': // Heap
sort_heap(arr,n);
for(int i = 0; i<n;i++)printf("%d ",arr[i]);
for(uint32_t i = 0; i<n;i++)printf("%p %d\n",&arr[i],arr[i]);
break;
case 'b': //Bubble
sort_bubble(arr,n);
for(int i = 0; i<n;i++)printf("%d ",arr[i]);
for(uint32_t i = 0; i<n;i++)printf("%p %d\n",&arr[i],arr[i]);
break;
case 'm': //Merge
sort_merge(arr,0,n-1);
for(int i = 0; i<n;i++)printf("%d ",arr[i]);
for(uint32_t i = 0; i<n;i++)printf("%p %d\n",&arr[i],arr[i]);
break;
default:
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
printf("\nPruint32_t 2(r/h/b/m) to sort or 3 to see var");
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
return 0;
}
@@ -63,7 +63,7 @@ int main(int argc,char **argv) {
}
default:
{
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
printf("\nPruint32_t 2(r/h/b/m) to sort or 3 to see var");
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
return 0;
}
@@ -82,7 +82,7 @@ void run_exp(void) {
fprintf(f, "# N Radix Heap Bubble \n");
int n = MILLION,end=MILLION,step = 50000;
uint32_t n = MILLION,end=MILLION,step = 50000;
for (;n<=end;n+=step){
uint32_t *arrA = (uint32_t*)malloc(sizeof(uint32_t) * n);
@@ -92,9 +92,11 @@ void run_exp(void) {
double tRadTotal = 0;
double tHeapTotal = 0;
double tBubblTotal = 0;
for (int i = 0; i < AVG_TIME_LOOPS; i++) {
for (uint32_t i = 0; i < AVG_TIME_LOOPS; i++) {
fill_rand(arrA, n);
arrC = arrB = arrA;
memcpy(arrB, arrA, n * sizeof(uint32_t));
memcpy(arrC, arrA, n * sizeof(uint32_t));
double ta = get_time();
sort_radix(arrA,n);
@@ -126,11 +128,11 @@ void run_exp(void) {
return;
}
int get_rand(int min, int max) {
uint32_t get_rand(uint32_t min, uint32_t max) {
return (double)rand() / (RAND_MAX + 1.0) * (max - min) + min;
}
void fill_rand(uint32_t *arr, int n) {
for (int i = 0; i < n; i++) arr[i] = get_rand(0, AVG_RAND_MAX);
void fill_rand(uint32_t *arr, uint32_t n) {
for (uint32_t i = 0; i < n; i++) arr[i] = get_rand(0, AVG_RAND_MAX);
}
double get_time() {
+60 -53
View File
@@ -1,60 +1,60 @@
#include "head.h"
//=== === === RADIX SORT === === ===
uint32_t get_max(uint32_t* arr,int n);
void counting_sort(uint32_t* arr, int n, int exp);
void sort_radix(uint32_t* arr,int n){
uint32_t get_max(uint32_t* arr,uint32_t n);
void counting_sort(uint32_t* arr, uint32_t n, uint32_t exp);
void sort_radix(uint32_t* arr,uint32_t n){
uint32_t max = get_max(arr, n);
for(uint32_t exp = 1; max / exp > 0; exp *= 10)
counting_sort(arr, n, exp);
}
uint32_t get_max(uint32_t* arr, int n) {
uint32_t get_max(uint32_t* arr, uint32_t n) {
uint32_t max = arr[0];
for(int i = 1; i < n; i++)
for(uint32_t i = 1; i < n; i++)
if(arr[i] > max)
max = arr[i];
return max;
}
void counting_sort(uint32_t* arr, int n, int exp) {
void counting_sort(uint32_t* arr, uint32_t n, uint32_t exp) {
uint32_t output[n];
uint32_t count[10] = {0};
for(int i = 0; i < n; i++)
for(uint32_t i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;
for(int i = 1; i < 10; i++)
for(uint32_t i = 1; i < 10; i++)
count[i] += count[i - 1];
for(int i = n - 1; i >= 0; i--) {
for(uint32_t i = n; i-- > 0;){
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}
for(int i = 0; i < n; i++)
for(uint32_t i = 0; i < n; i++)
arr[i] = output[i];
}
// === === === HEAP SORT === === ===
void heapify(uint32_t* arr, int n, int i);
void heapify(uint32_t* arr, uint32_t n, uint32_t i);
void swap(uint32_t* a, uint32_t *b);
void sort_heap(uint32_t* arr,int n){
for(int i = n/2 - 1; i >= 0; i--)
heapify(arr, n, i);
void sort_heap(uint32_t* arr,uint32_t n){
for(int i = n/2 - 1; i >= 0; i--)
heapify(arr, n, i);
for(int i = n - 1; i > 0; i--) {
for(uint32_t i = n - 1; i > 0; i--) {
swap(&arr[0], &arr[i]);
heapify(arr, i, 0);
}
}
void swap(uint32_t* a, uint32_t *b) {
int temp = *a;
uint32_t temp = *a;
*a = *b;
*b = temp;
}
void heapify(uint32_t* arr, int n, int i) {
int largest = i;
int left = 2 * i + 1;
int right = 2 * i + 2;
void heapify(uint32_t* arr, uint32_t n, uint32_t i) {
uint32_t largest = i;
uint32_t left = 2 * i + 1;
uint32_t right = 2 * i + 2;
if(left < n && arr[left] > arr[largest])
largest = left;
@@ -70,12 +70,12 @@ void heapify(uint32_t* arr, int n, int i) {
}
// === === === BUBBLE SORT === === ===
void sort_bubble(uint32_t* arr,int n){
for(int i = 0; i < n - 1; i++) {
int swapped = 0;
for(int j = 0; j < n - i - 1; j++) {
void sort_bubble(uint32_t* arr,uint32_t n){
for(uint32_t i = 0; i < n - 1; i++) {
uint32_t swapped = 0;
for(uint32_t j = 0; j < n - i - 1; j++) {
if(arr[j] > arr[j + 1]) {
int temp = arr[j];
uint32_t temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = 1;
@@ -86,38 +86,45 @@ void sort_bubble(uint32_t* arr,int n){
}
// === === === MERGE SORT === === ===
void merge(uint32_t* arr, int left, int mid, int right);
void sort_merge(uint32_t* arr, int left, int right){
if(left < right) {
int mid = left + (right - left) / 2;
void sort_merge(uint32_t* arr, uint32_t left, uint32_t right)
{
uint32_t n = right - left + 1;
sort_merge(arr, left, mid);
sort_merge(arr, mid + 1, right);
merge(arr, left, mid, right);
}
}
void merge(uint32_t* arr, int left, int mid, int right) {
int n1 = mid - left + 1;
int n2 = right - mid;
uint32_t *temp = malloc(sizeof(uint32_t) * n);
if(!temp) return;
int L[n1], R[n2];
for(uint32_t size = 1; size < n; size *= 2)
{
for(uint32_t start = 0; start < n; start += 2 * size)
{
uint32_t mid = start + size;
uint32_t end = start + 2 * size;
for(int i = 0; i < n1; i++)
L[i] = arr[left + i];
for(int j = 0; j < n2; j++)
R[j] = arr[mid + 1 + j];
if(mid > n) mid = n;
if(end > n) end = n;
int i = 0, j = 0, k = left;
while(i < n1 && j < n2) {
if(L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
uint32_t i = start;
uint32_t j = mid;
uint32_t k = start;
while(i < mid && j < end)
{
if(arr[left + i] <= arr[left + j])
temp[k++] = arr[left + i++];
else
temp[k++] = arr[left + j++];
}
while(i < mid)
temp[k++] = arr[left + i++];
while(j < end)
temp[k++] = arr[left + j++];
}
k++;
for(uint32_t i = 0; i < n; i++)
arr[left + i] = temp[i];
}
while(i < n1) { arr[k] = L[i]; i++; k++;}
while(j < n2) { arr[k] = R[j]; j++; k++;}
free(temp);
}
+1
View File
@@ -5,6 +5,7 @@ set encoding utf8
set grid xtics ytics ls 1 lc rgb "#bbbbbb" lw 1 dt 2
set title "Radix, Heap и Bubble (Log scale)"
set xlabel "Количество элементов в массиве, тыс" offset 0,-1
set ylabel "Время выполнения, с"
set xtics rotate by 90 right
Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Executable → Regular
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+44
View File
@@ -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"
}
]
+15
View File
@@ -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
+9
View File
@@ -0,0 +1,9 @@
#ifndef CASE
#define CASE
typedef struct{
int* ptrFirst;
int* ptrLast;
} CASE;
#endif
+17
View File
@@ -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
+16
View File
@@ -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
+19
View File
@@ -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
+109
View File
@@ -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
+39
View File
@@ -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.
+16
View File
@@ -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
View File
@@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "disabled"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+46
View File
@@ -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);
+18
View File
@@ -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);
+9
View File
@@ -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"
+16
View File
@@ -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);
+39
View File
@@ -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
BIN
View File
Binary file not shown.
+132
View File
@@ -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);
}
+69
View File
@@ -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;
}
+42
View File
@@ -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;
}
+115
View File
@@ -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;
}
+2
View File
@@ -0,0 +1,2 @@
10000 8000
2500 6500
BIN
View File
Binary file not shown.
+89
View File
@@ -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);
}*/
+122
View File
@@ -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;
}
+97
View File
@@ -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;
}
+348
View File
@@ -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;
}

Some files were not shown because too many files have changed in this diff Show More