-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.c
71 lines (61 loc) · 1.75 KB
/
app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* This sample program balances a two-wheeled Segway type robot such as Gyroboy in EV3 core set.
*
* References:
* http://www.hitechnic.com/blog/gyro-sensor/htway/
* http://www.cs.bgu.ac.il/~ami/teaching/Lejos-2013/classes/src/lejos/robotics/navigation/Segoway.java
*/
#include "ev3api.h"
#include "app.h"
#include <mruby.h>
#include <mruby/compile.h>
#include "mruby/irep.h"
#include "mruby/debug.h"
#include "mruby/opcode.h"
#include "mruby/value.h"
#include "mruby/string.h"
#include "mruby/array.h"
#include "mruby/proc.h"
//#define DEBUG
#ifdef DEBUG
#define _debug(x) (x)
#else
#define _debug(x)
#endif
#define ERR_CHECK(err) \
do { \
if ((err) != 0) { \
syslog(LOG_NOTICE, "ERROR: %s %d err=%d", __FUNCTION__, __LINE__, (err)); \
} \
} while (0)
void main_task(intptr_t unused)
{
syslog(LOG_NOTICE, "#### main_task start!");
static mrb_state *mrb = NULL;
mrb_value ret;
mrb = mrb_open();
struct RClass * ev3rt = mrb_class_get(mrb, "EV3RT");
mrb_define_const(mrb, ev3rt, "MAIN_TASK", mrb_fixnum_value(MAIN_TASK));
#include "main_task.h"
ret = mrb_load_irep (mrb, bcode);
if(mrb->exc){
syslog(LOG_NOTICE, "#### load_irep done");
if(!mrb_undef_p(ret)){
syslog(LOG_NOTICE, "#### EV3way-ET ERR");
mrb_value s = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0);
if (mrb_string_p(s)) {
char *p = RSTRING_PTR(s);
syslog(LOG_NOTICE, "#### mruby err msg:%s", p);
} else {
syslog(LOG_NOTICE, "#### error unknown!");
}
}else{
syslog(LOG_NOTICE, "#### mrb_undef_p(ret)");
}
}else{
// 正常終了
syslog(LOG_NOTICE, "#### mruby exit OK");
}
mrb_close(mrb);
//? ext_tsk();
}