status.c 1.55 KB
Newer Older
fleur's avatar
fleur committed
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
#include "epicardium.h"

#include "py/builtin.h"
#include "py/obj.h"
#include "py/runtime.h"

static mp_obj_t mp_status_start()
{
	epic_status_start();
	return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(
	status_start_obj, mp_status_start
);

static mp_obj_t mp_status_stop()
{
	epic_status_stop();
	return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(
	status_stop_obj, mp_status_stop
);

static mp_obj_t mp_status_get_power_status()
{
	int status = epic_status_get_power_status();
	return mp_obj_new_int(status);
}
static MP_DEFINE_CONST_FUN_OBJ_0(
	status_get_power_status_obj, mp_status_get_power_status
);

static mp_obj_t mp_status_power_led(mp_obj_t on_in)
{
	int on = mp_obj_get_int(on_in);
	epic_status_power_led(on);
	return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(
	status_power_led_obj, mp_status_power_led
);

static const mp_rom_map_elem_t status_module_globals_table[] = {
	{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_status) },
	{ MP_ROM_QSTR(MP_QSTR_start),
	  MP_ROM_PTR(&status_start_obj) },
	{ MP_ROM_QSTR(MP_QSTR_stop),
	  MP_ROM_PTR(&status_stop_obj) },
	{ MP_ROM_QSTR(MP_QSTR_get_power_status),
	  MP_ROM_PTR(&status_get_power_status_obj) },
	{ MP_ROM_QSTR(MP_QSTR_power_led),
	  MP_ROM_PTR(&status_power_led_obj) },
};
static MP_DEFINE_CONST_DICT(status_module_globals, status_module_globals_table);

const mp_obj_module_t status_module = {
	.base    = { &mp_type_module },
	.globals = (mp_obj_dict_t *)&status_module_globals,
};

/* clang-format off */
MP_REGISTER_MODULE(MP_QSTR_status, status_module, MODULE_STATUS_ENABLED);