Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wink
firmware
Commits
684ac29e
Commit
684ac29e
authored
Jul 17, 2019
by
Adrian
Committed by
Rahix
Jul 17, 2019
Browse files
feat(modules): Add timed vibrate function
parent
fd5e6c36
Changes
4
Hide whitespace changes
Inline
Side-by-side
epicardium/epicardium.h
View file @
684ac29e
...
...
@@ -11,6 +11,7 @@
#define API_UART_READ 0x2
#define API_LEDS_SET 0x3
#define API_VIBRA_SET 0x4
#define API_VIBRA_VIBRATE 0x5
/* clang-format on */
/**
...
...
@@ -66,4 +67,11 @@ API(API_LEDS_SET, void epic_leds_set(int led, uint8_t r, uint8_t g, uint8_t b));
*/
API
(
API_VIBRA_SET
,
void
epic_vibra_set
(
int
status
));
/**
* Turn vibration motor on for a given time
*
* :param millis: number of milliseconds to run the vibration motor.
*/
API
(
API_VIBRA_VIBRATE
,
void
epic_vibra_vibrate
(
int
millis
));
#endif
/* _EPICARDIUM_H */
epicardium/modules/vibra.c
View file @
684ac29e
#include
"gpio.h"
#include
"FreeRTOS.h"
#include
"timers.h"
static
const
gpio_cfg_t
motor_pin
=
{
PORT_0
,
PIN_8
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
};
static
TimerHandle_t
vibra_timer
;
void
epic_vibra_set
(
int
status
)
{
if
(
status
)
{
...
...
@@ -12,3 +16,17 @@ void epic_vibra_set(int status)
GPIO_OutClr
(
&
motor_pin
);
}
}
void
vTimerCallback
()
{
epic_vibra_set
(
0
);
}
void
epic_vibra_vibrate
(
int
millis
)
{
int
ticks
=
millis
*
(
configTICK_RATE_HZ
/
1000
);
epic_vibra_set
(
1
);
vibra_timer
=
xTimerCreate
(
"vibratimer"
,
ticks
,
pdFALSE
,
0
,
vTimerCallback
);
xTimerStart
(
vibra_timer
,
0
);
}
pycardium/modules/qstrdefs.h
View file @
684ac29e
...
...
@@ -23,4 +23,5 @@ Q(ticks_add)
Q
(
ticks_diff
)
/* vibra */
Q
(
vibra
)
\ No newline at end of file
Q
(
vibra
)
Q
(
vibrate
)
pycardium/modules/vibra.c
View file @
684ac29e
...
...
@@ -16,9 +16,18 @@ STATIC mp_obj_t mp_vibra_set(mp_obj_t state_obj)
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
vibra_set_obj
,
mp_vibra_set
);
STATIC
mp_obj_t
mp_vibra_vibrate
(
mp_obj_t
a_obj
)
{
int
millis
=
mp_obj_get_int
(
a_obj
);
epic_vibra_vibrate
(
millis
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
vibra_vibrate_obj
,
mp_vibra_vibrate
);
STATIC
const
mp_rom_map_elem_t
vibra_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_vibra
)
},
{
MP_ROM_QSTR
(
MP_QSTR_set
),
MP_ROM_PTR
(
&
vibra_set_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_vibrate
),
MP_ROM_PTR
(
&
vibra_vibrate_obj
)
}
};
STATIC
MP_DEFINE_CONST_DICT
(
vibra_module_globals
,
vibra_module_globals_table
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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