A wireless multichannel optogenetic headstage with on-the-fly spike detection