Temperature-induced switching of the bacterial flagellar motor