Beispiel #1
0
void
print_version()
{
    fprintf(stdout, "Version %s on %s", mraa_get_version(), mraa_get_platform_name());
    if (plat != NULL && plat->sub_platform != NULL)
        fprintf(stdout, " with %s", plat->sub_platform->platform_name);
    fprintf(stdout, "\n");
}
int main(int argc, char** argv)
{
    const char* board_name = mraa_get_platform_name();
    int i2c_bus, i, i2c_adapter;
    fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", 
mraa_get_version(), board_name);
    mraa_deinit();
    return MRAA_SUCCESS;
}
Beispiel #3
0
int
main(int argc, char** argv)
{
    mraa_platform_t platform = mraa_get_platform_type();
    mraa_gpio_context gpio, gpio_in = NULL;
    const char* board_name = mraa_get_platform_name();
    int ledstate = 0;

    switch (platform) {
        case MRAA_INTEL_GALILEO_GEN1:
            gpio = mraa_gpio_init_raw(3);
            break;
        case MRAA_INTEL_MINNOWBOARD_MAX:
            // there is no onboard LED that we can flash on the minnowboard max
            // but on the calamari lure pin 21 is an LED. If you don't have the
            // lure put an LED on pin 21
            gpio = mraa_gpio_init(21);
            break;
        case MRAA_INTEL_JOULE_EXPANSION:
            gpio = mraa_gpio_init(101);
            break;
        default:
            gpio = mraa_gpio_init(13);
    }

    fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);


    if (gpio == NULL) {
        fprintf(stdout, "Could not initilaize gpio\n");
        return 1;
    }

    // on platforms with physical button use gpio_in
    if (platform == MRAA_INTEL_MINNOWBOARD_MAX) {
        gpio_in = mraa_gpio_init(14);
        if (gpio_in != NULL) {
            mraa_gpio_dir(gpio_in, MRAA_GPIO_IN);
            // S1 on minnowboardmax's calamari lure maps to pin 14, SW1 != S1
            fprintf(stdout, "Press and hold S1 to stop, Press SW1 to shutdown!\n");
        }
    }

    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);

    for (;;) {
        if (gpio_in != NULL && mraa_gpio_read(gpio_in) == 0) {
            return 0;
        }
        ledstate = !ledstate;
        mraa_gpio_write(gpio, !ledstate);
        sleep(1);
    }

    return 0;
}
static char *get_boardtype() {
  #ifdef DEVICEINTEL
  const char* board = mraa_get_platform_name();
  if (board == NULL)
  {
    return "edison";
  }
  if (strncmp (board, "Intel Galileo ", 14)==0)
  {
    return "arduinogalileo";
  }
  else
  if (strncmp (board, "Intel Edison", 12)==0)
  {
    return "edison";
  }
  else
  if (strncmp (board, "MinnowBoard MAX", 16)==0)
  {
    return "minnowboardmax";
  }
  else
  {
    return NULL;
  }
  #else
  char *return_value = NULL;

  /* Open boardtype */
  int boardtype_fd = open(BOARDTYPE_PATH, O_RDONLY);
  wsyserr2(boardtype_fd == -1, goto _finish, "Could not open %s", BOARDTYPE_PATH);

  /* Allocate space for return value */
  char *boardtype = calloc(64, sizeof(char));
  wsyserr2(boardtype == NULL, goto _finish, "Could not calloc space for boardtype");

  /* Read the content of the boartype file */
  int read_rc = read(boardtype_fd, boardtype, 63);
  wsyserr2(read_rc == -1, goto _finish, "Could not read from %s", BOARDTYPE_PATH);
  werr2(read_rc == 63, goto _finish, "Board name too long in %s", BOARDTYPE_PATH);

  /* Success */
  return_value = boardtype;

  _finish: ;
    if (boardtype_fd != -1) {
      int close_rc = close(boardtype_fd);
      wsyserr2(close_rc == -1, return_value = NULL,
               "Could not close %s", BOARDTYPE_PATH);
    }

    return return_value;
    #endif
}
Beispiel #5
0
void startMRAA( void ) {

//	printf( "\n  I/O is enabled\n" );
	mraa_init();

	printf( "  MRAA library Version: %s\n", mraa_get_version() );

	mraa_platform_t platformType = mraa_get_platform_type();
    printf( "  Platform type: %d\n", platformType );
    char *platformName = mraa_get_platform_name();
    printf( "  Platform name: %s\n", platformName );
}
Beispiel #6
0
int
main(int argc, char **argv)
{
    mraa_platform_t platform = mraa_get_platform_type();
    mraa_gpio_context gpio, gpio_in = NULL;
    char* board_name = mraa_get_platform_name();
    int ledstate = 0;

    switch (platform) {
        case MRAA_INTEL_GALILEO_GEN1:
            gpio = mraa_gpio_init_raw(3);
            break;
        case MRAA_INTEL_MINNOWBOARD_MAX:
            gpio = mraa_gpio_init(21);
            break;
        default:
            gpio = mraa_gpio_init(13);
    }

    fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n",
        mraa_get_version(), board_name);


    if (gpio == NULL) {
        fprintf(stdout, "Could not initilaize gpio\n");
        return 1;
    }

    // on platforms with physical button use gpio_in
    if (platform == MRAA_INTEL_MINNOWBOARD_MAX) {
        gpio_in = mraa_gpio_init(14);
	if (gpio_in != NULL) {
            mraa_gpio_dir(gpio_in, MRAA_GPIO_IN);
            fprintf(stdout, "Press and hold S1 to stop\n");
        }
    }

    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);

    for (;;) {
        if (gpio_in != NULL && mraa_gpio_read(gpio_in) == 0) {
            return 0;
        }
        ledstate = !ledstate;
        mraa_gpio_write(gpio, !ledstate);
        sleep(1);
    }

    return 0;
}
Beispiel #7
0
mraa_init()
{
    if (plat != NULL) {
        return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
    }

    uid_t proc_euid = geteuid();
    struct passwd* proc_user = getpwuid(proc_euid);

#ifdef DEBUG
    setlogmask(LOG_UPTO(LOG_DEBUG));
#else
    setlogmask(LOG_UPTO(LOG_NOTICE));
#endif

    openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
    syslog(LOG_NOTICE, "libmraa version %s initialised by user '%s' with EUID %d",
           mraa_get_version(), (proc_user != NULL) ? proc_user->pw_name : "<unknown>", proc_euid);

#ifdef SWIGPYTHON
    // Initialise python threads, this allows use to grab the GIL when we are
    // required to do so
    Py_InitializeEx(0);
    PyEval_InitThreads();
#endif
    advance_func = (mraa_adv_func_t*) malloc(sizeof(mraa_adv_func_t));
    memset(advance_func, 0, sizeof(mraa_adv_func_t));

#if defined(X86PLAT)
    // Use runtime x86 platform detection
    platform_type = mraa_x86_platform();
#elif defined(ARMPLAT)
    // Use runtime ARM platform detection
    platform_type = mraa_arm_platform();
#else
#error mraa_ARCH NOTHING
#endif

    if (plat == NULL) {
        printf("mraa: FATAL error, failed to initialise platform\n");
        return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
    }

    syslog(LOG_INFO, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), platform_type);
    return MRAA_SUCCESS;
}
Beispiel #8
0
/**
 * Whilst the actual mraa init function is now called imraa_init, it's only
 * callable externally if IMRAA is enabled
 */
mraa_result_t
imraa_init()
{
    if (plat != NULL) {
        return MRAA_SUCCESS;
    }

    uid_t proc_euid = geteuid();
    struct passwd* proc_user = getpwuid(proc_euid);

#ifdef DEBUG
    setlogmask(LOG_UPTO(LOG_DEBUG));
#else
    setlogmask(LOG_UPTO(LOG_NOTICE));
#endif

    openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
    syslog(LOG_NOTICE, "libmraa version %s initialised by user '%s' with EUID %d",
           mraa_get_version(), (proc_user != NULL) ? proc_user->pw_name : "<unknown>", proc_euid);

    mraa_platform_t platform_type;
#if defined(X86PLAT)
    // Use runtime x86 platform detection
    platform_type = mraa_x86_platform();
#elif defined(ARMPLAT)
    // Use runtime ARM platform detection
    platform_type = mraa_arm_platform();
#elif defined(MOCKPLAT)
    // Use mock platform
    platform_type = mraa_mock_platform();
#else
#error mraa_ARCH NOTHING
#endif

    if (plat != NULL) {
        plat->platform_type = platform_type;
    } else {
        platform_name = NULL;
    }

    // Create null base platform if one doesn't already exist
    if (plat == NULL) {
        plat = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
        if (plat != NULL) {
            plat->platform_type = MRAA_NULL_PLATFORM;
            plat->platform_name = "Unknown platform";
        }
    }

#if defined(USBPLAT)
    // Now detect sub platform, note this is not an else since we could be in
    // an error case and fall through to MRAA_ERROR_PLATFORM_NOT_INITIALISED
    if (plat != NULL) {
        mraa_platform_t usb_platform_type = mraa_usb_platform_extender(plat);
        // if we have no known platform just replace usb platform with platform
        if (plat->platform_type == MRAA_UNKNOWN_PLATFORM && usb_platform_type != MRAA_UNKNOWN_PLATFORM) {
            plat->platform_type = usb_platform_type;
        }
    }
    if (plat == NULL) {
        printf("mraa: FATAL error, failed to initialise platform\n");
        return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
    }
#endif

#if defined(IMRAA)
    const char* subplatform_lockfile = "/tmp/imraa.lock";
    mraa_add_from_lockfile(subplatform_lockfile);
#endif

    // Look for IIO devices
    mraa_iio_detect();

    if (plat != NULL) {
        int length = strlen(plat->platform_name) + 1;
        if (mraa_has_sub_platform()) {
            // Account for ' + ' chars
            length += strlen(plat->sub_platform->platform_name) + 3;
        }
        platform_name = calloc(length, sizeof(char));
        if (mraa_has_sub_platform()) {
            snprintf(platform_name, length, "%s + %s", plat->platform_name, plat->sub_platform->platform_name);
        } else {
            strncpy(platform_name, plat->platform_name, length);
        }
    }

    lang_func = (mraa_lang_func_t*) calloc(1, sizeof(mraa_lang_func_t));
    if (lang_func == NULL) {
        return MRAA_ERROR_NO_RESOURCES;
    }

    syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), mraa_get_platform_type());
    return MRAA_SUCCESS;
}
int main(int argc, char** argv)
{
    mraa_platform_t platform;                /* Type of platform we are on */
    mraa_gpio_context gpio_led = NULL;       /* LED GPIO descriptor */
    mraa_gpio_context gpio_button = NULL;    /* BUTTON GPIO descriptor */
    mraa_aio_context adc_a0 = NULL;          /* Analog-Digital descriptor */
    uint32_t adc_val;                       /* ADC value */
    float delay;                             /* Delay between blinks */
    int ledstate = 0;                        /* LED state, 0=off, 1=on */


    /*
     * Print banner.
     */
     platform = mraa_get_platform_type();
     fprintf(stdout, "MRAA C Demonstration\n");
     fprintf(stdout, "LIBMRAA Version: %s\n", mraa_get_version());
     fprintf(stdout, "Board: %s\n", mraa_get_platform_name());

     /*
      * Check that we are running on the correct board
      */
     platform = mraa_get_platform_type();
     if (platform != MRAA_INTEL_GALILEO_GEN2)
        {
        fprintf(stderr, "ERROR: This program is for a Intel Galileo Gen 2 Board\n");
        exit (-1);
        }

    /*
     * Initialize the LED gpio pin and set it as an output
     */
    gpio_led = mraa_gpio_init(LED);
    if (gpio_led == NULL)
        {
        fprintf(stderr, "Could not initialize LED gpio\n");
        exit (-1);
        }
    mraa_gpio_dir(gpio_led, MRAA_GPIO_OUT);

    /*
     * Initialize the Button gpio pin and set it as an input
     */
     gpio_button = mraa_gpio_init(BUTTON);
     if (gpio_button == NULL)
         {
         fprintf(stderr, "Could not initialize BUTTON gpio\n");
         }
    mraa_gpio_dir(gpio_button, MRAA_GPIO_IN);

    /*
     * Initialize the Analog-Digital converter channel 0
     */

    adc_a0 = mraa_aio_init(0);
    if (adc_a0 == NULL)
        {
        fprintf(stderr, "Failed to initalize ADC channel A0\n");
        exit (-1);
        }

    printf("Vary the rate of blink by turning the poteniometer on A0\n");
    printf("Exit the program by pressing the button on D%d\n\n", BUTTON);

    /*
     * Run the loop until the BUTTON is held down.
     * Each time through the loop, read the potentiometer on A0 and
     * adjust the blink rate.
     */
    while (1)
        {
        if (mraa_gpio_read(gpio_button) == 1)
            break;

        if (adc_a0 != NULL)
            {
            adc_val = mraa_aio_read(adc_a0);
            /* fprintf(stdout, "ADC A0 = %d\n", adc_val); */
            if (adc_val != 0)
                delay = 1000000 * ((float)adc_val/1024);
            else
                delay = 1000000 * (1/1024);
            }

        ledstate = !ledstate;

        mraa_gpio_write(gpio_led, ledstate);

        usleep((long)delay);
        }

    /*
     * Clean up and exit
     */
    (void)mraa_gpio_close(gpio_led);
    (void)mraa_gpio_close(gpio_button);
    (void)mraa_aio_close(adc_a0);

    exit(0);
}
Beispiel #10
0
int	main(UNUSED(int argc), UNUSED(char** argv))
{
	uint32_t tso = rdtsc32();

	stdio_mode(STDIO_MODE_CANON);

	// initialize mraa and software SPI
	mraa_init();
	printf("MRAA paltform %s, version %s\n", mraa_get_platform_name(), mraa_get_version());
	mraa_spi_sw_context spi = sw_spi_init(MRAA_SCK, MRAA_MOSI, MRAA_MISO);
	
	// initialize RFM12BS
	rfm12_t rfm;
	memset(&rfm, 0,  sizeof(rfm));
	rfm12_init_spi(&rfm, spi, MRAA_CS1, MRAA_GP047);
	rfm12_init(&rfm, 0xD4, RFM12_BAND_868, 868.0, RFM12_BPS_9600);
	rfm12_set_mode(&rfm, RFM_MODE_RX);

	printf("started up in %u msec\n", millis(tso));

	// default application configuration
	cfg.flags |= APPF_ECHO_DAN;
	cfg.rfm = &rfm;

	// initialize command line interface
	console_io_t cli;
	memset(&cli, 0,  sizeof(cli));
	cli.prompt = '>';
	cli.data = &cfg;

	stdio_init(&cli, stdio_cmd_handler);
	stdio_mode(STDIO_MODE_RAW);

	dnode_t node;

	while(!cli.stop) {
		cli.interact(&cli, cli_cmd);

		if (rfm12_receive_data(&rfm, &node, sizeof(node), cfg.flags & RFM_RX_DEBUG) == sizeof(node)) {
			rfm12_set_mode(&rfm, RFM_MODE_RX);
			if (node.nid == NODE_TSYNC) {
				tso = rdtsc32();
				ts_unpack(&node);
				cfg.rtc_hour = node.hour;
				cfg.rtc_min = node.min;
				cfg.rtc_sec = node.sec;
			}
			if (cfg.flags & APPF_ECHO_DAN)
				print_node(&cli, &node);
		}

		if (millis(tso) >= 1000) {
			tso = rdtsc32();
			if (++cfg.rtc_sec == 60) {
				cfg.rtc_sec = 0;
				if (++cfg.rtc_min == 60) {
					cfg.rtc_min = 0;
					if (++cfg.rtc_hour == 24)
						cfg.rtc_hour = 0;
				}
			}
		}
		usleep(1); // be nice 
	}

	stdio_mode(STDIO_MODE_CANON);
	rfm12_close_spi(&rfm);
	sw_spi_close(spi);
	mraa_deinit();
}
Beispiel #11
0
/**
 * Return Platform Name. "Unknown" if no platform inited.
 *
 * @return platform name
 */
inline std::string getPlatformName()
{
    std::string ret_val(mraa_get_platform_name());
    return ret_val;
}