static void motion_init(struct motion_ctx *ctx) { simble_srv_init(ctx, simble_get_vendor_uuid_class(), VENDOR_UUID_SENSOR_SERVICE); simble_srv_char_add(ctx, &ctx->motion, simble_get_vendor_uuid_class(), VENDOR_UUID_MOTION_CHAR, u8"Motion", sizeof(ctx->motion_value)); simble_srv_char_add(ctx, &ctx->sampling_period_motion, simble_get_vendor_uuid_class(), VENDOR_UUID_SAMPLING_PERIOD_CHAR, u8"sampling period", sizeof(ctx->sampling_period)); // size in bytes // Resolution: 1ms, max value: 16777216 (4 hours) // A value of 0 will disable periodic notifications simble_srv_char_attach_format(&ctx->sampling_period_motion, BLE_GATT_CPF_FORMAT_UINT24, 0, ORG_BLUETOOTH_UNIT_UNITLESS); /* srv_char_attach_format(&ctx->motion, */ /* BLE_GATT_CPF_FORMAT_UINT16, */ /* 0, */ /* 0); */ ctx->disconnect_cb = motion_disconnected; ctx->motion.read_cb = motion_read; ctx->motion.notify = 1; ctx->motion.notify_status_cb = motion_notify_status_cb; ctx->sampling_period_motion.read_cb = sampling_period_read_cb; ctx->sampling_period_motion.write_cb = sampling_period_write_cb; simble_srv_register(ctx); }
void batt_serv_init(struct rtc_ctx *rtc_ctx) { struct batt_serv_ctx *ctx = &batt_serv_ctx; ctx->last_reading = 0; // init the service context simble_srv_init(ctx, BLE_UUID_TYPE_BLE, BLE_UUID_BATTERY_SERVICE); // add a characteristic to our service simble_srv_char_add(ctx, &ctx->batt_lvl, BLE_UUID_TYPE_BLE, BLE_UUID_BATTERY_LEVEL_CHAR, u8"Battery Level", 1); // size in bytes simble_srv_char_attach_format(&ctx->batt_lvl, BLE_GATT_CPF_FORMAT_UINT8, 0, ORG_BLUETOOTH_UNIT_PERCENTAGE); simble_srv_char_add(ctx, &ctx->sampling_period_batt_lvl, simble_get_vendor_uuid_class(), VENDOR_UUID_SAMPLING_PERIOD_CHAR, u8"sampling period", sizeof(ctx->sampling_period)); // size in bytes // Resolution: 1ms, max value: 16777216 (4 hours) // A value of 0 will disable periodic notifications simble_srv_char_attach_format(&ctx->sampling_period_batt_lvl, BLE_GATT_CPF_FORMAT_UINT24, 0, ORG_BLUETOOTH_UNIT_UNITLESS); ctx->batt_lvl.read_cb = batt_lvl_read_cb; ctx->disconnect_cb = batt_serv_disconnected; ctx->batt_lvl.notify = 1; ctx->batt_lvl.notify_status_cb = notify_status_cb; ctx->sampling_period_batt_lvl.read_cb = sampling_period_read_cb; ctx->sampling_period_batt_lvl.write_cb = sampling_period_write_cb; batt_serv_ctx.sampling_period = DEFAULT_SAMPLING_PERIOD; rtc_ctx->rtc_x[BATT_NOTIF_TIMER_ID].type = PERIODIC; rtc_ctx->rtc_x[BATT_NOTIF_TIMER_ID].period = batt_serv_ctx.sampling_period; rtc_ctx->rtc_x[BATT_NOTIF_TIMER_ID].enabled = false; rtc_ctx->rtc_x[BATT_NOTIF_TIMER_ID].cb = batt_lvl_notif_timer_cb; simble_srv_register(ctx); // register our service }