触摸屏调试通过
This commit is contained in:
parent
87309628fc
commit
41ca73cf74
19
NS2009.cpp
19
NS2009.cpp
@ -11,22 +11,19 @@ int Map_Data (int Data, int InMin, int InMax, int OutMin, int OutMax)
|
||||
return ((Data-InMin)*(OutMax-OutMin))/(InMax-InMin)+OutMin;
|
||||
}
|
||||
|
||||
NS2009::NS2009 (void)
|
||||
{
|
||||
NS2009::NS2009 (void) {
|
||||
Address = DEFAULT_NS2009_ADDR;
|
||||
FlipX = false;
|
||||
FlipY = false;
|
||||
}
|
||||
|
||||
NS2009::NS2009 (unsigned char _Address)
|
||||
{
|
||||
NS2009::NS2009 (unsigned char _Address) {
|
||||
Address = _Address;
|
||||
FlipX = false;
|
||||
FlipY = false;
|
||||
}
|
||||
|
||||
NS2009::NS2009 (bool _FlipX, bool _FlipY)
|
||||
{
|
||||
NS2009::NS2009 (bool _FlipX, bool _FlipY) {
|
||||
Address = DEFAULT_NS2009_ADDR;
|
||||
FlipX = _FlipX;
|
||||
FlipY = _FlipY;
|
||||
@ -44,11 +41,14 @@ unsigned int NS2009::ReadRegister (unsigned char Command)
|
||||
unsigned char ReadData[2], i=0;
|
||||
Wire.beginTransmission(Address);
|
||||
Wire.write(&Command, 1);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(Address, 2);
|
||||
while (Wire.available())
|
||||
while (i < 2){
|
||||
ReadData[i++] = Wire.read();
|
||||
}
|
||||
Wire.endTransmission();
|
||||
|
||||
return (ReadData[0] << 4) | (ReadData[1] >> 4);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void NS2009::Calibrate ()
|
||||
@ -97,8 +97,11 @@ void NS2009::Scan ()
|
||||
{
|
||||
CheckTouched ();
|
||||
RawX = ReadRegister(NS2009_READ_X);
|
||||
delay(1);
|
||||
X = Map_Data (RawX, MinX, MaxX, 0, SCREEN_SIZE_X);
|
||||
RawY = ReadRegister(NS2009_READ_Y);
|
||||
delay(1);
|
||||
|
||||
Y = Map_Data (RawY, MinY, MaxY, 0, SCREEN_SIZE_Y);
|
||||
if (FlipX)
|
||||
X = SCREEN_SIZE_X - X;
|
||||
|
@ -74,6 +74,7 @@ static bool jsonDocInitialised = false;
|
||||
static uint16_t chunkIndex;
|
||||
static uint32_t offsetIF; // IF frequency offset by half the bandwidth to position in the centre of the filter
|
||||
static uint32_t tgIF; // Track gen IF - SA IF plus any offset if both SI4432 defined
|
||||
pinMode (RF_SWITCH, OUTPUT);
|
||||
|
||||
|
||||
#ifdef RF_SWITCH
|
||||
|
@ -444,7 +444,6 @@ void setup()
|
||||
Wire.setPins(9,8);
|
||||
Wire.begin();
|
||||
Serial.begin ( 115200); // Start up the USB connection
|
||||
NS2009 TS; // address is the default one (0x48), no flip around X and Y axis
|
||||
|
||||
Serial.print("starrt init \r\n");
|
||||
bool fsStatus = false; // True if SPIFFS loads ok
|
||||
@ -476,6 +475,7 @@ void setup()
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* The touch screen needs to be calibrated. In previous versions, the instructions
|
||||
* were to un-comment the call to the "TouchCalibrate" here the first time you
|
||||
@ -497,17 +497,14 @@ void setup()
|
||||
#ifdef BACKLIGHT_LEVEL
|
||||
setUpLEDC(); // Set up the backlight control
|
||||
#endif
|
||||
|
||||
/*
|
||||
初始化ns2009配置
|
||||
*/
|
||||
Wire.beginTransmission(0x48);
|
||||
Wire.write(0x86);
|
||||
Wire.endTransmission();
|
||||
delay(4000);
|
||||
|
||||
while(1){
|
||||
TS.Scan ();
|
||||
if (TS.Touched)
|
||||
{
|
||||
Serial.printf("X=%3.d, RawX=%4d; Y=%3.d RawY=%4d\n\r", TS.X, TS.RawX, TS.Y, TS.RawY);
|
||||
delay (50);
|
||||
}
|
||||
delay (50);
|
||||
}
|
||||
/*
|
||||
* Display the splash screen:
|
||||
*/
|
||||
@ -537,6 +534,7 @@ void setup()
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Set the CS pins normally used for the SI4432 to high, so if present they do not interfere
|
||||
* with the bus signals
|
||||
|
17
ui.cpp
17
ui.cpp
@ -1010,20 +1010,27 @@ uint8_t getTouch ( uint16_t *x, uint16_t *y )
|
||||
return true; // Indicate touch is valid
|
||||
}
|
||||
|
||||
NS2009 Ts;
|
||||
|
||||
|
||||
static int touch_check ( void ) // Check for TS touched
|
||||
{
|
||||
uint16_t x = 0; // Used to store the "X" and
|
||||
uint16_t y = 0; // "Y" coordinates
|
||||
|
||||
int stat = getTouch ( &x, &y ); // Read the touch screen
|
||||
|
||||
Ts.Scan();
|
||||
|
||||
|
||||
// int stat = getTouch ( &x, &y ); // Read the touch screen
|
||||
|
||||
// Serial.printf ( "TouchCheck stat=%i, x=%i, y=%i \n", stat, x, y ); // Debugging
|
||||
|
||||
if ( stat ) // Valid touch if non-zero
|
||||
int stat = Ts.Touched;
|
||||
|
||||
if ( Ts.Touched ) // Valid touch if non-zero
|
||||
{
|
||||
last_touch_x = x; // Save coordinates for ???
|
||||
last_touch_y = y;
|
||||
last_touch_x = 320- Ts.Y; // Save coordinates for ???
|
||||
last_touch_y = 240 - Ts.X;
|
||||
}
|
||||
|
||||
if ( stat != last_touch_status ) // Did the status change?
|
||||
|
3
ui.h
3
ui.h
@ -8,7 +8,7 @@
|
||||
#include <Arduino.h> // Standard stuff
|
||||
#include "simpleSA.h" // General definitions for the program
|
||||
#include "preferences.h" // Things to save in flash memory
|
||||
|
||||
#include "ns2009.h"
|
||||
#ifndef _UI_H_
|
||||
#define _UI_H_ // Prevent double inclusion
|
||||
|
||||
@ -28,5 +28,6 @@
|
||||
|
||||
void UiProcessTouch ( void );
|
||||
void ShowSplash ( void );
|
||||
void touch_draw_test ( void );
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user