With two latches, probably a more simple solution exist. <!-- Begin schematic: In order to preserve an editable schematic, please don't edit this section directly. Click the "edit" link below the image in the preview instead. --> ![schematic](https://i.sstatic.net/GFL5K.png) <!-- End schematic -->