FB Rpi & ADS1115 [SOLVED}

For issues with communication ports, protocols, etc.
Post Reply
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

FB Rpi & ADS1115 [SOLVED}

Post by Dinosaur »

Hi All

Have gone around in circles for the last week trying to settle on a method to use I2C in FreeBasic.
Running Raspbian on a RaspberryPi Zero W2.
The project is to monitor Lithium Cells on my 200AH camping battery.
The ADS1115 has 4 single ended a2d inputs with 16 bit resolution, so ideal for the job.

It seems the whole Rpi world revolves around python with CircuitPython now complicating things.
Have no intention of getting involved with Python.

So, my only option is to use the C/C++ libraries that are out there.
Easier said then done.
You translate one file and include it in your code and all of a sudden you have another 10 dependencies
which you have to translate. With little C knowledge, if fbfrog doesn't translate it completely, then I am stuck.
fbrog works great on less complex .h files but a good example of a failure is the code below.
I2CDev.h

Code: Select all

#ifndef _I2CDEV_H_
#define _I2CDEV_H_
#define __PROG_TYPES_COMPAT__
#ifndef I2CDEV_IMPLEMENTATION
#define I2CDEV_IMPLEMENTATION       I2CDEV_ARDUINO_WIRE
#endif // I2CDEV_IMPLEMENTATION
#define I2CDEV_IMPLEMENTATION_WARNINGS
#define I2CDEV_ARDUINO_WIRE         1 // Wire object from Arduino
#define I2CDEV_BUILTIN_NBWIRE       2 // Tweaked Wire object from Gene Knight's NBWire project
                                     // ^^^ NBWire implementation is still buggy w/some interrupts!
#define I2CDEV_BUILTIN_FASTWIRE     3 // FastWire object from Francesco Ferrara's project
#define I2CDEV_I2CMASTER_LIBRARY    4 // I2C object from DSSCircuits I2C-Master Library at https://github.com/DSSCircuits/I2C-Master-Library
#define I2CDEV_BUILTIN_SBWIRE	    5 // I2C object from Shuning (Steve) Bian's SBWire Library at https://github.com/freespace/SBWire 
#define I2CDEV_TEENSY_3X_WIRE       6 // Teensy 3.x support using i2c_t3 library
#ifdef ARDUINO
    #if ARDUINO < 100
        #include "WProgram.h"
    #else
        #include "Arduino.h"
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        #include <Wire.h>
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_TEENSY_3X_WIRE
        #include <i2c_t3.h>
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_I2CMASTER_LIBRARY
        #include <I2C.h>
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_SBWIRE
        #include "SBWire.h"
    #endif
#endif

#ifdef SPARK
    #include "application.h"
    #define ARDUINO 101
    #define BUFFER_LENGTH 32
#endif

#ifndef I2CDEVLIB_WIRE_BUFFER_LENGTH
    #if defined(I2C_BUFFER_LENGTH)
        // Arduino ESP32 core Wire uses this
        #define I2CDEVLIB_WIRE_BUFFER_LENGTH I2C_BUFFER_LENGTH
    #elif defined(BUFFER_LENGTH)
        // Arduino AVR core Wire and many others use this
        #define I2CDEVLIB_WIRE_BUFFER_LENGTH BUFFER_LENGTH
    #elif defined(SERIAL_BUFFER_SIZE)
        // Arduino SAMD core Wire uses this
        #define I2CDEVLIB_WIRE_BUFFER_LENGTH SERIAL_BUFFER_SIZE
    #else
        // should be a safe fallback, though possibly inefficient
        #define I2CDEVLIB_WIRE_BUFFER_LENGTH 32
    #endif
#endif

// 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];")
#define I2CDEV_DEFAULT_READ_TIMEOUT     1000

class I2Cdev {
    public:
        I2Cdev();

        static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
        static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
        static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
        static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
        static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
        static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
        static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
        static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);

        static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data, void *wireObj=0);
        static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data, void *wireObj=0);
        static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data, void *wireObj=0);
        static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data, void *wireObj=0);
        static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data, void *wireObj=0);
        static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data, void *wireObj=0);
        static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, void *wireObj=0);
        static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, void *wireObj=0);

        static uint16_t readTimeout;
};

#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
    //////////////////////
    // FastWire 0.24
    // This is a library to help faster programs to read I2C devices.
    // Copyright(C) 2012
    // Francesco Ferrara
    //////////////////////

    /* Master */
    #define TW_START                0x08
    #define TW_REP_START            0x10

    /* Master Transmitter */
    #define TW_MT_SLA_ACK           0x18
    #define TW_MT_SLA_NACK          0x20
    #define TW_MT_DATA_ACK          0x28
    #define TW_MT_DATA_NACK         0x30
    #define TW_MT_ARB_LOST          0x38

    /* Master Receiver */
    #define TW_MR_ARB_LOST          0x38
    #define TW_MR_SLA_ACK           0x40
    #define TW_MR_SLA_NACK          0x48
    #define TW_MR_DATA_ACK          0x50
    #define TW_MR_DATA_NACK         0x58

    #define TW_OK                   0
    #define TW_ERROR                1

    class Fastwire {
        private:
            static boolean waitInt();

        public:
            static void setup(int khz, boolean pullup);
            static byte beginTransmission(byte device);
            static byte write(byte value);
            static byte writeBuf(byte device, byte address, byte *data, byte num);
            static byte readBuf(byte device, byte address, byte *data, byte num);
            static void reset();
            static byte stop();
    };
#endif

#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
    // NBWire implementation based heavily on code by Gene Knight <Gene@Telobot.com>
    // Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html
    // Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html

    #define NBWIRE_BUFFER_LENGTH 32

    class TwoWire {
        private:
            static uint8_t rxBuffer[];
            static uint8_t rxBufferIndex;
            static uint8_t rxBufferLength;

            static uint8_t txAddress;
            static uint8_t txBuffer[];
            static uint8_t txBufferIndex;
            static uint8_t txBufferLength;

            // static uint8_t transmitting;
            static void (*user_onRequest)(void);
            static void (*user_onReceive)(int);
            static void onRequestService(void);
            static void onReceiveService(uint8_t*, int);

        public:
            TwoWire();
            void begin();
            void begin(uint8_t);
            void begin(int);
            void beginTransmission(uint8_t);
            //void beginTransmission(int);
            uint8_t endTransmission(uint16_t timeout=0);
            void nbendTransmission(void (*function)(int)) ;
            uint8_t requestFrom(uint8_t, int, uint16_t timeout=0);
            //uint8_t requestFrom(int, int);
            void nbrequestFrom(uint8_t, int, void (*function)(int));
            void send(uint8_t);
            void send(uint8_t*, uint8_t);
            //void send(int);
            void send(char*);
            uint8_t available(void);
            uint8_t receive(void);
            void onReceive(void (*)(int));
            void onRequest(void (*)(void));
    };

    #define TWI_READY   0
    #define TWI_MRX     1
    #define TWI_MTX     2
    #define TWI_SRX     3
    #define TWI_STX     4

    #define TW_WRITE    0
    #define TW_READ     1

    #define TW_MT_SLA_NACK      0x20
    #define TW_MT_DATA_NACK     0x30

    #define CPU_FREQ            16000000L
    #define TWI_FREQ            100000L
    #define TWI_BUFFER_LENGTH   32

    /* TWI Status is in TWSR, in the top 5 bits: TWS7 - TWS3 */

    #define TW_STATUS_MASK              ((1 << TWS7)|(1 << TWS6)|(1 << TWS5)|(1 << TWS4)|(1 << TWS3))
    #define TW_STATUS                   (TWSR & TW_STATUS_MASK)
    #define TW_START                    0x08
    #define TW_REP_START                0x10
    #define TW_MT_SLA_ACK               0x18
    #define TW_MT_SLA_NACK              0x20
    #define TW_MT_DATA_ACK              0x28
    #define TW_MT_DATA_NACK             0x30
    #define TW_MT_ARB_LOST              0x38
    #define TW_MR_ARB_LOST              0x38
    #define TW_MR_SLA_ACK               0x40
    #define TW_MR_SLA_NACK              0x48
    #define TW_MR_DATA_ACK              0x50
    #define TW_MR_DATA_NACK             0x58
    #define TW_ST_SLA_ACK               0xA8
    #define TW_ST_ARB_LOST_SLA_ACK      0xB0
    #define TW_ST_DATA_ACK              0xB8
    #define TW_ST_DATA_NACK             0xC0
    #define TW_ST_LAST_DATA             0xC8
    #define TW_SR_SLA_ACK               0x60
    #define TW_SR_ARB_LOST_SLA_ACK      0x68
    #define TW_SR_GCALL_ACK             0x70
    #define TW_SR_ARB_LOST_GCALL_ACK    0x78
    #define TW_SR_DATA_ACK              0x80
    #define TW_SR_DATA_NACK             0x88
    #define TW_SR_GCALL_DATA_ACK        0x90
    #define TW_SR_GCALL_DATA_NACK       0x98
    #define TW_SR_STOP                  0xA0
    #define TW_NO_INFO                  0xF8
    #define TW_BUS_ERROR                0x00

    //#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
    //#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))

    #ifndef sbi // set bit
        #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= (1 << bit))
    #endif // sbi

    #ifndef cbi // clear bit
        #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~(1 << bit))
    #endif // cbi

    extern TwoWire Wire;

#endif // I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE

#endif /* _I2CDEV_H_ */
This results in a .bi file that is incomplete.

Code: Select all

#pragma once

#define _I2CDEV_H_
#define __PROG_TYPES_COMPAT__
#define I2CDEV_IMPLEMENTATION_WARNINGS
const I2CDEV_ARDUINO_WIRE = 1
const I2CDEV_IMPLEMENTATION = I2CDEV_ARDUINO_WIRE
const I2CDEV_BUILTIN_NBWIRE = 2
const I2CDEV_BUILTIN_FASTWIRE = 3
const I2CDEV_I2CMASTER_LIBRARY = 4
const I2CDEV_BUILTIN_SBWIRE = 5
const I2CDEV_TEENSY_3X_WIRE = 6
const I2CDEVLIB_WIRE_BUFFER_LENGTH = 32
const I2CDEV_DEFAULT_READ_TIMEOUT = 1000
'' TODO: class I2Cdev { public: I2Cdev(); static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0); static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data, void *wireObj=0); static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data, void *wireObj=0); static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data, void *wireObj=0); static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data, void *wireObj=0); static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data, void *wireObj=0); static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data, void *wireObj=0); static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, void *wireObj=0); static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, void *wireObj=0); static uint16_t readTimeout;};
The only library that I could complete the installation on was "wiringPi" with it's companion "wiringPiI2C".
However they are marked as being deprecated, so as I will probably do more with I2C , not a good choice.
Using I2C-Tools in the Linux terminal helps with a quick check but messy to write a program around.

Now what would be nice if I could just put "#include I2CDev.h" in my Freebasic code.

Finally to my question:
Has anyone done any work on I2C using FreeBasic ? or does anyone have a suggestions for alternate methods ?

Regards
Last edited by Dinosaur on Mar 06, 2023 9:29, edited 2 times in total.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: I2C to ADS1115

Post by srvaldez »

hello Dinosaur :)
the only thing that I can think of is making a C wrapper of the library, the following todo
'' TODO: class I2Cdev { public: ...
my guess would look like

Code: Select all

type I2Cdev
    public:
        sub I2Cdev()
        static function readBit(byval devAddr as ubyte, byval regAddr as ubyte, byval bitNum as ubyte, byval data as ubyte ptr, byval timeout as ushort=I2Cdev.readTimeout, byval wireObj as any ptr=0) as byte
        ...
        ...
        static readTimeout as ushort
end type
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: I2C to ADS1115

Post by Dinosaur »

Hi All

srvaldez thanks for the reply.
Converting the .h files manually is just beyond me.
I have managed to get the system running through a different thread, but still using wiringpiI2C library.
Simply have not been able to install any alternatives.
Got pigpio installed, but it failed to open the I2C .

In case someone is searching for "I2C to ADS1115" the following is a link to the other thread.
viewtopic.php?p=296992#p296992

Regards
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: I2C to ADS1115

Post by speedfixer »

try pigpio. I was a lot happier with it even before WiringPi was deprecated.

http://abyz.me.uk/rpi/pigpio/

I don't even remember what issues I had with it - it was that easy.
If you bump into a problem, ask. Its been awhile but I should be able to help you.

The 'default' included libs in Pi (and Linux) and corresponding documentation were just simply too confusing and too inconsistent. I was not even clear what libs were 'standard' and actually being used.

david
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: I2C to ADS1115

Post by Dinosaur »

Hi All

speedfixer many thanks for the offer.

I can't even get past the starting block with pigpio.
Running it from within Geany or sudo.

Code: Select all

#include once "pigpio.bi"
#inclib "pigpio"
Dim as long fd, fd2,msb,lsb,cfg,handle,i2creg,version
    ''---------------------------------------------
    version = gpioInitialise()
    Print "gpioInitialse response ";version
    handle = i2copen(1,&h48,0)
    print "i2copen response ";handle
    If handle <= 0 Then
        Print "Error with ic2 Opening "
        gpioTerminate()
        End
    EndIf
    ''---------------------------------------------
    i2cReg = 0
    fd2 = i2cReadWordData(handle,i2cReg)
    Print fd2,Bin(fd2)
    ''---------------------------------------------
    sleep 2000
    fd2 = i2cclose(fd)
    Print "i2cclose response ";fd2
End
If running without sudo from Geany, I get
'2023-02-23 06:31:40 initCheckPermitted:
'+---------------------------------------------------------+
'|Sorry, you don't have permission to run this program. |
'|Try running as root, e.g. precede the command with sudo. |
'+---------------------------------------------------------+


'gpioInitialse response -1
'2023-02-23 06:31:40 i2cOpen: pigpio uninitialised, call gpioInitialise()
'i2copen response -31
'Error with ic2 Opening
If I run the file with sudo in Terminal, I get:
'gpioInitialse response 79
'i2copen response 0
'Error with ic2 Opening
If I do a Load with gpio
dinosaur@raspberrypi:~/Projects/RpiZero $ gpio -v load ic2
gpio version: 2.70
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
Type: Pi Zero2-W, Revision: 00, Memory: 512MB, Maker: Sony
* Device tree is enabled.
*--> Raspberry Pi Zero 2 W Rev 1.0
* This Raspberry Pi supports user-level GPIO access.
dinosaur@raspberrypi:~/Projects/RpiZero $
I get the same results.

I would be interested in seeing what your initialisation and startup code is.

Regards
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: I2C to ADS1115

Post by speedfixer »

pigpio is a very robust. complete, mature system. Not small.

I reviewed what I have, and see that a 'little' more might be needed.
I am composing an email to you describing what I have.
With a direct reply to me, I will send zips with my libraries, etc.
We can make it work on the side, then share later.

I have hinted at what I have before in these forums - no one seems interested.

My email won't be short: its just what I do. I try hard to be complete in any explanation. I used to teach hightech stuff and fix/explain epic failures in a big multinational company. Both my tech boys think I'm just long winded.

Later, if it works for you - and we can boil down the essence of what I have - whatever we end up with can be put here for reference - any totally permissive license is fine.

david
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: I2C to ADS1115

Post by Dinosaur »

Hi All

With the guidance of Speedfixer and others I have written a small test program that hopefully will be found by any
beginners on the Rpi and in particular using the pigpio library.

Code: Select all

''======================================================================
'' These are the minimal routines to measure voltages of 4 A2D inputs
'' on the TI ADS1115 using FreeBasic on a RasppberryPi Zero W2.
'' It reads 100 samples of each channel, removes the extremes 
'' and then averages the rest.
'' .bi files are .h conversions using fbfrog and manually finalised
'' by SpeedFixer at FB Forum. The lib has to be compiled on Target Rpi 
'' No error checking is included.
'' With a simple resistor divider, this module is stable within 1 mV.
''======================================================================
#include once "pigpio.bi"
#include once "piTypes.bi"
#inclib "pigpio"
Sub Initialise
    A2D.Config(1) = &HC342  ''0,100,001,0,110,000,11 No 1               start,AN1,4.096V,Cont scan,475 sps,comp,Alert/Rdy
    A2D.Config(2) = &HC352  ''  101 AN2
    A2D.Config(3) = &HC362  ''  110 AN3
    A2D.Config(4) = &HC372  ''  111 AN4
End sub
Sub OpenPort()
    With Voltage(1)                                                     ''use AN1 as starting point
        .Version = gpioInitialise()
        .Handle = i2copen(1,&h48,0)                                     ''Get File handle  (Bus,Addr,Flag)
        If .Handle < 0 Then                                             ''0 means a valid handle ?????
            Locate 8,1:Print "Error with ic2 Opening";
            gpioTerminate()
            End
        EndIf
        Voltage(2).Handle = Voltage(1).Handle                           ''copy Handle to other channels
        Voltage(3).Handle = Voltage(1).Handle                       
        Voltage(4).Handle = Voltage(1).Handle           
    End With
End Sub
Sub ClearAccum()
    Dim as Integer Xq = A2D.Cell
    For Xq = 1 to 100
        Voltage(A2D.Cell).Sample(Xq) = 0                                ''Clear Array of 100 values
    Next    
    With Voltage(A2D.Cell)
        .Hi = 0: .Lo = 30000: .HiCnt  = 0                               ''Clear other parameters
        .LoCnt  = 0: .AccCnt = 0: .Accum = 0 : .Cnt = 0                 '' .Lo replaced by first value lower than 30000
    End With
End Sub
Sub Write_Config()
    With Voltage(A2D.Cell)
        .Reply = I2CWriteWordData(.Handle,1,A2D.Config(A2D.Cell))       ''Write Config Reg (1) for this Cell
        sleep 6                                                         ''@ 4 this gets repeats (old data)
        .Reply = I2CReadWordData( .Handle,1)                            ''read back Config Reg (1)
        Locate 7,1:Print "Reply vs write ;";Hex(.Reply), Hex(A2D.Config(A2D.Cell)) ''compare to what was written
    End With
End Sub     
Sub ReadaCell()
    With Voltage(A2D.Cell)                                              ''Using Cell Nbr ?
        Do      
            sleep 6                                                     ''at 4 gives duplicates (reads previous value)
            .i2cReg = 0                                                 ''Data Reg (0) 
            .Reply = i2cReadWordData( .Handle, .i2cReg)                 ''Read data from this channel using Handle
            SWAP16( .Reply)                                             ''little Endian to BigEndian
            If .Reply > 0 Then                                          ''Value should not be Negative
                .Cnt += 1                                               ''Inc sample counter
                .Sample(.Cnt) += .Reply                                 ''add another sample
                If .Cnt >= 100 Then exit Do                             ''enough
            EndIf
        Loop
    End With
End Sub     
Sub Analyze()
    Dim Xq as Integer
    For Xq = 1 to 100
        With Voltage(A2D.Cell)
            If .Sample(Xq) > .Hi Then .Hi = .Sample(Xq)                 ''after 100 checks, this will have the highest reading
            If .Sample(Xq) < .Lo Then .Lo = .Sample(Xq)                 ''       ditto                          lowest     
        End With
    Next
    ''----Separate the Hi & Lo , then accumulate the rest----
    For Xq = 1 to 100
        With Voltage(A2D.Cell)
            Select case .Sample(Xq)                                     
                Case is = .Hi                                           ''if this sample is the same as the Hi sample
                    .HiCnt += 1                                         ''inc the Hi sample counter
                    .Hi = .Sample(Xq)                                   ''refresh the Hi sample with this sample
                Case is = .Lo                                           ''if this sample is the same as the Lo sample
                    .LoCnt += 1                                         ''inc the Lo sample counter
                    .Lo     = .Sample(Xq)                               ''refresh the Lo sample with this sample
                Case Else                                               ''otherwise it is a sample to be averaged
                    .AccCnt += 1
                    .Accum  += .Sample(Xq)
            End Select
            .Avg = .Accum / .AccCnt                                     ''get the Average value of 100 samples
        End With
    Next
End Sub
Sub Show_Results()
    With Voltage(A2D.Cell)
        .Avg = .Avg * .125                                              ''@4.096 FS , 0.125 is calibration value
        .Avg = .Avg / 1000                                              ''convert mV to Volts
        Locate 2,1 :Print "AN? Hi-Count: Hi-Value: Lo-Count: Lo-Value: Avg-Count: Avg-Value:";
        Locate 2 + A2D.Cell ,1 :Print A2D.Cell                          ''the cell we are working on
        Locate 2 + A2D.Cell ,5 :Print .HiCnt                            ''how many Hi samples
        Locate 2 + A2D.Cell ,15:Print .Hi                               ''actual Hi value
        Locate 2 + A2D.Cell ,27:Print .LoCnt                            ''how many Lo samples
        Locate 2 + A2D.Cell ,35:Print .Lo                               ''actual Lo value
        Locate 2 + A2D.Cell ,47:Print .AccCnt                           ''how many samples to average
        Locate 2 + A2D.Cell ,57:Print Using "#.###";.Avg                ''actual volts measured
    End With
End Sub

    Initialise                                                          
    OpenPort
    Cls
    Dim as Integer Xq
    For Xq = 1 to 4
        Times.StartTime  = (Timer - Times.CalTime) * 1000               ''StartTime  = mSec
        A2D.Cell = Xq                                                   ''Nominate the Cell we are operating on/
        ClearAccum                                                      ''Clear all accumulated valuies from last Read
        Write_Config                                                    ''
        ReadaCell                                                       ''Read this Cell 100 times & Accumulate values.
        Analyze                                                         ''Throw away extremes & average the rest.
        Show_Results                                                    ''Screen print (will be redundant in full package)                                              ''Close I2C on this Port
    Next
    Locate 9,1
    End
The pigpio.bi file

Code: Select all

 'pigpio.bi

 'pigpio main include - simple, not daemon version

 'derived from:

 '#include "/rdkl/FB_PI/gpio/pigpio.bi"
 
 ' SOURCE
 'https://github.com/joan2937/pigpio

'ORIGINAL LICENSE FROM AUTHOR:
'This is free and unencumbered software released into the public domain.

'Anyone is free to copy, modify, publish, use, compile, sell, or
'distribute this software, either in source code form or as a compiled
'binary, for any purpose, commercial or non-commercial, and by any
'means.

'In jurisdictions that recognize copyright laws, the author or authors
'of this software dedicate any and all copyright interest in the
'software to the public domain. We make this dedication for the benefit
'of the public at large and to the detriment of our heirs and
'successors. We intend this dedication to be an overt act of
'relinquishment in perpetuity of all present and future rights to this
'software under copyright law.

'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 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.

'For more information, please refer to <http://unlicense.org/>

'translated by speedfixer with help from dkl AND his excellent fbfrog program.
' Please visit the site referenced above. MUCH more excellent information
' is presented by the author on how this library can be used.

'shared with you by Dinosaur and speedfixer



#pragma once

#include once "crt/stddef.bi"
#include once "crt/stdint.bi"
#include once "pthread.bi"

extern "C"

#define PIGPIO_H
const PIGPIO_VERSION = 79
#define PI_INPFIFO "/dev/pigpio"
#define PI_OUTFIFO "/dev/pigout"
#define PI_ERRFIFO "/dev/pigerr"
#define PI_ENVPORT "PIGPIO_PORT"
#define PI_ENVADDR "PIGPIO_ADDR"
#define PI_LOCKFILE "/var/run/pigpio.pid"
#define PI_I2C_COMBINED "/sys/module/i2c_bcm2708/parameters/combined"

type gpioHeader_t
    func as ushort
    size as ushort
end type

type gpioExtent_t
    size as uinteger
    ptr as any ptr
    data as ulong
end type

type gpioSample_t
    tick as ulong
    level as ulong
end type

type gpioReport_t
    seqno as ushort
    flags as ushort
    tick as ulong
    level as ulong
end type

type gpioPulse_t
    gpioOn as ulong
    gpioOff as ulong
    usDelay as ulong
end type

const WAVE_FLAG_READ = 1
const WAVE_FLAG_TICK = 2

type rawWave_t
    gpioOn as ulong
    gpioOff as ulong
    usDelay as ulong
    flags as ulong
end type

type rawWaveInfo_t
    botCB as ushort
    topCB as ushort
    botOOL as ushort
    topOOL as ushort
    deleted as ushort
    numCB as ushort
    numBOOL as ushort
    numTOOL as ushort
end type

type rawSPI_t
    clk as long
    mosi as long
    miso as long
    ss_pol as long
    ss_us as long
    clk_pol as long
    clk_pha as long
    clk_us as long
end type

type rawCbs_t
    info as ulong
    src as ulong
    dst as ulong
    length as ulong
    stride as ulong
    next as ulong
    pad(0 to 1) as ulong
end type

type pi_i2c_msg_t
    addr as ushort
    flags as ushort
    len as ushort
    buf as ubyte ptr
end type

const BSC_FIFO_SIZE = 512

type bsc_xfer_t
    control as ulong
    rxCnt as long
    rxBuf as zstring * 512
    txCnt as long
    txBuf as zstring * 512
end type

type gpioAlertFunc_t as sub(byval gpio as long, byval level as long, byval tick as ulong)
type gpioAlertFuncEx_t as sub(byval gpio as long, byval level as long, byval tick as ulong, byval userdata as any ptr)
type eventFunc_t as sub(byval event as long, byval tick as ulong)
type eventFuncEx_t as sub(byval event as long, byval tick as ulong, byval userdata as any ptr)
type gpioISRFunc_t as sub(byval gpio as long, byval level as long, byval tick as ulong)
type gpioISRFuncEx_t as sub(byval gpio as long, byval level as long, byval tick as ulong, byval userdata as any ptr)
type gpioTimerFunc_t as sub()
type gpioTimerFuncEx_t as sub(byval userdata as any ptr)
type gpioSignalFunc_t as sub(byval signum as long)
type gpioSignalFuncEx_t as sub(byval signum as long, byval userdata as any ptr)
type gpioGetSamplesFunc_t as sub(byval samples as const gpioSample_t ptr, byval numSamples as long)
type gpioGetSamplesFuncEx_t as sub(byval samples as const gpioSample_t ptr, byval numSamples as long, byval userdata as any ptr)

const PI_MIN_GPIO = 0
const PI_MAX_GPIO = 53
const PI_MAX_USER_GPIO = 31
const PI_OFF = 0
const PI_ON = 1
const PI_CLEAR = 0
const PI_SET = 1
const PI_LOW = 0
const PI_HIGH = 1
const PI_TIMEOUT = 2
const PI_INPUT = 0
const PI_OUTPUT = 1
const PI_ALT0 = 4
const PI_ALT1 = 5
const PI_ALT2 = 6
const PI_ALT3 = 7
const PI_ALT4 = 3
const PI_ALT5 = 2
const PI_PWM = 11
const PI_TRELLIS = 12
const PI_HILO = 13
const PI_ARDUINO = 22   ' USB(serial) controller
const PI_PCA_9685 = 23  ' i2c controller
const PI_DHT11 = 24
const PI_OW = 25        ' onewire temp
const PI_RGB = 26        ' 3 pins on PI; pwm
const PI_PUD_OFF = 0
const PI_PUD_DOWN = 1
const PI_PUD_UP = 2
const PI_DEFAULT_DUTYCYCLE_RANGE = 255
const PI_MIN_DUTYCYCLE_RANGE = 25
const PI_MAX_DUTYCYCLE_RANGE = 40000
const PI_SERVO_OFF = 0
const PI_MIN_SERVO_PULSEWIDTH = 500
const PI_MAX_SERVO_PULSEWIDTH = 2500
const PI_HW_PWM_MIN_FREQ = 1
const PI_HW_PWM_MAX_FREQ = 125000000
const PI_HW_PWM_MAX_FREQ_2711 = 187500000
const PI_HW_PWM_RANGE = 1000000
const PI_HW_CLK_MIN_FREQ = 4689
const PI_HW_CLK_MIN_FREQ_2711 = 13184
const PI_HW_CLK_MAX_FREQ = 250000000
const PI_HW_CLK_MAX_FREQ_2711 = 375000000
const PI_NOTIFY_SLOTS = 32
const PI_NTFY_FLAGS_EVENT = 1 shl 7
const PI_NTFY_FLAGS_ALIVE = 1 shl 6
const PI_NTFY_FLAGS_WDOG = 1 shl 5
#define PI_NTFY_FLAGS_BIT(x) (((x) shl 0) and 31)
const PI_WAVE_BLOCKS = 4
const PI_WAVE_MAX_PULSES = PI_WAVE_BLOCKS * 3000
const PI_WAVE_MAX_CHARS = PI_WAVE_BLOCKS * 300
const PI_BB_I2C_MIN_BAUD = 50
const PI_BB_I2C_MAX_BAUD = 500000
const PI_BB_SPI_MIN_BAUD = 50
const PI_BB_SPI_MAX_BAUD = 250000
const PI_BB_SER_MIN_BAUD = 50
const PI_BB_SER_MAX_BAUD = 250000
const PI_BB_SER_NORMAL = 0
const PI_BB_SER_INVERT = 1
const PI_WAVE_MIN_BAUD = 50
const PI_WAVE_MAX_BAUD = 1000000
const PI_SPI_MIN_BAUD = 32000
const PI_SPI_MAX_BAUD = 125000000
const PI_MIN_WAVE_DATABITS = 1
const PI_MAX_WAVE_DATABITS = 32
const PI_MIN_WAVE_HALFSTOPBITS = 2
const PI_MAX_WAVE_HALFSTOPBITS = 8
const PI_WAVE_MAX_MICROS = (30 * 60) * 1000000
const PI_MAX_WAVES = 250
const PI_MAX_WAVE_CYCLES = 65535
const PI_MAX_WAVE_DELAY = 65535
const PI_WAVE_COUNT_PAGES = 10
const PI_WAVE_MODE_ONE_SHOT = 0
const PI_WAVE_MODE_REPEAT = 1
const PI_WAVE_MODE_ONE_SHOT_SYNC = 2
const PI_WAVE_MODE_REPEAT_SYNC = 3
const PI_WAVE_NOT_FOUND = 9998
const PI_NO_TX_WAVE = 9999
const PI_FILE_SLOTS = 16
const PI_I2C_SLOTS = 512
const PI_SPI_SLOTS = 32
const PI_SER_SLOTS = 16
const PI_MAX_I2C_ADDR = &h7F
const PI_NUM_AUX_SPI_CHANNEL = 3
const PI_NUM_STD_SPI_CHANNEL = 2
const PI_MAX_I2C_DEVICE_COUNT = 1 shl 16
const PI_MAX_SPI_DEVICE_COUNT = 1 shl 16
const PI_I2C_RDRW_IOCTL_MAX_MSGS = 42
const PI_I2C_M_WR = &h0000
const PI_I2C_M_RD = &h0001
const PI_I2C_M_TEN = &h0010
const PI_I2C_M_RECV_LEN = &h0400
const PI_I2C_M_NO_RD_ACK = &h0800
const PI_I2C_M_IGNORE_NAK = &h1000
const PI_I2C_M_REV_DIR_ADDR = &h2000
const PI_I2C_M_NOSTART = &h4000
const PI_I2C_END = 0
const PI_I2C_ESC = 1
const PI_I2C_START = 2
const PI_I2C_COMBINED_ON = 2
const PI_I2C_STOP = 3
const PI_I2C_COMBINED_OFF = 3
const PI_I2C_ADDR = 4
const PI_I2C_FLAGS = 5
const PI_I2C_READ = 6
const PI_I2C_WRITE = 7
#define PI_SPI_FLAGS_BITLEN(x) ((x and 63) shl 16)
#define PI_SPI_FLAGS_RX_LSB(x) ((x and 1) shl 15)
#define PI_SPI_FLAGS_TX_LSB(x) ((x and 1) shl 14)
#define PI_SPI_FLAGS_3WREN(x) ((x and 15) shl 10)
#define PI_SPI_FLAGS_3WIRE(x) ((x and 1) shl 9)
#define PI_SPI_FLAGS_AUX_SPI(x) ((x and 1) shl 8)
#define PI_SPI_FLAGS_RESVD(x) ((x and 7) shl 5)
#define PI_SPI_FLAGS_CSPOLS(x) ((x and 7) shl 2)
#define PI_SPI_FLAGS_MODE(x) (x and 3)
const BSC_DR = 0
const BSC_RSR = 1
const BSC_SLV = 2
const BSC_CR = 3
const BSC_FR = 4
const BSC_IFLS = 5
const BSC_IMSC = 6
const BSC_RIS = 7
const BSC_MIS = 8
const BSC_ICR = 9
const BSC_DMACR = 10
const BSC_TDR = 11
const BSC_GPUSTAT = 12
const BSC_HCTRL = 13
const BSC_DEBUG_I2C = 14
const BSC_DEBUG_SPI = 15
const BSC_CR_TESTFIFO = 2048
const BSC_CR_RXE = 512
const BSC_CR_TXE = 256
const BSC_CR_BRK = 128
const BSC_CR_CPOL = 16
const BSC_CR_CPHA = 8
const BSC_CR_I2C = 4
const BSC_CR_SPI = 2
const BSC_CR_EN = 1
const BSC_FR_RXBUSY = 32
const BSC_FR_TXFE = 16
const BSC_FR_RXFF = 8
const BSC_FR_TXFF = 4
const BSC_FR_RXFE = 2
const BSC_FR_TXBUSY = 1
const BSC_SDA = 18
const BSC_MOSI = 20
const BSC_SCL_SCLK = 19
const BSC_MISO = 18
const BSC_CE_N = 21
const BSC_SDA_2711 = 10
const BSC_MOSI_2711 = 9
const BSC_SCL_SCLK_2711 = 11
const BSC_MISO_2711 = 10
const BSC_CE_N_2711 = 8
const PI_MAX_BUSY_DELAY = 100
const PI_MIN_WDOG_TIMEOUT = 0
const PI_MAX_WDOG_TIMEOUT = 60000
const PI_MIN_TIMER = 0
const PI_MAX_TIMER = 9
const PI_MIN_MS = 10
const PI_MAX_MS = 60000
const PI_MAX_SCRIPTS = 32
const PI_MAX_SCRIPT_TAGS = 50
const PI_MAX_SCRIPT_VARS = 150
const PI_MAX_SCRIPT_PARAMS = 10
const PI_SCRIPT_INITING = 0
const PI_SCRIPT_HALTED = 1
const PI_SCRIPT_RUNNING = 2
const PI_SCRIPT_WAITING = 3
const PI_SCRIPT_FAILED = 4
const PI_MIN_SIGNUM = 0
const PI_MAX_SIGNUM = 63
const PI_TIME_RELATIVE = 0
const PI_TIME_ABSOLUTE = 1
const PI_MAX_MICS_DELAY = 1000000
const PI_MAX_MILS_DELAY = 60000
const PI_BUF_MILLIS_MIN = 100
const PI_BUF_MILLIS_MAX = 10000
const PI_CLOCK_PWM = 0
const PI_CLOCK_PCM = 1
const PI_MIN_DMA_CHANNEL = 0
const PI_MAX_DMA_CHANNEL = 15
const PI_MIN_SOCKET_PORT = 1024
const PI_MAX_SOCKET_PORT = 32000
const PI_DISABLE_FIFO_IF = 1
const PI_DISABLE_SOCK_IF = 2
const PI_LOCALHOST_SOCK_IF = 4
const PI_DISABLE_ALERT = 8
const PI_MEM_ALLOC_AUTO = 0
const PI_MEM_ALLOC_PAGEMAP = 1
const PI_MEM_ALLOC_MAILBOX = 2
const PI_MAX_STEADY = 300000
const PI_MAX_ACTIVE = 1000000
const PI_CFG_DBG_LEVEL = 0
const PI_CFG_ALERT_FREQ = 4
const PI_CFG_RT_PRIORITY = 1 shl 8
const PI_CFG_STATS = 1 shl 9
const PI_CFG_NOSIGHANDLER = 1 shl 10
const PI_CFG_ILLEGAL_VAL = 1 shl 11
const RISING_EDGE = 0
const FALLING_EDGE = 1
const EITHER_EDGE = 2
const PI_MAX_PAD = 2
const PI_MIN_PAD_STRENGTH = 1
const PI_MAX_PAD_STRENGTH = 16
const PI_FILE_NONE = 0
const PI_FILE_MIN = 1
const PI_FILE_READ = 1
const PI_FILE_WRITE = 2
const PI_FILE_RW = 3
const PI_FILE_APPEND = 4
const PI_FILE_CREATE = 8
const PI_FILE_TRUNC = 16
const PI_FILE_MAX = 31
const PI_FROM_START = 0
const PI_FROM_CURRENT = 1
const PI_FROM_END = 2
const MAX_CONNECT_ADDRESSES = 256
const PI_MAX_EVENT = 31
const PI_EVENT_BSC = 31

declare function gpioInitialise() as long
declare sub gpioTerminate()
declare function gpioSetMode(byval gpio as ulong, byval mode as ulong) as long
declare function gpioGetMode(byval gpio as ulong) as long
declare function gpioSetPullUpDown(byval gpio as ulong, byval pud as ulong) as long
declare function gpioRead(byval gpio as ulong) as long
declare function gpioWrite(byval gpio as ulong, byval level as ulong) as long
declare function gpioPWM(byval user_gpio as ulong, byval dutycycle as ulong) as long
declare function gpioGetPWMdutycycle(byval user_gpio as ulong) as long
declare function gpioSetPWMrange(byval user_gpio as ulong, byval range as ulong) as long
declare function gpioGetPWMrange(byval user_gpio as ulong) as long
declare function gpioGetPWMrealRange(byval user_gpio as ulong) as long
declare function gpioSetPWMfrequency(byval user_gpio as ulong, byval frequency as ulong) as long
declare function gpioGetPWMfrequency(byval user_gpio as ulong) as long
declare function gpioServo(byval user_gpio as ulong, byval pulsewidth as ulong) as long
declare function gpioGetServoPulsewidth(byval user_gpio as ulong) as long
declare function gpioSetAlertFunc(byval user_gpio as ulong, byval f as gpioAlertFunc_t) as long
declare function gpioSetAlertFuncEx(byval user_gpio as ulong, byval f as gpioAlertFuncEx_t, byval userdata as any ptr) as long
declare function gpioSetISRFunc(byval gpio as ulong, byval edge as ulong, byval timeout as long, byval f as gpioISRFunc_t) as long
declare function gpioSetISRFuncEx(byval gpio as ulong, byval edge as ulong, byval timeout as long, byval f as gpioISRFuncEx_t, byval userdata as any ptr) as long
declare function gpioNotifyOpen() as long
declare function gpioNotifyOpenWithSize(byval bufSize as long) as long
declare function gpioNotifyBegin(byval handle as ulong, byval bits as ulong) as long
declare function gpioNotifyPause(byval handle as ulong) as long
declare function gpioNotifyClose(byval handle as ulong) as long
declare function gpioWaveClear() as long
declare function gpioWaveAddNew() as long
declare function gpioWaveAddGeneric(byval numPulses as ulong, byval pulses as gpioPulse_t ptr) as long
declare function gpioWaveAddSerial(byval user_gpio as ulong, byval baud as ulong, byval data_bits as ulong, byval stop_bits as ulong, byval offset as ulong, byval numBytes as ulong, byval str as zstring ptr) as long
declare function gpioWaveCreate() as long
declare function gpioWaveCreatePad(byval pctCB as long, byval pctBOOL as long, byval pctTOOL as long) as long
declare function gpioWaveDelete(byval wave_id as ulong) as long
declare function gpioWaveTxSend(byval wave_id as ulong, byval wave_mode as ulong) as long
declare function gpioWaveChain(byval buf as zstring ptr, byval bufSize as ulong) as long
declare function gpioWaveTxAt() as long
declare function gpioWaveTxBusy() as long
declare function gpioWaveTxStop() as long
declare function gpioWaveGetMicros() as long
declare function gpioWaveGetHighMicros() as long
declare function gpioWaveGetMaxMicros() as long
declare function gpioWaveGetPulses() as long
declare function gpioWaveGetHighPulses() as long
declare function gpioWaveGetMaxPulses() as long
declare function gpioWaveGetCbs() as long
declare function gpioWaveGetHighCbs() as long
declare function gpioWaveGetMaxCbs() as long
declare function gpioSerialReadOpen(byval user_gpio as ulong, byval baud as ulong, byval data_bits as ulong) as long
declare function gpioSerialReadInvert(byval user_gpio as ulong, byval invert as ulong) as long
declare function gpioSerialRead(byval user_gpio as ulong, byval buf as any ptr, byval bufSize as uinteger) as long
declare function gpioSerialReadClose(byval user_gpio as ulong) as long

declare function i2cOpen(byval i2cBus as ulong, byval i2cAddr as ulong, byval i2cFlags as ulong) as long
declare function i2cClose(byval handle as ulong) as long
declare function i2cWriteQuick(byval handle as ulong, byval bit as ulong) as long
declare function i2cWriteByte(byval handle as ulong, byval bVal as ulong) as long
declare function i2cReadByte(byval handle as ulong) as long
declare function i2cWriteByteData(byval handle as ulong, byval i2cReg as ulong, byval bVal as ulong) as long
declare function i2cWriteWordData(byval handle as ulong, byval i2cReg as ulong, byval wVal as ulong) as long
declare function i2cReadByteData(byval handle as ulong, byval i2cReg as ulong) as long
declare function i2cReadWordData(byval handle as ulong, byval i2cReg as ulong) as long
declare function i2cProcessCall(byval handle as ulong, byval i2cReg as ulong, byval wVal as ulong) as long
declare function i2cWriteBlockData(byval handle as ulong, byval i2cReg as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function i2cReadBlockData(byval handle as ulong, byval i2cReg as ulong, byval buf as zstring ptr) as long
declare function i2cBlockProcessCall(byval handle as ulong, byval i2cReg as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function i2cReadI2CBlockData(byval handle as ulong, byval i2cReg as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function i2cWriteI2CBlockData(byval handle as ulong, byval i2cReg as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function i2cReadDevice(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function i2cWriteDevice(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare sub i2cSwitchCombined(byval setting as long)
declare function i2cSegments(byval handle as ulong, byval segs as pi_i2c_msg_t ptr, byval numSegs as ulong) as long
declare function i2cZip(byval handle as ulong, byval inBuf as zstring ptr, byval inLen as ulong, byval outBuf as zstring ptr, byval outLen as ulong) as long
declare function bbI2COpen(byval SDA as ulong, byval SCL as ulong, byval baud as ulong) as long
declare function bbI2CClose(byval SDA as ulong) as long
declare function bbI2CZip(byval SDA as ulong, byval inBuf as zstring ptr, byval inLen as ulong, byval outBuf as zstring ptr, byval outLen as ulong) as long

declare function bscXfer(byval bsc_xfer as bsc_xfer_t ptr) as long
declare function bbSPIOpen(byval CS as ulong, byval MISO as ulong, byval MOSI as ulong, byval SCLK as ulong, byval baud as ulong, byval spiFlags as ulong) as long
declare function bbSPIClose(byval CS as ulong) as long
declare function bbSPIXfer(byval CS as ulong, byval inBuf as zstring ptr, byval outBuf as zstring ptr, byval count as ulong) as long
declare function spiOpen(byval spiChan as ulong, byval baud as ulong, byval spiFlags as ulong) as long
declare function spiClose(byval handle as ulong) as long
declare function spiRead(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function spiWrite(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function spiXfer(byval handle as ulong, byval txBuf as zstring ptr, byval rxBuf as zstring ptr, byval count as ulong) as long
declare function serOpen(byval sertty as zstring ptr, byval baud as ulong, byval serFlags as ulong) as long
declare function serClose(byval handle as ulong) as long
declare function serWriteByte(byval handle as ulong, byval bVal as ulong) as long
declare function serReadByte(byval handle as ulong) as long
declare function serWrite(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function serRead(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function serDataAvailable(byval handle as ulong) as long
declare function gpioTrigger(byval user_gpio as ulong, byval pulseLen as ulong, byval level as ulong) as long
declare function gpioSetWatchdog(byval user_gpio as ulong, byval timeout as ulong) as long
declare function gpioNoiseFilter(byval user_gpio as ulong, byval steady as ulong, byval active as ulong) as long
declare function gpioGlitchFilter(byval user_gpio as ulong, byval steady as ulong) as long
declare function gpioSetGetSamplesFunc(byval f as gpioGetSamplesFunc_t, byval bits as ulong) as long
declare function gpioSetGetSamplesFuncEx(byval f as gpioGetSamplesFuncEx_t, byval bits as ulong, byval userdata as any ptr) as long
declare function gpioSetTimerFunc(byval timer as ulong, byval millis as ulong, byval f as gpioTimerFunc_t) as long
declare function gpioSetTimerFuncEx(byval timer as ulong, byval millis as ulong, byval f as gpioTimerFuncEx_t, byval userdata as any ptr) as long
declare function gpioStartThread(byval f as function(byval as any ptr) as any ptr, byval userdata as any ptr) as pthread_t ptr
declare sub gpioStopThread(byval pth as pthread_t ptr)
declare function gpioStoreScript(byval script as zstring ptr) as long
declare function gpioRunScript(byval script_id as ulong, byval numPar as ulong, byval param as ulong ptr) as long
declare function gpioUpdateScript(byval script_id as ulong, byval numPar as ulong, byval param as ulong ptr) as long
declare function gpioScriptStatus(byval script_id as ulong, byval param as ulong ptr) as long
declare function gpioStopScript(byval script_id as ulong) as long
declare function gpioDeleteScript(byval script_id as ulong) as long
declare function gpioSetSignalFunc(byval signum as ulong, byval f as gpioSignalFunc_t) as long
declare function gpioSetSignalFuncEx(byval signum as ulong, byval f as gpioSignalFuncEx_t, byval userdata as any ptr) as long
declare function gpioRead_Bits_0_31() as ulong
declare function gpioRead_Bits_32_53() as ulong
declare function gpioWrite_Bits_0_31_Clear(byval bits as ulong) as long
declare function gpioWrite_Bits_32_53_Clear(byval bits as ulong) as long
declare function gpioWrite_Bits_0_31_Set(byval bits as ulong) as long
declare function gpioWrite_Bits_32_53_Set(byval bits as ulong) as long
declare function gpioHardwareClock(byval gpio as ulong, byval clkfreq as ulong) as long
declare function gpioHardwarePWM(byval gpio as ulong, byval PWMfreq as ulong, byval PWMduty as ulong) as long
declare function gpioTime(byval timetype as ulong, byval seconds as long ptr, byval micros as long ptr) as long
declare function gpioSleep(byval timetype as ulong, byval seconds as long, byval micros as long) as long
declare function gpioDelay(byval micros as ulong) as ulong
declare function gpioTick() as ulong
declare function gpioHardwareRevision() as ulong
declare function gpioVersion() as ulong
declare function gpioGetPad(byval pad as ulong) as long
declare function gpioSetPad(byval pad as ulong, byval padStrength as ulong) as long
declare function eventMonitor(byval handle as ulong, byval bits as ulong) as long
declare function eventSetFunc(byval event as ulong, byval f as eventFunc_t) as long
declare function eventSetFuncEx(byval event as ulong, byval f as eventFuncEx_t, byval userdata as any ptr) as long
declare function eventTrigger(byval event as ulong) as long
declare function pigshell alias "shell"(byval scriptName as zstring ptr, byval scriptString as zstring ptr) as long
declare function fileOpen(byval file as zstring ptr, byval mode as ulong) as long
declare function fileClose(byval handle as ulong) as long
declare function fileWrite(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function fileRead(byval handle as ulong, byval buf as zstring ptr, byval count as ulong) as long
declare function fileSeek(byval handle as ulong, byval seekOffset as long, byval seekFrom as long) as long
declare function fileList(byval fpat as zstring ptr, byval buf as zstring ptr, byval count as ulong) as long
declare function gpioCfgBufferSize(byval cfgMillis as ulong) as long
declare function gpioCfgClock(byval cfgMicros as ulong, byval cfgPeripheral as ulong, byval cfgSource as ulong) as long
declare function gpioCfgDMAchannel(byval DMAchannel as ulong) as long
declare function gpioCfgDMAchannels(byval primaryChannel as ulong, byval secondaryChannel as ulong) as long
declare function gpioCfgPermissions(byval updateMask as ulongint) as long
declare function gpioCfgSocketPort(byval port as ulong) as long
declare function gpioCfgInterfaces(byval ifFlags as ulong) as long
declare function gpioCfgMemAlloc(byval memAllocMode as ulong) as long
declare function gpioCfgNetAddr(byval numSockAddr as long, byval sockAddr as ulong ptr) as long
declare function gpioCfgInternals(byval cfgWhat as ulong, byval cfgVal as ulong) as long
declare function gpioCfgGetInternals() as ulong
declare function gpioCfgSetInternals(byval cfgVal as ulong) as long
declare function gpioCustom1(byval arg1 as ulong, byval arg2 as ulong, byval argx as zstring ptr, byval argc as ulong) as long
declare function gpioCustom2(byval arg1 as ulong, byval argx as zstring ptr, byval argc as ulong, byval retBuf as zstring ptr, byval retMax as ulong) as long
declare function rawWaveAddSPI(byval spi as rawSPI_t ptr, byval offset as ulong, byval spiSS as ulong, byval buf as zstring ptr, byval spiTxBits as ulong, byval spiBitFirst as ulong, byval spiBitLast as ulong, byval spiBits as ulong) as long
declare function rawWaveAddGeneric(byval numPulses as ulong, byval pulses as rawWave_t ptr) as long
declare function rawWaveCB() as ulong
declare function rawWaveCBAdr(byval cbNum as long) as rawCbs_t ptr
declare function rawWaveGetOOL(byval pos as long) as ulong
declare sub rawWaveSetOOL(byval pos as long, byval lVal as ulong)
declare function rawWaveGetOut(byval pos as long) as ulong
declare sub rawWaveSetOut(byval pos as long, byval lVal as ulong)
declare function rawWaveGetIn(byval pos as long) as ulong
declare sub rawWaveSetIn(byval pos as long, byval lVal as ulong)
declare function rawWaveInfo(byval wave_id as long) as rawWaveInfo_t
declare function getBitInBytes(byval bitPos as long, byval buf as zstring ptr, byval numBits as long) as long
declare sub putBitInBytes(byval bitPos as long, byval buf as zstring ptr, byval bit as long)
declare function time_time() as double
declare sub time_sleep(byval seconds as double)
declare sub rawDumpWave()
declare sub rawDumpScript(byval script_id as ulong)

const PI_CMD_MODES = 0
const PI_CMD_MODEG = 1
const PI_CMD_PUD = 2
const PI_CMD_READ = 3
const PI_CMD_WRITE = 4
const PI_CMD_PWM = 5
const PI_CMD_PRS = 6
const PI_CMD_PFS = 7
const PI_CMD_SERVO = 8
const PI_CMD_WDOG = 9
const PI_CMD_BR1 = 10
const PI_CMD_BR2 = 11
const PI_CMD_BC1 = 12
const PI_CMD_BC2 = 13
const PI_CMD_BS1 = 14
const PI_CMD_BS2 = 15
const PI_CMD_TICK = 16
const PI_CMD_HWVER = 17
const PI_CMD_NO = 18
const PI_CMD_NB = 19
const PI_CMD_NP = 20
const PI_CMD_NC = 21
const PI_CMD_PRG = 22
const PI_CMD_PFG = 23
const PI_CMD_PRRG = 24
const PI_CMD_HELP = 25
const PI_CMD_PIGPV = 26
const PI_CMD_WVCLR = 27
const PI_CMD_WVAG = 28
const PI_CMD_WVAS = 29
const PI_CMD_WVGO = 30
const PI_CMD_WVGOR = 31
const PI_CMD_WVBSY = 32
const PI_CMD_WVHLT = 33
const PI_CMD_WVSM = 34
const PI_CMD_WVSP = 35
const PI_CMD_WVSC = 36
const PI_CMD_TRIG = 37
const PI_CMD_PROC = 38
const PI_CMD_PROCD = 39
const PI_CMD_PROCR = 40
const PI_CMD_PROCS = 41
const PI_CMD_SLRO = 42
const PI_CMD_SLR = 43
const PI_CMD_SLRC = 44
const PI_CMD_PROCP = 45
const PI_CMD_MICS = 46
const PI_CMD_MILS = 47
const PI_CMD_PARSE = 48
const PI_CMD_WVCRE = 49
const PI_CMD_WVDEL = 50
const PI_CMD_WVTX = 51
const PI_CMD_WVTXR = 52
const PI_CMD_WVNEW = 53
const PI_CMD_I2CO = 54
const PI_CMD_I2CC = 55
const PI_CMD_I2CRD = 56
const PI_CMD_I2CWD = 57
const PI_CMD_I2CWQ = 58
const PI_CMD_I2CRS = 59
const PI_CMD_I2CWS = 60
const PI_CMD_I2CRB = 61
const PI_CMD_I2CWB = 62
const PI_CMD_I2CRW = 63
const PI_CMD_I2CWW = 64
const PI_CMD_I2CRK = 65
const PI_CMD_I2CWK = 66
const PI_CMD_I2CRI = 67
const PI_CMD_I2CWI = 68
const PI_CMD_I2CPC = 69
const PI_CMD_I2CPK = 70
const PI_CMD_SPIO = 71
const PI_CMD_SPIC = 72
const PI_CMD_SPIR = 73
const PI_CMD_SPIW = 74
const PI_CMD_SPIX = 75
const PI_CMD_SERO = 76
const PI_CMD_SERC = 77
const PI_CMD_SERRB = 78
const PI_CMD_SERWB = 79
const PI_CMD_SERR = 80
const PI_CMD_SERW = 81
const PI_CMD_SERDA = 82
const PI_CMD_GDC = 83
const PI_CMD_GPW = 84
const PI_CMD_HC = 85
const PI_CMD_HP = 86
const PI_CMD_CF1 = 87
const PI_CMD_CF2 = 88
const PI_CMD_BI2CC = 89
const PI_CMD_BI2CO = 90
const PI_CMD_BI2CZ = 91
const PI_CMD_I2CZ = 92
const PI_CMD_WVCHA = 93
const PI_CMD_SLRI = 94
const PI_CMD_CGI = 95
const PI_CMD_CSI = 96
const PI_CMD_FG = 97
const PI_CMD_FN = 98
const PI_CMD_NOIB = 99
const PI_CMD_WVTXM = 100
const PI_CMD_WVTAT = 101
const PI_CMD_PADS = 102
const PI_CMD_PADG = 103
const PI_CMD_FO = 104
const PI_CMD_FC = 105
const PI_CMD_FR = 106
const PI_CMD_FW = 107
const PI_CMD_FS = 108
const PI_CMD_FL = 109
const PI_CMD_SHELL = 110
const PI_CMD_BSPIC = 111
const PI_CMD_BSPIO = 112
const PI_CMD_BSPIX = 113
const PI_CMD_BSCX = 114
const PI_CMD_EVM = 115
const PI_CMD_EVT = 116
const PI_CMD_PROCU = 117
const PI_CMD_WVCAP = 118
const PI_CMD_SCRIPT = 800
const PI_CMD_ADD = 800
const PI_CMD_AND = 801
const PI_CMD_CALL = 802
const PI_CMD_CMDR = 803
const PI_CMD_CMDW = 804
const PI_CMD_CMP = 805
const PI_CMD_DCR = 806
const PI_CMD_DCRA = 807
const PI_CMD_DIV = 808
const PI_CMD_HALT = 809
const PI_CMD_INR = 810
const PI_CMD_INRA = 811
const PI_CMD_JM = 812
const PI_CMD_JMP = 813
const PI_CMD_JNZ = 814
const PI_CMD_JP = 815
const PI_CMD_JZ = 816
const PI_CMD_TAG = 817
const PI_CMD_LD = 818
const PI_CMD_LDA = 819
const PI_CMD_LDAB = 820
const PI_CMD_MLT = 821
const PI_CMD_MOD = 822
const PI_CMD_NOP = 823
const PI_CMD_OR = 824
const PI_CMD_POP = 825
const PI_CMD_POPA = 826
const PI_CMD_PUSH = 827
const PI_CMD_PUSHA = 828
const PI_CMD_RET = 829
const PI_CMD_RL = 830
const PI_CMD_RLA = 831
const PI_CMD_RR = 832
const PI_CMD_RRA = 833
const PI_CMD_STA = 834
const PI_CMD_STAB = 835
const PI_CMD_SUB = 836
const PI_CMD_SYS = 837
const PI_CMD_WAIT = 838
const PI_CMD_X = 839
const PI_CMD_XA = 840
const PI_CMD_XOR = 841
const PI_CMD_EVTWT = 842
const PI_INIT_FAILED = -1
const PI_BAD_USER_GPIO = -2
const PI_BAD_GPIO = -3
const PI_BAD_MODE = -4
const PI_BAD_LEVEL = -5
const PI_BAD_PUD = -6
const PI_BAD_PULSEWIDTH = -7
const PI_BAD_DUTYCYCLE = -8
const PI_BAD_TIMER = -9
const PI_BAD_MS = -10
const PI_BAD_TIMETYPE = -11
const PI_BAD_SECONDS = -12
const PI_BAD_MICROS = -13
const PI_TIMER_FAILED = -14
const PI_BAD_WDOG_TIMEOUT = -15
const PI_NO_ALERT_FUNC = -16
const PI_BAD_CLK_PERIPH = -17
const PI_BAD_CLK_SOURCE = -18
const PI_BAD_CLK_MICROS = -19
const PI_BAD_BUF_MILLIS = -20
const PI_BAD_DUTYRANGE = -21
const PI_BAD_DUTY_RANGE = -21
const PI_BAD_SIGNUM = -22
const PI_BAD_PATHNAME = -23
const PI_NO_HANDLE = -24
const PI_BAD_HANDLE = -25
const PI_BAD_IF_FLAGS = -26
const PI_BAD_CHANNEL = -27
const PI_BAD_PRIM_CHANNEL = -27
const PI_BAD_SOCKET_PORT = -28
const PI_BAD_FIFO_COMMAND = -29
const PI_BAD_SECO_CHANNEL = -30
const PI_NOT_INITIALISED = -31
const PI_INITIALISED = -32
const PI_BAD_WAVE_MODE = -33
const PI_BAD_CFG_INTERNAL = -34
const PI_BAD_WAVE_BAUD = -35
const PI_TOO_MANY_PULSES = -36
const PI_TOO_MANY_CHARS = -37
const PI_NOT_SERIAL_GPIO = -38
const PI_BAD_SERIAL_STRUC = -39
const PI_BAD_SERIAL_BUF = -40
const PI_NOT_PERMITTED = -41
const PI_SOME_PERMITTED = -42
const PI_BAD_WVSC_COMMND = -43
const PI_BAD_WVSM_COMMND = -44
const PI_BAD_WVSP_COMMND = -45
const PI_BAD_PULSELEN = -46
const PI_BAD_SCRIPT = -47
const PI_BAD_SCRIPT_ID = -48
const PI_BAD_SER_OFFSET = -49
const PI_GPIO_IN_USE = -50
const PI_BAD_SERIAL_COUNT = -51
const PI_BAD_PARAM_NUM = -52
const PI_DUP_TAG = -53
const PI_TOO_MANY_TAGS = -54
const PI_BAD_SCRIPT_CMD = -55
const PI_BAD_VAR_NUM = -56
const PI_NO_SCRIPT_ROOM = -57
const PI_NO_MEMORY = -58
const PI_SOCK_READ_FAILED = -59
const PI_SOCK_WRIT_FAILED = -60
const PI_TOO_MANY_PARAM = -61
const PI_NOT_HALTED = -62
const PI_SCRIPT_NOT_READY = -62
const PI_BAD_TAG = -63
const PI_BAD_MICS_DELAY = -64
const PI_BAD_MILS_DELAY = -65
const PI_BAD_WAVE_ID = -66
const PI_TOO_MANY_CBS = -67
const PI_TOO_MANY_OOL = -68
const PI_EMPTY_WAVEFORM = -69
const PI_NO_WAVEFORM_ID = -70
const PI_I2C_OPEN_FAILED = -71
const PI_SER_OPEN_FAILED = -72
const PI_SPI_OPEN_FAILED = -73
const PI_BAD_I2C_BUS = -74
const PI_BAD_I2C_ADDR = -75
const PI_BAD_SPI_CHANNEL = -76
const PI_BAD_FLAGS = -77
const PI_BAD_SPI_SPEED = -78
const PI_BAD_SER_DEVICE = -79
const PI_BAD_SER_SPEED = -80
const PI_BAD_PARAM = -81
const PI_I2C_WRITE_FAILED = -82
const PI_I2C_READ_FAILED = -83
const PI_BAD_SPI_COUNT = -84
const PI_SER_WRITE_FAILED = -85
const PI_SER_READ_FAILED = -86
const PI_SER_READ_NO_DATA = -87
const PI_UNKNOWN_COMMAND = -88
const PI_SPI_XFER_FAILED = -89
const PI_BAD_POINTER = -90
const PI_NO_AUX_SPI = -91
const PI_NOT_PWM_GPIO = -92
const PI_NOT_SERVO_GPIO = -93
const PI_NOT_HCLK_GPIO = -94
const PI_NOT_HPWM_GPIO = -95
const PI_BAD_HPWM_FREQ = -96
const PI_BAD_HPWM_DUTY = -97
const PI_BAD_HCLK_FREQ = -98
const PI_BAD_HCLK_PASS = -99
const PI_HPWM_ILLEGAL = -100
const PI_BAD_DATABITS = -101
const PI_BAD_STOPBITS = -102
const PI_MSG_TOOBIG = -103
const PI_BAD_MALLOC_MODE = -104
const PI_TOO_MANY_SEGS = -105
const PI_BAD_I2C_SEG = -106
const PI_BAD_SMBUS_CMD = -107
const PI_NOT_I2C_GPIO = -108
const PI_BAD_I2C_WLEN = -109
const PI_BAD_I2C_RLEN = -110
const PI_BAD_I2C_CMD = -111
const PI_BAD_I2C_BAUD = -112
const PI_CHAIN_LOOP_CNT = -113
const PI_BAD_CHAIN_LOOP = -114
const PI_CHAIN_COUNTER = -115
const PI_BAD_CHAIN_CMD = -116
const PI_BAD_CHAIN_DELAY = -117
const PI_CHAIN_NESTING = -118
const PI_CHAIN_TOO_BIG = -119
const PI_DEPRECATED = -120
const PI_BAD_SER_INVERT = -121
const PI_BAD_EDGE = -122
const PI_BAD_ISR_INIT = -123
const PI_BAD_FOREVER = -124
const PI_BAD_FILTER = -125
const PI_BAD_PAD = -126
const PI_BAD_STRENGTH = -127
const PI_FIL_OPEN_FAILED = -128
const PI_BAD_FILE_MODE = -129
const PI_BAD_FILE_FLAG = -130
const PI_BAD_FILE_READ = -131
const PI_BAD_FILE_WRITE = -132
const PI_FILE_NOT_ROPEN = -133
const PI_FILE_NOT_WOPEN = -134
const PI_BAD_FILE_SEEK = -135
const PI_NO_FILE_MATCH = -136
const PI_NO_FILE_ACCESS = -137
const PI_FILE_IS_A_DIR = -138
const PI_BAD_SHELL_STATUS = -139
const PI_BAD_SCRIPT_NAME = -140
const PI_BAD_SPI_BAUD = -141
const PI_NOT_SPI_GPIO = -142
const PI_BAD_EVENT_ID = -143
const PI_CMD_INTERRUPTED = -144
const PI_NOT_ON_BCM2711 = -145
const PI_ONLY_ON_BCM2711 = -146
const PI_PIGIF_ERR_0 = -2000
const PI_PIGIF_ERR_99 = -2099
const PI_CUSTOM_ERR_0 = -3000
const PI_CUSTOM_ERR_999 = -3999
const PI_DEFAULT_BUFFER_MILLIS = 120
const PI_DEFAULT_CLK_MICROS = 5
const PI_DEFAULT_CLK_PERIPHERAL = PI_CLOCK_PCM
const PI_DEFAULT_IF_FLAGS = 0
const PI_DEFAULT_FOREGROUND = 0
const PI_DEFAULT_DMA_CHANNEL = 14
const PI_DEFAULT_DMA_PRIMARY_CHANNEL = 14
const PI_DEFAULT_DMA_SECONDARY_CHANNEL = 6
const PI_DEFAULT_DMA_PRIMARY_CH_2711 = 7
const PI_DEFAULT_DMA_SECONDARY_CH_2711 = 6
const PI_DEFAULT_DMA_NOT_SET = 15
const PI_DEFAULT_SOCKET_PORT = 8888
#define PI_DEFAULT_SOCKET_PORT_STR "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR "127.0.0.1"
const PI_DEFAULT_UPDATE_MASK_UNKNOWN = &h0000000FFFFFFCll
const PI_DEFAULT_UPDATE_MASK_B1 = &h03E7CF93
const PI_DEFAULT_UPDATE_MASK_A_B2 = &hFBC7CF9C
const PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS = &h0080480FFFFFFCll
const PI_DEFAULT_UPDATE_MASK_ZERO = &h0080000FFFFFFCll
const PI_DEFAULT_UPDATE_MASK_PI2B = &h0080480FFFFFFCll
const PI_DEFAULT_UPDATE_MASK_PI3B = &h0000000FFFFFFCll
const PI_DEFAULT_UPDATE_MASK_PI4B = &h0000000FFFFFFCll
const PI_DEFAULT_UPDATE_MASK_COMPUTE = &h00FFFFFFFFFFFFll
const PI_DEFAULT_MEM_ALLOC_MODE = PI_MEM_ALLOC_AUTO
const PI_DEFAULT_CFG_INTERNALS = 0

end extern
The piTypes.bi

Code: Select all

Type Timing
    CalTime     as  Double              ''Timer is Double, read once at Start of program
    mSec        as  Double              ''These are (Timer - CalTime) * 1000
    StartTime   as  ULong
End TYPE
Dim Shared Times    as Timing
Type A2Ds
    Cell            as Integer
    Config(1 to 4)  as UInteger<16>
End Type
Dim shared A2D as A2Ds
Type Voltages
    Cnt     as Long
    Accum   as ULong
    Avg     as Single
    AccCnt  as Integer<16>
    Sample(1 to 100) as Integer<16>
    Hi      as Integer<16>      ''Register of Hi values
    HiCnt   as Integer<16>          ''how many in Register
    Lo      as Integer<16>
    LoCnt   as Integer<16>
    Repeats as Integer<16>
    Reply   as Integer<16>
    Handle  as Long
    i2cReg  as UInteger<16>
    Version as Integer<16>
    A2D     as Integer<16>
End Type
Dim shared Voltage(1 to 4) as Voltages
#macro SWAP16(v)                        ''Thank you D.J Peters
    swap cptr(ubyte ptr,@v)[0],cptr(ubyte ptr,@v)[1]
#endmacro 
Regards
Post Reply