Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
a8622795
Commit
a8622795
authored
Jun 11, 2015
by
Mike Wen
Browse files
add 433MHz transmission
parent
8044014f
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/rc.c
0 → 100644
View file @
a8622795
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
//#include "driver/easygpio.h"
//static Ping_Data pingA;
#define defPulseLen 185
#define defProtocol 1
#define defRepeat 10
#define defBits 24
void
transmit
(
int
pin
,
int
pulseLen
,
int
nHighPulses
,
int
nLowPulses
)
{
platform_gpio_write
(
pin
,
1
);
os_delay_us
(
pulseLen
*
nHighPulses
);
platform_gpio_write
(
pin
,
0
);
os_delay_us
(
pulseLen
*
nLowPulses
);
}
//rc.send(0,267715,24,185,1) --GPIO, code, bits, pulselen, protocol
static
int
ICACHE_FLASH_ATTR
rc_send
(
lua_State
*
L
)
{
const
uint8_t
pin
=
luaL_checkinteger
(
L
,
1
);
platform_gpio_mode
(
pin
,
PLATFORM_GPIO_OUTPUT
,
PLATFORM_GPIO_FLOAT
);
//platform_gpio_mode(pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_PULLUP);
//platform_gpio_mode(pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_PULLDOWN);
platform_gpio_write
(
pin
,
0
);
long
code
=
luaL_checklong
(
L
,
2
);
//const uint8_t bits = luaL_checkinteger(L, 3);
uint8_t
bits
=
luaL_checkinteger
(
L
,
3
);
const
uint8_t
pulseLen
=
luaL_checkinteger
(
L
,
4
);
const
uint8_t
Protocol
=
luaL_checkinteger
(
L
,
5
);
const
uint8_t
repeat
=
luaL_checkinteger
(
L
,
6
);
NODE_ERR
(
"pulseLen:%d
\n
"
,
pulseLen
);
NODE_ERR
(
"Protocol:%d
\n
"
,
Protocol
);
NODE_ERR
(
"repeat:%d
\n
"
,
repeat
);
NODE_ERR
(
"send:"
);
int
c
,
k
,
nRepeat
;
bits
=
bits
-
1
;
for
(
c
=
bits
;
c
>=
0
;
c
--
)
{
k
=
code
>>
c
;
if
(
k
&
1
)
NODE_ERR
(
"1"
);
else
NODE_ERR
(
"0"
);
}
NODE_ERR
(
"
\n
"
);
for
(
nRepeat
=
0
;
nRepeat
<
repeat
;
nRepeat
++
)
{
for
(
c
=
bits
;
c
>=
0
;
c
--
)
{
k
=
code
>>
c
;
if
(
k
&
1
){
//send1
if
(
Protocol
==
1
){
transmit
(
pin
,
pulseLen
,
3
,
1
);
}
else
if
(
Protocol
==
2
){
transmit
(
pin
,
pulseLen
,
2
,
1
);
}
else
if
(
Protocol
==
3
){
transmit
(
pin
,
pulseLen
,
9
,
6
);
}
}
else
{
//send0
if
(
Protocol
==
1
){
transmit
(
pin
,
pulseLen
,
1
,
3
);
}
else
if
(
Protocol
==
2
){
transmit
(
pin
,
pulseLen
,
1
,
2
);
}
else
if
(
Protocol
==
3
){
transmit
(
pin
,
pulseLen
,
4
,
11
);
}
}
}
//sendSync();
if
(
Protocol
==
1
){
transmit
(
pin
,
pulseLen
,
1
,
31
);
}
else
if
(
Protocol
==
2
){
transmit
(
pin
,
pulseLen
,
1
,
10
);
}
else
if
(
Protocol
==
3
){
transmit
(
pin
,
pulseLen
,
1
,
71
);
}
}
return
1
;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const
LUA_REG_TYPE
rc_map
[]
=
{
{
LSTRKEY
(
"send"
),
LFUNCVAL
(
rc_send
)},
{
LNILKEY
,
LNILVAL
}
};
//LUALIB_API int luaopen_ultra(lua_State *L) {
LUALIB_API
int
luaopen_rc
(
lua_State
*
L
)
{
// TODO: Make sure that the GPIO system is initialized
LREGISTER
(
L
,
"rc"
,
rc_map
);
return
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment