Skip to content

Commit

Permalink
add pin number config for sample
Browse files Browse the repository at this point in the history
  • Loading branch information
luhuadong committed Oct 6, 2020
1 parent db877ae commit 3861f48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
27 changes: 5 additions & 22 deletions examples/gp2y10_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,13 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

#include "gp2y10.h"

#define GP2Y10_ILED_PIN GET_PIN(F, 15) /* D2 */
#define GP2Y10_AOUT_PIN GET_PIN(C, 3) /* A2 */

/* cat_gp2y10 by static */
static void cat_gp2y10_static(void)
{
struct gp2y10_device gp2y10;

if (RT_EOK == gp2y10_init(&gp2y10, GP2Y10_ILED_PIN, GP2Y10_AOUT_PIN))
{
rt_uint32_t dust = gp2y10_get_dust_density(&gp2y10);
rt_kprintf("Dust: %d ug/m3\n", dust);
}
else {
rt_kprintf("GP2Y10 read error\n");
}
}
#define GP2Y10_ILED_PIN PKG_USING_GP2Y10_SAMPLE_ILED_PIN
#define GP2Y10_AOUT_PIN PKG_USING_GP2Y10_SAMPLE_AOUT_PIN

/* cat_gp2y10 by dynamic */
static void cat_gp2y10_dynamic(void)
static void cat_gp2y10(void)
{
gp2y10_device_t gp2y10 = gp2y10_create(GP2Y10_ILED_PIN, GP2Y10_AOUT_PIN);

Expand All @@ -43,13 +27,12 @@ static void cat_gp2y10_dynamic(void)
rt_kprintf("Dust: %d ug/m3\n", dust);
}
else {
rt_kprintf("GP2Y10 read error\n");
rt_kprintf("Read gp2y10 sensor failed.\n");
}

gp2y10_delete(gp2y10);
}

#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(cat_gp2y10_static, read gp2y10 dust density);
MSH_CMD_EXPORT(cat_gp2y10_dynamic, read gp2y10 dust density);
MSH_CMD_EXPORT(cat_gp2y10, read gp2y10 dust density);
#endif
9 changes: 5 additions & 4 deletions examples/sensor_gp2y10_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

#include "gp2y10.h"

#define GP2Y10_ILED_PIN GET_PIN(F, 15) /* D2 */
#define GP2Y10_AOUT_PIN GET_PIN(C, 3) /* A2 */
#define GP2Y10_ILED_PIN PKG_USING_GP2Y10_SAMPLE_ILED_PIN
#define GP2Y10_AOUT_PIN PKG_USING_GP2Y10_SAMPLE_AOUT_PIN

static void read_dust_entry(void *args)
{
Expand Down Expand Up @@ -61,7 +60,9 @@ static int gp2y10_read_sample(void)
if (dust_thread)
rt_thread_startup(dust_thread);
}
INIT_APP_EXPORT(gp2y10_read_sample);
#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(gp2y10_read_sample, read gp2y10 sensor data);
#endif

static int rt_hw_gp2y10_port(void)
{
Expand Down

0 comments on commit 3861f48

Please sign in to comment.