p=peripheral.wrap("left")
m=peripheral.wrap("top")
item=""
file=fs.open("item","r")
local derInfo=0
local total=0
if file then
	item=file.readLine()
	file.close()
	print("Gestion de "..item)
else
	print("Pas d'item, creation")
	info=p.getStackInSlot(1)
	item=info.display_name
	file=fs.open("item","w")
	file.write(item)
	file.close()
end
redstone.setOutput("right",false)
function transmet()
	if derInfo~=total then
		donne={}
		donne.nom=item
		donne.total=total
		m.transmit(50,0,textutils.serialize(donne))
	end
end


while true do
	i=1
  ok=true
  total=0
  while ok do	
  	if p.getStackInSlot(i)~=nil then
		info=p.getStackInSlot(1)
    	total=total+info.qty
    end
    i=i+1
    if i==73 then
      ok=false      
    end
  end 
  if total<4500 then
	redstone.setOutput("right",true)
	print("pas plein "..total)
	os.sleep(30)
	transmet()
  else
	redstone.setOutput("right",false)
	print("plein "..total)	
	os.sleep(30)
	transmet()
	os.sleep(240)
  end
end