improve analog read and device-loop logic