Tell me #2

Closed
opened 2024-07-27 21:38:11 +03:00 by mironov1338 · 2 comments
mironov1338 commented 2024-07-27 21:38:11 +03:00 (Migrated from github.com)

Hi, I'm looking at your code and would like to ask what it means to you
image

typedef struct {
union {
struct {
union {
uint8_t r;
uint8_t red;
};

        union {
            uint8_t g;
            uint8_t green;
        };

        union {
            uint8_t b;
            uint8_t blue;
        };
    };

    uint8_t raw[3];    // What does it mean?
    uint32_t num;    // What does it mean?
};

} CRGB;

Hi, I'm looking at your code and would like to ask what it means to you ![image](https://github.com/user-attachments/assets/dbc2e3e5-b49a-40db-85db-6e3cd8b4283e) typedef struct { union { struct { union { uint8_t r; uint8_t red; }; union { uint8_t g; uint8_t green; }; union { uint8_t b; uint8_t blue; }; }; uint8_t raw[3]; // What does it mean? uint32_t num; // What does it mean? }; } CRGB;
okhsunrog commented 2024-07-27 21:50:32 +03:00 (Migrated from github.com)

@mironov1338 hi. Actually I copied the type from the lib I forked mine from: https://github.com/8-DK/ESP32_SPI_WS2812_idf

I can explain to you, what it means. It's union, so it's just another handy way to address the fields of the struct. You can call then by names of colors, .red or .r, or you can call them by index, if you want, for example, for some reason iterate over them in an array. uint32_t num could be handy for "serialization", when you want so save the pixel as one integer value. Unions in C give you a way to access bytes of data in a different way. It has no overhead, doesn't increase size of CRGB struct and it's there because I thought it might be handy sometimes in the feature.

@mironov1338 hi. Actually I copied the type from the lib I forked mine from: https://github.com/8-DK/ESP32_SPI_WS2812_idf I can explain to you, what it means. It's union, so it's just another handy way to address the fields of the struct. You can call then by names of colors, .red or .r, or you can call them by index, if you want, for example, for some reason iterate over them in an array. uint32_t num could be handy for "serialization", when you want so save the pixel as one integer value. Unions in C give you a way to access bytes of data in a different way. It has no overhead, doesn't increase size of CRGB struct and it's there because I thought it might be handy sometimes in the feature.
mironov1338 commented 2024-07-27 22:07:39 +03:00 (Migrated from github.com)

Thx bro>< you a monster!

Thx bro>< you a monster!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: okhsunrog/esp_ws28xx#2
No description provided.