# Lily **Repository Path**: eglwang/Lily ## Basic Information - **Project Name**: Lily - **Description**: 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 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-05-13 - **Last Updated**: 2023-12-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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: ```c #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 ```c #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: ```c /* 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" ```hpp 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](./demo_main.cpp) ![basic use](./media/run-result.png) ## usage ### Task pool see: tp_addTask, tp_addTaskArg ```c 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 ```c 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