"""
Dummy GPIO implementation for testing.
"""

import time
import math

class GPIO(object):
    """
    Dummy GPIO implementation.
    """
    INTERVAL = 0.05
    SIG_FREQ = 0.1
    SIG_AMPL = 100
    SIG_OFFSET = 50
    _signal = 0

    BOARD = 'BOARD'
    IN = 'IN'
    OUT = 'OUT'
    PUD_UP = 'PUD_UP'
    FALLING = 'FALLING'
    RISING = 'RISING'

    PORTC = [21, 19, 15, 13, 11, 7, 5, 3]

    @staticmethod
    def setmode(mode):
        print 'Dummy GPIO: setmode(%s)' % mode

    @staticmethod
    def setup(pin, inout, pull_up_down=None):
        print 'Dummy GPIO: setup(%s, %s, %s)' % (pin, inout, pull_up_down)

    @staticmethod
    def wait_for_edge(port, edge):
        GPIO._signal = (int(math.sin(3.14156 * time.time() * GPIO.SIG_FREQ) * GPIO.SIG_AMPL) + GPIO.SIG_OFFSET) & 0xFF;
        time.sleep(GPIO.INTERVAL)

    @staticmethod
    def cleanup():
        print 'Dummy GPIO: cleanup()'

    @staticmethod
    def input(pin):
        return '{0:08b}'.format(GPIO._signal)[GPIO.PORTC.index(pin)] == '1'
