Exemple #1
0
def copyfiles_to_usb():
    isUSB = os.path.isdir(usb_dir_path)
    time.sleep(3)
    oledBkpDisp1()
    emmctousb.EMMC_TO_USB_COPY()
    oledExp.clear()
    print("Copy Done")
    oledExp.setCursor(1, 0)
    oledExp.write("Copy Done")
    oledExp.setCursor(2, 0)
    oledExp.write("Remove Pendrive")
    oledExp.setCursor(3, 0)
    oledExp.write("to enter Run Mode")
    oledExp.setCursor(6, 0)
    oledExp.write("*********************")
    oledExp.setCursor(7, 8)
    oledExp.write("BKP MODE")
    print("Remove Pendrive")
    count3 = 0
    while (isUSB):
        isUSB = os.path.isdir(usb_dir_path)
        time.sleep(1)
        count3 = count3 + 1
        if count3 == 60:
            RUN_MODE()
        else:
            pass
    else:
        oledExp.clear()
        print("Enters Run mode after Files Copied")
Exemple #2
0
 def __init__(self):
     isUSB = os.path.isdir(usb_dir_path)
     count = 0
     while isUSB:
         r = RTC_DATE_TIME()
         print("Remove Pendrive to enter run mode")
         oledExp.setCursor(0, 0)
         oledExp.write(r.rtc_dateTime)
         oledExp.setCursor(1, 0)
         oledExp.write("*********************")
         oledExp.setCursor(2, 3)
         oledExp.write("Remove USB to ")
         oledExp.setCursor(3, 3)
         oledExp.write("enter run mode ")
         oledExp.setCursor(6, 0)
         oledExp.write("*********************")
         oledExp.setCursor(7, 3)
         oledExp.write("WAITING MODE")
         time.sleep(1)
         count = count + 1
         # oledExp.clear()
         isUSB = os.path.isdir(usb_dir_path)
         del r
         if count == 60:
             RUN_MODE()
         else:
             pass
     else:
         oledExp.clear()
         RUN_MODE()
Exemple #3
0
def start_write():
    if oledExp.driverInit() != 0:
        print 'ERROR: Could not initialize the OLED Expansion'
        return False

# this clears the screen
    oledExp.clear()

    # this sets the colour
    oledExp.setDisplayMode(0)

    #this sets it to receive text
    oledExp.setTextColumns()

    #this places the cursor on the second row, first column
    oledExp.setCursor(1, 0)

    oledExp.write('Welcome.')

    oledExp.setCursor(3, 0)

    oledExp.write('Loading ticker..')

    oledExp.setCursor(5, 0)

    oledExp.write('Prices in EUR.')
Exemple #4
0
def access_lock(uid):
        oledExp.write("Your UID is: " + uid)
        relayExp.setChannel(7,0,1)
        time.sleep(5)
        relayExp.setChannel(7,0,0)
        oledExp.clear()
        return
Exemple #5
0
 def ConfDoneMsg(self):
     oledExp.clear()
     oledExp.setCursor(7, 0)
     oledExp.write("CONFIGURATION MODE")
     oledExp.setCursor(6, 0)
     oledExp.write("*********************")
     oledExp.setCursor(3, 0)
     oledExp.write("Configuartion done")
Exemple #6
0
def welcomeMessage():
    oledExp.setVerbosity(0)
    oledExp.driverInit()
    oledExp.clear()
    oledExp.setCursor(3, 0)
    oledExp.write("Welcome to OnionOmega")
    oledExp.setCursor(4, 0)
    oledExp.write("Data Logger Project")
    time.sleep(5)
Exemple #7
0
 def WrongSelectionOfKey(self):
     oledExp.clear()
     oledExp.setCursor(3, 0)
     oledExp.write("Invalid Selection")
     oledExp.setCursor(4, 0)
     oledExp.write("Select 1 or 2 or 3")
     time.sleep(2)
     oledExp.clear()
     self.ModesOfDataLogger()
Exemple #8
0
 def ConfigureMode_Page2(self):
     oledExp.clear()
     oledExp.setCursor(3, 0)
     oledExp.write("Invalid Selection")
     oledExp.setCursor(4, 0)
     oledExp.write("Select 1 or 2 or 3")
     time.sleep(2)
     oledExp.clear()
     self.MenuOfConfigureMode()
Exemple #9
0
def setDoneScreen():
	# clear the screen
	oledExp.clear()

	# set the cursor the middle line
	oledExp.setTextColumns()
	oledExp.setCursor(3,0)
	# write out the text
	oledExp.write( "TEMP SENSOR OFFLINE" )
Exemple #10
0
    def site_details(self):
        disp.ConnectToPC()
        siteId = ''
        monitoringId = ''
        analyzerId = ''
        parameterId = ''
        while len(siteId) == 0:
            # Serial input
            ser.write('Enter site ID: ')
            siteId = ser.read()  # read serial port
            time.sleep(0.03)
            data_left = ser.inWaiting()  # check for remaining byte
            siteId += ser.read(data_left)
            ser.write(siteId + '\r\n')
            oledExp.clear()
            oledExp.setCursor(1, 0)
            oledExp.write(siteId)
            time.sleep(1)
        while len(monitoringId) == 0:
            ser.write('Enter monitoring ID: ')
            monitoringId = ser.read()  # read serial port
            time.sleep(0.03)
            data_left = ser.inWaiting()  # check for remaining byte
            monitoringId += ser.read(data_left)
            ser.write(monitoringId + '\r\n')
            oledExp.setCursor(2, 0)
            oledExp.write(monitoringId)
            time.sleep(1)
        while len(analyzerId) == 0:
            ser.write('Enter analyserID: ')
            analyzerId = ser.read()  # read serial port
            time.sleep(0.03)
            data_left = ser.inWaiting()  # check for remaining byte
            analyzerId += ser.read(data_left)
            ser.write(analyzerId + '\r\n')
            oledExp.setCursor(3, 0)
            oledExp.write(analyzerId)
            time.sleep(1)
        while len(parameterId) == 0:
            ser.write('Enter ParameterID: ')
            parameterId = ser.read()  # read serial port
            time.sleep(0.03)
            data_left = ser.inWaiting()  # check for remaining byte
            parameterId += ser.read(data_left)
            ser.write(parameterId + '\r\n')
            oledExp.setCursor(4, 0)
            oledExp.write(parameterId)

        f = open('confdata.txt', 'w')
        f.write(siteId + '\n')
        f.write(monitoringId + '\n')
        f.write(analyzerId + '\n')
        f.write(parameterId + '\n')
        time.sleep(5)
        disp.ConfDoneMsg()
Exemple #11
0
def oledBkpDisp1():
    oledExp.clear()
    oledExp.setCursor(0, 0)
    oledExp.write("Enter FROM and TO")
    oledExp.setCursor(1, 0)
    oledExp.write("dates in the format:")
    oledExp.setCursor(2, 0)
    oledExp.write("dd*mm*yy ")
    oledExp.setCursor(3, 0)
    oledExp.write("Ex: 23/01/20")
    time.sleep(2)
Exemple #12
0
 def isdatesAcceptable(self):
     if self.td < self.fd:
         print("TO DATE should be greater than FROM DATE ")
         oledExp.write("TO DATE should be greater than FROM DATE")
         oledExp.setCursor(3, 0)
         oledExp.write("TRY AGAIN")
         time.sleep(2)
         oledExp.clear()
         return False
     else:
         return True
Exemple #13
0
 def goto_menu(self):
     oledExp.setCursor(5,0)
     oledExp.write("Press '#' to return")
     oledExp.setCursor(6, 0)
     oledExp.write("Main Menu")
     key2=k.getPressKey()
     if key2=='#':
         oledExp.setCursor(7, 0)
         oledExp.write(key2)
         time.sleep(2)
         oledExp.clear()
         self.__init__()
Exemple #14
0
def displayModes():
    oledExp.clear()
    oledExp.setCursor(2, 0)
    oledExp.write("Select mode(1,2,3):")
    oledExp.setCursor(3, 0)
    oledExp.write("1. CONFIGURE MODE")
    oledExp.setCursor(4, 0)
    oledExp.write("2. RUN MODE")
    oledExp.setCursor(5, 0)
    oledExp.write("3. BACKUP MODE")
    oledExp.setCursor(6, 0)
    oledExp.write("Mode of Operation:")
Exemple #15
0
    def modeSelection(self):
        self.keypad_init()
        rpos = 0
        if True:
            for rpin in self.r:
                omega_gpio.setoutput(self.r[0], 0)
                omega_gpio.setoutput(self.r[1], 0)
                omega_gpio.setoutput(self.r[2], 0)
                omega_gpio.setoutput(self.r[3], 0)
                omega_gpio.setoutput(rpin, 1)
                time.sleep(0.05)
                cpos = 0
                for cpin in self.c:
                    input = omega_gpio.readinput(cpin)
                    self.values[rpos][cpos] = input
                    cpos = cpos + 1
                rpos = rpos + 1

            for x in range(0, 4):
                for y in range(0, 4):
                    if self.values[x][y] != self.lastvalues[x][y]:
                        keycode = self.key[x][y]
                        if self.values[x][y] == 1:
                            if keycode == '1':
                                oledExp.setCursor(7, 0)
                                oledExp.write(keycode)
                                time.sleep(2)
                                configure.DL_SETTINGS()
                                dlmode.RUN_MODE()
                            elif keycode == '2':
                                oledExp.setCursor(7, 0)
                                oledExp.write(keycode)
                                time.sleep(2)
                                dlmode.DIRECT_RUN_MODE()
                            elif keycode == '3':
                                oledExp.setCursor(7, 0)
                                oledExp.write(keycode)
                                time.sleep(2)
                                dlmode.DIRECT_BACKUP_MODE()
                            else:
                                #print(keycode)

                                oledExp.clear()
                                oledExp.setCursor(3, 0)
                                oledExp.write("Invalid Selection")
                                oledExp.setCursor(4, 0)
                                oledExp.write("Select 1 or 2 or 3")
                                time.sleep(2)

            lastvalues = copy.deepcopy(self.values)
Exemple #16
0
    def MenuOfConfigureMode(self):
	oledExp.clear()
        oledExp.setCursor(7, 0)
        oledExp.write("CONFIGURATION MODE")
        oledExp.setCursor(6, 0)
        oledExp.write("*********************")
        oledExp.setCursor(1, 0)
        oledExp.write("1. SET DATE AND TIME ")
        oledExp.setCursor(2, 0)
        oledExp.write("2. To Edit Other Parameters")
        oledExp.setCursor(3, 0)
        oledExp.write("3. To Read Configuration")
        oledExp.setCursor(4, 0)
        oledExp.write("Your Selection: ")
Exemple #17
0
def print_status():
    global g_buttonsConnected, g_ipAddr
    oledExp.clear()
    oledExp.setCursor(0, 0)
    oledExp.write("Host  : " + g_ipAddr)
    oledExp.setCursor(1, 0)
    oledExp.write("Broker: " + broker)
    oledExp.setCursor(2, 0)
    if g_buttonsConnected:
        oledExp.write("Client: Connected")
    else:
        oledExp.write("                 ")

    print_relay_status()
    print_gpio_status()
Exemple #18
0
 def read_confdata(self):
     f = open('confdata.txt', 'r')
     lines = f.readlines()
     SiteID = lines[0].rstrip('\n')
     MonitoringID = lines[1].rstrip('\n')
     AnalyzerID = lines[2].rstrip('\n')
     ParameterID = lines[3].rstrip('\n')
     oledExp.clear()
     oledExp.setCursor(0, 0)
     oledExp.write(SiteID)
     oledExp.setCursor(1, 0)
     oledExp.write(MonitoringID)
     oledExp.setCursor(2, 0)
     oledExp.write(AnalyzerID)
     oledExp.setCursor(3, 0)
     oledExp.write(ParameterID)
def writeHeadline(title, time, author):
    if oledExp.driverInit() != 0:
        print 'ERROR: Could not initialize the OLED Expansion'
        return False

    oledExp.clear()

    # writes the authors at the bottom - might overflow back to page 0
    oledExp.setCursor(6, 0)
    oledExp.write(author)

    # writes the headline to the screen to clear overflow from author
    oledExp.setCursor(0, 0)
    oledExp.write('    ' + title)  # indenting the title to look a bit better

    # writes timestamp at the end to ensure it doesn't get overwritten
    oledExp.setCursor(5, 0)
    oledExp.write(time)
Exemple #20
0
    def __init__(self):
        oledExp.setCursor(7, 0)
        oledExp.write("CONFIGURATION MODE")
        oledExp.setCursor(6, 0)
        oledExp.write("*********************")
        oledExp.setCursor(1, 0)
        oledExp.write("1. SET DATE AND TIME ")
        oledExp.setCursor(2, 0)
        oledExp.write("2. To Edit Other Parameters")
        oledExp.setCursor(3,0)
        oledExp.write("3. To Read Configuration")
        oledExp.setCursor(4, 0)
        oledExp.write("Your Selection: ")
        selection = k.getPressKey()
        oledExp.setCursor(5, 0)
        oledExp.write(selection)
        time.sleep(2)
        oledExp.clear()

        if (selection == '1'):
            print("----------------------SET DATE AND TIME----------------------")
            self.set_date_time()
        elif (selection == '2'):
            print("----------------To Edit Other Parameters---------------")
            self.site_details()
        elif (selection == '3'):
            print("---------------To Read Configuration--------------------")
            self.read_confdata()
        else:             
	    oledExp.clear()             
	    oledExp.setCursor(4, 0)             
	    oledExp.write("Invalid Selection")             
            time.sleep(3)             
            oledExp.clear()
	    self.__init__()
    def setTime(self):
        while True:
            ser.write("Set time in the format hr:min:sec: ")
            time_string = ser.read()

            try:
                self.hr = int(time_string[0:2])
                self.min = int(time_string[3:5])
                self.sec = int(time_string[6:8])

                if 0 <= self.hr <= 24 and 0 <= self.min <= 59 and 0 <= self.sec <= 59:
                    self.isvalid_ts = True
                else:
                    self.isvalid_ts = False

                isvalid_time_string = self.isvalid_ts
                len_of_time = len(time_string)

                if isvalid_time_string == True and time_string[
                        2] == '*' and time_string[
                            5] == '*' and len_of_time == 8:
                    break
                elif isvalid_time_string == True and time_string[
                        2] == '*' and time_string[
                            5] == '*' and len_of_time != 8:
                    oledExp.write("Format should be hr*min*sec Ex- 13*01*02")
                    time.sleep(2)
                    oledExp.clear()
                    print("Format should be hr*min*sec")
                elif isvalid_time_string == True and (time_string[2] != '*' or
                                                      time_string[5] != '*'):
                    oledExp.write("Format should be hr*min*sec Ex- 13*01*02")
                    time.sleep(2)
                    oledExp.clear()
                elif isvalid_time_string == False and (
                        time_string[2] == '*' and time_string[5] == '*'
                        and len_of_time == 8):
                    oledExp.write("Invalid Time. ")
                    time.sleep(2)
                    oledExp.clear()

            except:
                oledExp.write("Format should be hr:min:sec Ex- 13:01:02")
                time.sleep(2)
                oledExp.clear()
        self.timeString = str(self.hr) + ":" + str(self.min) + ":" + str(
            self.sec)
Exemple #22
0
 def __init__(self):
     isUSB = os.path.isdir(usb_dir_path)
     if isUSB:
         copyfiles_to_usb()
     else:
         oledExp.setCursor(2, 0)
         oledExp.write("Connect USB to enter BACKUP Mode")
         # print("USB not Connected")
         oledExp.setCursor(6, 0)
         oledExp.write("*********************")
         oledExp.setCursor(7, 3)
         oledExp.write("WAITING MODE")
         count2 = 0
         while (isUSB == 0):
             isUSB = os.path.isdir(usb_dir_path)
             time.sleep(1)
             count2 = count2 + 1
             if count2 == 60:
                 RUN_MODE()
             else:
                 pass
         else:
             oledExp.clear()
             copyfiles_to_usb()
    def setDate(self):
        while True:
            print("class SET_DATE_AND_TIME  func setDate file setdatetime: ")
            ser.write("Enter date in the format dd/mm/yy\r\n")
            date_string = ser.read()

            try:
                self._dd = int(date_string[0:2])
                self._mm = int(date_string[3:5])
                self._yy = int(date_string[6:8]) + 2000
                isvalid_date_string = check_date(self._yy, self._mm, self._dd)
                lfd = len(date_string)

                if isvalid_date_string == True and date_string[
                        2] == '/' and date_string[5] == '/' and lfd == 8:
                    break
                elif isvalid_date_string == True and date_string[
                        2] == '/' and date_string[5] == '/' and lfd != 8:
                    oledExp.write("Format should be dd*mm*yy")
                    time.sleep(2)
                    oledExp.clear()
                    print("Format should be dd/mm/yy")
                elif isvalid_date_string == True and (date_string[2] != '/' or
                                                      date_string[5] != '/'):
                    oledExp.write("Format should be dd/mm/yy")
                    time.sleep(2)
                    oledExp.clear()
                elif isvalid_date_string == False and (date_string[2] == '/'
                                                       and date_string[5]
                                                       == '/' and lfd == 8):
                    oledExp.write("Invalid Date. ")
                    time.sleep(2)
                    oledExp.clear()

            except:
                oledExp.write("Format should be dd*mm*yy")
                print("setDate except")
                time.sleep(2)
                oledExp.clear()
        self.dateString = str(self._dd) + "-" + str(self._mm) + "-" + str(
            self._yy)
Exemple #24
0
    def checkKey(self):
        a = [0, 1, 2, 3, 11, 18, 8, 9]
        r = [0, 1, 2, 3]
        c = [18, 11, 8, 9]

        key = [
            ["1", "2", "3", "A"],
            ["4", "5", "6", "B"],
            ["7", "8", "9", "C"],
            ["*", "0", "#", "D"],
        ]

        values = [
            ["0", "0", "0", "0"],
            ["0", "0", "0", "0"],
            ["0", "0", "0", "0"],
            ["0", "0", "0", "0"],
            ["0", "0", "0", "0"],
        ]

        lastvalues = copy.deepcopy(values)

        # close before open if used
        for pin in a:
            try:
                omega_gpio.closepin(pin)
            except:
                e = 1  # dummy command :-)

        # pin init
        for pin in r:
            omega_gpio.initpin(pin, 'out')

        for pin in c:
            omega_gpio.initpin(pin, 'in')

        if True:
            rpos = 0
            for rpin in r:
                omega_gpio.setoutput(r[0], 0)
                omega_gpio.setoutput(r[1], 0)
                omega_gpio.setoutput(r[2], 0)
                omega_gpio.setoutput(r[3], 0)
                omega_gpio.setoutput(rpin, 1)
                time.sleep(0.05)
                cpos = 0
                for cpin in c:
                    input = omega_gpio.readinput(cpin)
                    values[rpos][cpos] = input
                    cpos = cpos + 1
                rpos = rpos + 1

            for x in range(0, 4):
                for y in range(0, 4):
                    if values[x][y] != lastvalues[x][y]:
                        keycode = key[x][y]
                        if values[x][y] == 1:
                            if keycode == 'D':
				oledExp.clear()
                                oledExp.write("System reseting...")
                                time.sleep(5)
                                os.execl(sys.executable, sys.executable, * sys.argv)   #for resetting the program
                            elif keycode == 'A':
				f = open('confdata.txt', 'r') 
				lines = f.readlines() 
				SiteID = lines[0].rstrip('\n') 
				MonitoringID= lines[1].rstrip('\n') 
				AnalyzerID= lines[2].rstrip('\n') 
				ParameterID= lines[3].rstrip('\n')
				oledExp.clear()
                                oledExp.setCursor(0, 0)
                                oledExp.write(SiteID)
				oledExp.setCursor(1,0)
				oledExp.write(MonitoringID)
				oledExp.setCursor(2,0)                                 
				oledExp.write(AnalyzerID)
				oledExp.setCursor(3,0)                                 
				oledExp.write(ParameterID)
                                time.sleep(5)
                                oledExp.clear()
                            else:
				oledExp.clear()
                                oledExp.setCursor(0,0)
                                oledExp.write("Press 'D' for Reset")
				oledExp.setCursor(1,0)
				oledExp.write("'A' for userData")
				time.sleep(5)
				oledExp.clear()
            lastvalues = copy.deepcopy(values)
Exemple #25
0
lcd = oledExp.driverInit()
if lcd != 0:
    print('Error initalizing OLED Expansion')
# set verbosity
oledExp.setVerbosity(0)
# set the brightness
lcd = oledExp.setBrightness(127)
if lcd != 0:
    print('Error setting the brightness for the OLED Expansion')

# set up the boot display (show an image for 10 seconds)
imgBoot = "/home/proofingBox/initImg.lcd"
if os.path.exists(imgBoot):
    oledExp.drawFromFile(imgBoot)
time.sleep(1)
oledExp.clear()

## get the target and actual temperature values
## TODO preparation the readout: https://docs.onion.io/omega2-docs/communicating-with-1w-devices.html
tempTrg = "25"
# tempAct = awk -F= '/t=/ {printf "%.03f\n", $2/1000}' /sys/devices/w1_bus_master1/XXXXX/w1_slave
tempAct = "21"

## get the relay status


## get the uptime
def get_uptime():
    with open('/proc/uptime', 'r') as f:
        uptimeS = float(f.readline().split()[0])
        uptimeMin = uptimeS / (60 * 1.0)
Exemple #26
0
def clear():
    oledExp.clear()
Exemple #27
0
import OmegaExpansion.oledExp as oled

oled.driverInit()
oled.setDisplayPower(1)
oled.setDisplayMode(0)
oled.clear()

oled.setCursor(0, 0)
oled.write("Hello")
oled.setCursor(2,0)
oled.write("World!")
Exemple #28
0
# invert the colours
ret = oledExp.setDisplayMode(1)
print "setDisplayMode return: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# dim
ret = oledExp.setDim(1)
print "setDim return: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# clear the display
ret = oledExp.clear()
print "clear return: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# write a message
ret = oledExp.write("Welcome to the Omega")
print "write return: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# set the cursor
ret = oledExp.setCursor(3, 8)
print "write return: ", ret
Exemple #29
0
# invert the colours
ret 	= oledExp.setDisplayMode(1)
print "setDisplayMode return: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# dim
ret 	= oledExp.setDim(1)
print "setDim return: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# clear the display
ret 	= oledExp.clear()
print "clear return: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# write a message
ret 	= oledExp.write("Welcome to the Omega")
print "write return: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# set the cursor
ret 	= oledExp.setCursor(3,8)
print "write return: ", ret
Exemple #30
0
    def __init__(self):
        print("Enters Run mode")
        # oledExp.setCursor(6, 0)
        # oledExp.write("*********************")
        # oledExp.setCursor(7, 7)
        # oledExp.write("RUN MODE")
        # time.sleep(1)
        # oledExp.clear()
        res_add = ''
        bkp_data = ''

        voltage = ''
        current = ''
        power = ''
        resistance = ''
        capacitance = ''
        conductance = ''
        inductance = ''
        impedance = ''
        frequency = ''

        realPower = ''
        reactivePower = ''
        apparentPower = ''
        ampereHour = ''
        joule = ''
        electricField = ''
        magneticField = ''
        magneticFlux = ''
        oledExp.clear()
        while True:
            #k.checkKey()
            r = RTC_DATE_TIME()
            _seconds = int(r.seconds)
            _minutes = int(r.minutes)
            secs = _seconds
            mnts = _minutes
            '''
            isUSB = os.path.isdir(usb_dir_path)
            if isUSB:
                print("USB Inserted")
                oledExp.setCursor(3, 0)
                oledExp.write("USB Connected")
                time.sleep(1)
                oledExp.clear()
                copyfiles_to_usb()
            
            '''
            cdir = pth1 + '/CDIR_' + r.dir_format
            isDir = os.path.isdir(cdir)
            while (isDir == 0):
                cdirectory = 'CDIR_' + r.dir_format
                MAKE_DIRECTORY(pth1, cdirectory)
                pth2 = os.path.join(pth1, cdirectory)
                idirectory = 'IDIR_' + r.dir_format
                MAKE_DIRECTORY(pth2, idirectory)
                # date time synchronize
                # ds3231.write_now()  # through Wifi
                break

            if secs % 10 == 0:
                res1 = a.analyserRequest('rawData')
                res2 = a.analyserRequest('userData')

                ser.write('#01\r\n')
                resp1 = ser.read()  # read serial port
                time.sleep(0.03)
                data_left = ser.inWaiting()  # check for remaining byte
                resp1 += ser.read(data_left)
                # print (res1)

                ser.write('#02\r\n')
                resp2 = ser.read()  # read serial port
                time.sleep(0.03)
                data_left = ser.inWaiting()  # check for remaining byte
                resp2 += ser.read(data_left)
                # print (res2)

                resA = resp1 + '\n' + resp2 + '\n'
                resB = res1 + '\n' + res2 + '\n'
                res = resA + resB

                x1 = resp1.index('V')
                x2 = resp1.index('A')
                x3 = resp1.index('KW')
                x4 = resp1.index('R')
                x5 = resp1.index('C')
                x6 = resp1.index('G')
                x7 = resp1.index('L')
                x8 = resp1.index('Z')
                x9 = resp1.index('F')

                voltage = resp1[x1 + 2:x2 - 1]
                current = resp1[x2 + 2:x3 - 1]
                power = resp1[x3 + 3:x4 - 1]
                resistance = resp1[x4 + 2:x5 - 1]
                capacitance = resp1[x5 + 2:x6 - 1]
                conductance = resp1[x6 + 2:x7 - 1]
                inductance = resp1[x7 + 2:x8 - 1]
                impedance = resp1[x8 + 2:x9 - 1]
                frequency = resp1[x9 + 2:]

                y1 = resp2.index('KW')
                y2 = resp2.index('VAR')
                y3 = resp2.index('KVA')
                y4 = resp2.index('Ah')
                y5 = resp2.index('J')
                y6 = resp2.index('E')
                y7 = resp2.index('M')
                y8 = resp2.index('Wb')

                realPower = resp2[y1 + 3:y2 - 1]
                reactivePower = resp2[y2 + 4:y3 - 1]
                apparentPower = resp2[y3 + 4:y4 - 1]
                ampereHour = resp2[y4 + 3:y5 - 1]
                joule = resp2[y5 + 2:y6 - 1]
                electricField = resp2[y6 + 2:y7 - 1]
                magneticField = resp2[y7 + 2:y8 - 1]
                magneticFlux = resp2[y8 + 3:]

                res_add = res_add + res
                time.sleep(1)
                oledExp.clear()

                if secs == 0:
                    fln = 'File_hr' + r.hours + '_mnts' + str(mnts - 1)
                    pth = '/mnt/mtdblock6/BKP_DLPV3b'
                    WRITE_DATA_IN_FILE(pth, fln, res_add)
                    bkp_data = bkp_data + res_add
                    print(res_add)
                    res_add = ''

                    # create ZIp file
                    with zipfile.ZipFile(
                            'Files.zip', 'a',
                            compression=zipfile.ZIP_DEFLATED) as my_zip:
                        my_zip.write(fln + ".txt")
                        # Send Zip file to server
                    os.remove(fln + ".txt")
                    # time.sleep(1)

                    if mnts % 2 == 0 and secs == 0:  # for 1hr data
                        pth2 = pth1 + '/CDIR_' + r.dir_format + '/IDIR_' + r.dir_format
                        bkp_fln = 'File_hr' + r.hours + '_mnts' + str(mnts - 2)
                        # Saves file in EMMC
                        WRITE_DATA_IN_FILE(pth2, bkp_fln, bkp_data)
                        bkp_data = ''
                        # time.sleep(1)

            if 0 <= secs <= 9:
                oledExp.setCursor(0, 0)
                oledExp.write(r.rtc_dateTime)
                oledExp.setCursor(1, 0)
                oledExp.write("*********************")
                oledExp.setCursor(2, 0)
                oledExp.write("VOLTAGE = " + str(voltage) + " V")
                oledExp.setCursor(3, 0)
                oledExp.write("CURRENT = " + str(current) + " A")
                oledExp.setCursor(4, 0)
                oledExp.write("POWER = " + str(power) + " KW")
                oledExp.setCursor(6, 0)
                oledExp.write("*********************")
                oledExp.setCursor(7, 7)
                oledExp.write("RUN MODE")

            elif 10 <= secs <= 19:
                oledExp.setCursor(0, 0)
                oledExp.write(r.rtc_dateTime)
                oledExp.setCursor(1, 0)
                oledExp.write("*********************")
                oledExp.setCursor(2, 0)
                oledExp.write("RES = " + str(resistance) + " Ohm")
                oledExp.setCursor(3, 0)
                oledExp.write("CAP = " + str(capacitance) + " uf")
                oledExp.setCursor(4, 0)
                oledExp.write("CON = " + str(conductance) + " mho")
                oledExp.setCursor(6, 0)
                oledExp.write("*********************")
                oledExp.setCursor(7, 7)
                oledExp.write("RUN MODE")

            elif 20 <= secs <= 29:
                oledExp.setCursor(0, 0)
                oledExp.write(r.rtc_dateTime)
                oledExp.setCursor(1, 0)
                oledExp.write("*********************")
                oledExp.setCursor(2, 0)
                oledExp.write("L = " + str(inductance) + " H")
                oledExp.setCursor(3, 0)
                oledExp.write("Z = " + str(impedance) + " Ohm")
                oledExp.setCursor(4, 0)
                oledExp.write("FREQ = " + str(frequency) + " Hz")
                oledExp.setCursor(6, 0)
                oledExp.write("*********************")
                oledExp.setCursor(7, 7)
                oledExp.write("RUN MODE")

            elif 30 <= secs <= 39:
                oledExp.setCursor(0, 0)
                oledExp.write(r.rtc_dateTime)
                oledExp.setCursor(1, 0)
                oledExp.write("*********************")
                oledExp.setCursor(2, 0)
                oledExp.write("P = " + str(realPower) + " KW")
                oledExp.setCursor(3, 0)
                oledExp.write("Q = " + str(reactivePower) + " KVAR")
                oledExp.setCursor(4, 0)
                oledExp.write("S = " + str(apparentPower) + " KVA")
                oledExp.setCursor(6, 0)
                oledExp.write("*********************")
                oledExp.setCursor(7, 7)
                oledExp.write("RUN MODE")

            elif 40 <= secs <= 49:
                oledExp.setCursor(0, 0)
                oledExp.write(r.rtc_dateTime)
                oledExp.setCursor(1, 0)
                oledExp.write("*********************")
                oledExp.setCursor(2, 0)
                oledExp.write("Bat.Level= " + str(ampereHour) + " Ah")
                oledExp.setCursor(3, 0)
                oledExp.write("ENERGY= " + str(joule) + " J")
                oledExp.setCursor(4, 0)
                oledExp.write("Elec. Fld= " + str(electricField) + " v/m")
                oledExp.setCursor(6, 0)
                oledExp.write("*********************")
                oledExp.setCursor(7, 7)
                oledExp.write("RUN MODE")

            elif 50 <= secs <= 59:
                oledExp.setCursor(0, 0)
                oledExp.write(r.rtc_dateTime)
                oledExp.setCursor(1, 0)
                oledExp.write("*********************")
                oledExp.setCursor(2, 0)
                oledExp.write("Mag. Fld= " + str(magneticField) + " T")
                oledExp.setCursor(3, 0)
                oledExp.write("Mag. Flux= " + str(magneticFlux) + " Wb")
                oledExp.setCursor(6, 0)
                oledExp.write("*********************")
                oledExp.setCursor(7, 7)
                oledExp.write("RUN MODE")
            del r
            time.sleep(0.5)
Exemple #31
0
from OmegaExpansion import oledExp
from random import randint
import time

bitmap = [[[1 for i in range(64)] for j in range(64)],
          [[1 for i in range(32)] for j in range(32)],
          [[1 for i in range(24)] for j in range(24)],
          [[1 for i in range(16)] for j in range(16)],
          [[1 for i in range(8)] for j in range(8)],
          [[1 for i in range(4)] for j in range(4)],
          [[1 for i in range(2)] for j in range(2)],
          [[1 for i in range(1)] for j in range(1)]]

for i in range(len(bitmap)):
    translated = OledLib.translateBitmap(bitmap[i])
    oledExp.clear()
    w = len(bitmap[i][0])
    h = len(bitmap[i])
    oledExp.write("Bitmap bliting size: " + str(w) + "x" + str(h))
    time.sleep(2)
    oledExp.clear()
    frames = 0
    exampleStart = int(round(time.time() * 1000))
    for i in range(200):
        x = randint(0, OledLib.OLED_WIDTH - 1 -
                    w) if OledLib.OLED_WIDTH > w else 0
        y = randint(0, OledLib.OLED_HEIGHT - 1 -
                    h) if OledLib.OLED_HEIGHT > h else 0
        # print("x: " + str(x) + ", y: " + str(y))
        OledLib.bitmapBlit(x, y, translated)
        frames += 1
Exemple #32
0
import OmegaExpansion.oledExp as oled

oled.driverInit()
oled.setDisplayPower(1)
oled.setDisplayMode(0)
oled.clear()

oled.setCursor(0, 0)
oled.write("Hello")
oled.setCursor(2, 0)
oled.write("World!")