You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2022/08/11 13:13:58 UTC

[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #1320: apps/bleservo: Initial commit.

apache-mynewt-bot commented on PR #1320:
URL: https://github.com/apache/mynewt-nimble/pull/1320#issuecomment-1211973098

   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### apps/bleservo/src/ble_servo.h
   <details>
   
   ```diff
   @@ -28,13 +28,13 @@
    #endif
    
    #define  PWM_CH_CFG_PIN  31
   -#define  PWM_CH_CFG_INV  false 
   +#define  PWM_CH_CFG_INV  false
    #define  PWM_CH_NUM      0
    #define  PWM_IRQ_PRIO    1
    
   -/* 
   - * Servomotors work with 50 Hz PWM signal and accept pulse duration from around 1000us minimum (0 degree rotation) 
   - * to 2000us maximum (180 degree rotation). Unfortunataly those values of minimum and maximum 
   +/*
   + * Servomotors work with 50 Hz PWM signal and accept pulse duration from around 1000us minimum (0 degree rotation)
   + * to 2000us maximum (180 degree rotation). Unfortunataly those values of minimum and maximum
     * PWM pulse duration are only approximate and might differ with different servos, because they are not standardized.
     * Values defined below allow to adjust them for each servo you might use.
     */
   ```
   
   </details>
   
   #### apps/bleservo/src/gatt_svr.c
   <details>
   
   ```diff
   @@ -31,12 +31,12 @@
    
    /* 5c3a659e-897e-45e1-b016-007107c96df6 */
    static const ble_uuid128_t gatt_svr_chr_servo_angle_uuid =
   -        BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
   +    BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
                             0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
    
    /* 6d456567-8995-45e1-b016-007107c96df6 */
    static const ble_uuid128_t gatt_svr_chr_servo_pulse_duration_uuid =
   -        BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
   +    BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
                             0xe1, 0x45, 0x95, 0x89, 0x67, 0x65, 0x45, 0x6d);
    
    /* Values kept in characteristics */
   @@ -50,11 +50,11 @@
    
    static int
    gatt_svr_chr_access_servo_angle(uint16_t conn_handle, uint16_t attr_handle,
   -                               struct ble_gatt_access_ctxt *ctxt, void *arg);
   +                                struct ble_gatt_access_ctxt *ctxt, void *arg);
    
    static int
    gatt_svr_chr_access_servo_pulse_duration(uint16_t conn_handle, uint16_t attr_handle,
   -                               struct ble_gatt_access_ctxt *ctxt, void *arg);
   +                                         struct ble_gatt_access_ctxt *ctxt, void *arg);
    
    static int
    gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
   @@ -82,29 +82,29 @@
            .type = BLE_GATT_SVC_TYPE_PRIMARY,
            .uuid = &gatt_svr_svc_servo_uuid.u,
            .characteristics = (struct ble_gatt_chr_def[]) { {
   -            /* Characteristic: servo angle*/
   -            .uuid = &gatt_svr_chr_servo_angle_uuid.u,
   -            .val_handle = &gatt_angle_val_handle,
   -            .access_cb = gatt_svr_chr_access_servo_angle,
   -            .flags = BLE_GATT_CHR_F_READ |
   -                     BLE_GATT_CHR_F_WRITE |
   -                     BLE_GATT_CHR_F_NOTIFY
   -        }, {
   -            /* Characteristic: servo PWM pulse duration*/
   -            .uuid = &gatt_svr_chr_servo_pulse_duration_uuid.u,
   -            .val_handle = &gatt_pulse_duration_val_handle,
   -            .access_cb = gatt_svr_chr_access_servo_pulse_duration,
   -            .flags = BLE_GATT_CHR_F_READ |
   -                     BLE_GATT_CHR_F_WRITE |
   -                     BLE_GATT_CHR_F_NOTIFY
   -        }, {
   -            0, /* No more characteristics in this service */
   -        }, }
   +                                                             /* Characteristic: servo angle*/
   +                                                             .uuid = &gatt_svr_chr_servo_angle_uuid.u,
   +                                                             .val_handle = &gatt_angle_val_handle,
   +                                                             .access_cb = gatt_svr_chr_access_servo_angle,
   +                                                             .flags = BLE_GATT_CHR_F_READ |
   +                                                                      BLE_GATT_CHR_F_WRITE |
   +                                                                      BLE_GATT_CHR_F_NOTIFY
   +                                                         }, {
   +                                                             /* Characteristic: servo PWM pulse duration*/
   +                                                             .uuid = &gatt_svr_chr_servo_pulse_duration_uuid.u,
   +                                                             .val_handle = &gatt_pulse_duration_val_handle,
   +                                                             .access_cb = gatt_svr_chr_access_servo_pulse_duration,
   +                                                             .flags = BLE_GATT_CHR_F_READ |
   +                                                                      BLE_GATT_CHR_F_WRITE |
   +                                                                      BLE_GATT_CHR_F_NOTIFY
   +                                                         }, {
   +                                                             0, /* No more characteristics in this service */
   +                                                         }, }
        },
    
   -        {
   -            0, /* No more services */
   -        },
   +    {
   +        0,     /* No more services */
   +    },
    };
    
    static int
   ```
   
   </details>
   
   #### apps/bleservo/src/main.c
   <details>
   
   ```diff
   @@ -72,11 +72,9 @@
    {
        if (gatt_value > SERVO_MAX_ANGLE_VAL) {
            servo_angle = SERVO_MAX_ANGLE_VAL;
   -    }
   -    else if (gatt_value < SERVO_MIN_ANGLE_VAL) {
   +    } else if (gatt_value < SERVO_MIN_ANGLE_VAL) {
            servo_angle = SERVO_MIN_ANGLE_VAL;
   -    }
   -    else {
   +    } else {
            servo_angle = gatt_value;
        }
    
   @@ -92,11 +90,9 @@
    {
        if (gatt_value > SERVO_MAX_PULSE_DURATION_US) {
            servo_pwm_pulse_duration = SERVO_MAX_PULSE_DURATION_US;
   -    }
   -    else if (gatt_value < SERVO_MIN_PULSE_DURATION_US) {
   +    } else if (gatt_value < SERVO_MIN_PULSE_DURATION_US) {
            servo_pwm_pulse_duration = SERVO_MIN_PULSE_DURATION_US;
   -    }
   -    else {
   +    } else {
            servo_pwm_pulse_duration = gatt_value;
        }
    
   @@ -108,9 +104,9 @@
    
    
    static void
   -pwm_frac_update_ev_cb (struct os_event *ev)
   -{
   -    struct os_mbuf* om;
   +pwm_frac_update_ev_cb(struct os_event *ev)
   +{
   +    struct os_mbuf * om;
    
        if (was_angle_passed == true) {
            frac = angle_to_frac(servo_angle);
   @@ -126,7 +122,7 @@
        /* Notifications are send to keep client's info about pwm pulse duration and angle values up to date */
        om = ble_hs_mbuf_from_flat(&servo_angle, sizeof(servo_angle));
        ble_gatts_notify_custom(conn_handle, get_gatt_angle_val_handle(), om);
   -    
   +
        om = ble_hs_mbuf_from_flat(&servo_pwm_pulse_duration, sizeof(servo_pwm_pulse_duration));
        ble_gatts_notify_custom(conn_handle, get_gatt_pulse_duration_val_handle(), om);
    }
   @@ -176,7 +172,7 @@
    
        rc = pwm_configure_channel(servo, PWM_CH_NUM, &chan_conf);
        assert(rc == 0);
   -    
   +
        rc = pwm_set_duty_cycle(servo, PWM_CH_NUM, frac);
        rc = pwm_enable(servo);
        assert(rc == 0);
   @@ -230,9 +226,8 @@
                /* Connection failed; resume advertising */
                bleservo_advertise();
                conn_handle = 0;
   -        }
   -        else {
   -          conn_handle = event->connect.conn_handle;
   +        } else {
   +            conn_handle = event->connect.conn_handle;
            }
    
            break;
   @@ -254,7 +249,7 @@
            MODLOG_DFLT(INFO, "subscribe event; cur_notify=%d\n value handle; "
                              "val_handle=%d\n",
                        event->subscribe.cur_notify, servo_angle);
   -        break;    
   +        break;
    
        case BLE_GAP_EVENT_MTU:
            MODLOG_DFLT(INFO, "mtu update event; conn_handle=%d mtu=%d\n",
   @@ -335,7 +330,8 @@
    uint16_t
    frac_to_angle(uint16_t frac_)
    {
   -    return (SERVO_MAX_ANGLE_VAL * frac_ - SERVO_MAX_ANGLE_VAL * servo_frac_min_val) / (servo_frac_max_val - servo_frac_min_val);
   +    return (SERVO_MAX_ANGLE_VAL * frac_ - SERVO_MAX_ANGLE_VAL * servo_frac_min_val) /
   +           (servo_frac_max_val - servo_frac_min_val);
    }
    
    uint16_t
   ```
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org