Write a function to control a peripheral device based on specific inputs.
Implement peripheral_commands(readings), where each integer uses bit 0 for the requested state, with 1 meaning active and 0 meaning deactivated, and bit 1 as an emergency flag. Return one command for each reading. Require two consecutive non-emergency readings requesting a state change before returning ACTIVATE or DEACTIVATE; otherwise return NOOP. An emergency reading returns SAFE_STOP and permanently latches the controller in safe-stop mode, so later non-emergency readings return NOOP.
def peripheral_commands(readings):