-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadc.cpp
More file actions
76 lines (58 loc) · 1.47 KB
/
adc.cpp
File metadata and controls
76 lines (58 loc) · 1.47 KB
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
72
73
74
75
76
/**************************************************************************
* Copyright (C), AirM2M Tech. Co., Ltd.
*
* Name: adc.cpp
* Author: panjun
* Version: V0.1
* Date: 2016/09/13
*
* Description:
* ADC.
* History:
* panjun 16/09/13 Initially create file.
**************************************************************************/
#include "stdafx.h"
#include "lua.hpp"
#include "platform.h"
#include "platform_conf.h"
#include "platform_pmd.h"
// adc.open(id)
static int adc_open(lua_State *L) {
INT id = luaL_checkinteger(L, 1);
INT mode = luaL_checkinteger(L, 2);
INT ret;
MOD_CHECK_ID(adc, id);
ret = platform_adc_open(id, mode);
lua_pushinteger(L, ret);
return 1;
}
static int adc_close(lua_State *L) {
int ret;
ret = platform_adc_close();
lua_pushinteger(L, ret);
return 1;
}
// adc.read(id)
static int adc_read(lua_State *L) {
int id = luaL_checkinteger(L,1);
int adc, volt;
MOD_CHECK_ID(adc, id);
platform_adc_read(id, &adc, &volt);
lua_pushinteger(L, adc);
lua_pushinteger(L, volt);
return 2;
}
#define MIN_OPT_LEVEL 2
// Module function map
const luaL_Reg adc_map[] =
{
{"open", adc_open},
{"read", adc_read},
{"close", adc_close},
{NULL, NULL}
};
LUALIB_API int luaopen_adc( lua_State *L )
{
luaL_register( L, AUXLIB_ADC, adc_map );
return 1;
}