Commit 8484ea73 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

added sqlite and linux build

parent abccad09
......@@ -69,7 +69,6 @@
(number->string (list-ref d 2))))
(define centre-layout (layout 'wrap-content 'wrap-content 1 'centre))
(define (insert elt fn sorted-lst)
......@@ -270,7 +269,6 @@
"\n" token ": " value))))))
(string-append "{" (_ l "") "\n" "}"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (layout width height weight gravity) (list "layout" width height weight gravity))
......@@ -279,6 +277,8 @@
(define (layout-weight l) (list-ref l 3))
(define (layout-gravity l) (list-ref l 4))
(define centre-layout (layout 'wrap-content 'wrap-content 1 'centre))
(define (widget-type w) (list-ref w 0))
(define (widget-id w) (list-ref w 1))
......
......@@ -15,6 +15,13 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define db "test.db")
(display (db-open db))(newline)
(display (db-exec db "select * from COMPANY"))(newline)
(define (mbutton id title fn)
(button (make-id id) title 20 fillwrap fn))
......@@ -130,9 +137,9 @@
(let ((clear-focal-toggles
(lambda ()
(list
(update-widget 'toggle-button (make-id "pup-focal-moving") 'checked 0)
(update-widget 'toggle-button (make-id "pup-focal-foraging") 'checked 0)
(update-widget 'toggle-button (make-id "pup-focal-resting") 'checked 0)))))
(update-widget 'toggle-button (get-id "pup-focal-moving") 'checked 0)
(update-widget 'toggle-button (get-id "pup-focal-foraging") 'checked 0)
(update-widget 'toggle-button (get-id "pup-focal-resting") 'checked 0)))))
(activity
"pup-focal"
......@@ -417,16 +424,15 @@
"tag-location"
(vert
(text-view (make-id "title") "Tag Location" 40 fillwrap)
(spacer 10)
(text-view (make-id "tag-location-gps-text") "GPS")
(text-view (make-id "tag-location-gps-text") "GPS" 20 fillwrap)
(horiz
(text-view (make-id "tag-location-gps-lat") "LAT")
(text-view (make-id "tag-location-gps-lng") "LNG"))
(text-view (make-id "tag-location-gps-lat") "LAT" 20 fillwrap)
(text-view (make-id "tag-location-gps-lng") "LNG" 20 fillwrap))
(text-view (make-id "tag-location-name-text") "Name")
(text-view (make-id "tag-location-name-text") "Name" 20 fillwrap)
(edit-text (make-id "tag-location-name") "" 30 fillwrap (lambda (v) '()))
(text-view (make-id "tag-location-pack-text") "Associated pack")
(text-view (make-id "tag-location-pack-text") "Associated pack" 20 fillwrap)
(spinner (make-id "tag-location-pack") (list "Pack 1" "Pack 2") fillwrap (lambda (v) '()))
(text-view (make-id "tag-location-radius-text") "Approx radius of area" 20 fillwrap)
......
......@@ -4,9 +4,12 @@ include $(CLEAR_VARS)
LOCAL_MODULE := starwisp-core
LOCAL_CFLAGS := -DANDROID_NDK -O3 --fast-math -Wno-write-strings
LOCAL_CFLAGS := -DANDROID_NDK -O3 -Wno-write-strings
LOCAL_SRC_FILES := \
core/list.cpp \
core/db.cpp \
sqlite/sqlite3.c \
scheme/scheme.cpp \
app-android.c
......
env = Environment(CCFLAGS='-O3 -std=gnu++0x -ggdb -DUSE_MATH=1 -Wno-write-strings')
target = ARGUMENTS.get('TARGET','LINUX')
if target=='LINUX':
env.Append(LIBS = ['glut', 'GL', 'png', 'pthread', 'dl'])
env.Append(CCFLAGS=' -DFLX_LINUX')
env.Append(CPPPATH = '.')
if target=='RPI':
# raspberry pi
env.Append(LIBS = ['glutes', 'GLESv1_CM', 'EGL', 'bcm_host', 'X11', 'png'])
env.Append(CCFLAGS=' -DFLX_RPI -fpermissive')
env.Append(CPPPATH = '/opt/vc/include:.')
env.Append(LIBPATH = '/opt/vc/lib')
env.Program( target = 'app',
source = ['main.cpp',
'core/list.cpp',
'core/db.cpp',
'sqlite/sqlite3.c',
'scheme/scheme.cpp'
] )
// Copyright (C) 2013 Dave Griffiths
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "db.h"
#include <stdio.h>
db::db(const char *fn) :
m_running(1)
{
snprintf(m_status,2048,"Starting up");
int rc = sqlite3_open(fn, &m_db);
if(rc)
{
snprintf(m_status,2048,"Can't open database: %s",sqlite3_errmsg(m_db));
m_running=0;
}
else
{
snprintf(m_status,2048,"Opened database successfully");
}
}
db::~db()
{
}
static int callback(void *d, int argc, char **argv, char **azColName){
int i;
list *data=(list*)d;
list *row = new list;
for(i=0; i<argc; i++)
{
row->add_to_end(new db::value_node(argv[i] ? argv[i] : "NULL"));
}
data->add_to_end(new db::row_node(row));
return 0;
}
/*
void db::print_data(list *d)
{
row_node *row=(row_node*)d->m_head;
while (row!=NULL)
{
value_node *value=(value_node*)row->m_row->m_head;
while (value!=NULL)
{
cerr<<value->m_value<<" ";
value=(value_node*)value->m_next;
}
row=(row_node*)row->m_next;
cerr<<endl;
}
}
*/
list *db::exec(const char *sql)
{
if (!m_running) return NULL;
char *err = 0;
list *data = new list;
int rc = sqlite3_exec(m_db, sql, callback, data, &err);
if( rc != SQLITE_OK )
{
snprintf(m_status,4096,"SQL error: %s",err);
m_running=0;
sqlite3_free(err);
}
else
{
snprintf(m_status,4096,"SQL GOOD.");
}
return data;
}
// Copyright (C) 2013 Dave Griffiths
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sqlite/sqlite3.h"
#include "core/list.h"
#include <string.h>
using namespace std;
class db
{
public:
db(const char *fn);
~db();
list *exec(const char *sql);
class value_node: public list::node
{
public:
value_node(const char *v) { m_value=strdup(v); }
~value_node() { free(m_value); }
char *m_value;
};
class row_node: public list::node
{
public:
row_node(list *v) { m_row=v; }
~row_node() { delete m_row; }
list *m_row;
};
private:
sqlite3 *m_db;
int m_running;
char m_status[4096];
};
#include "core/db.h"
#include "core/list.h"
#include "string.h"
class db_container
{
public:
db_container() {}
void add(const char *fn, db *d)
{
m_dbs.add_to_end(new db_node(fn,d));
}
db *get(const char *fn)
{
db_node *cur=(db_node*)m_dbs.m_head;
while (cur!=NULL)
{
if (!strcmp(fn,cur->m_fn)) return cur->m_db;
cur=(db_node*)cur->m_next;
}
return NULL;
}
class db_node : public list::node
{
public:
db_node(const char *fn, db *d)
{
m_fn=strdup(fn);
m_db=d;
}
~db_node()
{
free(m_fn);
delete m_db;
}
char *m_fn;
db *m_db;
};
private:
list m_dbs;
};
/*
Copyright (c) 2006 Henry Strickland & Ryan Seto
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
(* http://www.opensource.org/licenses/mit-license.php *)
*/
#ifndef FLX_FIXED
#define FLX_FIXED
class Fixed {
private:
public:
#ifdef _EE
short g; // the guts
const static int BP= 8; // how many low bits are right of Binary Point
#else
int g; // the guts
const static int BP= 16; // how many low bits are right of Binary Point
#endif
const static int BP2= BP*2; // how many low bits are right of Binary Point
const static int BPhalf= BP/2; // how many low bits are right of Binary Point
static double STEP() { return 1.0 / (1<<BP); } // smallest step we can represent
// for private construction via guts
enum FixedRaw { RAW };
Fixed(FixedRaw, int guts) : g(guts) {}
//public:
Fixed() : g(0) {}
Fixed(const Fixed& a) : g( a.g ) {}
Fixed(float a) : g( int(a / (float)STEP()) ) {}
Fixed(double a) : g( int(a / (double)STEP()) ) {}
Fixed(int a) : g( a << BP ) {}
Fixed(long a) : g( a << BP ) {}
Fixed& operator =(const Fixed& a) { g= a.g; return *this; }
Fixed& operator =(float a) { g= Fixed(a).g; return *this; }
Fixed& operator =(double a) { g= Fixed(a).g; return *this; }
Fixed& operator =(int a) { g= Fixed(a).g; return *this; }
Fixed& operator =(long a) { g= Fixed(a).g; return *this; }
operator float() const { return g * (float)STEP(); }
operator double() const { return g * (double)STEP(); }
operator int() const { return g>>BP; }
operator long() const { return g>>BP; }
Fixed operator +() const { return Fixed(RAW,g); }
Fixed operator -() const { return Fixed(RAW,-g); }
Fixed operator +(const Fixed& a) const { return Fixed(RAW, g + a.g); }
Fixed operator -(const Fixed& a) const { return Fixed(RAW, g - a.g); }
#if 1
// more acurate, using long long
Fixed operator *(const Fixed& a) const { return Fixed(RAW, (int)( ((long long)g * (long long)a.g ) >> BP)); }
#else
// faster, but with only half as many bits right of binary point
Fixed operator *(const Fixed& a) const { return Fixed(RAW, (g>>BPhalf) * (a.g>>BPhalf) ); }
#endif
Fixed operator /(const Fixed& a) const { return Fixed(RAW, int( (((long long)g << BP2) / (long long)(a.g)) >> BP) ); }
Fixed operator +(float a) const { return Fixed(RAW, g + Fixed(a).g); }
Fixed operator -(float a) const { return Fixed(RAW, g - Fixed(a).g); }
Fixed operator *(float a) const { return Fixed(RAW, (g>>BPhalf) * (Fixed(a).g>>BPhalf) ); }
Fixed operator /(float a) const { return Fixed(RAW, int( (((long long)g << BP2) / (long long)(Fixed(a).g)) >> BP) ); }
Fixed operator +(double a) const { return Fixed(RAW, g + Fixed(a).g); }
Fixed operator -(double a) const { return Fixed(RAW, g - Fixed(a).g); }
Fixed operator *(double a) const { return Fixed(RAW, (g>>BPhalf) * (Fixed(a).g>>BPhalf) ); }
Fixed operator /(double a) const { return Fixed(RAW, int( (((long long)g << BP2) / (long long)(Fixed(a).g)) >> BP) ); }
Fixed& operator +=(Fixed a) { return *this = *this + a; return *this; }
Fixed& operator -=(Fixed a) { return *this = *this - a; return *this; }
Fixed& operator *=(Fixed a) { return *this = *this * a; return *this; }
Fixed& operator /=(Fixed a) { return *this = *this / a; return *this; }
Fixed& operator +=(int a) { return *this = *this + (Fixed)a; return *this; }
Fixed& operator -=(int a) { return *this = *this - (Fixed)a; return *this; }
Fixed& operator *=(int a) { return *this = *this * (Fixed)a; return *this; }
Fixed& operator /=(int a) { return *this = *this / (Fixed)a; return *this; }
Fixed& operator +=(long a) { return *this = *this + (Fixed)a; return *this; }
Fixed& operator -=(long a) { return *this = *this - (Fixed)a; return *this; }
Fixed& operator *=(long a) { return *this = *this * (Fixed)a; return *this; }
Fixed& operator /=(long a) { return *this = *this / (Fixed)a; return *this; }
Fixed& operator +=(float a) { return *this = *this + a; return *this; }
Fixed& operator -=(float a) { return *this = *this - a; return *this; }
Fixed& operator *=(float a) { return *this = *this * a; return *this; }
Fixed& operator /=(float a) { return *this = *this / a; return *this; }
Fixed& operator +=(double a) { return *this = *this + a; return *this; }
Fixed& operator -=(double a) { return *this = *this - a; return *this; }
Fixed& operator *=(double a) { return *this = *this * a; return *this; }
Fixed& operator /=(double a) { return *this = *this / a; return *this; }
bool operator ==(const Fixed& a) const { return g == a.g; }
bool operator !=(const Fixed& a) const { return g != a.g; }
bool operator <=(const Fixed& a) const { return g <= a.g; }
bool operator >=(const Fixed& a) const { return g >= a.g; }
bool operator <(const Fixed& a) const { return g < a.g; }
bool operator >(const Fixed& a) const { return g > a.g; }
bool operator ==(float a) const { return g == Fixed(a).g; }
bool operator !=(float a) const { return g != Fixed(a).g; }
bool operator <=(float a) const { return g <= Fixed(a).g; }
bool operator >=(float a) const { return g >= Fixed(a).g; }
bool operator <(float a) const { return g < Fixed(a).g; }
bool operator >(float a) const { return g > Fixed(a).g; }
bool operator ==(double a) const { return g == Fixed(a).g; }
bool operator !=(double a) const { return g != Fixed(a).g; }
bool operator <=(double a) const { return g <= Fixed(a).g; }
bool operator >=(double a) const { return g >= Fixed(a).g; }
bool operator <(double a) const { return g < Fixed(a).g; }
bool operator >(double a) const { return g > Fixed(a).g; }
};
inline Fixed operator +(float a, const Fixed& b) { return Fixed(a)+b; }
inline Fixed operator -(float a, const Fixed& b) { return Fixed(a)-b; }
inline Fixed operator *(float a, const Fixed& b) { return Fixed(a)*b; }
inline Fixed operator /(float a, const Fixed& b) { return Fixed(a)/b; }
inline bool operator ==(float a, const Fixed& b) { return Fixed(a) == b; }
inline bool operator !=(float a, const Fixed& b) { return Fixed(a) != b; }
inline bool operator <=(float a, const Fixed& b) { return Fixed(a) <= b; }
inline bool operator >=(float a, const Fixed& b) { return Fixed(a) >= b; }
inline bool operator <(float a, const Fixed& b) { return Fixed(a) < b; }
inline bool operator >(float a, const Fixed& b) { return Fixed(a) > b; }
inline Fixed operator +(double a, const Fixed& b) { return Fixed(a)+b; }
inline Fixed operator -(double a, const Fixed& b) { return Fixed(a)-b; }
inline Fixed operator *(double a, const Fixed& b) { return Fixed(a)*b; }
inline Fixed operator /(double a, const Fixed& b) { return Fixed(a)/b; }
inline bool operator ==(double a, const Fixed& b) { return Fixed(a) == b; }
inline bool operator !=(double a, const Fixed& b) { return Fixed(a) != b; }
inline bool operator <=(double a, const Fixed& b) { return Fixed(a) <= b; }
inline bool operator >=(double a, const Fixed& b) { return Fixed(a) >= b; }
inline bool operator <(double a, const Fixed& b) { return Fixed(a) < b; }
inline bool operator >(double a, const Fixed& b) { return Fixed(a) > b; }
inline int& operator +=(int& a, const Fixed& b) { a = (Fixed)a + b; return a; }
inline int& operator -=(int& a, const Fixed& b) { a = (Fixed)a - b; return a; }
inline int& operator *=(int& a, const Fixed& b) { a = (Fixed)a * b; return a; }
inline int& operator /=(int& a, const Fixed& b) { a = (Fixed)a / b; return a; }
inline long& operator +=(long& a, const Fixed& b) { a = (Fixed)a + b; return a; }
inline long& operator -=(long& a, const Fixed& b) { a = (Fixed)a - b; return a; }
inline long& operator *=(long& a, const Fixed& b) { a = (Fixed)a * b; return a; }
inline long& operator /=(long& a, const Fixed& b) { a = (Fixed)a / b; return a; }
inline float& operator +=(float& a, const Fixed& b) { a = a + b; return a; }
inline float& operator -=(float& a, const Fixed& b) { a = a - b; return a; }
inline float& operator *=(float& a, const Fixed& b) { a = a * b; return a; }
inline float& operator /=(float& a, const Fixed& b) { a = a / b; return a; }
inline double& operator +=(double& a, const Fixed& b) { a = a + b; return a; }
inline double& operator -=(double& a, const Fixed& b) { a = a - b; return a; }
inline double& operator *=(double& a, const Fixed& b) { a = a * b; return a; }
inline double& operator /=(double& a, const Fixed& b) { a = a / b; return a; }
#endif
// Copyright (C) 2010 Dave Griffiths
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "list.h"
list::list() : m_head(NULL)
{
}
list::~list()
{
clear();
}
void list::clear()
{
node *p=m_head;
while (p!=NULL)
{
node *t=p->m_next;
delete p;
p=t;
}
m_head=NULL;
}
u32 list::size()
{
u32 s=0;
node *p=m_head;
while (p!=NULL)
{
s++;
p=p->m_next;
}
return s;
}
list::node *list::last()
{
node *p=m_head;
while (p!=NULL && p->m_next!=NULL) p=p->m_next;
return p;
}
void list::add_to_front(node* n)
{
n->m_next=m_head;
m_head=n;
}
void list::add_to_end(node* n)
{
n->m_next=NULL;
if (m_head==NULL) m_head=n;
else last()->m_next=n;
}
// you need to delete returned node
list::node *list::remove_from_front()
{
if (m_head==NULL) return NULL;
node *ret=m_head;
m_head=m_head->m_next;
return ret;
}
// you need to delete n
void list::remove(node* n)
{