"""
Want a pv api for the tpggui to write to so that the nttable updates itself
only add patterns to the table, and if they don't exist anymore make verified = None
Needed to use the MonitoredPv class to make this work
May be a better way of doing this, want to clear the update PV after it is put to
"""

from epics import PV, caput
import time
from p4p.client.thread import Context

#need this implementation to allow for putting to the PV after it is updated
class MonitoredPv:
    def __init__(self, name):
        self._updated = False

        def callback(self=self, **kwargs):
            self._updated = True

        self.PV = PV(name, callback)

    def updated(self):
        if self._updated:
            self._updated = False
            return True
        return False

pattern_pv = "nttable:test:pv:timing"

updatePV = MonitoredPv("TPG:SYS0:1:PATT_UPDATE")



while True:
    """"""
    for i in range (10):
        time.sleep(0.1)
        if updatePV.updated():
            print(updatePV.PV.value)
            if updatePV.PV.value == 1:
                updatePV.PV.put(0)