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.
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;
}
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
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
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();
}
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);
// ...
}
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;
}
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);
}
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。