Albert-Jan Knevels / Mbed 2 deprecated CherryStone

Dependencies:   mbed

main.cpp

Committer:
EiJay
Date:
2014-07-29
Revision:
9:190ec4ad9ac7
Parent:
8:7f7c9353bc05
Child:
10:59582af3b94a

File content as of revision 9:190ec4ad9ac7:

#include "mbed.h"
#include "MLX90393.h"


int main()
{
    //mBed indicators
    DigitalOut myled(LED1);

    //PC-communication
    Serial pc (USBTX, USBRX);
    pc.baud(9600);
    char hostCommand;
    int hostData1;
    int hostData2;
    int hostData3;
    //Chip communication
    SPI spi(p5, p6, p7);
    spi.format(MLX90393::spi_bits,MLX90393::spi_mode);
    spi.frequency(1000000);
    MLX90393 sensor(p26,&spi);


    //variables
    char read_buffer[10];
    int content_buffer[63];
    //if you remove this line the program will fail
    //also make sure that you always send the status back to the host
    hostCommand = 0;
    while(1) {
        pc.scanf(" %i, %i, %i, %i", &hostCommand, &hostData1, &hostData2, &hostData3);
        switch(hostCommand) {
            case 0: {
                //wait_ms(1);
                break;
            }
            case 1: {
                /*
                ** Send 'read register' command to MLX90393.
                * @param *receiveBuffer Pointer to receiveBuffer, will contain response of IC after command is sent.
                * @param address The register to be read out.
                * @param mode Communication mode (0=I2C, 1=SPI).
                * @note The receiveBuffer will contain the status byte, followed by 2 bytes for the data at the specific register.
                */
                //void RR(char *receiveBuffer, int address, int mode);
                for (int i = 0; i<63; i++) {
                    sensor.RR(read_buffer,i,1);
                    content_buffer[i] = (read_buffer[0]*65536)+(read_buffer[1]*256) + read_buffer[2];
                    //printf("%i",content_buffer[i]);
                }
                for (int i = 0; i<63; i++) {
                   printf("%i\n",content_buffer[i]);
                }
                break;
            }
            case 2: {
                break;
            }
            case 3: {
                break;
            }
            case 4: {
                break;
            }
            case 5: {
                //exit
                //printf("**gelukt** \n\r");
                sensor.EX(read_buffer,1);
                printf("%i\n",read_buffer[0]);
                break;
            }
            case 6: {
                //single measurement
                sensor.SM(read_buffer,hostData1,1);
                printf("%i\n",read_buffer[0]);
                break;
            }
            case 7: {
                break;
            }
            case 8: {
                //burst
                sensor.SB(read_buffer,hostData1,1);
                printf("%i\n",read_buffer[0]);
                break;
            }
            case 9: {
                //wake up on change
                sensor.SWOC(read_buffer,hostData1,1);
                printf("%i\n",read_buffer[0]);
                break;
            }
        }
    }
}