add display rotation
This commit is contained in:
@@ -13,6 +13,7 @@ void display_setup( TTGOClass *ttgo ) {
|
||||
|
||||
ttgo->openBL();
|
||||
ttgo->bl->adjust( 0 );
|
||||
ttgo->tft->setRotation( display_config.rotation / 90 );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -74,4 +75,16 @@ void display_set_brightness( uint32_t brightness ) {
|
||||
|
||||
display_config.brightness = brightness;
|
||||
ttgo->bl->adjust( brightness );
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t display_get_rotation( void ) {
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
return( display_config.rotation );
|
||||
}
|
||||
|
||||
void display_set_rotation( uint32_t rotation ) {
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
display_config.rotation = rotation;
|
||||
ttgo->tft->setRotation( rotation / 90 );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
}
|
||||
|
||||
@@ -7,9 +7,13 @@
|
||||
#define DISPLAY_MIN_BRIGHTNESS 32
|
||||
#define DISPLAY_MAX_BRIGHTNESS 255
|
||||
|
||||
#define DISPLAY_MIN_ROTATE 0
|
||||
#define DISPLAY_MAX_ROTATE 270
|
||||
|
||||
typedef struct {
|
||||
uint32_t brightness = DISPLAY_MIN_BRIGHTNESS;
|
||||
uint32_t timeout = DISPLAY_MIN_TIMEOUT;
|
||||
uint32_t rotation = 0;
|
||||
} display_config_t;
|
||||
|
||||
#define DISPLAY_CONFIG_FILE "/display.cfg"
|
||||
@@ -58,5 +62,17 @@
|
||||
* @param brightness brightness from 0-255
|
||||
*/
|
||||
void display_set_brightness( uint32_t brightness );
|
||||
/*
|
||||
* @brief read the rotate from the display
|
||||
*
|
||||
* @return rotation from 0-270 degree in 90 degree steps
|
||||
*/
|
||||
uint32_t display_get_rotation( void );
|
||||
/*
|
||||
* @brief set the rotate for the display
|
||||
*
|
||||
* @param rotation from 0-270 in 90 degree steps
|
||||
*/
|
||||
void display_set_rotation( uint32_t rotation );
|
||||
|
||||
#endif // _DISPLAY_H
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <TTGO.h>
|
||||
#include "motor.h"
|
||||
#include "powermgm.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef _MOTOR_H
|
||||
#define _MOTOR_H
|
||||
|
||||
#include "TTGO.h"
|
||||
|
||||
/*
|
||||
* @ brief setup motor I/O
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,8 @@ void pmu_setup( TTGOClass *ttgo ) {
|
||||
Serial.printf("target voltage set failed!\r\n");
|
||||
if ( ttgo->power->setChargeControlCur( 300 ) )
|
||||
Serial.printf("charge current set failed!\r\n");
|
||||
if ( ttgo->power->setAdcSamplingRate( AXP_ADC_SAMPLING_RATE_200HZ ) )
|
||||
Serial.printf("adc sample set failed!\r\n");
|
||||
|
||||
// Turn off unused power
|
||||
ttgo->power->setPowerOutPut( AXP202_EXTEN, AXP202_OFF );
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "wifictl.h"
|
||||
#include "timesync.h"
|
||||
#include "motor.h"
|
||||
#include "touch.h"
|
||||
|
||||
EventGroupHandle_t powermgm_status = NULL;
|
||||
|
||||
@@ -24,6 +25,7 @@ void powermgm_setup( TTGOClass *ttgo ) {
|
||||
bma_setup( ttgo );
|
||||
wifictl_setup();
|
||||
timesync_setup( ttgo );
|
||||
touch_setup( ttgo );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef _POWERMGM_H
|
||||
#define _POWERMGM_H
|
||||
|
||||
#include "TTGO.h"
|
||||
|
||||
#define POWERMGM_STANDBY _BV(0)
|
||||
#define POWERMGM_PMU_BUTTON _BV(1)
|
||||
#define POWERMGM_PMU_BATTERY _BV(2)
|
||||
|
||||
49
src/hardware/touch.cpp
Normal file
49
src/hardware/touch.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "config.h"
|
||||
#include "touch.h"
|
||||
|
||||
lv_indev_t *touch_indev = NULL;
|
||||
|
||||
static bool touch_read(lv_indev_drv_t * drv, lv_indev_data_t*data);
|
||||
static bool touch_getXY( int16_t &x, int16_t &y );
|
||||
|
||||
void touch_setup( TTGOClass *ttgo ) {
|
||||
touch_indev = lv_indev_get_next( NULL );
|
||||
|
||||
touch_indev->driver.read_cb = touch_read;
|
||||
}
|
||||
|
||||
static bool touch_getXY( int16_t &x, int16_t &y ) {
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
TP_Point p;
|
||||
|
||||
if ( !ttgo->touch->touched() ) {
|
||||
return false;
|
||||
}
|
||||
p = ttgo->touch->getPoint();
|
||||
|
||||
uint8_t rotation = ttgo->tft->getRotation();
|
||||
switch ( rotation ) {
|
||||
case 0:
|
||||
x = TFT_WIDTH - p.x;
|
||||
y = TFT_HEIGHT - p.y;
|
||||
break;
|
||||
case 1:
|
||||
x = TFT_WIDTH - p.y;
|
||||
y = p.x;
|
||||
break;
|
||||
case 3:
|
||||
x = p.y;
|
||||
y = TFT_HEIGHT - p.x;
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool touch_read(lv_indev_drv_t * drv, lv_indev_data_t*data) {
|
||||
data->state = touch_getXY(data->point.x, data->point.y) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
|
||||
return false;
|
||||
}
|
||||
9
src/hardware/touch.h
Normal file
9
src/hardware/touch.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _TOUCH_H
|
||||
|
||||
#define _TOUCH_H
|
||||
|
||||
#include "TTGO.h"
|
||||
|
||||
void touch_setup( TTGOClass *ttgo );
|
||||
|
||||
#endif // _TOUCH_H
|
||||
Reference in New Issue
Block a user