/* === === === 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);
}*/

