def captureSamples(cursor):
    if (CLEARDATA): cursor.execute("DELETE FROM %s" % (TABLE))
    myData = dataDevice.device()
    myDataNames = myData.getName()

    if (DEBUG):
        print(FORMATBODY % ("##", myDataNames[VAL0], myDataNames[VAL1],
                            myDataNames[VAL2], myDataNames[VAL3]))
    for x in range(10):
        data = myData.getNew()
        for i, dataName in enumerate(myDataNames):
            sqlquery = "INSERT INTO %s (itm_name, itm_value) " %(TABLE) + \
                       "VALUES('%s', %s)" \
                        %(str(dataName),str(data[i]))
            if (SHOWSQL): print(sqlquery)
            cursor.execute(sqlquery)


#            cursor.execute("INSERT INTO ? (itm_name, itm_value) VALUES('?', ?)",
#                        (TABLE,str(dataName),data[i]))
#            cursor.execute("INSERT INTO ? (itm_name, itm_value) VALUES('?', ?)",
#                        (str(TABLE),str(dataName),str(data[i])))
##            sqlquery = "INSERT INTO %s (itm_name, itm_value) VALUES(?, ?)" %(TABLE)
#           sqlquery = "INSERT INTO ? (itm_name, itm_value) VALUES(?, ?)"
##            cursor.execute(sqlquery,(str(dataName),str(data[i])))

        if (DEBUG):
            print(FORMATBODY %
                  (x, data[VAL0], data[VAL1], data[VAL2], data[VAL3]))
        time.sleep(DELAY)
    cursor.commit()
Ejemplo n.º 2
0
def main():
    global run
    gpiosetup()
    myData = dataDevice.device()
    myDataNames = myData.getName()
    run = True
    index = 0
    while (run):
        data = myData.getNew()
        printLCD(myDataNames[index], str(data[index]))
        time.sleep(1)
        index = checkBtn(index, len(myDataNames))
def main():
    counter = 0
    myData = dataDevice.device()
    myDataNames = myData.getName()
    header = (FORMATHEADER % ("Time", myDataNames[VAL0], myDataNames[VAL1],
                              myDataNames[VAL2], myDataNames[VAL3]))
    if (DEBUG): print(header)
    if (FILE): f.write(header + "\n")
    while (1):
        data = myData.getNew()
        counter += 1
        body = (FORMATBODY %
                (counter, timestamp(), data[0], data[1], data[2], data[3]))
        if (DEBUG): print(body)
        if (FILE): f.write(body + "\n")
        time.sleep(0.1)
Ejemplo n.º 4
0
#!/usr/bin/python3
#live_graph.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import data_adc as dataDevice

PADDING = 5
myData = dataDevice.device()
dispdata = []
timeplot = 0
fig, ax = plt.subplots()
line, = ax.plot(dispdata)


def update(data):
    global dispdata, timeplot
    timeplot += 1
    dispdata.append(data)
    ax.set_xlim(0, timeplot)
    ymin = min(dispdata) - PADDING
    ymax = max(dispdata) + PADDING
    ax.set_ylim(ymin, ymax)
    line.set_data(range(timeplot), dispdata)
    return line


def data_gen():
    while True:
        yield myData.getNew()[0]