From 41ca73cf74f585f4c277cb00f411700a9990d53e Mon Sep 17 00:00:00 2001 From: caiyu <290198250@qq.com> Date: Sun, 23 Feb 2025 15:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A6=E6=91=B8=E5=B1=8F=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NS2009.cpp | 19 +++++++++++-------- SweepLo.ino | 1 + sketch_jan8a.ino | 20 +++++++++----------- ui.cpp | 17 ++++++++++++----- ui.h | 3 ++- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/NS2009.cpp b/NS2009.cpp index a38338a..0a99a03 100644 --- a/NS2009.cpp +++ b/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; diff --git a/SweepLo.ino b/SweepLo.ino index dcdcae2..7495437 100644 --- a/SweepLo.ino +++ b/SweepLo.ino @@ -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 diff --git a/sketch_jan8a.ino b/sketch_jan8a.ino index 51517bf..98ded66 100644 --- a/sketch_jan8a.ino +++ b/sketch_jan8a.ino @@ -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 diff --git a/ui.cpp b/ui.cpp index abc7fe3..d75dc2d 100644 --- a/ui.cpp +++ b/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? diff --git a/ui.h b/ui.h index c958f51..8a6566f 100644 --- a/ui.h +++ b/ui.h @@ -8,7 +8,7 @@ #include // 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