-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.c
executable file
·70 lines (58 loc) · 1.77 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
#include "ev3api.h"
#include "syssvc/serial.h" // for Bluetooth(log)
#include "app.h"
#if defined(BUILD_MODULE)
#include "module_cfg.h"
#else
#include "kernel_cfg.h"
#endif
#include "mruby.h"
#include "mruby/irep.h"
#include "mruby/string.h"
#define DEBUG
#ifdef DEBUG
#define _debug(x) (x)
#else
#define _debug(x)
#endif
/* LCDフォントサイズ */
#define CALIB_FONT (EV3_FONT_SMALL)
#define CALIB_FONT_WIDTH (6/*TODO: magic number*/)
#define CALIB_FONT_HEIGHT (8/*TODO: magic number*/)
/* メインタスク */
void main_task(intptr_t unused)
{
/* LCD画面にログを表示 */
ev3_lcd_fill_rect(0, 0, EV3_LCD_WIDTH, EV3_LCD_HEIGHT, EV3_LCD_WHITE);
ev3_lcd_draw_string("detection system", 0, CALIB_FONT_HEIGHT*1);
static mrb_state *mrb = NULL;
mrb_value ret;
mrb = mrb_open();
mrbc_context *context = mrbc_context_new(mrb);
memfile_t memfile;
ER ercd = ev3_memfile_load("/ev3rt/apps/main_task.rb", &memfile);
if (ercd != E_OK) {
ev3_lcd_fill_rect(0, 0, EV3_LCD_WIDTH, EV3_LCD_HEIGHT, EV3_LCD_WHITE);
ev3_lcd_draw_string("load error main_task.rb", 0, 10);
ext_tsk();
}
ret = mrb_load_nstring_cxt(mrb, memfile.buffer, memfile.filesz, context);
if(mrb->exc){
if(!mrb_undef_p(ret)){ //エラーを表示するための処理。LCDとbluetooth両方に出力
ev3_lcd_fill_rect(0, 0, EV3_LCD_WIDTH, EV3_LCD_HEIGHT, EV3_LCD_WHITE);
ev3_lcd_draw_string("mruby exec ERR", 0, CALIB_FONT_HEIGHT*1);
mrb_value s = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0);
if (mrb_string_p(s)) {
ev3_lcd_draw_string(RSTRING_PTR(s), 0, CALIB_FONT_HEIGHT*3);
serial_wri_dat(SIO_PORT_BT, RSTRING_PTR(s), RSTRING_LEN(s));
} else {
ev3_lcd_draw_string("error unknown", 0, CALIB_FONT_HEIGHT*3);
}
}
}
mrb_close(mrb);
ext_tsk();
}
int _fini(void){
return 0;
}