reduced message bytes for BLE

Dependencies:   BLE_API mbed nRF51822

Fork of Inp_Fiber_Logo_FOTA by inupathy

Committer:
shimoyamada
Date:
Thu Aug 31 07:49:28 2017 +0000
Revision:
14:698909b62531
Parent:
0:2f6112d75752
correct the length of IBI value for BLE transfer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jojisdogakane 0:2f6112d75752 1 #include "mbed.h" // remove line if not using mbed
jojisdogakane 0:2f6112d75752 2
jojisdogakane 0:2f6112d75752 3 #include <stdbool.h>
jojisdogakane 0:2f6112d75752 4 #include <stdint.h>
jojisdogakane 0:2f6112d75752 5 #include <stdlib.h>
jojisdogakane 0:2f6112d75752 6 #include "nrf_delay.h"
jojisdogakane 0:2f6112d75752 7 #include "nrf_gpio.h"
jojisdogakane 0:2f6112d75752 8 #include "neopixel.h"
jojisdogakane 0:2f6112d75752 9
jojisdogakane 0:2f6112d75752 10
jojisdogakane 0:2f6112d75752 11 void neopixel_init(neopixel_strip_t *strip, uint8_t pin_num, uint16_t num_leds)
jojisdogakane 0:2f6112d75752 12 {
jojisdogakane 0:2f6112d75752 13 strip->leds = (color_t*) malloc(sizeof(color_t) * num_leds);
jojisdogakane 0:2f6112d75752 14 strip->pin_num = pin_num;
jojisdogakane 0:2f6112d75752 15 strip->num_leds = num_leds;
jojisdogakane 0:2f6112d75752 16 nrf_gpio_cfg_output(pin_num);
jojisdogakane 0:2f6112d75752 17 NRF_GPIO->OUTCLR = (1UL << pin_num);
jojisdogakane 0:2f6112d75752 18 for (int i = 0; i < num_leds; i++)
jojisdogakane 0:2f6112d75752 19 {
jojisdogakane 0:2f6112d75752 20 strip->leds[i].simple.g = 0;
jojisdogakane 0:2f6112d75752 21 strip->leds[i].simple.r = 0;
jojisdogakane 0:2f6112d75752 22 strip->leds[i].simple.b = 0;
jojisdogakane 0:2f6112d75752 23 }
jojisdogakane 0:2f6112d75752 24 }
jojisdogakane 0:2f6112d75752 25
jojisdogakane 0:2f6112d75752 26 void neopixel_clear(neopixel_strip_t *strip)
jojisdogakane 0:2f6112d75752 27 {
jojisdogakane 0:2f6112d75752 28 for (int i = 0; i < strip->num_leds; i++)
jojisdogakane 0:2f6112d75752 29 {
jojisdogakane 0:2f6112d75752 30 strip->leds[i].simple.g = 0;
jojisdogakane 0:2f6112d75752 31 strip->leds[i].simple.r = 0;
jojisdogakane 0:2f6112d75752 32 strip->leds[i].simple.b = 0;
jojisdogakane 0:2f6112d75752 33 }
jojisdogakane 0:2f6112d75752 34 neopixel_show(strip);
jojisdogakane 0:2f6112d75752 35 }
jojisdogakane 0:2f6112d75752 36
jojisdogakane 0:2f6112d75752 37 void neopixel_show(neopixel_strip_t *strip)
jojisdogakane 0:2f6112d75752 38 {
jojisdogakane 0:2f6112d75752 39 const uint8_t PIN = strip->pin_num;
jojisdogakane 0:2f6112d75752 40 NRF_GPIO->OUTCLR = (1UL << PIN);
jojisdogakane 0:2f6112d75752 41 //nrf_delay_us(50);
jojisdogakane 0:2f6112d75752 42 nrf_delay_us(100);
jojisdogakane 0:2f6112d75752 43 for (int i = 0; i < strip->num_leds; i++)
jojisdogakane 0:2f6112d75752 44 {
jojisdogakane 0:2f6112d75752 45 for (int j = 0; j < 3; j++)
jojisdogakane 0:2f6112d75752 46 {
jojisdogakane 0:2f6112d75752 47 if ((strip->leds[i].grb[j] & 128) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 48 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 49
jojisdogakane 0:2f6112d75752 50 if ((strip->leds[i].grb[j] & 64) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 51 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 52
jojisdogakane 0:2f6112d75752 53 if ((strip->leds[i].grb[j] & 32) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 54 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 55
jojisdogakane 0:2f6112d75752 56 if ((strip->leds[i].grb[j] & 16) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 57 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 58
jojisdogakane 0:2f6112d75752 59 if ((strip->leds[i].grb[j] & 8) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 60 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 61
jojisdogakane 0:2f6112d75752 62 if ((strip->leds[i].grb[j] & 4) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 63 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 64
jojisdogakane 0:2f6112d75752 65 if ((strip->leds[i].grb[j] & 2) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 66 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 67
jojisdogakane 0:2f6112d75752 68 if ((strip->leds[i].grb[j] & 1) > 0) {NEOPIXEL_SEND_ONE}
jojisdogakane 0:2f6112d75752 69 else {NEOPIXEL_SEND_ZERO}
jojisdogakane 0:2f6112d75752 70 }
jojisdogakane 0:2f6112d75752 71 }
jojisdogakane 0:2f6112d75752 72 }
jojisdogakane 0:2f6112d75752 73
jojisdogakane 0:2f6112d75752 74 uint8_t neopixel_set_color(neopixel_strip_t *strip, uint16_t index, uint8_t red, uint8_t green, uint8_t blue )
jojisdogakane 0:2f6112d75752 75 {
jojisdogakane 0:2f6112d75752 76 if (index < strip->num_leds)
jojisdogakane 0:2f6112d75752 77 {
jojisdogakane 0:2f6112d75752 78 strip->leds[index].simple.r = red;
jojisdogakane 0:2f6112d75752 79 strip->leds[index].simple.g = green;
jojisdogakane 0:2f6112d75752 80 strip->leds[index].simple.b = blue;
jojisdogakane 0:2f6112d75752 81 }
jojisdogakane 0:2f6112d75752 82 else
jojisdogakane 0:2f6112d75752 83 return 1;
jojisdogakane 0:2f6112d75752 84 return 0;
jojisdogakane 0:2f6112d75752 85 }
jojisdogakane 0:2f6112d75752 86
jojisdogakane 0:2f6112d75752 87 uint8_t neopixel_set_color_and_show(neopixel_strip_t *strip, uint16_t index, uint8_t red, uint8_t green, uint8_t blue)
jojisdogakane 0:2f6112d75752 88 {
jojisdogakane 0:2f6112d75752 89 if (index < strip->num_leds)
jojisdogakane 0:2f6112d75752 90 {
jojisdogakane 0:2f6112d75752 91 strip->leds[index].simple.r = red;
jojisdogakane 0:2f6112d75752 92 strip->leds[index].simple.g = green;
jojisdogakane 0:2f6112d75752 93 strip->leds[index].simple.b = blue;
jojisdogakane 0:2f6112d75752 94 neopixel_show(strip);
jojisdogakane 0:2f6112d75752 95 }
jojisdogakane 0:2f6112d75752 96 else
jojisdogakane 0:2f6112d75752 97 return 1;
jojisdogakane 0:2f6112d75752 98 return 0;
jojisdogakane 0:2f6112d75752 99 }
jojisdogakane 0:2f6112d75752 100
jojisdogakane 0:2f6112d75752 101 void neopixel_destroy(neopixel_strip_t *strip)
jojisdogakane 0:2f6112d75752 102 {
jojisdogakane 0:2f6112d75752 103 free(strip->leds);
jojisdogakane 0:2f6112d75752 104 strip->num_leds = 0;
jojisdogakane 0:2f6112d75752 105 strip->pin_num = 0;
jojisdogakane 0:2f6112d75752 106 }