Neopixels in ANCS notification handler issue







I am having trouble pairing the metawear board when I'm using neopixels in the ANCS notification handler.  The board pairs fine if I do something simple like make the onboard LED flash.  But as soon as I do something with the neopixels, it crashes.

Here's where it's crashing in the metawear SDK:

#0    0x00173d90 in __51-[MBLCommand programCommandsToRunOnEvent:commands:]_block_invoke98 at /Users/sschiffli/Code/metawear-ios-api/MetaWear/MBLCommand.m:152

#1    0x0017ebc6 in __34-[MBLRegister recievedData:error:]_block_invoke at /Users/sschiffli/Code/metawear-ios-api/MetaWear/MBLRegister.m:268

And here's my code snippet that causes it to crash:

        let event5:MBLEvent = device.ancs.eventWithCategoryIds(MBLANCSCategoryID.Any, eventIds: MBLANCSEventID.NotificationAdded, eventFlags: MBLANCSEventFlag.Any, attributeId: MBLANCSNotificationAttributeID.AppIdentifier, attributeData: "com.lumalegacy.Luma")

        event5.programCommandsToRunOnEvent({

            device.led.flashLEDColor(UIColor.blueColor(), withIntensity: 1.0, numberOfFlashes: 3)

            let length:UInt8 = 7; // Specific to your NeoPixel stand

            let color:MBLColorOrdering = MBLColorOrdering.GRB; // Specific to your NeoPixel stand

            let speed:MBLStrandSpeed = MBLStrandSpeed.Slow; // Specific to your NeoPixel stand

            let strand:MBLNeopixelStrand = device.neopixel.strandWithColor(color, speed: speed, pin: 0, length: length);


            for(var i:UInt8 = 0; i < 100; i++){

                strand.setPixel(i % length, color: UIColor.redColor())

                strand.turnStrandOff()

            }

        })


Does anyone have experience using neopixels in the ANCS event handler for iOS, or see what I'm doing wrong here?  Thanks!

Comments

  • I would think about the problem in a slightly different way, maybe this fits into your use case.  You want lights to come on when you get an ANCS event, then you need a different event to signal that lights should turn off. (say a button press).  That could be coded like this:

        self.strand = [device.neopixel strandWithColor:MBLColorOrderingGRB

                                                 speed:MBLStrandSpeedSlow

                                                   pin:NeopixelSignalPin

                                                length:NeopixelPixels];

        

        self.ancsEvent = [device.ancs eventWithCategoryIds:MBLANCSCategoryIDAny

                                                  eventIds:MBLANCSEventIDNotificationAdded

                                                eventFlags:MBLANCSEventFlagAny

                                          attributeId:MBLANCSNotificationAttributeIDAppIdentifier

                                             attributeData:@com.lumalegacy.Luma];

        [self.ancsEvent programCommandsToRunOnEvent:^{

            for (int i = 0; i < NeopixelPixels; i++) {

                [self.strand setPixel:i color:[UIColor redColor]];

            }

        }];

        

        [device.mechanicalSwitch.switchUpdateEvent programCommandsToRunOnEvent:^{

            [self.strand clearFromStartPixel:0 endPixel:NeopixelPixels - 1];

        }];

This discussion has been closed.