예제 #1
0
파일: gui.py 프로젝트: rustinbee/cate_iot
def main():
    # setup colour map
    cmap = cm.get_cmap('Spectral_r')

    # set up display
    pygame.init()
    pygame.font.init()
    display = pygame.display.set_mode((320, 240))
    pygame.display.set_caption('Thermal Cam')
    pygame.mouse.set_visible(True)
    font = pygame.font.SysFont('freemono', 10)

    # mlx90640 settings
    MLX_I2C_ADDR = 0x33
    hertz_default = 8
    API.SetRefreshRate(MLX_I2C_ADDR, hertz_to_refresh_rate[hertz_default])
    API.SetChessMode(MLX_I2C_ADDR)

    # Extract calibration data from EEPROM and store in RAM
    eeprom_data = ffi.new("uint16_t[832]")
    params = ffi.new("paramsMLX90640*")
    API.DumpEE(MLX_I2C_ADDR, eeprom_data)
    API.ExtractParameters(eeprom_data, params)

    TA_SHIFT = 8 # the default shift for a MLX90640 device in open air
    emissivity = 0.95

    frame_buffer = ffi.new("uint16_t[834]")
    image_buffer = ffi.new("float[768]")

    last = time.monotonic()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        API.GetFrameData(MLX_I2C_ADDR, frame_buffer);
        now = time.monotonic()
        diff = now - last
        last = now

        # reflected temperature based on the sensor
        # ambient temperature
        tr = API.GetTa(frame_buffer, params) - TA_SHIFT

        # The object temperatures for all 768 pixels in a
        # frame are stored in the mlx90640To array
        API.CalculateTo(frame_buffer, params, emissivity, tr, image_buffer);

        ta_np = temperature_data_to_ndarray(image_buffer)
        ta_img = td_to_image(ta_np, cmap)

        pyg_img = pygame.image.fromstring(ta_img.tobytes(), ta_img.size, ta_img.mode)
        display.blit(pyg_img, (0,0))

        show_text(display, "Calc Hz: %03.1f" % (1/diff), (0, 10+2), font, action=increment_refresh_rate)
        show_text(display, "Temp Ref: %05.1f" % tr, (0, 10+2+10+2), font)

        pygame.display.update()
예제 #2
0
for i in range(5):
    print(params.outlierPixels[i])

# TODO: if absolute - wait 4 mins

TA_SHIFT = 8  # the default shift for a MLX90640 device in open air
emissivity = 0.95

frame_buffer = ffi.new("uint16_t[834]")
image_buffer = ffi.new("float[768]")

print("Calc Hertz should be close to chosen value (%s)" % hertz)
last = time.monotonic()
while True:
    API.GetFrameData(MLX_I2C_ADDR, frame_buffer)
    now = time.monotonic()
    diff = now - last
    print("Calc Hz: %s" % (1 / diff))
    last = now

    # reflected temperature based on the sensor
    # ambient temperature
    tr = API.GetTa(frame_buffer, params) - TA_SHIFT

    # The object temperatures for all 768 pixels in a
    # frame are stored in the mlx90640To array
    API.CalculateTo(frame_buffer, params, emissivity, tr, image_buffer)
    print("Subpage no: %s" % API.GetSubPageNumber(frame_buffer))

    print(temperature_data_to_ndarray(image_buffer))
예제 #3
0
 def get_temp_array(self):
     API.GetFrameData(MLX_I2C_ADDR, frame_buffer);
     tr = API.GetTa(frame_buffer, params) - TA_SHIFT
     API.CalculateTo(frame_buffer, params, emissivity, tr, image_buffer);
     return temperature_data_to_ndarray(image_buffer)