A WiFiDipCortex based robot. Control is via sockets over WiFi. See also: https://github.com/mfurseman/robo-android

Dependencies:   Motordriver USBDevice cc3000_hostdriver_mbedsocket_hacked mbed

main.cpp

Committer:
mfurseman
Date:
2014-10-21
Revision:
1:b66a2d756c8a
Parent:
0:993d6b65e255
Child:
2:50c151183047

File content as of revision 1:b66a2d756c8a:

#include "mbed.h"
#include "cc3000.h"
#include "USBSerial.h"


/* Quickly change debug flag to remove blocking serial code */
#define DEBUG
#ifdef DEBUG
USBSerial serial;
#define debug(x, ...) serial.printf(x, ##__VA_ARGS__);
#else
#define debug(x, ...)
#endif


using namespace mbed_cc3000;


/* On board LED */
DigitalOut led(P0_1);

/* Serial library for WiFi module */
cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37));

/* Struct to hold connection data */
tNetappIpconfigRetArgs ipinfo;


/* Prints CC3000 connection info */
void printConnectionInfo() {
    if (( wifi.is_enabled() ) && ( wifi.is_dhcp_configured() )) {
        wifi.get_ip_config(&ipinfo);
    }    
    debug("\r\n");
    if (! wifi.is_enabled() ) {
        debug("CC3000 Disabled\r\n"); 
    }
    else if ( wifi.is_dhcp_configured() ) {
        debug("SSID : %-33s|\r\n", ipinfo.uaSSID);
        debug("IP : %-35s|\r\n", wifi.getIPAddress());   
    }
    else if ( wifi.is_connected() ) {
        debug("Connecting, waiting for DHCP\r\n"); 
    }
    else {
        debug("Not Connected\r\n");   
    }
}


/* WiFi DipCortex board setup */
void init() {
    NVIC_SetPriority(SSP1_IRQn, 0x0); 
    NVIC_SetPriority(PIN_INT0_IRQn, 0x1);
    
    // SysTick set to lower priority than Wi-Fi SPI bus interrupt
    NVIC_SetPriority(SysTick_IRQn, 0x2); 
    
    // Enable RAM1
    LPC_SYSCON->SYSAHBCLKCTRL |= (0x1 << 26);
    
    // This may be neccassary for CC3000
    wait(1);
}


/* Connects WiFi assuming existing SmartConfig */
void connectWifi() {
    wifi.start(0);
    wait_ms(750);
    wifi._wlan.ioctl_set_connection_policy(0, 0, 1);
    // TODO: Timeout and switch on smart config here
}


int main(void) {
    init();    
    connectWifi();

    while(1) {
        printConnectionInfo();
        debug("test message\r\n");
        led = !led;
        wait(1);
   }
}