nRF52 Mesh开发 (2) SDK例程Light_switch server 添加一个element控制开发板其他LED灯

  1. server文件结构:

                                             

使用SEGGER编译的话直接打开.emProject文件即可;img文件中包含程序运行过程图;include文件包含该例程下的头文件;

2. 具体操作:

在main.cpp文件中#define ONOFF_SERVER_0_LED          (BSP_LED_0)下添加如下代码,前项声明另外一个元素用于控制开发板中第二个led灯

#define ONOFF_SERVER_1_LED          (BSP_LED_1) //led灯
#define APP_ONOFF_ELEMENT_INDEX1   (1)//元素索引

static void app_onoff_server_set_cb1(const app_onoff_server_t *p_server, bool onoff);//开关灯回调函数
static void app_onoff_server_get_cb1(const app_onoff_server_t *p_server, bool *p_present_onoff);//获取灯状态回调函数

APP_ONOFF_SERVER_DEF(m_onoff_server_1,
APP_CONFIG_FORCE_SEGMENTATION,
APP_CONFIG_MIC_SIZE,
app_onoff_server_set_cb1,
app_onoff_server_get_cb1)//开关灯服务的前项声明

/* Callback for updating the hardware state */
static void app_onoff_server_set_cb1(const app_onoff_server_t * p_server, bool onoff)
{
    /* Resolve the server instance here if required, this example uses only 1 instance. */

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting GPIO value: %d\n", onoff)

    hal_led_pin_set(ONOFF_SERVER_1_LED, onoff);
}

/* Callback for reading the hardware state */
static void app_onoff_server_get_cb1(const app_onoff_server_t * p_server, bool * p_present_onoff)
{
    /* Resolve the server instance here if required, this example uses only 1 instance. */

    *p_present_onoff = hal_led_pin_get(ONOFF_SERVER_1_LED);
}

在nrf_mesh_config_app.h文件中修改 ACCESS_MODEL_COUNT 和ACCESS_ELEMENT_COUNT宏参数数目

#define ACCESS_MODEL_COUNT (4)
#define ACCESS_ELEMENT_COUNT (2)

3. 程序下载到板子中后在手机中使用nRF Mesh app配置node即可,便可发现多了有个元素

                                            

最后Mesh开发学习推荐SIG官方提供的Mesh开发学习指导v2.0 。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值