         if segue.identifier == "tinker"
         {
             self.lastTappedNonTinkerDevice = nil
-//            self.flashingTimer?.invalidate()
+            //            self.flashingTimer?.invalidate()
             
             if let vc = segue.destinationViewController as? SPKTinkerViewController
             {

            TSMessage.showNotificationWithTitle("Device is being flashed", subtitle: "Device is currently being flashed, please wait for the process to finish.", type: .Warning)
            
        }
        else if self.devices[indexPath.row].connected
        {
            switch devices[indexPath.row].isRunningTinker()
            {
            case true :
                
                self.selectedDevice = self.devices[indexPath.row]
                self.performSegueWithIdentifier("tinker", sender: self)
            default :
                if let ntd = self.lastTappedNonTinkerDevice where self.devices[indexPath.row].id == ntd.id
                {
                    self.selectedDevice = self.devices[indexPath.row]
                    self.performSegueWithIdentifier("tinker", sender: self)
                }
                else
                {
                    let device = self.devices[indexPath.row]
                    self.lastTappedNonTinkerDevice = device
                    NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: #selector(DeviceListViewController.resetLastTappedDevice(_:)), userInfo: nil, repeats: false)
                    
                    // TODO: add "not running tinker, do you want to flash?"
                    TSMessage.showNotificationInViewController(self, title: "Device not running Tinker", subtitle: "Do you want to flash Tinker firmware to this device? Tap device again to Tinker with it anyway", image: UIImage(named: "imgQuestionWhite"), type: .Message, duration: -1, callback: { () -> Void in
                        // callback for user dismiss by touching inside notification
                        TSMessage.dismissActiveNotification()
                        } , buttonTitle: " Flash ", buttonCallback: { () -> Void in
                            self.lastTappedNonTinkerDevice = nil
                            
                            // TODO: duplicate code - fix
                            switch (device.type)
                            {
                            case .Core:
                                //                                        Mixpanel.sharedInstance().track("Tinker: Reflash Tinker",
                                Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Core"])
                                
                                device.flashKnownApp("tinker", completion: { (error:NSError?) -> Void in
                                    if let e=error
                                    {
                                        TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
                                    }
                                    else
                                    {
                                        TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
                                        //                                                self.deviceIDsBeingFlashed[device.id] = defaultFlashingTime
                                        //                                                self.flashingTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "flashingTimerFunc:", userInfo: nil, repeats: true)
                                        device.isFlashing = true
                                        self.deviceIDflashingDict[device.id] = kDefaultCoreFlashingTime
                                        self.photonSelectionTableView.reloadData()
                                        
                                    }
                                })
                                
                            case .Photon:
                                Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Photon"])
                                
                                let bundle = NSBundle.mainBundle()
                                let path = bundle.pathForResource("photon-tinker", ofType: "bin")
                                //                                        var error:NSError?
                                if let binary: NSData? = NSData.dataWithContentsOfMappedFile(path!) as? NSData // fix deprecation
                                {
                                    let filesDict = ["tinker.bin" : binary!]
                                    device.flashFiles(filesDict, completion: { (error:NSError?) -> Void in
                                        if let e=error
                                        {
                                            TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
                                        }
                                        else
                                        {
                                            TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
                                            //                                                    self.deviceIDsBeingFlashed[device.id] = defaultFlashingTime
                                            //                                                    self.flashingTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "flashingTimerFunc:", userInfo: nil, repeats: true)
                                            device.isFlashing = true
                                            self.deviceIDflashingDict[device.id] = kDefaultPhotonFlashingTime
                                            self.photonSelectionTableView.reloadData()
                                            
                                        }
                                    })
                                    
                                }
                            case .Electron:
                                Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Electron"])
                                // TODO: support flashing tinker to Electron
//                                TSMessage.showNotificationWithTitle("Not supported", subtitle: "Operation not supported yet, coming soon.", type: .Warning)
                                
                                
                                // heading
                                let optionMenu = UIAlertController(title: "Flashing Tinker to Electron", message: "Flashing Tinker to Electron will consume X KB of data from your data plan, are you sure you want to continue?", preferredStyle: .Alert)
                                
                                
                                let yesAction = UIAlertAction(title: "Yes", style: .Default, handler: {
                                    (alert: UIAlertAction!) -> Void in
                                    // check if this works otherwise put binary
                                    device.flashKnownApp("tinker", completion: { (error:NSError?) -> Void in
                                        if let e=error
                                        {
                                            TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
                                        }
                                        else
                                        {
                                            TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your Electron is being flashed with Tinker firmware...", type: .Success)
                                            device.isFlashing = true
                                            self.deviceIDflashingDict[device.id] = kDefaultElectronFlashingTime
                                            self.photonSelectionTableView.reloadData()
                                            
                                        }
                                    })

                                    
                                })
                                
                                                              // cancel
                                let cancelAction = UIAlertAction(title: "No", style: .Cancel, handler: {
                                    (alert: UIAlertAction!) -> Void in
                                })
                                
                                
                                // 4
                                optionMenu.addAction(yesAction)
                                optionMenu.addAction(cancelAction)
                                
                                // 5
                                self.presentViewController(optionMenu, animated: true, completion: nil)
                                
                                
                            }
                        }, atPosition: .Top, canBeDismissedByUser: true)
                    
                    
                    //TSMessage.showNotificationWithTitle("Device not running Tinker", subtitle: "This device firmware is not Tinker, tap it again if you want to Tinker with it anyway.", type: .Warning)
                    
                }
            }
            
        }
        else
        {
            self.lastTappedNonTinkerDevice = nil
            TSMessage.showNotificationWithTitle("Device offline", subtitle: "This device is offline, please turn it on and refresh in order to Tinker with it.", type: .Error)
        }
    }
    

            vc.delegate = self
            self.presentViewController(vc, animated: true, completion: nil)
        }
        
    }
    
    
    func showSparkCoreAppPopUp()
    {
        Mixpanel.sharedInstance().track("Tinker: User wants to setup a Core")
        
        let popup = Popup(title: "Core setup", subTitle: "Setting up a Core requires the legacy Spark Core app. Do you want to install/open it now?", cancelTitle: "No", successTitle: "Yes", cancelBlock: {()->() in }, successBlock: {()->() in
            let sparkCoreAppStoreLink = "itms://itunes.apple.com/us/app/apple-store/id760157884?mt=8";
            Mixpanel.sharedInstance().track("Tinker: Send user to old Spark Core app")
