sabato 1 gennaio 2011

Allarme! v0.1


A python alarm for my iBookG4.
It will be useful when I'll leave the desk of the public library looking for a cup of coffee.
It works on my Debian setup and probably will NOT work on your system without modifications.



#!/usr/bin/python

#Allarme! v0.1
#reads /sys/devices/ams/current file (senso) to get informations from the
#internal tilt sensor of Apple's iBooks. It works on my Debian iBookG4 and
#probably it will NOT work on your system without modifications.
#If the variation of one of sensor's values is greater than threshold (thr)
#it will play a sound (not included) located in $HOME/.allarme.wav and
#print a warning message (messo) on the console.
#Copyright 2011 Francesco Aggazio.

#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program.  If not, see .

import os
import time
import pygame

thr = 2
messo = "Mollami!"
senso = "/sys/devices/ams/current"
home = os.environ['HOME']

inf = open(senso, "r")
incat = inf.readline()
inli = incat.split()
x = int(inli[0])
y = int(inli[1])
z = int(inli[2])

pygame.init()

while 1:
  exx = x
  exy = y
  exz = z
  f = open(senso, "r")
  cat = f.readline()
  li = cat.split()
  x = int(li[0])
  y = int(li[1])
  z = int(li[2])
  dfx = abs(abs(exx) - abs(x))
  dfy = abs(abs(exy) - abs(y))
  dfz = abs(abs(exz) - abs(z))
  if dfx > thr or dfy > thr or dfz > thr:
    print messo
    pygame.mixer.Sound(os.path.join(home, ".allarme.wav")).play()
  #print exx, " ", exy, " ", exz, " : ", x, " ", y, " ", z
  time.sleep(1)

Nessun commento:

Posta un commento