Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
poelzi committed Jun 27, 2010
0 parents commit 02caeba
Show file tree
Hide file tree
Showing 14 changed files with 485 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
__init__.pyc settings.pyc
settings.py~
Empty file added __init__.py
Empty file.
Empty file added db/__init__.py
Empty file.
Empty file added db/management/__init__.py
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions db/management/commands/uberclock.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.core.management.base import BaseCommand, CommandError
from uberclock_server.db.models import DBWriter
from django.conf import settings
import sys

import serial

class Command(BaseCommand):
args = ''
help = 'Runs a background daemon'

def handle(self, *args, **options):
if settings.CLOCK_HARDWARE.lower() == "ezchronos":
self.ez_chronos(*args, **options)

def ez_chronos(self, *args, **options):
ser = serial.Serial(settings.EZ_SERIAL, 115200,timeout=1)

pv = DBWriter(ser)
pv.debug = 1
pv.reset()
pv.start_ap()
try:
pv.loop_smpl_get()
except KeyboardInterrupt:
pv.reset()
ser.close()
sys.exit(0)

44 changes: 44 additions & 0 deletions db/models.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.db import models
from uberclock_server.tools import ez_chronos
import struct
# Create your models here.



class Entry(models.Model):
date = models.DateTimeField("Date", null=False, auto_now_add=True)
value = models.IntegerField(max_length=10, null=False)
counter = models.IntegerField(max_length=3, null=True)

def __repr__(self):
return "<Entry %s %d>" %(self.date, self.value)

class DBWriter(ez_chronos.CommandDispatcher):

def smpl_0x01(self, data):
# acceleration data
data = self.get_smpl_data(data)
print "x: %3d y: %3d z: %3d" %(ord(data[0]), ord(data[1]), ord(data[2]))

# ppt buttons
#UP
def smpl_0x32(self, data):
# acceleration data
print "UP pressed"
#STAR
def smpl_0x12(self, data):
# acceleration data
print "STAR pressed"
#SHARP
def smpl_0x22(self, data):
# acceleration data
print "SHARP pressed"

def smpl_0x03(self, data):
# acceleration data
mdata = self.get_smpl_data(data)
var = struct.unpack('H', mdata[:2])[0]
counter = ord(mdata[2])
print "%3d %6d %s" %(counter, var, "#"*max(min((var/500), 80),1))
entry = Entry(value=var, counter=counter)
entry.save()
23 changes: 23 additions & 0 deletions db/tests.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""

from django.test import TestCase

class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)

__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

1 change: 1 addition & 0 deletions db/views.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
# Create your views here.
15 changes: 15 additions & 0 deletions manage.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), "external"))

from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)

if __name__ == "__main__":
execute_manager(settings)
107 changes: 107 additions & 0 deletions settings.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,107 @@
# Django settings for uberclock_server project.

import os.path

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.expanduser('~/.uberclock/db.sqlite'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '9y1#-)6*b#my9hr8ktaq^iodt82-1)h_%sj-sgeuc_e6u2y=k)'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'uberclock_server.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
# 'django.contrib.messages',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
'uberclock_server.db',
)

CLOCK_HARDWARE = "ezchronos"

EZ_SERIAL = "/dev/ttyACM0"

import os

if not os.path.exists(os.path.expanduser("~/.uberclock")):
os.mkdir(os.path.expanduser("~/.uberclock"))

Empty file added tools/__init__.py
Empty file.
Loading

0 comments on commit 02caeba

Please sign in to comment.