Skip to content

Commit

Permalink
Use NeoMaple library for SMT32 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
KooLru authored and user2684 committed Mar 25, 2018
1 parent 58fc106 commit 558451a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*~
*.tmp
*.part
*.rsls
8 changes: 8 additions & 0 deletions NodeManagerLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,12 @@
#include <SparkFun_APDS9960.h>
#endif
#ifdef USE_NEOPIXEL
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
#include <NeoMaple.h>
#else
#include <Adafruit_NeoPixel.h>
#endif
#endif

// include third party libraries for enabled features
#ifdef MY_GATEWAY_SERIAL
Expand Down Expand Up @@ -1715,7 +1719,11 @@ class SensorNeopixel: public Sensor {
void onLoop(Child* child);
void onReceive(MyMessage* message);
protected:
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
NeoMaple* _pixels;
#else
Adafruit_NeoPixel* _pixels;
#endif
int _num_pixels = 16;
};
#endif
Expand Down
43 changes: 33 additions & 10 deletions NodeManagerLibrary.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3892,8 +3892,13 @@ void SensorNeopixel::setNumPixels(int value) {

// what to do during setup
void SensorNeopixel::onSetup() {
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
_pixels = new NeoMaple(_num_pixels, NEO_GRB + NEO_KHZ800);
#else
_pixels = new Adafruit_NeoPixel(_num_pixels, _pin, NEO_GRB + NEO_KHZ800);
#endif
_pixels->begin();
_pixels->show();
}

// what to do during loop
Expand All @@ -3904,17 +3909,26 @@ void SensorNeopixel::onLoop(Child *child) {
void SensorNeopixel::onReceive(MyMessage* message) {
Child* child = getChild(message->sensor);
if (child == nullptr) return;
if (message->getCommand() == C_REQ && message->type == child->type) {
setColor(message->getString());
}
if (message->getCommand() == C_SET && message->type == child->type) {
char* string = (char*)message->getString();
setColor(string);
//setColor(message->getString());
}
}

void SensorNeopixel::setColor(char* string) {
Child* child = children.get(1);
// if the second char is not a comma, return
if (strncmp(string+1,",",1) != 0) return;
int pixel_num = atoi(string);
int color = atoi(string+2);
Child* child = children.get(1);
long color = 0;
char * p = strstr(string, ",");
if (p){
char pixelnum[6];
int pos = (int) (p - string);
strncpy(pixelnum, string, pos);
pixelnum[pos] = 0;

int pixel_num = atoi(pixelnum);

color = strtol(string + pos+1, NULL, 16);
#if FEATURE_DEBUG == ON
Serial.print(_name);
Serial.print(F(" I="));
Expand All @@ -3925,9 +3939,18 @@ void SensorNeopixel::setColor(char* string) {
Serial.println(color);
#endif
_pixels->setPixelColor(pixel_num,color);
_pixels->show();
((ChildInt*)child)->setValueInt(color);
}
else //set All pixels to single color
{
color = strtol(string, NULL, 16);
for(int i=0;i<_num_pixels;i++)
_pixels->setPixelColor(i,color);
}

_pixels->show();
((ChildInt*)child)->setValueInt(color);
}

#endif

/*
Expand Down

0 comments on commit 558451a

Please sign in to comment.