Add files via upload
This commit is contained in:
parent
1334743d7b
commit
5d43c9eb94
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
enum GpioType :uint8_t
|
||||
{
|
||||
GPIO_INPUT = 0,
|
||||
GPIO_OUTPUT = 1,
|
||||
GPIO_PWM = 2
|
||||
};
|
||||
|
||||
enum GpioState :bool
|
||||
{
|
||||
LOW = false,
|
||||
HIGH = true,
|
||||
};
|
||||
|
||||
enum PinId :uint8_t
|
||||
{
|
||||
// >= 50 GPIO_CHIP2
|
||||
Pin_Servo_Left_Enable = 56,
|
||||
Pin_Servo_Right_Enable = 57,
|
||||
};
|
||||
|
||||
enum PwmId :uint8_t
|
||||
{
|
||||
Pwm_Led_Left_B = 6,
|
||||
Pwm_Led_Left_G = 7,
|
||||
Pwm_Led_Left_R = 8,
|
||||
Pwm_Led_Right_B = 9,
|
||||
Pwm_Led_Right_G = 10,
|
||||
Pwm_Led_Right_R = 11,
|
||||
};
|
||||
|
||||
namespace GPIO
|
||||
{
|
||||
// Initialize IO pin
|
||||
// state is optional for GPIO
|
||||
// return 0 = success
|
||||
// return -1 = initialized failed
|
||||
// return -2 = wrong type
|
||||
int8_t init(PinId id, GpioType type, GpioState state = GpioState::LOW);
|
||||
|
||||
// Initialize PWM pin
|
||||
// return 0 = success
|
||||
// return -1 = initialized failed
|
||||
int8_t init(PwmId id);
|
||||
|
||||
// return 0 success
|
||||
// return -1 write failed
|
||||
// return -2 undefined id
|
||||
int8_t writePin(PinId id, GpioState state);
|
||||
|
||||
// return 0 success
|
||||
// return -1 write failed
|
||||
// return -2 undefined id
|
||||
int8_t writePwm(PwmId id, uint16_t value);
|
||||
|
||||
};
|
|
@ -0,0 +1,69 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#define LCD_WIDTH 240
|
||||
#define LCD_HEIGHT 240
|
||||
|
||||
enum LcdColorDepth :uint8_t
|
||||
{
|
||||
// 0x06 = 18 bit, 0x03 = 12 bit
|
||||
LCD_12BIT = 0x03,
|
||||
LCD_18BIT = 0x06,
|
||||
};
|
||||
|
||||
enum LcdSide :uint8_t
|
||||
{
|
||||
LcdLeft = 0,
|
||||
LcdRight = 1,
|
||||
};
|
||||
|
||||
struct LcdData
|
||||
{
|
||||
uint8_t side;
|
||||
uint8_t* buffer;
|
||||
};
|
||||
|
||||
namespace LcdControl
|
||||
{
|
||||
// Initialize lcd
|
||||
// return 0 success
|
||||
// return 1 already initialized
|
||||
// return -1 open device failed
|
||||
// return -2 ioctl failed
|
||||
int8_t init(LcdColorDepth depth = LCD_12BIT);
|
||||
|
||||
// release file descriptor and deinitialize
|
||||
// return 0 success
|
||||
// return 1 already closed or not opened
|
||||
int8_t release();
|
||||
|
||||
// retuns state of lcds
|
||||
// return true initialized
|
||||
// return false not initialized
|
||||
bool isActive();
|
||||
|
||||
// fill lcd with RGB
|
||||
void LcdColorFill(LcdSide side, uint8_t R, uint8_t G, uint8_t B);
|
||||
|
||||
// write buffer data to lcd
|
||||
// return 0 success
|
||||
// return -1 ioct error
|
||||
// return -2 not active
|
||||
int8_t writeLcd(LcdData* frame_data);
|
||||
|
||||
//return lcd buffer size
|
||||
// pixel count * Color data byte size
|
||||
// ex. 240*240*3
|
||||
int getBufferSize();
|
||||
|
||||
// returns lcd color depth
|
||||
LcdColorDepth getColorDepth();
|
||||
|
||||
// brightness value min = 0, max = 10
|
||||
int8_t setBrightness(uint8_t value);
|
||||
|
||||
//converts 24 bit image to lcd image depth
|
||||
void LcdBufferFrom24Bit(uint8_t* output, uint8_t* input);
|
||||
};
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
// just for information, ignored if used more than defined (220 degree)
|
||||
// Arm servos can not rotate more than that.
|
||||
#define SERVO_ARM_MAX_ANGLE 220
|
||||
|
||||
enum ServoChannel : uint8_t
|
||||
{
|
||||
SERVO_LEFT,
|
||||
SERVO_RIGHT,
|
||||
SERVO_0,
|
||||
SERVO_1,
|
||||
};
|
||||
|
||||
namespace ServoMotor
|
||||
{
|
||||
// initialize all motors
|
||||
void Init();
|
||||
|
||||
//return true if module ready
|
||||
bool isActive();
|
||||
|
||||
// setup servo default values
|
||||
// 'min_us, max_us' depends on your servo and effects angle of movement
|
||||
// most PWM range them between (500us - 2500us)
|
||||
// 'angle' ignored for SERVO_LEFT & SERVO_RIGHT,
|
||||
// return 0 success
|
||||
// return -1 frequency interval error
|
||||
// return -2 angle error
|
||||
int8_t setup(ServoChannel channel, uint16_t min_us, uint16_t max_us, uint16_t angle, bool invert);
|
||||
|
||||
// sets servo position
|
||||
// return 0 success
|
||||
// return -1 max angle exceed error
|
||||
// return -2 speed range error (0-100)
|
||||
// return -3 undefined channel
|
||||
int8_t set(ServoChannel channel, float angle, uint8_t speed);
|
||||
|
||||
// stops servo
|
||||
// return 0 success
|
||||
// return -1 undefined servo
|
||||
int8_t stop(ServoChannel channel);
|
||||
};
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,13 @@
|
|||
|
||||
|
||||
# LcdControl Example program
|
||||
|
||||
### Compile example program
|
||||
This example needs some static libraries and header files located under '/Doly/libs' & '/Doly/include'
|
||||
Make sure you have already copy '/Doly' folder under your root directory.
|
||||
|
||||
```bash
|
||||
g++ -L../Doly/libs -I../Doly/include -Wall -o test main.cpp -lLcdControl
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
#include "LcdControl.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <thread>
|
||||
|
||||
/// <summary>
|
||||
/// This program demonstrates how to setup and control servos,
|
||||
/// Also this program requires LcdControl library
|
||||
/// LcdControl is part of Project Doly, libararies and headers are located under '/Doly'
|
||||
/// Do not forget to Copy and Link related libraries.
|
||||
/// </summary>
|
||||
|
||||
int FillBufferExample();
|
||||
|
||||
int main()
|
||||
{
|
||||
// initialize Lcd
|
||||
// default Color depth is 12 Bit (4096 color)
|
||||
LcdControl::init(LCD_12BIT);
|
||||
|
||||
LcdColorDepth depth = LcdControl::getColorDepth();
|
||||
|
||||
// Fill with buffer example
|
||||
FillBufferExample();
|
||||
|
||||
// wait 2 seconds
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
|
||||
// fill with color example
|
||||
LcdControl::LcdColorFill(LcdLeft, 0, 0, 255);
|
||||
LcdControl::LcdColorFill(LcdRight, 255, 0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FillBufferExample()
|
||||
{
|
||||
// get LCD buffer size
|
||||
// buffer size depends on color depth
|
||||
// ex. Color depth 12 Bit frame size = 240px * 240px * 1.5
|
||||
// Color depth 18 Bit frame size = 240px * 240px * 3
|
||||
int buffer_size = LcdControl::getBufferSize();
|
||||
|
||||
// allocate & clear buffer
|
||||
uint8_t buf[buffer_size];
|
||||
memset(&buf, 0xFF, buffer_size);
|
||||
|
||||
// create data for each side
|
||||
LcdData frame_left;
|
||||
frame_left.buffer = buf;
|
||||
frame_left.side = LcdLeft;
|
||||
|
||||
LcdData frame_right;
|
||||
frame_right.buffer = buf;
|
||||
frame_right.side = LcdRight;
|
||||
|
||||
int retval = 0;
|
||||
// write buffer to LCD
|
||||
if (LcdControl::writeLcd(&frame_left) < 0)
|
||||
{
|
||||
printf("Left Lcd write failed! \n");
|
||||
retval = -1;
|
||||
}
|
||||
// write buffer to LCD
|
||||
if (LcdControl::writeLcd(&frame_right) < 0)
|
||||
{
|
||||
printf("Right Lcd write failed! \n");
|
||||
retval = -1;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
|
||||
# LcdControl Example program
|
||||
|
||||
### Compile example program
|
||||
This example needs some static libraries and header files located under '/Doly/libs' & '/Doly/include'
|
||||
Make sure you have already copy '/Doly' folder under your root directory.
|
||||
|
||||
```bash
|
||||
g++ -L../Doly/libs -I../Doly/include -Wall -o test main.cpp -lServoMotor -lTimer -lGpio -lpthread
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#include "ServoMotor.h"
|
||||
#include "Gpio.h"
|
||||
#include <thread>
|
||||
|
||||
/// <summary>
|
||||
/// This program demonstrates how to setup and control servos,
|
||||
/// Also this program requires pthread, ServoMotor, Gpio, Timer libraries
|
||||
/// ServoMotor, Gpio, Timer are part of Project Doly, libararies and headers are located under '/Doly'
|
||||
/// Do not forget to Copy and Link related libraries.
|
||||
/// </summary>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup Servo power control GPIO as output and set HIGH as a default value
|
||||
GPIO::init(Pin_Servo_Left_Enable, GPIO_OUTPUT, HIGH);
|
||||
GPIO::init(Pin_Servo_Right_Enable, GPIO_OUTPUT, HIGH);
|
||||
|
||||
// Initialize and configure servo motors
|
||||
ServoMotor::Init();
|
||||
// Setup needs channel, bandwitdh range, max angle and working direction parameters
|
||||
// Setup ignores the 'max angle' parameter for both arm servos, however they are already defined internally.
|
||||
ServoMotor::setup(SERVO_LEFT, 500, 2500, SERVO_ARM_MAX_ANGLE, false);
|
||||
ServoMotor::setup(SERVO_RIGHT, 500, 2500, SERVO_ARM_MAX_ANGLE, true);
|
||||
|
||||
// Sets servo zero positions
|
||||
// The 'speed' paramater range between 1-100
|
||||
ServoMotor::set(SERVO_LEFT, 0, 100);
|
||||
ServoMotor::set(SERVO_RIGHT, 0, 100);
|
||||
|
||||
// wait to get zero position
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
||||
|
||||
|
||||
// Sets servo positions
|
||||
// The 'speed' paramater range between 1-100
|
||||
ServoMotor::set(SERVO_LEFT, 90, 1);
|
||||
ServoMotor::set(SERVO_RIGHT, 90, 1);
|
||||
|
||||
// wait
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
|
||||
ServoMotor::set(SERVO_LEFT, SERVO_ARM_MAX_ANGLE, 100);
|
||||
ServoMotor::set(SERVO_RIGHT, SERVO_ARM_MAX_ANGLE, 100);
|
||||
|
||||
// wait servo
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
||||
|
||||
// disable servo power
|
||||
GPIO::writePin(Pin_Servo_Left_Enable, LOW);
|
||||
GPIO::writePin(Pin_Servo_Right_Enable, LOW);
|
||||
|
||||
return 0;
|
||||
}
|
Binary file not shown.
|
Binary file not shown.
|
Binary file not shown.
|
Binary file not shown.
|
Binary file not shown.
|
Binary file not shown.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue