Skip to content

Commit 00d4fdd

Browse files
committed
Added Inkplate 4TEMPERA factory prog. and fixed some stuff in the driver
1 parent 52e9948 commit 00d4fdd

File tree

35 files changed

+880
-2993
lines changed

35 files changed

+880
-2993
lines changed

examples/Inkplate4TEMPERA/Advanced/Sensors/Inkplate4TEMPERA_Accelerometer_Gyroscope_Read/Inkplate4TEMPERA_Accelerometer_Gyroscope_Read.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ void setup()
6969
// In case of initialization failure, notify the user
7070
display.setCursor(50, 50);
7171
display.setFont();
72-
display.print("ERROR: can't init lsm6ds3!");
72+
display.print("ERROR: can't init LSM6DS3!");
73+
display.display();
7374

7475
// Go to sleep
7576
esp_deep_sleep_start();

examples/Inkplate4TEMPERA/Basic/Inkplate4TEMPERA_Black_And_White/Inkplate4TEMPERA_Black_And_White.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void setup()
397397
display.clearDisplay(); // Clear any data that may have been in (software) frame buffer.
398398
//(NOTE! This does not clean image on screen, it only clears it in the frame buffer inside ESP32).
399399
display.display(); // Clear everything that has previously been on a screen
400-
display.setCursor(70, 300);
400+
display.setCursor(40, 300);
401401
display.setTextSize(3);
402402
display.print("Welcome to Inkplate 4TEMPERA!");
403403
display.display(); // Write hello message

examples/Inkplate4TEMPERA/Diagnostics/Inkplate4TEMPERA_Factory_Programming_VCOM/Inkplate4TEMPERA_Factory_Programming_VCOM.ino

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
* Tests will also be done, to pass all tests:
1515
* - Edit the WiFi information in test.cpp.
1616
* - Connect a slave device via EasyC on address 0x30 (you may change this in test.cpp also).
17-
* In the InkplateEasyCTester folder, you can find the code for uploading to Dasduino Core
17+
* In the InkplateEasyCTester folder, you can find the code for uploading to Dasduino Core
1818
* or Dasduino ConnectPlus to convert Dasduino to an I2C slave device for testing an easyC connector
1919
* if you don't have a device with address 0x30.
20-
* - For testing the fuel gauge, connect a battery and edit it's mAh capacity in test.cpp
20+
* - If a battery's connected, edit the mAh capacity in test.cpp
2121
* - Insert a formatted microSD card (doesn't have to be empty)
2222
* - When prompted:
23+
* - Touch the corner
2324
* - Wave in front of the gesture sensor
24-
* - Shake the device
25-
* - Tap the touchscreen
2625
* - Press wake button to finish testing
2726
*
2827
*License v3.0: https://www.gnu.org/licenses/lgpl-3.0.en.html Please review the
@@ -45,8 +44,8 @@
4544

4645
// Include our functions and image
4746
#include "Peripheral.h"
48-
#include "test.h"
4947
#include "demo_image.h"
48+
#include "test.h"
5049

5150
// Create object on Inkplate library and set library to work in monochorme mode
5251
Inkplate display(INKPLATE_1BIT);
@@ -137,9 +136,9 @@ void setup()
137136

138137
void loop()
139138
{
140-
// Peripheral mode
139+
// Peripheral mode
141140
// More about peripheral mode: https://inkplate.readthedocs.io/en/latest/peripheral-mode.html
142-
141+
143142
if (Serial.available())
144143
{
145144
while (Serial.available())

examples/Inkplate4TEMPERA/Diagnostics/Inkplate4TEMPERA_Factory_Programming_VCOM/Peripheral.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,4 +629,5 @@ void run(char commandBuffer[], size_t n, Inkplate *display)
629629
*s = 0;
630630
*e = 0;
631631
}
632-
}
632+
}
633+
}

examples/Inkplate4TEMPERA/Diagnostics/Inkplate4TEMPERA_Factory_Programming_VCOM/test.cpp

Lines changed: 84 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ const uint8_t easyCDeviceAddress = 0x30;
1212
const int TOUCHSCREEN_TIMEOUT = 30;
1313
const int GESTURE_TIMEOUT = 30;
1414

15+
// If you're testing with a battery:
1516
// Change this to the battery you're using to test the device
1617
int batteryCapacity = 600;
1718

1819
// Short way to add a margin to move the print from the left edge
1920
#define ADD_PRINT_MARGIN display.print(" ");
2021

22+
// The flag which is set when the APDS interrupt is tested
23+
volatile bool apdsIntFlag = false;
24+
2125
void testPeripheral()
2226
{
2327
// Set display for test report
@@ -34,6 +38,7 @@ void testPeripheral()
3438
if (!(Wire.endTransmission() == 0) ||
3539
(display.readPowerGood() != PWR_GOOD_OK)) // Check if there was an error in communication
3640
{
41+
// Notify over Serial because the TPS doesn't work
3742
Serial.println("- TPS Fail!");
3843
failHandler();
3944
}
@@ -68,8 +73,8 @@ void testPeripheral()
6873

6974
// Try to communicate with I/O expander
7075
Wire.beginTransmission(IO_EXT_ADDR);
71-
if (Wire.endTransmission() ==
72-
0) // Check if there was an error in communication and print out the results on display.
76+
// Check if there was an error in communication and print out the results on display.
77+
if (Wire.endTransmission() == 0)
7378
{
7479
display.println("OK");
7580
display.partialUpdate(0, 1);
@@ -85,13 +90,13 @@ void testPeripheral()
8590
display.frontlight(true); // Enable frontlight circuit
8691
display.setFrontlight(63); // Set frontlight intensity to the max.
8792
ADD_PRINT_MARGIN
88-
display.println("- Frontlight test (visual check)*");
93+
display.println("- Frontlight test (visual check)");
8994
display.partialUpdate(0, 1);
9095
delay(1000);
9196

9297
// Check the touchscreen (init and touch)
9398
ADD_PRINT_MARGIN
94-
display.print("- Touchscreen init*: ");
99+
display.print("- Touchscreen init: ");
95100
display.partialUpdate(0, 1);
96101
if (checkTouch(TOUCHSCREEN_TIMEOUT))
97102
{
@@ -106,7 +111,7 @@ void testPeripheral()
106111

107112
// Check the micro SD card
108113
ADD_PRINT_MARGIN
109-
display.print("- microSD card slot:* ");
114+
display.print("- microSD card slot: ");
110115
display.partialUpdate(0, 1);
111116
if (checkMicroSDCard())
112117
{
@@ -164,22 +169,16 @@ void testPeripheral()
164169
failHandler();
165170
}
166171

167-
// Check battery
168-
float batteryVoltage = 0;
172+
// Check Temperature via TPS
169173
float temperature = 0;
170174
ADD_PRINT_MARGIN
171-
display.print("- Battery and temperature: ");
175+
display.print("- Temperature: ");
172176
display.partialUpdate(0, 1);
173-
if (checkBatteryAndTemp(&temperature, &batteryVoltage))
177+
if (checkTemp(&temperature))
174178
{
175179
display.println("OK");
176180
ADD_PRINT_MARGIN
177181
ADD_PRINT_MARGIN
178-
display.print("- Battery voltage: ");
179-
display.print(batteryVoltage);
180-
display.println("V");
181-
ADD_PRINT_MARGIN
182-
ADD_PRINT_MARGIN
183182
display.print("- Temperature: ");
184183
display.print(temperature);
185184
display.println("c");
@@ -253,7 +252,7 @@ void testPeripheral()
253252

254253
float gyroAccX, gyroAccY, gyroAccZ;
255254
ADD_PRINT_MARGIN
256-
display.print("- Check Gyroscope*: ");
255+
display.print("- Check Gyroscope: ");
257256
display.partialUpdate(0, 1);
258257
if (checkGyroscope(&gyroAccX, &gyroAccY, &gyroAccZ))
259258
{
@@ -290,9 +289,14 @@ void testPeripheral()
290289
ADD_PRINT_MARGIN
291290
display.print("- Check gesture sensor (swipe, 30s): ");
292291
display.partialUpdate(0, 1);
293-
if (checkGestureSensor(GESTURE_TIMEOUT))
292+
String gesture = " ";
293+
if (checkGestureSensor(GESTURE_TIMEOUT, &gesture))
294294
{
295295
display.println("OK");
296+
ADD_PRINT_MARGIN
297+
ADD_PRINT_MARGIN
298+
display.print("- Gesture: ");
299+
display.println(gesture);
296300
}
297301
else
298302
{
@@ -414,16 +418,14 @@ int checkI2C(int address)
414418
}
415419
}
416420

417-
int checkBatteryAndTemp(float *temp, float *batVoltage)
421+
int checkTemp(float *temp)
418422
{
419423
int temperature;
420424
float voltage;
421425
int result = 1;
422426

423427
temperature = display.readTemperature();
424-
voltage = display.readBattery();
425428
*temp = temperature;
426-
*batVoltage = voltage;
427429

428430
// Check the temperature sensor of the TPS65186.
429431
// If the result is -10 or +85, something is wrong.
@@ -432,13 +434,6 @@ int checkBatteryAndTemp(float *temp, float *batVoltage)
432434
result = 0;
433435
}
434436

435-
// Check the battery voltage.
436-
// If the measured voltage is below 2.8V and above 4.6V, charger is dead.
437-
if (voltage <= 2.8 || voltage >= 4.6)
438-
{
439-
result = 0;
440-
}
441-
442437
return result;
443438
}
444439

@@ -486,7 +481,7 @@ int checkTouch(uint8_t _tsTimeout)
486481
}
487482

488483
// Now wait for the touch
489-
display.print("OK");
484+
display.println("OK");
490485
ADD_PRINT_MARGIN
491486
display.print("Touch the corner (30s): ");
492487
display.drawRect(400, 0, 200, 200, BLACK);
@@ -503,7 +498,7 @@ int checkTouch(uint8_t _tsTimeout)
503498
// See how many fingers are detected (max 2) and copy x and y position of each finger on touchscreen
504499
n = display.tsGetData(x, y);
505500

506-
if ((x[0] > 900) && (x[0] < 1024) && (y[0] > 0) && (y[0] < 124))
501+
if ((x[0] > 400) && (x[0] < 600) && (y[0] > 0) && (y[0] < 200))
507502
return 1;
508503
}
509504
}
@@ -581,51 +576,58 @@ void checkBuzzer()
581576
delay(100);
582577
}
583578

584-
int checkGestureSensor(int _gestTimeout)
579+
int checkGestureSensor(int _gestTimeout, String * gesture)
585580
{
586-
// Init and save result
587-
int beginResult = display.apds9960.begin();
588-
if (beginResult == 0)
589-
return 0;
581+
// Init APDS and enable the gesture sensor
582+
display.apds9960.init();
583+
display.apds9960.enableGestureSensor(true);
590584

591-
// Wait 30 seconds to detect touch in specified area, otherwise return 0 (error).
592-
unsigned long _timeout = millis();
585+
unsigned long _timeout;
586+
_timeout = millis();
587+
588+
// Set the interrupt chain from the APDS, to the GPIO expander to the ESP32
589+
display.pinModeIO(9, INPUT_PULLUP, IO_INT_ADDR);
590+
display.setIntPin(9, IO_INT_ADDR);
591+
pinMode(GPIO_NUM_34, INPUT);
592+
attachInterrupt(GPIO_NUM_34, ISR, FALLING);
593+
594+
// Wait 30 seconds to detect gesture
593595
while (((unsigned long)(millis() - _timeout)) < (_gestTimeout * 1000UL))
594596
{
595-
if (display.apds9960.gestureAvailable())
597+
// If the APDS interrupt was read
598+
if (apdsIntFlag)
596599
{
597-
// a gesture was detected, read and print to Serial Monitor
598-
int gesture = display.apds9960.readGesture();
599-
ADD_PRINT_MARGIN
600-
ADD_PRINT_MARGIN
601-
switch (gesture) // Determine which gesture was captured
600+
// Get the gesture
601+
if (display.apds9960.isGestureAvailable())
602602
{
603-
case GESTURE_UP:
604-
display.println("- UP detected!");
605-
break;
606-
607-
case GESTURE_DOWN:
608-
display.println("- DOWN detected!");
609-
break;
610-
611-
case GESTURE_LEFT:
612-
display.println("- LEFT detected!");
613-
break;
614-
615-
case GESTURE_RIGHT:
616-
display.println("- RIGHT detected!");
617-
break;
618-
619-
default:
620-
// ignore
621-
break;
603+
switch (display.apds9960.readGesture())
604+
{
605+
// Return the gesture value depending which gesture was made
606+
case DIR_UP:
607+
* gesture = "UP";
608+
break;
609+
case DIR_DOWN:
610+
* gesture = "DOWN";
611+
break;
612+
case DIR_LEFT:
613+
* gesture = "LEFT";
614+
break;
615+
case DIR_RIGHT:
616+
* gesture = "RIGHT";
617+
break;
618+
case DIR_NEAR:
619+
* gesture = "NEAR";
620+
break;
621+
case DIR_FAR:
622+
* gesture = "FAR";
623+
break;
624+
default:
625+
* gesture = "NONE";
626+
}
627+
return 1;
622628
}
623-
624-
return 1;
625629
}
626630
}
627-
628-
// We got here? Timeout was reached
629631
return 0;
630632
}
631633

@@ -634,21 +636,27 @@ int checkGyroscope(float *acX, float *acY, float *acZ)
634636
// This actually returns 0 on success
635637
int beginResult = display.lsm6ds3.begin();
636638

637-
float accelX = display.lsm6ds3.readFloatAccelX();
638-
float accelY = display.lsm6ds3.readFloatAccelY();
639-
float accelZ = display.lsm6ds3.readFloatAccelZ();
639+
// Multiply by 9.81 to get m/s^2
640+
float accelX = display.lsm6ds3.readFloatAccelX() * 9.81;
641+
float accelY = display.lsm6ds3.readFloatAccelY() * 9.81;
642+
float accelZ = display.lsm6ds3.readFloatAccelZ() * 9.81;
643+
644+
float gyroX = display.lsm6ds3.readFloatGyroX();
645+
float gyroY = display.lsm6ds3.readFloatGyroY();
646+
float gyroZ = display.lsm6ds3.readFloatGyroZ();
640647

641648
// Let's calculate the total magnitude of the readings
642649
float magnitude = sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ);
643-
// This should be approx 9.81, allow for some margin of error
650+
651+
// This should be approx 9.81, allow for some margin of error
644652
if (magnitude <= 8.5 || magnitude > 10.8)
645653
return 0;
646654

647-
// Also save via pointer
655+
// Also save accel values via pointer
648656
*acX = accelX;
649657
*acY = accelY;
650658
*acZ = accelZ;
651-
659+
652660
// On success of begin, 0 is returned
653661
// In our case, 1 is a success, so flip it
654662
if (beginResult == 0)
@@ -667,4 +675,10 @@ void failHandler()
667675
// Inf. loop... halt the program!
668676
while (true)
669677
delay(1000);
678+
}
679+
680+
// The ISR which tests the interrupt from the gesture sensor
681+
void IRAM_ATTR ISR()
682+
{
683+
apdsIntFlag = true;
670684
}

examples/Inkplate4TEMPERA/Diagnostics/Inkplate4TEMPERA_Factory_Programming_VCOM/test.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ int checkWiFi(const char *_ssid, const char *_pass, uint8_t _wifiTimeout);
2020
int checkMicroSDCard();
2121
int rtcCheck();
2222
int checkI2C(int address);
23-
int checkBatteryAndTemp(float *temp, float *batVoltage);
23+
int checkTemp(float *temp);
2424
int touchPads(uint8_t _timeoutTouchpads);
2525
int checkTouch(uint8_t _tsTimeout);
2626
int checkBME(float * bmeTemp, float * bmeHumidity, float * bmePres);
2727
int checkFuelGauge(int *_soc, int *_volts, int *_current);
28-
int checkGestureSensor(int _gestTimeout);
28+
int checkGestureSensor(int _gestTimeout, String * gesture);
2929
int checkGyroscope(float * acX, float * acY, float * acZ);
3030
void checkBuzzer();
3131
void failHandler();
32+
void IRAM_ATTR ISR();
3233

3334
#endif

examples/Inkplate4TEMPERA/Projects/Inkplate4TEMPERA_Image_Frame_Gesture/Inkplate4TEMPERA_Image_Frame_Gesture.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void setup()
8686
// Make sure gesture is at lowest sensitivity so it doesn't accidentially get triggered
8787
display.apds9960.setGestureGain(0);
8888

89-
// Get the file count and file dir indexes and save them to RTC memory
89+
// Get the file count and file indexes in the directory and save them to RTC memory
9090
getFileCount();
9191

9292
// Remember that this config was completed

0 commit comments

Comments
 (0)