upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for rotaryencoder.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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 OR COPYRIGHT HOLDERS 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.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "rotaryencoder.h"
#include "upm_utilities.h"
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a Grove Rotary Encoder, using signal pins D2 and D3
if (!sensor)
{
printf("rotaryencoder_init() failed.\n");
return 1;
}
while (shouldRun)
{
printf("Position: %d\n", rotaryencoder_get_position(sensor));
upm_delay_ms(100);
}
printf("Exiting...\n");
return 0;
}

Go to the source code of this file.

Data Structures

struct  _rotaryencoder_context
 

Functions

rotaryencoder_context rotaryencoder_init (int pin_a, int pin_b)
 
void rotaryencoder_close (rotaryencoder_context dev)
 
void rotaryencoder_set_position (const rotaryencoder_context dev, int count)
 
int rotaryencoder_get_position (const rotaryencoder_context dev)
 

Typedefs

typedef struct _rotaryencoder_contextrotaryencoder_context
 

Function Documentation

rotaryencoder_context rotaryencoder_init ( int  pin_a,
int  pin_b 
)

RotaryEncoder initialization

Parameters
pinADigital pin to use for signal A
pinBDigital pin to use for signal B

Here is the call graph for this function:

void rotaryencoder_close ( rotaryencoder_context  dev)

RotaryEncoder close function

Here is the caller graph for this function:

void rotaryencoder_set_position ( const rotaryencoder_context  dev,
int  count 
)

Resets the position to a given number.

Parameters
countInteger to initialize the position to

Here is the caller graph for this function:

int rotaryencoder_get_position ( const rotaryencoder_context  dev)

Gets the position value.

Here is the caller graph for this function:

Typedef Documentation

Device context