Hi all,

I'm trying to make an web application using Klone. I'm using the i2c protocol 
and it seems to work however i have some trouble with klone.

First thing, i've made an index.kl1 with some submit buttons and try to read it 
out in status.kl1 this workt but when i use some c code the file does not 
continue and i get an "Page can not be displayed" error while the command is 
correctly sent. below my code is shown it would most likely have some newbee 
ways of getting thinks to work but usealy i get thinks to work ;) i've red that 
placing response_redirect(response, "index.kl1") woulda work but  unfortunately 
no uni formal happiness on that part......


Another guestion, i've red on the klone webpage that everything between <%!%> 
is like placing your code you've usealy but above the main part like globals 
and functions however when i try to put the int I2C_Open(void) and void 
I2C_Close(void) i get error meassages??   

can somebody help me further.....??? 

<%!
    #include <foxio/foxio.h>
    #include "asm/etraxgpio.h"

    #include <foxio/i2c_errno.h>
    #include <foxio/etraxi2c.h>

I2C_DATA i2cdata_Output01;                                      

int fd_i2c;
                                        
%>
<%      
int I2C_Open(void) 
{
            int RetVal = 0;
            
            fd_i2c = open( "/dev/i2c", O_RDWR );
            
            if ( fd_i2c <= 0 ) 
            {
                printf( "I2C: open error on /dev/i2c\n" );
                RetVal = -1;
            }

            return( RetVal );
}

void I2C_Close(void) 
        {
            close( fd_i2c );
        }

int retcode;
        int i[7];
        int k;
retcode = I2C_Open();

if ( 0 != retcode ) 
    {
        exit( 1 );
    }

        i2cdata_Output01.slave     = 0x42;
        i2cdata_Output01.wlen      = 2;
        i2cdata_Output01.wbuf[ 0 ] = 0xff;
        i2cdata_Output01.wbuf[ 1 ] = 0xff;
        i2cdata_Output01.rlen      = 2;

vars_t *args = request_get_args(request);


if(vars_get_value(args, "1_on_off"))
{

        if ( EI2CNOERRORS != ioctl( fd_i2c, _IO( ETRAXI2C_IOCTYPE, I2C_READ ), 
&i2cdata_Output01 ) )
                    {
                         I2C_Close();
                         return;
                    }
                        k = i2cdata_Output01.rbuf[ 0 ]; 
                        if( k/128 > 0){i[0]=0;k=k-128;}else{i[0]=1;}
                        if( k/64 > 0){i[1]=0;k=k-64;}else{i[1]=1;}              
        
                        if( k/32 > 0){i[2]=0;k=k-32;}else{i[2]=1;}              
        
                        if( k/16 > 0){i[3]=0;k=k-16;}else{i[3]=1;}
                        if( k/8 > 0){i[4]=0;k=k-8;}else{i[4]=1;}
                        if( k/4 > 0){i[5]=0;k=k-4;}else{i[5]=1;}
                        if( k/2 > 0){i[6]=0;k=k-2;}else{i[6]=1;}
                        if( k/1 > 0){i[7]=0;k=k-1;}else{i[7]=1;}
        
                        if(i[7] == 0)
                                { 
                                        i2cdata_Output01.wbuf[ 0 ]  = 
i2cdata_Output01.rbuf[ 0 ]-0x01;
                                        i2cdata_Output01.wbuf[ 1 ]  = 
i2cdata_Output01.rbuf[ 1 ];
                                        if ( EI2CNOERRORS != ioctl( fd_i2c, 
_IO( ETRAXI2C_IOCTYPE, I2C_WRITE ), &i2cdata_Output01 ) )
                                                {
                                                        I2C_Close();
                                                        io_printf(out, 
"ERROR");                                                                       
                                                 
                                                        return;
                                        }       
                                }       
                        else
                        { 
                                        i2cdata_Output01.wbuf[ 0 ]  = 
i2cdata_Output01.rbuf[ 0 ]+0x01;
                                        i2cdata_Output01.wbuf[ 1 ]  = 
i2cdata_Output01.rbuf[ 1 ];
                                        if ( EI2CNOERRORS != ioctl( fd_i2c, 
_IO( ETRAXI2C_IOCTYPE, I2C_WRITE ), &i2cdata_Output01 ) )
                                                {
                                                        I2C_Close();
                                                        io_printf(out, 
"ERROR");                                                                       
                                                 
                                                        return;
                                        }       
                        }
response_redirect(response, "index.kl1");                               
} 

Reply via email to