Exemplo n.º 1
0
def bit_sensor():  #摄像头
    print("开始测试摄像头...")
    try:
        lcd.draw_string(30, 50, 'Start test Camera (End by touch) ', lcd.RED,
                        lcd.BLACK)
        sensor.reset()
        sensor.set_pixformat(sensor.RGB565)
        sensor.set_framesize(sensor.QVGA)
        sensor.run(1)
        sensor.skip_frames()
    except:
        #break
        lcd.draw_string(90, 120, 'Camera test failed! ', lcd.GREEN, lcd.BLACK)
        print("摄像头初始化失败!")

    i = 0
    fm.register(9, fm.fpioa.GPIO1)
    key_4 = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP)
    while (key_4.value() == 1):
        lcd.display(sensor.snapshot())
        i = i + 1
        if i > 150:
            break
    lcd.draw_string(90, 90, 'End Camera test ', lcd.RED, lcd.BLACK)
    time.sleep(1)
    lcd.clear()
    print("摄像头实时显示测试完成")
Exemplo n.º 2
0
 def on_draw(self):
     self.is_dirty = False
     if not self.__initialized:
         self.__lazy_init()
     x_offset = 4
     y_offset = 6
     lcd.clear()
     for i in range(self.current_offset, len(self.current_dir_files)):
         # gc.collect()
         file_name = self.current_dir_files[i]
         print(file_name)
         try:
             f_stat = os.stat('/sd/' + file_name)
             if S_ISDIR(f_stat[0]):
                 file_name = file_name + '/'
             # gc.collect()
             file_readable_size = sizeof_fmt(f_stat[6])
             lcd.draw_string(lcd.width() - 50, y_offset, file_readable_size,
                             lcd.WHITE, lcd.BLUE)
         except Exception as e:
             print("-------------------->", e)
         is_current = self.current_selected_index == i
         line = "%s %d %s" % ("->" if is_current else "  ", i, file_name)
         lcd.draw_string(x_offset, y_offset, line, lcd.WHITE, lcd.RED)
         # gc.collect()
         y_offset += 18
         if y_offset > lcd.height():
             print(y_offset, lcd.height(), "y_offset > height(), break")
             break
Exemplo n.º 3
0
def main(model_addr=0x300000, lcd_rotation=0, sensor_hmirror=False, sensor_vflip=False):
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_hmirror(sensor_hmirror)
    sensor.set_vflip(sensor_vflip)
    sensor.run(1)

    lcd.init(type=1)
    lcd.rotation(lcd_rotation)
    lcd.clear(lcd.WHITE)

    task = kpu.load(model_addr)
    anchors = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
    kpu.init_yolo2(task, 0.5, 0.3, 5, anchors) # threshold:[0,1], nms_value: [0, 1]
    try:
        while(True):
            img = sensor.snapshot()
            t = time.ticks_ms()
            objects = kpu.run_yolo2(task, img)
            t = time.ticks_ms() - t
            if objects:
                for obj in objects:
                    img.draw_rectangle(obj.rect())
            img.draw_string(0, 200, "t:%dms" %(t), scale=2)
            lcd.display(img)
    except Exception as e:
        sys.print_exception(e)
    finally:
        kpu.deinit(task)
Exemplo n.º 4
0
def main(labels=None,
         model_addr="/sd/m.kmodel",
         sensor_window=(224, 224),
         lcd_rotation=0,
         sensor_hmirror=False,
         sensor_vflip=False):
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_windowing(sensor_window)
    sensor.set_hmirror(sensor_hmirror)
    sensor.set_vflip(sensor_vflip)
    sensor.run(1)

    lcd.init(type=1)
    lcd.rotation(lcd_rotation)
    lcd.clear(lcd.WHITE)

    if not labels:
        with open('labels.txt', 'r') as f:
            exec(f.read())
    if not labels:
        print("no labels.txt")
        img = image.Image(size=(320, 240))
        img.draw_string(90, 110, "no labels.txt", color=(255, 0, 0), scale=2)
        lcd.display(img)
        return 1
    try:
        img = image.Image("startup.jpg")
        lcd.display(img)
    except Exception:
        img = image.Image(size=(320, 240))
        img.draw_string(90,
                        110,
                        "loading model...",
                        color=(255, 255, 255),
                        scale=2)
        lcd.display(img)

    task = kpu.load(model_addr)

    try:
        while (True):
            img = sensor.snapshot()
            t = time.ticks_ms()
            fmap = kpu.forward(task, img)
            t = time.ticks_ms() - t
            plist = fmap[:]
            pmax = max(plist)
            max_index = plist.index(pmax)
            img.draw_string(0,
                            0,
                            "%.2f : %s" % (pmax, labels[max_index].strip()),
                            scale=2)
            img.draw_string(0, 200, "t:%dms" % (t), scale=2)
            lcd.display(img)
    except Exception as e:
        raise e
    finally:
        kpu.deinit(task)
Exemplo n.º 5
0
def run():
    lcd.clear()
    lcd.message("Loading...")

    weather_live_req = live_weather_request()
    weather_forecast_req = forecast_weather_request()
    bus_arrival_req = bus_request()

    grequests.map((weather_live_req, weather_forecast_req, bus_arrival_req))

    weathers = list()
    if weather_live_req.response is not None:
        weathers.append(
            weather_live_from_json(weather_live_req.response.json()))
    else:
        weathers.append(None)

    if weather_forecast_req.response is not None:
        weathers.append(
            weather_forecast_from_json(
                weather_forecast_req.response.json(),
                datetime.datetime.now() + datetime.timedelta(hours=12)))
    else:
        weathers.append(None)

    weather_str = weather_view(weathers)

    arrivals = arrivals_from_xml(
        ElementTree.fromstring(bus_arrival_req.response.content))
    bus_str = bus_arrival_view(arrivals)
    lcd_str = bus_str + "\n" + weather_str

    lcd.clear()
    lcd.message(lcd_str)
Exemplo n.º 6
0
 def run(self):
     try:
         self.run_inner()
     except Exception as e:
         import uio
         string_io = uio.StringIO()
         sys.print_exception(e, string_io)
         s = string_io.getvalue()
         print("showing blue screen:", s)
         lcd.clear(lcd.BLUE)
         msg = "** " + str(e)
         chunks, chunk_size = len(msg), 29
         msg_lines = [
             msg[i:i + chunk_size] for i in range(0, chunks, chunk_size)
         ]
         # "A problem has been detected and windows has been shut down to prevent damange to your m5stickv :)"
         lcd.draw_string(1, 1, "A problem has been detected and windows",
                         lcd.WHITE, lcd.BLUE)
         lcd.draw_string(1, 1 + 5 + 16, "Technical information:", lcd.WHITE,
                         lcd.BLUE)
         current_y = 1 + 5 + 16 * 2
         for line in msg_lines:
             lcd.draw_string(1, current_y, line, lcd.WHITE, lcd.BLUE)
             current_y += 16
             if current_y >= lcd.height():
                 break
         lcd.draw_string(1, current_y, s, lcd.WHITE, lcd.BLUE)
         lcd.draw_string(1,
                         lcd.height() - 17,
                         "Will reboot after 10 seconds..", lcd.WHITE,
                         lcd.BLUE)
         time.sleep(10)
         machine.reset()
Exemplo n.º 7
0
def storeData():
	"fuction to store data in database"
	global imgName
	lcd.string("Storing data...", LINE_3)
	try:
		#create instance of a database with host, username, password and database name
		db = sqldb.connect(host, username, password, 'maindb')
		#create cursor object
		cursor = db.cursor()
		img_path = "./images/" + imgName
		#insert values in database. isoformat() will give mysql compatible datetime object
		cursor.execute("INSERT INTO data (troughid, cropid, name, date, weight, imagepath, location) VALUES (%s, %s, %s, %s, %s, %s, %s)", (troughID, cropID, cropName, datetime.datetime.now().isoformat(), measuredWeight, img_path, locationName))
		db.commit()  #commit the changes
		lcd.clear()
		#lcd.string("Successfully stored", LINE_1)
		#lcd.string("in local database", LINE_2)
		lcd.string("      Success", LINE_2)
		time.sleep(1)
	except:
		lcd.clear()
		#lcd.string("Failed to store", LINE_1)
		#lcd.string("in local database", LINE_2)
		lcd.string("      FAILED", LINE_1)
		time.sleep(3)
	db.close()
Exemplo n.º 8
0
def main():
    lcd.clear()

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(PIN, GPIO.IN)

    outer_loop()    
Exemplo n.º 9
0
 def on_draw(self):
     if not self.__initialized:
         self.__lazy_init()
     x_offset = 4
     y_offset = 6
     lcd.clear()
     print("progress 0")
     for i in range(self.current_offset,
                    len(self.current_dir_file_info_list)):
         # gc.collect()
         print("progress 1")
         file_info = self.current_dir_file_info_list[i]
         file_name = file_info["file_name"]
         f_stat = file_info["stat"]
         if f_stat != None:
             if S_ISDIR(f_stat[0]):
                 file_name = file_name + '/'
             file_readable_size = sizeof_fmt(f_stat[6])
             lcd.draw_string(lcd.width() - 50, y_offset, file_readable_size,
                             lcd.WHITE, lcd.BLUE)
         is_current = self.current_selected_index == i
         line = "%s %d %s" % ("->" if is_current else "  ", i, file_name)
         lcd.draw_string(x_offset, y_offset, line, lcd.WHITE, lcd.RED)
         # gc.collect()
         print("progress 2")
         y_offset += 18
         if y_offset > lcd.height():
             print("y_offset > height(), break")
             break
         print("progress 3")
Exemplo n.º 10
0
def main():
    lcd.clear()

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(PIN, GPIO.IN)

    outer_loop()
Exemplo n.º 11
0
def disp(title, item):
    lcd.clear()
    img = image.Image()
    img.draw_string(0, 0, '<<' + title + '>>', (255,0,0), scale=3)
    for i in range(4):
        c = " " if i != 1 else ">"
        img.draw_string(0, i * 25 + 25, c + item[i], scale=3)
    lcd.display(img)
Exemplo n.º 12
0
def show_ip(msg, ip):
	lcd.clear()
	lcd.setaddress(0, 0)
	lcd.puts(msg)

	ip_len = len(ip)
	lcd.setaddress(1, 16-ip_len)
	lcd.puts(ip)
Exemplo n.º 13
0
def inner_loop():
    global SHOTS
    lcd.clear()

    lcd.display(2, "", 1)
    lcd.display(3, "TAP TO SHOOT", 2)
    lcd.display(4, "ready", 1)
    print("Starting inner foot pedal loop...")
    start = time()
    prev_input = 0
    firstloop = 1
    while True:
        input = GPIO.input(PIN)
        if (not prev_input) and input:
            if firstloop != 1:
                print("Button pressed")
                shoot()
                SHOTS += 1
                lcd.display(2, str(SHOTS / 2), 1)
                start = time()
            firstloop = 0
        prev_input = input
        # slight pause to debounce
        sleep(DEBOUNCEPAUSE)

        # check that a camera hasn't turned off
        # can we do this more quickly?  it's interfering with the pedal.
        # cmdoutput("lsusb | grep Canon | wc -l") == "2"                                      # 1.16 sec
        # cmdoutput(PTPCAM + " -l | grep 0x | wc -l") == "2"                                  # 0.42 sec
        # cmdoutput("gphoto2 --auto-detect|grep usb|sed -e 's/.*Camera *//g' | wc -l") == "2" # 0.36 sec
        # cmdoutput("gphoto2 --auto-detect | grep Camera | wc -l") == "2"                     # 0.34 sec, still too long
        if (
            camera_count(BRAND) == 2
        ):  # 0.58 sec from command line, faster inside the program? yes!
            pass
        else:
            print("Number of camera devices does not equal 2. Try again.")
            for cam in LEFTCAM, RIGHTCAM:
                cmd = PTPCAM + " --dev=" + cam + " --chdk='lua play_sound(3)'"
                p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
            lcd.display(2, "A CAMERA IS OFF.", 1)
            lcd.display(3, "RESTARTING...", 1)
            lcd.display(4, "", 1)
            sleep(PAUSE)
            return

        now = time()
        if now - start > TMOUT:
            lcd.display(2, "", 1)
            lcd.display(3, "TIMEOUT", 2)
            lcd.display(4, "", 1)
            print("Foot pedal not pressed for", TMOUT, "seconds.")
            download_from_cams()
            delete_from_cams()
            print("Quitting inner loop")
            return
        text = marquee.next()
        lcd.display(1, text, 1)
Exemplo n.º 14
0
def tare():
    global baseValue
    global taredWeight
    lcd.clear()
    lcd.string("Taring weight...", LINE_1)
    lcval = lc.read_average_value(10)
    diff = math.fabs(baseValue - lcval)
    taredWeight = (diff /
                   49000.0) * 230.0  #store the calculated weight in variable
Exemplo n.º 15
0
def inner_loop():
    global SHOTS
    lcd.clear()

    lcd.display(2, "", 1)
    lcd.display(3, "TAP TO SHOOT", 2)
    lcd.display(4, "ready", 1)
    print "Starting inner foot pedal loop..."
    start = time()
    prev_input = 0
    firstloop = 1
    while True:
        input = GPIO.input(PIN)
        if ((not prev_input) and input):
            if (firstloop != 1):
                print("Button pressed")
                shoot()
                SHOTS += 1
                lcd.display(2, str(SHOTS / 2), 1)
                start = time()
            firstloop = 0
        prev_input = input
        #slight pause to debounce
        sleep(DEBOUNCEPAUSE)

        # check that a camera hasn't turned off
        # can we do this more quickly?  it's interfering with the pedal.
        #cmdoutput("lsusb | grep Canon | wc -l") == "2"                                      # 1.16 sec
        #cmdoutput(PTPCAM + " -l | grep 0x | wc -l") == "2"                                  # 0.42 sec
        #cmdoutput("gphoto2 --auto-detect|grep usb|sed -e 's/.*Camera *//g' | wc -l") == "2" # 0.36 sec
        #cmdoutput("gphoto2 --auto-detect | grep Camera | wc -l") == "2"                     # 0.34 sec, still too long
        if camera_count(BRAND) == 2:                                       # 0.58 sec from command line, faster inside the program? yes!
            pass
        else:
            print "Number of camera devices does not equal 2. Try again."
            for cam in LEFTCAM, RIGHTCAM:
                cmd=PTPCAM + " --dev=" + cam + " --chdk='lua play_sound(3)'"
                p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
            lcd.display(2, "A CAMERA IS OFF.", 1)
            lcd.display(3, "RESTARTING...", 1)
            lcd.display(4, "", 1)
            sleep(PAUSE)
            return

        now = time()
        if now - start > TMOUT:
            lcd.display(2, "", 1)
            lcd.display(3, "TIMEOUT", 2)
            lcd.display(4, "", 1)
            print "Foot pedal not pressed for", TMOUT, "seconds."
            download_from_cams()
            delete_from_cams()
            print "Quitting inner loop"
            return
        text = marquee.next()
        lcd.display(1, text, 1)
Exemplo n.º 16
0
def showInfo(string, ret):
    global x, y
    if ret:
        lcd.draw_string(x, y, string, lcd.GREEN, lcd.BLACK)
    else:
        lcd.draw_string(x, y, string, lcd.RED, lcd.BLACK)
    y = y + 16
    if y > 240:
        y = 0
        lcd.clear(lcd.BLACK)
Exemplo n.º 17
0
def disp():
    lcd.clear()
    img = image.Image()
    img.draw_string(0, 0, '<< MENU >>', (255, 0, 0), scale=3)
    lcd.display(img)
    for i in range(4):
        c = " " if i != 2 else ">"
        img.draw_string(0, i * 25 + 25, c + prog[i][0], scale=3)
        lcd.display(img)
        print(prog[i])
Exemplo n.º 18
0
def main(anchors, labels=None, model_addr="/sd/m.kmodel"):
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_windowing((224, 224))
    sensor.run(1)

    lcd.init(type=1)
    lcd.clear(lcd.WHITE)

    if not labels:
        with open('labels.txt', 'r') as f:
            exec(f.read())
    if not labels:
        print("no labels.txt")
        img = image.Image(size=(320, 240))
        img.draw_string(90, 110, "no labels.txt", color=(255, 0, 0), scale=2)
        lcd.display(img)
        return 1
    try:
        img = image.Image("startup.jpg")
        lcd.display(img)
    except Exception:
        img = image.Image(size=(320, 240))
        img.draw_string(90,
                        110,
                        "loading model...",
                        color=(255, 255, 255),
                        scale=2)
        lcd.display(img)

    task = kpu.load(model_addr)
    kpu.init_yolo2(task, 0.5, 0.3, 5,
                   anchors)  # threshold:[0,1], nms_value: [0, 1]
    try:
        while (True):
            img = sensor.snapshot()
            t = time.ticks_ms()
            objects = kpu.run_yolo2(task, img)
            t = time.ticks_ms() - t
            if objects:
                for obj in objects:
                    pos = obj.rect()
                    img.draw_rectangle(pos)
                    img.draw_string(pos[0],
                                    pos[1],
                                    "%s : %.2f" %
                                    (labels[obj.classid()], obj.value()),
                                    scale=2)
            img.draw_string(0, 200, "t:%dms" % (t), scale=2)
            lcd.display(img)
    except Exception as e:
        sys.print_exception(e)
    finally:
        kpu.deinit(task)
Exemplo n.º 19
0
def touch_key():  #触摸按键
    fm.register(9, fm.fpioa.GPIO2)
    fm.register(10, fm.fpioa.GPIO3)
    fm.register(11, fm.fpioa.GPIO4)
    fm.register(15, fm.fpioa.GPIO5)
    fm.register(17, fm.fpioa.GPIO6)
    fm.register(18, fm.fpioa.GPIO7)
    key_a = GPIO(GPIO.GPIO2, GPIO.IN, GPIO.PULL_UP)
    key_i = GPIO(GPIO.GPIO3, GPIO.IN, GPIO.PULL_UP)
    key_s = GPIO(GPIO.GPIO4, GPIO.IN, GPIO.PULL_UP)
    key_t = GPIO(GPIO.GPIO5, GPIO.IN, GPIO.PULL_UP)
    key_e = GPIO(GPIO.GPIO6, GPIO.IN, GPIO.PULL_UP)
    key_m = GPIO(GPIO.GPIO7, GPIO.IN, GPIO.PULL_UP)
    img = image.Image()
    print("开始触摸按键测试...")
    print("按下key1开始...")
    lcd.draw_string(90, 30, 'Start test Touch_key ', lcd.RED, lcd.BLACK)
    lcd.draw_string(90, 50, 'Press key 1 to start ', lcd.RED, lcd.BLACK)
    lcd.draw_string(20, 10, ' ||  Direction', lcd.RED, lcd.BLACK)
    lcd.draw_string(20, 20, ' || ', lcd.RED, lcd.BLACK)
    lcd.draw_string(20, 30, '\||/ ', lcd.RED, lcd.BLACK)
    lcd.draw_string(20, 40, ' \/ ', lcd.RED, lcd.BLACK)
    time.sleep(1)

    while True:
        if key_a.value() == 0:
            print("key_a", key_a.value())
            while (key_i.value()):
                print("key_i =", key_i.value())
                lcd.draw_string(90, 100, ' key 1 ok! ', lcd.RED, lcd.BLACK)
                time.sleep(0.05)
            while (key_s.value()):
                print("key_s =", key_s.value())
                lcd.draw_string(90, 120, ' key 2 ok! ', lcd.RED, lcd.BLACK)
                time.sleep(0.05)
            while (key_t.value()):
                print("key_t =", key_t.value())
                lcd.draw_string(90, 140, ' key 3 ok! ', lcd.RED, lcd.BLACK)
                time.sleep(0.05)
            while (key_e.value()):
                print("key_e =", key_e.value())
                lcd.draw_string(90, 160, ' key 4 ok! ', lcd.RED, lcd.BLACK)
                time.sleep(0.05)
            while (key_m.value()):
                print("key_m =", key_m.value())
                lcd.draw_string(90, 180, ' key 5 ok! ', lcd.RED, lcd.BLACK)
                time.sleep(0.05)
            lcd.draw_string(90, 200, ' key 6 ok! ', lcd.RED, lcd.BLACK)
            print("触摸按键测试完成")
            lcd.draw_string(30, 220, 'End Touch_key test ! ', lcd.RED,
                            lcd.BLACK)
            time.sleep(1)
            lcd.clear()
            break
Exemplo n.º 20
0
 def loop(self):
     sec = time.ticks_ms() // 1000
     if sec != self.last_sec:
         self.last_sec = sec
         if sec % 5 == 0:
             self.update()
     if self.button_a.value() == 0:
         lcd.clear(lcd.WHITE)
         lcd.draw_string(30, 30, "Sleep...", lcd.RED, lcd.WHITE)
         time.sleep_ms(3000)
         self._axp192.setEnterSleepMode()
     time.sleep_ms(1)
Exemplo n.º 21
0
def init():
    print("Initialization")
    global baseValue
    #initialize lcd
    lcd.lcd_init()
    lcd.string("      Welcome", LINE_1)
    lcd.string(" Remove any object", LINE_2)
    lcd.string(" from the platform.", LINE_3)
    time.sleep(2)
    lcd.clear()
    lcd.string("    Calibrating", LINE_1)
    lcd.string("   Please wait...", LINE_2)
    baseValue = lc.base_value()
Exemplo n.º 22
0
def take_video(second, video_name):
    videoname = ("/sd/" + str(video_name) + ".avi")
    v = video.open(videoname, record=1, interval=200000, quality=50)
    i = 0
    while True:
        img = snapshot()
        lcd.display(img)
        img_len = v.record(img)
        i += 1
        if i >= second*5:
            break
    v.record_finish()
    lcd.clear()
Exemplo n.º 23
0
	def status(self) :      
		log('Taking picture')
		out = os.system("fswebcam -r " + config.resolution +
					'--log syslog -q --jpeg -1' +
					" -d " + config.camera + 					
					" " + config.tempDirectory + "/" + 					
					config.pictureName)
		log("Camera app returned " + str(out))
		
		lcd.clear()        
		lcd.message("Status request:") 
		lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
		lcd.message("Pin is " + str(state))
Exemplo n.º 24
0
def mqtt():
    try:
        global c, d, last_message, message_interval
        c = connect_and_subscribe()
        d = dht.DHT11(machine.Pin(0))
        # lcd.blink_cursor_off()
        while True:
            lcd.move_to(0, 0)
            lcd.putstr("Be Happy :)")
            time.sleep(1)
            c.check_msg()  #wait messageW
            if (time.time() - last_message) > message_interval:
                d.measure()
                temperature = d.temperature()
                lcd.clear()
                if (temperature > 29):
                    topic_hub = TOPIC + "/auto"
                    c.publish(topic_hub, str("on"))
                    led.value(1)
                    state = 0
                else:
                    topic_hub = TOPIC + "/auto"
                    c.publish(topic_hub, str("off"))
                    led.value(0)
                    state = 1
                # print("temperature",temperature)
                humidity = d.humidity()
                lcd.move_to(0, 1)
                show = "T:" + str(temperature) + "C "
                lcd.putstr(show)
                show = "H:" + str(humidity) + "% "
                lcd.putstr(show)
                if (state == 1):
                    show = "OFF"
                else:
                    show = "ON"
                lcd.putstr(show)
                #lcd.putstr("Humidity:%d",humidity)
                # print("humidity",humidity)
                temperature_topic_pub = TOPIC + "/temperature"
                humidity_topic_pub = TOPIC + "/humidity"
                c.publish(temperature_topic_pub, str(temperature))
                c.publish(humidity_topic_pub, str(humidity))
                last_message = time.time()

    except OSError as e:
        print(e)
        restart_and_reconnect()

    finally:
        close_connect()
Exemplo n.º 25
0
 def on_draw(self):
     if not self.__initialized:
         self.__lazy_init()
     lcd.clear()
     y = 3
     lcd.draw_string(3, 3, self.system_uname.machine, lcd.WHITE, lcd.BLUE)
     y += 16
     lcd.draw_string(3, y, self.system_uname.version,
                     lcd.WHITE, lcd.BLUE)
     y += 16
     lcd.draw_string(3, y, self.device_id, lcd.WHITE, lcd.BLUE)
     for info in self.fs_info_list:
         y += 16
         lcd.draw_string(3, y, info, lcd.WHITE, lcd.BLUE)
Exemplo n.º 26
0
def setup():
    global g_isLoop
    global g_i2c
    global g_clock
    g_i2c = I2C(I2C.I2C0, freq=400000, scl=28, sda=29)
    lcd.init()
    lcd.rotation(2)
    lcd.clear()
    #lcd.font(lcd.FONT_DejaVu24)
    g_clock = time.clock()

    g_isLoop = True

    setBacklight(1)
Exemplo n.º 27
0
def init():
	"initialization function"
	global baseValue
	lcd.string("      Welcome", LINE_1)
	lcd.string(" Remove any object", LINE_2)
	lcd.string(" from the platform.", LINE_3)
	time.sleep(5)
	lcd.clear()
	lcd.string("      Welcome", LINE_1)
	lcd.string("   Please wait...", LINE_2)
	baseValue = lc.base_value()
	fetchCropInfoFromServer()
	fetchTroughInfoFromServer()
	fetchLocationInfoFromServer()
Exemplo n.º 28
0
def screen():
    print("开始屏幕显示测试...")
    img = image.Image()
    img.draw_rectangle(0, 0, 320, 240, color=(255, 0, 0), fill=True)
    lcd.display(img)
    time.sleep(1)
    img.draw_rectangle(0, 0, 320, 240, color=(0, 255, 0), fill=True)
    lcd.display(img)
    time.sleep(1)
    img.draw_rectangle(0, 0, 320, 240, color=(0, 0, 255), fill=True)
    lcd.display(img)
    time.sleep(1)
    lcd.clear()
    print("屏幕显示测试完成")
Exemplo n.º 29
0
def shooting_mode():
    time.sleep(.2)
    lcd.clear()

    while(True):
        img = sensor.snapshot()
        if but_a.value() == 0:
            filename = "_".join(map(str, time.localtime()))
            img.save("/flash/" + filename + ".jpg")
            play_sound("/flash/Shutter.wav")
            lcd.display(img)
            time.sleep(3)
        else:
            lcd.display(img)
        if but_b.value() == 0:
            preview_mode()
Exemplo n.º 30
0
def mic():  #麦克风
    from aibit import *
    print("开始测试麦克风...")
    lcd.draw_string(30, 50, 'Start test MIC (End by touch) ', lcd.RED,
                    lcd.BLACK)
    #fm.register(9, fm.fpioa.GPIO1)
    #key_4 = GPIO(GPIO.GPIO1,GPIO.IN,GPIO.PULL_UP)
    mic = Mic()
    while ((mic.get_intensity() < 50)):
        value = mic.get_intensity()
        lcd.draw_string(30, 70, 'MIC : ' + str(value), lcd.RED, lcd.BLACK)
        time.sleep(0.1)
        print(value)
    lcd.draw_string(30, 90, ' MIC test ok! ', lcd.RED, lcd.BLACK)
    time.sleep(1)
    lcd.clear()
    print("麦克风测试完成")
Exemplo n.º 31
0
def takePicture():
	"fucntion to take picture using USB camera"
	global imgName
	global pictureTaken
	lcd.string("Taking picture...", LINE_2)
	if os.path.exists('/dev/video0'):
		#create image file name with current date
		imgName = "image-" + datetime.datetime.now().isoformat() + ".jpg"
		#capture image and save in images directory. if image file does not exists in folder then retake the image
		while os.path.isfile("/var/www/data/images/%s" %imgName) == False:
			os.system("fswebcam -r 640x480 -S 10 --no-banner /var/www/data/images/%s" %imgName)
		pictureTaken = 1  #if picture is successfully taken then set pictureTaken flag to 1
	else:	#if camera is not attached display error message
		lcd.clear()
		lcd.string("      FAILED", LINE_1)
		lcd.string("No camera attached", LINE_2)
		time.sleep(3)
Exemplo n.º 32
0
def takePicture():
    lcd.clear()
    lcd.string("Taking picture...", LINE_1)
    if os.path.exists('/dev/video0'):
        #create image file name with current date
        imgName = "image-" + datetime.datetime.now().isoformat() + str(
            constants.USER_ID) + ".jpg"
        imagepath = "/home/pi/ghfarm/images/%s" % imgName
        #capture image and save in images directory. if image file does not exists in folder then retake the image
        while os.path.isfile(imagepath) == False:
            os.system("fswebcam -r 640x480 -S 10 --no-banner %s" % imagepath)
        return True, imgName
    else:  #if camera is not attached display error message
        lcd.clear()
        lcd.string("      FAILED", LINE_1)
        lcd.string("No camera attached", LINE_2)
        time.sleep(2)
        return False, "NoCamera"
Exemplo n.º 33
0
def storeData(data):
    lcd.clear()
    lcd.string("Storing data...", LINE_1)
    lcd.string("Weight: " + str(data['weight']), LINE_2)
    lcd.string("CropID: " + str(data['crop_id']), LINE_3)
    lcd.string("FarmID: " + str(data['farmid']), LINE_4)
    f = open(constants.data_offline, 'a')
    t = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    crops = {
        'weight': data['weight'],
        'crop_id': data['crop_id'],
        'time': t,
        'imagename': data['imagename'],
        'farmid': data['farmid']
    }
    crop_details = json.dumps(crops)
    f.write(crop_details + '\n')
    time.sleep(0.5)
    print("Done")
Exemplo n.º 34
0
def checkMPU6050():
    global img
    i2cdev = i2c.scan()
    if 104 not in i2cdev:
        showInfo('setupMPU6050 failed', False)
        return
    # img = image.Image()
    i2c.writeto(addr, bytearray([107, 0]))
    while button.value():
        a = get_values()
        if False:
            lcd.clear()
            string = 'AcX:' + str(a['AcX']) + ' GyX:' + str(a['GyX'])
            lcd.draw_string(0, 0, string, lcd.GREEN, lcd.BLACK)

            string = 'AcY:' + str(a['AcY']) + ' GyY:' + str(a['GyY'])
            lcd.draw_string(0, 16, string, lcd.GREEN, lcd.BLACK)

            string = 'AcZ:' + str(a['AcZ']) + ' GyZ:' + str(a['GyZ'])
            lcd.draw_string(0, 32, string, lcd.GREEN, lcd.BLACK)
            string = 'Tmp:' + str(a['Tmp']) + '*C'
            lcd.draw_string(0, 48, string, lcd.GREEN, lcd.BLACK)

            time.sleep(0.2)
        else:
            img.clear()
            string = 'AcX:' + str(a['AcX'])
            img.draw_string(0, 0, string, lcd.RED, scale=2)
            string = 'AcY:' + str(a['AcY'])
            img.draw_string(0, 16, string, lcd.RED, scale=2)
            string = 'AcZ:' + str(a['AcZ'])
            img.draw_string(0, 32, string, lcd.RED, scale=2)
            string = 'GyX:' + str(a['GyX'])
            img.draw_string(0, 48, string, lcd.RED, scale=2)
            string = 'GyY:' + str(a['GyY'])
            img.draw_string(0, 64, string, lcd.RED, scale=2)
            string = 'GyZ:' + str(a['GyZ'])
            img.draw_string(0, 80, string, lcd.RED, scale=2)
            string = 'Tmp:' + str(a['Tmp']) + '*C'
            img.draw_string(0, 96, string, lcd.RED, scale=2)
            lcd.display(img)
            time.sleep(0.5)
Exemplo n.º 35
0
def outer_loop():
    lcd.clear()

    global SHOTS
    # debounce code from http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/
    lcd.display(2, "TURN ON CAMERAS,", 1)
    lcd.display(3, "TAP PEDAL TO START", 1)
    print "Starting outer foot pedal loop..."
    prev_input = 0
    firstloop = 1
    # start = time()
    while True:
        try:
            input = GPIO.input(PIN)
            if ((not prev_input) and input):
                if (firstloop != 1):
                    print("Button pressed")
                    lcd.display(2, "starting up", 2)
                    lcd.display(3, "PLEASE WAIT", 2)
                    detect_cams()
                    # delete_from cams confuses ptpcam -> do that at the end
                    switch_to_record_mode()
                    set_zoom()
                    flash_off()
                    set_iso()
                    set_ndfilter()
                    SHOTS = 0
                    inner_loop()
                    # start = time()
                    lcd.display(2, "TURN ON CAMERAS,", 1)
                    lcd.display(3, "TAP PEDAL TO START", 1)
                    print "Rejoining outer foot pedal loop..."
                firstloop = 0
            prev_input = input
            # slight pause to debounce
            sleep(DEBOUNCEPAUSE)
        except KeyboardInterrupt:
            lcd.clear()
            lcd.display(2, "GOODBYE", 2)
            sleep(PAUSE)
            lcd.clear()
            print "Quitting."
            sys.exit()
        text = marquee.next()
        lcd.display(1, text, 1)
Exemplo n.º 36
0
import lcd, sensor, time
lcd.init()
lcd.clear(0x00)

sensor.reset()
sensor.set_contrast(2)
sensor.set_brightness(0)
sensor.set_saturation(2)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA2)

clock = time.clock()
while (True):
    clock.tick()
    image = sensor.snapshot()
    lcd.write_image(image)
    print(clock.fps())
Exemplo n.º 37
0
def conway_rand():
    lcd.clear()                 # clear the LCD
    for x in range(128):        # loop over x coordinates
        for y in range(32):     # loop over y coordinates
            if pyb.rand() & 1:  # get a 1-bit random number
                lcd.set(x, y)   # set the pixel randomly
Exemplo n.º 38
0
	def on(self) :
		lcd.clear()
		lcd.message("ON command")
		GPIO.output(config.lightsPin, True)        
		time.sleep(config.displayTime)
Exemplo n.º 39
0
	lcd.lcd_init()
	
	log("Control Server started\n")
	
	
	
	try :
		state = 'off'
		GPIO.output(config.backlightPin, False)
		lcd.home()
		lcd.message('Message service', style=2)
		lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
		lcd.message('started', style=2)        
		time.sleep(3)
		while True:            
			lcd.clear()
			time.sleep(.1)
			if config.verbose: log('Checking messages...')
			lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
			lcd.message("Checking", style=2)
			lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
			lcd.message("messages", style=2)
			time.sleep(3)
			number = 0
			
			try :
				#raise TypeError("Test Error...")
				name, sender, subj, text = mailmanager.getMail()     
				#print sender
				#print subj
				
Exemplo n.º 40
0
import sensor, imlib, lcd
lcd.init()
lcd.clear(0xFF)
while (True):
  image = sensor.snapshot()
  lcd.write_image(image)
Exemplo n.º 41
0
def no_gps_fix():
	lcd.clear(fd) #clear display
	lcd.writeString("NO GPS FIX", fd)
	return
Exemplo n.º 42
0
def main():
	lcd.init()
	lcd.clear()
	while(1):
	    	stats()
    		sleep(1)
Exemplo n.º 43
0
				Msast=str(MINUTES)
				Ssast=str(SECONDS)
				sast_time = "SAST: " + Hsast.zfill(2) + ":" + Msast.zfill(2) + ":" + Ssast.zfill(2) + "      "
								
				if SECONDS ==30: #reset the lcd display every minute to remove display errors
					lcd.reset(fd)
				if SECONDS >=59:
					GPIO.output(arm_pulse, True)
				else:
					GPIO.output(arm_pulse, False)
									
				diff=SECONDS-old_sast
				old_sast=SECONDS
				if diff >= 1 or diff==-59:								#If the time has changed by 1 second update the display
					#======================================================print to LCD display
					lcd.clear(fd) #clear display
					type = True
					lcd.writeString(sast_time, fd)
					try:
						IP = get_ip_address('eth0')
					except:
						IP= "No Network"
					if IP:
						ip_chars = list(IP)
						display_ip(ip_chars)
					lcd.writeString(sidereal_time, fd)
					
			else:	#else if gpsd reports no fix switch off led
				GPIO.output(gps_stat, False)
				if fix_flag:
					no_gps_fix()