Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Support

Pages: 1 ... 28 29 [30] 31 32 ... 59
436
What's New / Re: C for Android
« on: July 30, 2012, 03:00:22 AM »
I have seen the light.  :o

This is a SDL native Android Linux example using the Android native app glue API. I'm able to touch the screen and spin the cube in any direction. It's as fast as any desktop I've run the same OpenGL cube demo on. (smooth as silk) It runs in its own thread, with its own
event loop for receiving input events and doing other things.  From what I read, Java based application are single threaded only. I would think this would attract some interest from the gaming community.

I compiled this demo on my non-rooted SGT2_10.1 tablet.

Attached zip contains the demo in a .apk install package for android. (make sure you enable off market apps)



Code: [Select]
#include <jni.h>
#include <errno.h>

#include <EGL/egl.h>
#include <GLES/gl.h>

#include <android/sensor.h>
#include <android/log.h>
#include <android_native_app_glue.h>

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))

/**
 * Our saved state data.
 */
struct saved_state {
    float angle;
    int32_t x;
    int32_t y;
};

/**
 * Shared state for our app.
 */
struct engine {
    struct android_app* app;

    ASensorManager* sensorManager;
    const ASensor* accelerometerSensor;
    ASensorEventQueue* sensorEventQueue;

    int animating;
    EGLDisplay display;
    EGLSurface surface;
    EGLContext context;
    int32_t width;
    int32_t height;
    struct saved_state state;
};

/**
 * Initialize an EGL context for the current display.
 */
static int engine_init_display(struct engine* engine) {
    // initialize OpenGL ES and EGL

    /*
     * Here specify the attributes of the desired configuration.
     * Below, we select an EGLConfig with at least 8 bits per color
     * component compatible with on-screen windows
     */
    const EGLint attribs[] = {
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_BLUE_SIZE, 8,
            EGL_GREEN_SIZE, 8,
            EGL_RED_SIZE, 8,
            EGL_NONE
    };
    EGLint w, h, dummy, format;
    EGLint numConfigs;
    EGLConfig config;
    EGLSurface surface;
    EGLContext context;

    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

    eglInitialize(display, 0, 0);

    /* Here, the application chooses the configuration it desires. In this
     * sample, we have a very simplified selection process, where we pick
     * the first EGLConfig that matches our criteria */
    eglChooseConfig(display, attribs, &config, 1, &numConfigs);

    /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
     * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
     * As soon as we picked a EGLConfig, we can safely reconfigure the
     * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

    ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);

    surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
    context = eglCreateContext(display, config, NULL, NULL);

    if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
        LOGW("Unable to eglMakeCurrent");
        return -1;
    }

    eglQuerySurface(display, surface, EGL_WIDTH, &w);
    eglQuerySurface(display, surface, EGL_HEIGHT, &h);

    engine->display = display;
    engine->context = context;
    engine->surface = surface;
    engine->width = w;
    engine->height = h;
    engine->state.angle = 0;

    // Initialize GL state.
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
    glEnable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);
    glDisable(GL_DEPTH_TEST);

    return 0;
}

/**
 * Just the current frame in the display.
 */
static void engine_draw_frame(struct engine* engine) {
    if (engine->display == NULL) {
        // No display.
        return;
    }

    // Just fill the screen with a color.
    glClearColor(((float)engine->state.x)/engine->width, engine->state.angle,
            ((float)engine->state.y)/engine->height, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    eglSwapBuffers(engine->display, engine->surface);
}

/**
 * Tear down the EGL context currently associated with the display.
 */
static void engine_term_display(struct engine* engine) {
    if (engine->display != EGL_NO_DISPLAY) {
        eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
        if (engine->context != EGL_NO_CONTEXT) {
            eglDestroyContext(engine->display, engine->context);
        }
        if (engine->surface != EGL_NO_SURFACE) {
            eglDestroySurface(engine->display, engine->surface);
        }
        eglTerminate(engine->display);
    }
    engine->animating = 0;
    engine->display = EGL_NO_DISPLAY;
    engine->context = EGL_NO_CONTEXT;
    engine->surface = EGL_NO_SURFACE;
}

/**
 * Process the next input event.
 */
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
    struct engine* engine = (struct engine*)app->userData;
    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
        engine->animating = 1;
        engine->state.x = AMotionEvent_getX(event, 0);
        engine->state.y = AMotionEvent_getY(event, 0);
        return 1;
    }
    return 0;
}

/**
 * Process the next main command.
 */
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
    struct engine* engine = (struct engine*)app->userData;
    switch (cmd) {
        case APP_CMD_SAVE_STATE:
            // The system has asked us to save our current state.  Do so.
            engine->app->savedState = malloc(sizeof(struct saved_state));
            *((struct saved_state*)engine->app->savedState) = engine->state;
            engine->app->savedStateSize = sizeof(struct saved_state);
            break;
        case APP_CMD_INIT_WINDOW:
            // The window is being shown, get it ready.
            if (engine->app->window != NULL) {
                engine_init_display(engine);
                engine_draw_frame(engine);
            }
            break;
        case APP_CMD_TERM_WINDOW:
            // The window is being hidden or closed, clean it up.
            engine_term_display(engine);
            break;
        case APP_CMD_GAINED_FOCUS:
            // When our app gains focus, we start monitoring the accelerometer.
            if (engine->accelerometerSensor != NULL) {
                ASensorEventQueue_enableSensor(engine->sensorEventQueue,
                        engine->accelerometerSensor);
                // We'd like to get 60 events per second (in us).
                ASensorEventQueue_setEventRate(engine->sensorEventQueue,
                        engine->accelerometerSensor, (1000L/60)*1000);
            }
            break;
        case APP_CMD_LOST_FOCUS:
            // When our app loses focus, we stop monitoring the accelerometer.
            // This is to avoid consuming battery while not being used.
            if (engine->accelerometerSensor != NULL) {
                ASensorEventQueue_disableSensor(engine->sensorEventQueue,
                        engine->accelerometerSensor);
            }
            // Also stop animating.
            engine->animating = 0;
            engine_draw_frame(engine);
            break;
    }
}

/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(struct android_app* state) {
    struct engine engine;

    // Make sure glue isn't stripped.
    app_dummy();

    memset(&engine, 0, sizeof(engine));
    state->userData = &engine;
    state->onAppCmd = engine_handle_cmd;
    state->onInputEvent = engine_handle_input;
    engine.app = state;

    // Prepare to monitor accelerometer
    engine.sensorManager = ASensorManager_getInstance();
    engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
            ASENSOR_TYPE_ACCELEROMETER);
    engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
            state->looper, LOOPER_ID_USER, NULL, NULL);

    if (state->savedState != NULL) {
        // We are starting with a previous saved state; restore from it.
        engine.state = *(struct saved_state*)state->savedState;
    }

    // loop waiting for stuff to do.

    while (1) {
        // Read all pending events.
        int ident;
        int events;
        struct android_poll_source* source;

        // If not animating, we will block forever waiting for events.
        // If animating, we loop until all events are read, then continue
        // to draw the next frame of animation.
        while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
                (void**)&source)) >= 0) {

            // Process this event.
            if (source != NULL) {
                source->process(state, source);
            }

            // If a sensor has data, process it now.
            if (ident == LOOPER_ID_USER) {
                if (engine.accelerometerSensor != NULL) {
                    ASensorEvent event;
                    while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
                            &event, 1) > 0) {
                        LOGI("accelerometer: x=%f y=%f z=%f",
                                event.acceleration.x, event.acceleration.y,
                                event.acceleration.z);
                    }
                }
            }

            // Check if we are exiting.
            if (state->destroyRequested != 0) {
                engine_term_display(&engine);
                return;
            }
        }

        if (engine.animating) {
            // Done with events; draw next animation frame.
            engine.state.angle += .01f;
            if (engine.state.angle > 1) {
                engine.state.angle = 0;
            }

            // Drawing is throttled to the screen update rate, so there
            // is no need to do timing here.
            engine_draw_frame(&engine);
        }
    }
}

437
What's New / Re: C for Android
« on: July 28, 2012, 11:57:33 AM »
It would be cool if I could get a ScriptBasic distribution going that was compiled native on Android. There are a lot of unknowns so I thought I would try getting BaCon working on Android first. Here is where I am with that effort.

I'm happy to report that sockets and console screen attributes seem to be working fine under Android. BaCon's runtime is about 45KB but the executables don't get much bigger even with user specific code. Other than REGEX not working, BaCon seems to work well under Android. This was just a proof of concept effort. If there is any real interest in this, I will put together an ADB install that includes the following.

  • bash for Android
  • C4droid + gcc plug-in
  • bacon.bash
  • getting started docs

Based on want I have going with SB, I should be able to create a BaCon install that allows the user to compile scripts and not have to root their device to do so.

BINDUMP


MASTERMIND

438
What's New / C for Android
« on: July 11, 2012, 12:01:10 AM »
I installed the C4droid compiler and GCC plug-in. Here is my test Hello ScriptBasic compiled on my Samsung Galaxy Tab 2 10.1 tablet. Believe it or not, you can compile C programs on a non-rooted device. Using the /data/local/... gets around the requirement to use the /data/data/app_id directory structure for ownership and permissions management. I sure hope this doesn't change in future Android releases.

shell@android:/data/local/c4bin $ ls -l
-rwxrwxrwx app_101  app_101      3409 2012-07-11 00:51 c.out
shell@android:/data/local/c4bin $ ./c.out
Hello ScriptBasic
32|shell@android:/data/local/c4bin $

439
What's New / Re: ScriptBasic for Android
« on: July 09, 2012, 05:28:13 PM »
If you have a Bluetooth keyboard for your Android device and the CAPS is sticking for you, download Dre’s Bluetooth Keyboard.apk to solve the problem. It worked for my Samsung Galaxy Tab 2 10.1 using ConnectBot and SL4A TERM. I didn't notice the problem as often with e-mail and browser forms. It seems the keyboard gets out of sync with the terminal app and works in the opposite way.


440
Round Table / Re: Samsung vs. Apple
« on: July 06, 2012, 06:18:04 PM »

441
Round Table / Re: Samsung vs. Apple
« on: July 06, 2012, 06:11:59 PM »
Apple wins sales ban on Samsung Galaxy Tab 10.1 tablet

I wonder how long before the Galaxy Tab 2 10.1 is restricted in the U.S. market?

442
General Discussions / Android Linux
« on: July 06, 2012, 12:33:14 AM »
I thought I would start an Android Linux thread that isn't ScriptBasic specific. I ran into this link that explains the Android File System Hierarchy

I now have a rooted and unrooted Samsung Galaxy Tab 2 10.1 tablets to develop with. I will post my adventures in the world of root with rules. Android Linux is not your old man's Unix or even your brother's Linux. It's a prefab OS that comes with it's own set of rules.


443
Round Table / Samsung vs. Apple
« on: July 04, 2012, 10:01:57 AM »
Round II

Samsung takes another hit from Apple with an injunction on sales of the Galaxy Nexus. I thought I would start a list of Apple attacks to see how far this greed factor has evolved.

  • Samsung Galaxy Tab 10.1
  • Samsung Galaxy Nexus

I'm willing to bet that the Galaxy S III is next on the list.

Update

It looks like Apple already tried to prevent the Galaxy S III from hitting US markets but failed in the attempt. I see this as only round one with the S III and with the win with the Tab 10.1 and Nexus, the tide may be turning for Apple.

444
Round Table / Samsung vs. Apple
« on: June 27, 2012, 11:34:05 AM »
Apple wins U.S. sales injunction against Samsung Galaxy Tab 10.1



Apple has prevailed in seeking a preliminary sales injunction against Samsung’s Galaxy Tab 10.1 tablet over the alleged infringement of the iPad’s patented design.

The win marks a major victory for Apple in the ongoing “thermonuclear war” against rival mobile operating system Google’s Android.

U.S. District Judge Lucy Koh previously rejected Apple’s attempt to block the tablet in the U.S., but was forced to reconsider her position following an appeals court ruling.

Once Apple posts a $2.6 million bond to protect Samsung against damages should the injunction be appealed and overturned, the sales ban can come into force.

Sure glad I got mine in time. You may want to run down to your favorite electronics store and pick one up before they are all gone. I bet the phone carriers selling the SGT2_10.1 are PISSED!!!  

Update

It looks like this injunction only covers the original Galaxy Tab and not the Galaxy Tab 2 10.1 tablet. Why would Apple go for an injunction on an obsolete device? The Tab 2 is almost a clone. (speakers now in front, and a few minor improvements over the original)

445
What's New / Re: ScriptBasic for Android
« on: June 26, 2012, 12:30:23 AM »
I added an ANSI screen attribute library to ScriptBasic. It runs fine on both Ubuntu and Android Linux.



Scripting the Android device remotely on Ubuntu.



Code: [Select]
' SL4A and console screen mnemonics demo

IMPORT DVM
INCLUDE "ansi.inc"

CLS

PRINT GRAPHICS_ON
PRINT "l",STRING(38,"q"),"k"
FOR i = 2 TO 15
  PRINT AT(1,i),"x",AT(40,i),"x"
NEXT i
PRINTNL
PRINT "m",STRING(38,"q"),"j"
PRINT AT(1,3),"t",STRING(38,"q"),"u"
PRINT AT(30,3),"w"
FOR i = 4 TO 15
  PRINT AT(30,i),"x"
NEXT i
PRINT AT(30,i),"v"
PRINT GRAPHICS_OFF

PRINT AT(2,2),BOLD,COLOR(7,4,STRING(10," ") & "SAMSUNG Tab 2 10.1" & STRING(10," "))
PRINT AT(2,4),BOLD,COLOR(7,6," Phone Type" & STRING(17," "))
PRINT AT(2,5),BOLD,COLOR(7,6," Screen Brightness" & STRING(10," "))
PRINT AT(2,6),BOLD,COLOR(7,6," Airplane Mode" & STRING(14," "))
PRINT AT(2,7),BOLD,COLOR(7,6," Ringer Slient Mode" & STRING(9," "))
PRINT AT(2,8),BOLD,COLOR(7,6," Screen On" & STRING(18," "))
PRINT AT(2,9),BOLD,COLOR(7,6," Max Media Volume" & STRING(11," "))
PRINT AT(2,10),BOLD,COLOR(7,6," Max Ringer Volume" & STRING(10," "))
PRINT AT(2,11),BOLD,COLOR(7,6," Media Volume" & STRING(15," "))
PRINT AT(2,12),BOLD,COLOR(7,6," Ringer Volume" & STRING(14," "))
PRINT AT(2,13),BOLD,COLOR(7,6," Vibrate Mode" & STRING(15," "))
PRINT AT(2,14),BOLD,COLOR(7,6," Vibrate Mode Ringer" & STRING(8," "))
PRINT AT(2,15),BOLD,COLOR(7,6," Vibrate Mode Notify" & STRING(8," "))

PRINT AT(33,4),DVM::getPhoneType()
PRINT AT(33,5),DVM::getScreenBrightness()
IF DVM::checkAirplaneMode() = "false" THEN
  PRINT AT(33,6),COLOR(1,0,"false")
ELSE
  PRINT AT(33,6),COLOR(2,0,"true")
END IF
IF DVM::checkRingerSilentMode() = "false" THEN
  PRINT AT(33,7),COLOR(1,0,"false")
ELSE
  PRINT AT(33,7),COLOR(2,0,"true")
END IF
IF DVM::checkScreenOn() = "false" THEN
  PRINT AT(33,8),COLOR(1,0,"false")
ELSE
  PRINT AT(33,8),COLOR(2,0,"true")
END IF
PRINT AT(33,9),DVM::getMaxMediaVolume()
PRINT AT(33,10),DVM::getMaxRingerVolume()
PRINT AT(33,11),DVM::getMediaVolume()
PRINT AT(33,12),DVM::getRingerVolume()
IF DVM::getVibrateMode() = "false" THEN
  PRINT AT(33,13),COLOR(1,0,"false")
ELSE
  PRINT AT(33,13),COLOR(2,0,"true")
END IF
IF DVM::getVibrateMode(TRUE) = "false" THEN
  PRINT AT(33,14),COLOR(1,0,"false")
ELSE
  PRINT AT(33,14),COLOR(2,0,"true")
END IF
IF DVM::getVibrateMode(FALSE) = "false" THEN
  PRINT AT(33,15),COLOR(1,0,"false")
ELSE
  PRINT AT(33,15),COLOR(2,0,"true")
END IF

PRINT AT(1,18)
LINE INPUT z

  • CLS - Clear screen and home the cursor. (x1:y1)
  • COLOR(fg,bg,text) - Set the foreground, background and text to be displayed in color.
  • AT(x,y) - Position the cursor to the (x:y) position on the screen.
  • NORMAL - Return attributes to the default state.
  • BOLD - Bold the text follow the attribute.
  • UNDERLINE_ON - Start underline text mode.
  • UNDERLINE_OFF - End  underline text mode.
  • REVERSE_ON - Start reverse video mode.
  • REVERSE_OFF - End reverse video mode.
  • INS - Insert a blank character at the current cursor position moving the text to the right.
  • DEL - Delete a character at the current cursor position and shift text to the left.
  • INS_LINE - Insert a blank line on the row the cursor is at and shift lines of text down.
  • DEL_LINE - Delete a line on the row the cursor is at and shift lines of text up.
  • GRAPHICS_ON - Switch to the graphics/line draw character set.
  • GRAPHICS_OFF - Return back to the standard charater set.
Note: All of the above screen attributes are in the form of a string. (except CLS)

ansi.inc
Code: [Select]
' Console Display Enhancement Library

SUB CLS
  PRINT "\033[2J\033[1;1H"
END SUB

FUNCTION COLOR(fg,bg,text)
  COLOR = "\033[" & (fg + 30) & ";" & (bg + 40) & "m" & text & "\033[0m"
END FUNCTION

FUNCTION AT(x,y)
  AT = "\033[" & y & ";" & x & "H"
END FUNCTION

GLOBAL CONST NORMAL = "\033[22m"
GLOBAL CONST BOLD = "\033[1m"
GLOBAL CONST UNDERLINE_ON = "\033[4m"
GLOBAL CONST UNDERLINE_OFF = "\033[24m"
GLOBAL CONST REVERSE_ON = "\033[7m"
GLOBAL CONST REVERSE_OFF = "\033[27m"
GLOBAL CONST INS = "\033[1@"
GLOBAL CONST DEL = "\033[1P"
GLOBAL CONST INS_LINE = "\033[1L"
GLOBAL CONST DEL_LINE = "\033[1M"
GLOBAL CONST GRAPHICS_ON = "\033(0"
GLOBAL CONST GRAPHICS_OFF = "\033(B"


446
SQLite / Re: SQLite3 SB ext. module
« on: June 22, 2012, 06:08:37 PM »
While testing the new SQLite3 extension module, I discovered a problem with the FetchHash() and FetchArray() functions. Armando sent me a fix which seems to work based on my limited testing. The following is an example of reading the raw_contacts table from the Android system DB.

Code: [Select]
import sqlite.bas

db = sqlite::open("contacts2.db")

stmt = sqlite::query(db,"select * from raw_contacts")

while (sqlite::row(stmt) = sqlite::SQLITE3_ROW)
  if sqlite::fetchhash(stmt,column) then
    for x = 0 to ubound(column) step 2
      PRINT column[x]," - ",column[x+1],"\n"
    next x
  end if
wend

sqlite::close(db)

jrs@laptop:~/sbdev$ scriba t6_sqlite.sb
_id - 1
account_name - 1
account_type - 1
data_set - 1
sourceid - 1
raw_contact_is_read_only - 0
version - 2
dirty - 1
deleted - 0
contact_id - 1
aggregation_mode - 0
aggregation_needed - 0
custom_ringtone - 0
send_to_voicemail - 0
times_contacted - 0
last_time_contacted - 0
starred - 0
display_name - John Spikowski
display_name_alt - Spikowski, John
display_name_source - 40
phonetic_name - 40
phonetic_name_style - 3
sort_key - John Spikowski
sort_key_alt - Spikowski, John
name_verified - 0
sync1 - 0
sync2 - 0
sync3 - 0
sync4 - 0
jrs@laptop:~/sbdev$


447
SQLite / SQLite3 SB ext. module - Android
« on: June 20, 2012, 07:53:47 PM »
Attached is Armando's SQLite3 ScriptBasic extension module for Android Linux. SQLite3 is statically linked into the SB ext. module so there is no external SQLite3 dependencies required. (my SGT2 10.1 doesn't seem to have a /system/bin/sqlite3 command line utility and I haven't found where there may be a share object version of SQLite3 installed) This Android Developer SQLite3 reference doesn't hold true on my SGT2_10.1 at least.




448
SQLite / Re: SQLite3 SB ext. module
« on: June 17, 2012, 10:17:38 PM »
Armando (AIR) released a beta version of his SQLite3 extension module for ScriptBasic. This release follows the standard SB high level function calls that are used in the MySQL, ODBC and PostgreSQL extensions modules. In most cases, just changing open/connect statement is all that is needed to move between DB extension module libraries. You don't need to install any SQLite3 libraries or dependencies to use this extension module. Everything is included in the extension module shared object.

t_sqlite3.sb
Code: [Select]
import sqlite.bas

db = sqlite::open("testsql")

sqlite::execute(db,"CREATE TABLE demo (someval integer, sometxt text);")
sqlite::execute(db,"INSERT INTO demo VALUES (123,'hello');")
sqlite::execute(db, "INSERT INTO demo VALUES (234, 'cruel');")
sqlite::execute(db, "INSERT INTO demo VALUES (345, 'world');")

stmt = sqlite::query(db,"SELECT * FROM demo")

while (sqlite::row(stmt) = sqlite::SQLITE3_ROW)
  if sqlite::fetchhash(stmt,column) then
    print column{"someval"},"\t-\t",column{"sometxt"},"\n"
  end if
wend

sqlite::close(db)

jrs@ip-10-166-185-35:~/test$ scriba t_sqlite3.sb
123   -   hello
234   -   cruel
345   -   world
jrs@ip-10-166-185-35:~/test$

sqlite.bas
Code: [Select]
' """
FILE: sqlite.bas

This is the BASIC import file for the module sqlite.

This file was generated by headerer.pl from the file interface.c
Do not edit this file, rather edit the file interface.c and use
headerer.pl to regenerate this file.
"""

module sqlite

SQLITE3_OK          =   0
SQLITE3_ERROR       =   1
SQLITE3_INTERNAL    =   2
SQLITE3_PERM        =   3
SQLITE3_ABORT       =   4
SQLITE3_BUSY        =   5
SQLITE3_LOCKED      =   6
SQLITE3_NOMEM       =   7
SQLITE3_READONLY    =   8
SQLITE3_INTERRUPT   =   9
SQLITE3_IOERR       =  10
SQLITE3_CORRUPT     =  11
SQLITE3_NOTFOUND    =  12  
SQLITE3_FULL        =  13
SQLITE3_CANTOPEN    =  14  
SQLITE3_PROTOCOL    =  15  
SQLITE3_EMPTY       =  16  
SQLITE3_SCHEMA      =  17
SQLITE3_TOOBIG      =  18
SQLITE3_CONStraint  =  19
SQLITE3_MISMATCH    =  20
SQLITE3_MISUSE      =  21
SQLITE3_NOLFS       =  22
SQLITE3_AUTH        =  23
SQLITE3_ROW         = 100
SQLITE3_DONE        = 101

SQLITE3_STATIC      =   0
SQLITE_TRANSIENT    =  -1

SQLITE_INTEGER      =   1
SQLITE_FLOAT        =   2
SQLITE_TEXT         =   3
SQLITE_BLOB         =   4
SQLITE_NULL         =   5
      
' FUNCTION DECLARATIONS
declare sub     ::OPEN         alias "sql3_open"         lib "sqlite"
declare sub     ::CLOSE        alias "sql3_close"        lib "sqlite"
declare sub     ::EXECUTE      alias "sql3_execute"      lib "sqlite"
declare sub     ::QUERY        alias "sql3_query"        lib "sqlite"
declare sub     ::ROW          alias "sql3_row"          lib "sqlite"
declare sub     ::ROW_VALUE    alias "sql3_row_value"    lib "sqlite"
declare sub     ::COLUMN_COUNT alias "sql3_column_count" lib "sqlite"
declare sub     ::COLUMN_NAME  alias "sql3_column_name"  lib "sqlite"
declare sub     ::FINALIZE     alias "sql3_finalize"     lib "sqlite"
declare sub     ::VERSION      alias "sql3_version"      lib "sqlite"
declare sub     ::ErrorCode    alias "sql3_errorcode"    lib "sqlite"
declare sub     ::ErrorMsg     alias "sql3_errormsg"     lib "sqlite"
declare sub     ::FETCHHASH    alias "sql3_fetchhash"    lib "sqlite"
declare sub     ::FETCHARRAY   alias "sql3_fetcharray"   lib "sqlite"

end module

interface.c
Code: [Select]
/*
  FILE   : interface.c
  HEADER : interface.h
  BAS    : sqlite.bas
  AUTHOR : Armando I. Rivera

  DATE:

  CONTENT:
  This is the interface.c file for the ScriptBasic module sqlite3

NTLIBS:
UXLIBS: -lc -ldl -lpthread
DWLIBS: -lsqlite3 -lpthread
ADLIBS:
*/

/*
TO_BAS:
SQLITE3_OK          =   0
SQLITE3_ERROR       =   1
SQLITE3_INTERNAL    =   2
SQLITE3_PERM        =   3
SQLITE3_ABORT       =   4
SQLITE3_BUSY        =   5
SQLITE3_LOCKED      =   6
SQLITE3_NOMEM       =   7
SQLITE3_READONLY    =   8
SQLITE3_INTERRUPT   =   9
SQLITE3_IOERR       =  10
SQLITE3_CORRUPT     =  11
SQLITE3_NOTFOUND    =  12  
SQLITE3_FULL        =  13
SQLITE3_CANTOPEN    =  14  
SQLITE3_PROTOCOL    =  15  
SQLITE3_EMPTY       =  16  
SQLITE3_SCHEMA      =  17
SQLITE3_TOOBIG      =  18
SQLITE3_CONStraint  =  19
SQLITE3_MISMATCH    =  20
SQLITE3_MISUSE      =  21
SQLITE3_NOLFS       =  22
SQLITE3_AUTH        =  23
SQLITE3_ROW         = 100
SQLITE3_DONE        = 101

SQLITE3_STATIC      =   0
SQLITE_TRANSIENT    =  -1

SQLITE_INTEGER      =   1
SQLITE_FLOAT        =   2
SQLITE_TEXT         =   3
SQLITE_BLOB         =   4
SQLITE_NULL         =   5
      
*/

#include <stdio.h>
#include <string.h>

#include "../../basext.h"
#include "sqlite3.h"

besVERSION_NEGOTIATE
  return (int)INTERFACE_VERSION;
besEND

besSUB_START
  long *p;

  besMODULEPOINTER = besALLOC(sizeof(long));
  if( besMODULEPOINTER == NULL )return 0;

  p = (long*)besMODULEPOINTER;
  return 0;
besEND

besSUB_FINISH
  long *p;

  p = (long*)besMODULEPOINTER;
  if( p == NULL )return 0;
  return 0;
besEND

/**
=section OPEN
=H Open/Create an sqlite3 database file
*/

besFUNCTION(sql3_open)
     sqlite3 *db;
     const char *fileName;
     int i;

     besARGUMENTS("s")
          &fileName
     besARGEND

     i = sqlite3_open(fileName, &db);
     besRETURN_POINTER(db)
besEND

/**
=section CLOSE
=H Close an sqlite3 database file
*/
besFUNCTION(sql3_close)
     sqlite3 *db;
     int i;

     besARGUMENTS("p")
          &db
     besARGEND

     i = sqlite3_close(db);
     besRETURN_LONG(i)
besEND

/**
=section EXECUTE
=H Execute an SQL statement/command
*/
besFUNCTION(sql3_execute)
    sqlite3 *db;
    char *sqlcmd;
    int ret;

    besARGUMENTS("ps")
        &db,&sqlcmd
    besARGEND
    ret = sqlite3_exec(db,sqlcmd,NULL,NULL,NULL);
    besRETURN_LONG(ret)
besEND

/**
=section QUERY
=H Pass a Query to an sqlite3 database file
*/
besFUNCTION(sql3_query)
    sqlite3 *db;
    sqlite3_stmt *stmt;
    char *sqlcmd;
    int ret;

    besARGUMENTS("ps")
        &db,&sqlcmd
    besARGEND
    ret = sqlite3_prepare_v2(db,sqlcmd,strlen(sqlcmd)+1,&stmt,NULL);
    besRETURN_POINTER(stmt)
besEND

/**
=section ROW
=H Retrieve the next Row from a database file
*/
besFUNCTION(sql3_row)
     sqlite3_stmt *stmt;
     int i;

     besARGUMENTS("p")
          &stmt
     besARGEND

     i = sqlite3_step(stmt);
     besRETURN_LONG(i)

besEND

/**
=section ROW_VALUE
=H Retrieve the value at position y in database row
*/
besFUNCTION(sql3_row_value)
     sqlite3_stmt *stmt;
     const char* cur_column_text;
     int i;

     besARGUMENTS("pi")
          &stmt,&i
     besARGEND

     cur_column_text = sqlite3_column_text(stmt,i);
     besRETURN_STRING(cur_column_text)

besEND

/**
=section COLUMN_COUNT
=H Retrieve number of columns in table
*/
besFUNCTION(sql3_column_count)
     sqlite3_stmt *stmt;
     int i;

     besARGUMENTS("p")
          &stmt
     besARGEND

     i = sqlite3_column_count(stmt);
     besRETURN_LONG(i)

besEND

/**
=section COLUMN_NAME
=H Retrieve column name at pos i in table
*/
besFUNCTION(sql3_column_name)
     sqlite3_stmt *stmt;
     const char* cur_column_name;
     int i;

     besARGUMENTS("pi")
          &stmt,&i
     besARGEND

     cur_column_name = sqlite3_column_name(stmt,i);
     besRETURN_STRING(cur_column_name)

besEND

/**
=section FINALIZE
=H Finalize an sqlite3 database file
*/
besFUNCTION(sql3_finalize)
     sqlite3_stmt *stmt;
     int i;

     besARGUMENTS("p")
          &stmt
     besARGEND

     i = sqlite3_finalize(stmt);
     besRETURN_LONG(i)
besEND

/**
=section VERSION
=H Retrieve sqlite3 version string
*/
besFUNCTION(sql3_version)
    const char *ver = sqlite3_libversion();
    besRETURN_STRING(ver)
besEND

/**
=section ErrorCode
=H Returns status code for sqlite function call
*/
besFUNCTION(sql3_errorcode)
     sqlite3 *db;
     int i;

     besARGUMENTS("p")
          &db
     besARGEND

     i = sqlite3_errcode(db);
     besRETURN_LONG(i)
besEND

/**
=section ErrorMsg
=H Returns text that describes the error
*/
besFUNCTION(sql3_errormsg)
     sqlite3 *db;
     const char *errString;

     besARGUMENTS("p")
          &db
     besARGEND

     errString = sqlite3_errmsg(db);
     besRETURN_STRING(errString)
besEND

/**
=section FETCHHASH
=H Returns Hash containing row contents in Key/Value pair
*/
besFUNCTION(sql3_fetchhash)
    VARIABLE Argument;
    unsigned long __refcount_;
    sqlite3_stmt *stmt;
    LEFTVALUE Lval;
    unsigned int numfields;
    int i;
    const char* cur_column_name;
    const char* cur_column_text;
    
     besARGUMENTS("p")
          &stmt
     besARGEND
    
     Argument = besARGUMENT(2);

     besLEFTVALUE(Argument,Lval);
     if( ! Lval )return 0x00081001;
    
     besRELEASE(*Lval);
     *Lval = NULL;
    
    
     numfields = sqlite3_column_count(stmt);
     if( numfields == 0 ){
        besRETURNVALUE = NULL;
        return COMMAND_ERROR_SUCCESS;
     }
    
     *Lval = besNEWARRAY(0,2*numfields-1);
     if( *Lval == NULL )return COMMAND_ERROR_MEMORY_LOW;
    
     for( i= 0 ; ((unsigned)i) < numfields ; i++ ) {
        cur_column_name = sqlite3_column_name(stmt,i);
        cur_column_text = sqlite3_column_text(stmt,i);
        ARRAYVALUE(*Lval,2*i) = besNEWSTRING(strlen(cur_column_name));
        if( ARRAYVALUE(*Lval,2*i) == NULL )return COMMAND_ERROR_MEMORY_LOW;
        memcpy(STRINGVALUE(ARRAYVALUE(*Lval,2*i)),cur_column_name, strlen(cur_column_name));
        
        ARRAYVALUE(*Lval,2*i+1) = besNEWSTRING(strlen(cur_column_text));
        if( ARRAYVALUE(*Lval,2*i+1) == NULL )return COMMAND_ERROR_MEMORY_LOW;
        memcpy(STRINGVALUE(ARRAYVALUE(*Lval,2*i+1)),cur_column_text,strlen(cur_column_text));
     }
    
     besALLOC_RETURN_LONG;
     LONGVALUE(besRETURNVALUE) = -1;
besEND

/**
=section FETCHARRAY
=H Returns Array containing row contents
*/
besFUNCTION(sql3_fetcharray)
    VARIABLE Argument;
    unsigned long __refcount_;
    sqlite3_stmt *stmt;
    LEFTVALUE Lval;
    unsigned int numfields;
    int i;
    const char* cur_column_text;
    
     besARGUMENTS("p")
          &stmt
     besARGEND

     Argument = besARGUMENT(2);

     besLEFTVALUE(Argument,Lval);
     if( ! Lval )return 0x00081001;
    
     besRELEASE(*Lval);
     *Lval = NULL;

     numfields = sqlite3_column_count(stmt);
     if( numfields == 0 ){
        besRETURNVALUE = NULL;
        return COMMAND_ERROR_SUCCESS;
     }
    
     *Lval = besNEWARRAY(0,numfields-1);
     if( *Lval == NULL )return COMMAND_ERROR_MEMORY_LOW;
    
     for( i= 0 ; ((unsigned)i) < numfields ; i++ ) {
        cur_column_text = sqlite3_column_text(stmt,i);
        
        ARRAYVALUE(*Lval,i) = besNEWSTRING(strlen(cur_column_text));
        if( ARRAYVALUE(*Lval,i) == NULL )return COMMAND_ERROR_MEMORY_LOW;
        memcpy(STRINGVALUE(ARRAYVALUE(*Lval,i)),cur_column_text,strlen(cur_column_text));
     }
    
     besALLOC_RETURN_LONG;
     LONGVALUE(besRETURNVALUE) = -1;
besEND

START_FUNCTION_TABLE(SQLITE_SLFST)
// Ext. module
  EXPORT_MODULE_FUNCTION(versmodu)
  EXPORT_MODULE_FUNCTION(bootmodu)
  EXPORT_MODULE_FUNCTION(finimodu)

// MOUDLE FUNCTIONS
  EXPORT_MODULE_FUNCTION(sql3_open)
  EXPORT_MODULE_FUNCTION(sql3_close)
  EXPORT_MODULE_FUNCTION(sql3_execute)
  EXPORT_MODULE_FUNCTION(sql3_query)
  EXPORT_MODULE_FUNCTION(sql3_row)
  EXPORT_MODULE_FUNCTION(sql3_row_value)
  EXPORT_MODULE_FUNCTION(sql3_column_count)
  EXPORT_MODULE_FUNCTION(sql3_column_name)
  EXPORT_MODULE_FUNCTION(sql3_version)
  EXPORT_MODULE_FUNCTION(sql3_finalize)
  EXPORT_MODULE_FUNCTION(sql3_version)
  EXPORT_MODULE_FUNCTION(sql3_errorcode)
  EXPORT_MODULE_FUNCTION(sql3_errormsg)
  EXPORT_MODULE_FUNCTION(sql3_fetchhash)
  EXPORT_MODULE_FUNCTION(sql3_fetcharray)
END_FUNCTION_TABLE

I would like to thank Armando for all his contributions to the ScriptBasic open source project.

449
What's New / Re: ScriptBasic for Android
« on: June 17, 2012, 01:51:44 PM »
When I started looking for a Android tablet and settled on the Samsung Galaxy Tab 2 10.1, my next decision was broadband mobility. I could buy the unit from one of the carriers (AT&T, Verizon, ...) or save a lot of money and get the 4G compatible WIFI version. (from Costco) As long as I'm home and connect via WIFI to my Comcast router (21 MBits/sec) or at Starbucks via their AT&T 4G WIFI, I still had a leash. If I would have purchased one of the carrier units, I still had to sign up for their data plan @ $50 / month. (5 GB)  

The solution I went with is the AT&T Mobile Hotspot Elevate 4G ($119 for the modem, $50 /5 GB, 2 yr. contract, $35 activation & shipping)
 


Quote
Experience 4G LTE speeds on all your Wi-Fi enabled devices. AT&T Mobile Hotspot Elevate 4G connects up to five Wi-Fi enabled devices to the Internet with speeds up to 10x faster than 3G. With no software to install and an LCD screen to guide you, setup is fast and intuitive. Just turn on the device and connect your laptop (or another Wi-Fi enabled device) over Wi-Fi. AT&T Mobile Hotspot Elevate 4G helps you get the information you need quickly while away from your home or office, even when traveling abroad.

450
What's New / Re: ScriptBasic for Android
« on: June 16, 2012, 10:30:45 PM »
I got tired of sharing the screen with the keyboard when at my desk so I got a Logitech® Bluetooth® keyboard and the case acts as a stand.



Quote from: product feedback comment
Just bought the keyboard at a frys after looking at the Samsung Galaxy Tab 10.1 keyboard dock (which is pretty ugly and from that the reviews say does not even work all the time). So far this baby is one of the best keyboards I've used and makes typing a pleasure on the my galaxy tab 10.1. I would recommend it to anyone planning on doing much typing on their tablet.

I was worried I was going to have to install a null virtual keyboard so it wouldn't pop up all the time. Android 4.x is smart enough to know you have an external KB attached and keeps the virtual one at bay unless you force it to be displayed by taping on the keyboard icon. Just like a PC, if I press a key while it is asleep the screen turns on like I pressed the power button. (Sweet !)

I created a new Android image for the emulator that matches my SGT2_10.1 screen size. I use a window scale .80 to allow the emulator to take the same screen real estate on my laptop as it does physically.

Laptop = 15" screen
Tablet = 10" screen

It's convent that the the tablet and my laptop both run at 1280 x 800 resolution. (tablet has better pixel density) Xfinity TV (Comcast On-Demand) runs great on the tablet and it's like having your TV in your hand. You can also use the tablet to view channel line-up and program your DVR. (both Android free apps)



Pages: 1 ... 28 29 [30] 31 32 ... 59