@@ -633,8 +633,11 @@ void Sensor::loop(MyMessage* message) {
633
633
_track_last_value && child->isNewValue () ||
634
634
_track_last_value && child->force_update_timer ->isRunning () && child->force_update_timer ->isOver ()
635
635
)
636
- #endif
637
636
child->sendValue ();
637
+ #else
638
+ child->sendValue ();
639
+ #endif
640
+
638
641
}
639
642
#if FEATURE_HOOKING == ON
640
643
// if a hook function is defined, call it
@@ -3934,17 +3937,16 @@ void SensorAPDS9960::onInterrupt() {
3934
3937
SensorNeopixel::SensorNeopixel (NodeManager& node_manager, int pin, int child_id): Sensor(node_manager, pin) {
3935
3938
_name = " NEOPIXEL" ;
3936
3939
children.allocateBlocks (1 );
3937
- new ChildInt (this , _node->getAvailableChildId (child_id), S_COLOR_SENSOR, V_RGB ,_name);
3940
+ new ChildString (this , _node->getAvailableChildId (child_id), S_COLOR_SENSOR, V_RGB ,_name);
3938
3941
}
3939
3942
3940
3943
// setter/getter
3941
3944
void SensorNeopixel::setNumPixels (int value) {
3942
3945
_num_pixels = value;
3943
3946
}
3944
-
3945
3947
// what to do during setup
3946
3948
void SensorNeopixel::onSetup () {
3947
- #if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4 )
3949
+ #if defined(CHIP_STM32 )
3948
3950
_pixels = new NeoMaple (_num_pixels, NEO_GRB + NEO_KHZ800);
3949
3951
#else
3950
3952
_pixels = new Adafruit_NeoPixel (_num_pixels, _pin, NEO_GRB + NEO_KHZ800);
@@ -3968,39 +3970,65 @@ void SensorNeopixel::onReceive(MyMessage* message) {
3968
3970
}
3969
3971
}
3970
3972
3973
+ // string format:
3974
+ // RRGGBB color for all LEDs
3975
+ // LED,RRGGBB color for specific LED
3976
+ // LEDfrom-LEDto,RRGGBB color for LED range from LEDfrom to LEDto
3971
3977
void SensorNeopixel::setColor (char * string) {
3972
3978
Child* child = children.get (1 );
3973
3979
long color = 0 ;
3980
+ // find separator
3974
3981
char * p = strstr (string, " ," );
3975
3982
if (p){
3976
- char pixelnum[6 ];
3983
+ // extract LED or LED range part
3984
+ char pixelnum[10 ];
3977
3985
int pos = (int ) (p - string);
3986
+ if (pos >= 10 )
3987
+ return ;
3978
3988
strncpy (pixelnum, string, pos);
3979
3989
pixelnum[pos] = 0 ;
3980
3990
3981
- int pixel_num = atoi (pixelnum);
3982
-
3983
- color = strtol (string + pos+1 , NULL , 16 );
3991
+ int pixel_num = 0 ;
3992
+ int pixel_end = 0 ;
3993
+ // may be range, try find range separator -
3994
+ char * r = strstr (pixelnum, " -" );
3995
+ if (r){
3996
+ pixel_end = atoi (r+1 );
3997
+ *r = 0 ; // null terminating instead of delimeter
3998
+ pixel_num = atoi (pixelnum);
3999
+ }
4000
+ else {
4001
+ pixel_num = atoi (pixelnum);
4002
+ pixel_end = pixel_num;
4003
+ }
4004
+ color = strtol (string + pos + 1 , NULL , 16 );
3984
4005
#if FEATURE_DEBUG == ON
3985
4006
Serial.print (_name);
3986
4007
Serial.print (F (" I=" ));
3987
4008
Serial.print (child->child_id );
3988
4009
Serial.print (F (" N=" ));
3989
4010
Serial.print (pixel_num);
4011
+ if (pixel_num != pixel_end)
4012
+ {
4013
+ Serial.print (F (" -" ));
4014
+ Serial.print (pixel_end);
4015
+ }
3990
4016
Serial.print (F (" C=" ));
3991
4017
Serial.println (color);
3992
4018
#endif
3993
- _pixels->setPixelColor (pixel_num,color);
4019
+ // set LED to color
4020
+ for (int i=pixel_num;i<=pixel_end;i++)
4021
+ _pixels->setPixelColor (i,color);
3994
4022
}
3995
4023
else // set All pixels to single color
3996
4024
{
3997
4025
color = strtol (string, NULL , 16 );
3998
4026
for (int i=0 ;i<_num_pixels;i++)
3999
4027
_pixels->setPixelColor (i,color);
4000
4028
}
4001
-
4002
4029
_pixels->show ();
4003
- ((ChildInt*)child)->setValueInt (color);
4030
+ // send value back
4031
+ ((ChildString*)child)->setValueString (string);
4004
4032
}
4005
4033
4006
4034
#endif
@@ -4697,14 +4725,15 @@ void NodeManager::hello() {
4697
4725
4698
4726
// reboot the board
4699
4727
void NodeManager::reboot () {
4700
- #ifdef CHIP_AVR
4701
4728
#if FEATURE_DEBUG == ON
4702
4729
Serial.println (F (" REBOOT" ));
4703
4730
#endif
4704
4731
if (_reboot_pin > -1 ) {
4705
4732
// reboot the board through the reboot pin which is connected to RST by setting it to low
4706
4733
digitalWrite (_reboot_pin, LOW);
4707
- } else {
4734
+ }
4735
+ #ifdef CHIP_AVR
4736
+ else {
4708
4737
// Software reboot with watchdog timer. Enter Watchdog Configuration mode:
4709
4738
WDTCSR |= (1 <<WDCE) | (1 <<WDE);
4710
4739
// Reset enable
@@ -4789,13 +4818,21 @@ void NodeManager::setupInterrupts() {
4789
4818
pinMode (INTERRUPT_PIN_1,INPUT);
4790
4819
if (_interrupt_1_initial > -1 ) digitalWrite (INTERRUPT_PIN_1,_interrupt_1_initial);
4791
4820
// for non sleeping nodes, we need to handle the interrupt by ourselves
4821
+ #if defined(CHIP_STM32)
4822
+ if (_status != SLEEP) attachInterrupt (digitalPinToInterrupt (INTERRUPT_PIN_1), _onInterrupt_1, (ExtIntTriggerMode)_interrupt_1_mode);
4823
+ #else
4792
4824
if (_status != SLEEP) attachInterrupt (digitalPinToInterrupt (INTERRUPT_PIN_1), _onInterrupt_1, _interrupt_1_mode);
4825
+ #endif
4793
4826
}
4794
4827
if (_interrupt_2_mode != MODE_NOT_DEFINED) {
4795
4828
pinMode (INTERRUPT_PIN_2, INPUT);
4796
4829
if (_interrupt_2_initial > -1 ) digitalWrite (INTERRUPT_PIN_2,_interrupt_2_initial);
4797
4830
// for non sleeping nodes, we need to handle the interrupt by ourselves
4831
+ #if defined(CHIP_STM32)
4832
+ if (_status != SLEEP) attachInterrupt (digitalPinToInterrupt (INTERRUPT_PIN_2), _onInterrupt_2, (ExtIntTriggerMode)_interrupt_2_mode);
4833
+ #else
4798
4834
if (_status != SLEEP) attachInterrupt (digitalPinToInterrupt (INTERRUPT_PIN_2), _onInterrupt_2, _interrupt_2_mode);
4835
+ #endif
4799
4836
}
4800
4837
#if FEATURE_DEBUG == ON
4801
4838
Serial.print (F (" INT P=" ));
0 commit comments