Create comparator using macro

edited March 2021 in iOS

Hello,

I am getting an error EXC_BAD_ACCESS (code=2, address=0x65f6b65320) on closure of the following line:
let source: TaskCompletionSource<OpaquePointer> = bridgeTransfer(ptr: context!)
within the tasky interface to mbl_mw_dataprocessor_multi_comparator_create when I run the following code:

func macroSet() {
        mbl_mw_macro_record(self.device.board, 0)
        mbl_mw_switch_get_state_data_signal(self.device.board).counterCreateCount().continueOnSuccessWith { count in
            count.comparatorCreate(op: MBL_MW_COMPARATOR_OP_EQ, mode: MBL_MW_COMPARATOR_MODE_ABSOLUTE, references: [Float(2)]).continueOnSuccessWith { comp in
                mbl_mw_event_record_commands(comp)
                self.device.flashLED(color: .red, intensity: 1.0, _repeat: 1)
                comp.eventEndRecord()
            }
            count.comparatorCreate(op: MBL_MW_COMPARATOR_OP_EQ, mode: MBL_MW_COMPARATOR_MODE_ABSOLUTE, references: [Float(4)]).continueOnSuccessWith { comp in
                mbl_mw_event_record_commands(comp)
                self.device.flashLED(color: .blue, intensity: 1.0, _repeat: 1)
                mbl_mw_dataprocessor_counter_set_state(count, 0)
                comp.eventEndRecord()
            }
        }
        self.device.macroEndRecord().continueOnSuccessWith { id in
            mbl_mw_macro_execute(self.device.board, UInt8(id))
        }
    }

Comments

  • edited March 2021

    Here is the task (bolts swift) interface:

    connectNearest().continueWith { t in
            guard let device = t.result else {
                return
            }
            print("macro")
            mbl_mw_macro_record(device.board, 1)
            let switcher = mbl_mw_switch_get_state_data_signal(device.board)
            print("switch: ", switcher as Any)
            switcher?.counterCreate().continueOnSuccessWithTask(device.apiAccessExecutor) { counter -> Task<OpaquePointer> in
                self.counter = counter
                print("counter :",counter)
                return counter.comparatorCreate(op: MBL_MW_COMPARATOR_OP_EQ, mode: MBL_MW_COMPARATOR_MODE_ABSOLUTE, references: [Float(4)])
            }.continueOnSuccessWithTask(device.apiAccessExecutor) { comparator -> Task<Void> in
                print("comp: ", comparator)
                mbl_mw_event_record_commands(comparator)
                print("led")
                device.flashLED(color: .red, intensity: 1.0, _repeat: 1)
                mbl_mw_dataprocessor_counter_set_state(self.counter, 0)
                print("event end")
                return comparator.eventEndRecord()
            }.continueOnSuccessWithTask(device.apiAccessExecutor) { _ -> Task<Int32> in
                print("macro end")
                return device.macroEndRecord()
            }.continueOnSuccessWith(device.apiAccessExecutor) { id in
                self.id = Int(id)
                print("macro with id: ",id)
            }.continueWith(device.apiAccessExecutor) { _ in
                print("macro execute")
                mbl_mw_macro_execute(device.board, UInt8(self.id))
                print("done")
            }
    }
    
  • Thanks Laura! Really appreciate your time here. I noticed that you never called mbl_mw_macro_record - is this call necessary to record a macro?

  • aw crap, it just didn't copy paste. Let me fix that.

Sign In or Register to comment.