English 中文(简体)
• 如何利用ESP32自由RTOS为LED矩阵提供任务
原标题:How to use render task(s) for LED matrix with ESP32 FreeRTOS

I have an ESP32/Arduino application that drives, amongst others, an LED matrix. It uses SimpleFSM to implement the state machine handling user interaction, sensor input, etc.. Sometimes the LED matrix displays static "icons", sometimes it displays animations. The two use cases differ at code level conceptually:

  • Static: some way of iterating over all LEDs and set them to 0 or 1 i.e. it s finite.
  • Dynamic/animation: do the same but in an infinite loop until an app state change requires to display new information on the LED matrix.

如何执行提供部分内容的自由RTOS-辅助手段?

起初,如果需要做一些新事情,但只造成痛苦,我想开始一项新的任务。 旧的/以前的任务必须首先在新任务开始之前终止。 此外,任务应当是长期性的,最好是无限期的。

因此,看来自由广播卫星轨道是启动一个单一无限运行的交付任务。 关于国家变革,主要任务将告诉它停止做目前的工作,而是开始做其他事情。 你们如何放弃“工作单位”的任务? 如何防止任务完成,而任务又使任务变得固定不变,而不是使任务再次结束? 完成这项任务是否可能利用它的国家机器?

问题回答

Should the render task maybe use it s own little state machine for that?

是的,[单一]任务应当保持自己的状态。

完成这项任务时,应有一个要求/工作问题,即它污染。

主要任务是用户互动。 如果它决定改变所展示的内容,它就要求完成这项任务。

授权是对请求的质疑。 如果一项新请求已经提出,就开始这一行动。 否则,它将继续处理目前/现有的工作请求。


这里有一些伪装。 将相关职能替换为自由法庭等职能:

typedef enum {
    ACTION_IDLE,

    ACTION_ZERO,
    ACTION_ONE,

    ACTION_ANIM_CIRCLE,
    ACTION_ANIM_SQUARE,
    ACTION_ANIM_TRIANGLE,
} action_t;

typedef struct {
    action_t req_action;
    int req_state;
    // ...
} request_t;

void
render_task(void)
{
    request_t *reqcur = NULL;
    request_t *reqnew = NULL;

    while (1) {
        // new work to do?
        reqnew = dequeue_request_nowait(&render_task_work);

        // yes, release old and setup new work
        if (reqnew != NULL) {
            // release old request block to free queue
            if (reqcur != NULL)
                enqueue_request(&render_task_free,reqcur);

            // setup new request
            reqcur = reqnew;
            init = 1;
        }
        else
            init = 0;

        // handle current work
        if (reqcur != NULL) {
            switch (reqcur->req_action) {
            case ACTION_IDLE:
                break;

            case ACTION_ZERO:
                if (init)
                    display_zeros();
                reqcur->req_action = ACTION_IDLE;
                break;

            case ACTION_ONE:
                if (init)
                    display_ones();
                reqcur->req_action = ACTION_IDLE;
                break;

            case ACTION_ANIM_CIRCLE:
            case ACTION_ANIM_SQUARE:
            case ACTION_ANIM_TRIANGLE:
                if (init)
                    reset_animation(reqcur);
                display_animation_frame(reqcur);
                advance_animation_state(reqcur);
                break;
            }
        }

        // prevent infinitely fast rendering ...
        // NOTE: this could be done via a timeout on a _blocking_ dequeue
        // operation above
        wait_for_frame_start(timeout);
    }
}

以上是一份简单版本的工人校对池。 某些背景见我的回答:。 C. 当地变数中的数据与制作当地复制件相近? AKA 这种配对汇合是否有意义?





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签