#!/usr/bin/wish8.0
load /usr/local/lib/libBLT.so.2.4
load ../s2000.so
namespace import blt::*

set spectro [open /dev/adc500 r+] 
fconfigure $spectro -blocking 0 -translation binary -buffering none

vector Y X XNM TMP CALIB(2048)
set CALIB(0:2047) .0001 
TMP set { 0 2047 }
TMP populate X 2046 

# calculate pixel to nanometers
# please insert the correct values for your spectrometer
proc calcXNM { } {
	set lambda_null 624.686491
	set lambda_factor 0.35986096
	set lambda_factor2 -2.276e-5
        TMP set [X * X]
        TMP set [TMP * $lambda_factor2 ]
        XNM set [X * $lambda_factor]
        XNM set [XNM + $lambda_null]
        XNM set [XNM + TMP]
}
calcXNM

button .exit -text Exit -command { exit 0 }
graph .graph -width 500 -height 200 -title "Spectrum" 
.graph xaxis configure  -title "nm"
.graph element create line -xdata XNM -ydata Y -symbol none
pack .graph .exit -expand true -fill both

# connect vector Y to the spectrometer
# multiply the spectrometer data with vector CALIB 
# before writing them to vector Y ( for sensivity calibration ) 

s2000_link_vector $spectro Y CALIB
