1 Star 2 Fork 0

G.L.Wang / Lily

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Lily V2

Lily is a, bash likehood, cmdline tool, written by C, which can run in normal low-end MCUs, featured on the pseudo multitask ability, the pipeline mechanism, runtime variables, flowing-control statements, the calculator tool, and a bunch of built-in commands.

In version of sts, there's no any additional files, you can directly add it to you project and run in, or build it as a library.

Update Logs

  • Added support for escape characters.
  • Added support for multi-line input.
  • Added "hashlib.c" and introducing a faster searching for cmds, vars and funs
  • Updated Pipe structure.
  • Added event broadcasting mechanism.
  • Added "Lily_modules.h" header file.
  • Renamed some APIs.
  • Remove "li_flash.c".
  • Added a demo file "demo_main.cpp" to enumerate in Linux and Windows.

prepare

you are suppose to implement some interfaces before you can use this module in your project, see the followings:

    #include "Lily_help.h"

    // get a relative time/ms
    int get_time_ms()
    {
        int time;
        // ....
        return time;
    }

    // direct the output stream
    void* std_out(void*arg, char*msg, int len)
    {
        // printf("%.*s", len, msg);
        return NULL;
    }

    // implement a Pipe object
    Pipe std_pipe_handle=NULL;

    int main(int argc, char*argv[])
    {
        lily_millis = get_time_ms;
        // setup your output pipe
        std_pipe_handle = li_new_output_device("std",  NULL, std_out);
        // setup the input pipe to Lily
        Pipe lily_pipe_handle = lily_pipe_io_setup(std_pipe_handle);
        pipe_connect_to(std_pipe_handle, lily_pipe_handle);
        const char* cmd = "echo Hello World";
        // input date to Lily using the Pipe
        pipe_release_data(std_pipe_handle,cmd,strlen(cmd));
        // or you can use 'lily_in()' instead
        
        // ...

        // 
        //call for 'lily_tick()' periodically and define a right 'tick_freq' in 'Lily_config.h', if your want to use features like timers and sleep functions.

        // starts messages loop
        tp_run_tasks();
        return 0;
    }

config

you must create a configuring file named "Lily_config.h"

the file defines some optional features,
it may looks like this

#ifndef LILY_CONFIG_H
#define LILY_CONFIG_H

// the length of task pool
#define Tasks_LEN 32

// the code name of the module
#define _VersionMsg "Robin"
// the frequency for triggering 'lily_tick()'
#define tick_freq 100
// use debug mode?
#define in_debug

#endif

custom

in "Lily_modules.h", you can custom you-wanted cmds, adding you private cmds, modules without changing any kernel files.
for example:

/* your files: my_module.c */
#include "Lily_help.h"

int cmd1(int argn, char*argv[])
{
    // ...
    return 0;
}

void my_module_init()
{
    public_a_cmd("myCmd",cmd1);
}

then add the following statement in "Lily_modules.h"

load(my_module)

note here that the initialization function of your module should be named with "my_module" and suffixed with "_init".

here's a picture showing the basic usage of Lily using demo_main.cpp

basic use

usage

Task pool

see: tp_addTask, tp_addTaskArg

        int printStr(char*s)
        {
            lily_out(s);
            return 0;
        }

        void main()
        {
            // ...
            char*s="hallo";
            tp_addTaskArg((TasksArg_def)printStr,s);
            // ...
            tp_run_tasks();
        }

cmds, funs and vars

see: public_a_cmd_link,public_a_fun_link_n,public_a_fun_link_int,public_a_var_ref

   void OLED_Clear(){
       //do whatever
   }
   void fun2(float a,float b){
       //do whatever with a,b 
   }
   int cmd1(int argc, char *argv[])
   {
       for(int i=0;i<argc;i++)
           lily_out(argv[i]);
       return 0;
   }


   void main()
   {
       float kp=12;

       public_a_cmd_link("cmd1", cmd1);

       public_a_field_ref_type("kp", &kp, 'f');

       public_a_fun_link_n("clc", OLED_Clear, 0);
       public_a_fun_link_n("clc", fun2, 2);

       // ...
   }

timers

see: add_timer_once,public_a_timer...

    int shine_cursor()
    {   
        //...
        return 0;
    }

    void main()
    {
        li_new_timer(shine_cursor, Hz(2));
        li_remove_timer(shine_cursor);
        li_new_timer(delay_work, Second(2));
        ...
    }

    int delay_work()
    {
        ...
        remove_timer(delay_work);
        return 0;
    }

broadcast

see: li_new_event, event_broadcast_from,event_register_to

    Broadcast timeout_broadcast=NULL;

    int alarm_user(){
        // turn buzzer on
        return 0;
    }

    void main()
    {
        timeout_broadcast = li_new_event("timeout");

        event_register_to(timeout_broadcast, alarm_user);
        // ...
        event_broadcast_from(timeout_broadcast);
        // ...
        event_deregister_from(timeout_broadcast, alarm_user);
    }

pipe

see also: new_input_device, new_output_device,pipe_connect_to,pipe_disconnect,pipe_release_data

Pipe p_in, p_out;
void *out(void*arg,char*msg,int n)
{
    ...
}

void main()
{
    p_in = new_input_device("in");
    p_out = new_output_device("out", NULL, out);

    pipe_connect_to(p_in, p_out);
    const char*msg = "hi, this is a msg";
    pipe_release_data(p_in, msg, strlen(msg));
}

here's a picture showing the basic usage of pipe and redirect std output

basic use

MIT License Copyright (c) 2022 eglwang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Lily is a, bash likehood, cmdline tool, written by C, which can run in normal low-end MCUs, featured on the pseudo multitask ability, the pipeline mechanism, runtime variables, flowing-control stateme 展开 收起
C++ 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/eglwang/Lily.git
git@gitee.com:eglwang/Lily.git
eglwang
Lily
Lily
main

搜索帮助