Skip to content

Commit

Permalink
add testSensorPack
Browse files Browse the repository at this point in the history
  • Loading branch information
borntoleave committed Nov 7, 2023
1 parent 72604af commit b89a808
Show file tree
Hide file tree
Showing 16 changed files with 6,533 additions and 0 deletions.
2,601 changes: 2,601 additions & 0 deletions ModuleTests/testSensorPack/Adafruit_NeoPixel.cpp

Large diffs are not rendered by default.

366 changes: 366 additions & 0 deletions ModuleTests/testSensorPack/Adafruit_NeoPixel.h

Large diffs are not rendered by default.

443 changes: 443 additions & 0 deletions ModuleTests/testSensorPack/Arduino_APDS9960.cpp

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions ModuleTests/testSensorPack/Arduino_APDS9960.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
This file is part of the Arduino_APDS9960 library.
Copyright (c) 2019 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef ARDUINO_APDS9960
#define ARDUINO_APDS9960

#include <Arduino.h>
#include <Wire.h>

enum {
GESTURE_NONE = -1,
GESTURE_UP = 0,
GESTURE_DOWN = 1,
GESTURE_LEFT = 2,
GESTURE_RIGHT = 3
};

class APDS9960 {
public:
APDS9960(TwoWire &wire, int intPin);
virtual ~APDS9960();

bool begin();
void end();

int gestureAvailable();
int readGesture();

int colorAvailable();
bool readColor(int& r, int& g, int& b);
bool readColor(int& r, int& g, int& b, int& c);

int proximityAvailable();
int readProximity();

void setGestureSensitivity(uint8_t sensitivity);

void setInterruptPin(int pin);

bool setLEDBoost(uint8_t boost);

private:
bool setGestureIntEnable(bool en);
bool setGestureMode(bool en);
int gestureFIFOAvailable();
int handleGesture();

bool enablePower();
bool disablePower();
bool enableColor();
bool disableColor();
bool enableProximity();
bool disableProximity();
bool enableWait();
bool disableWait();
bool enableGesture();
bool disableGesture();

private:
TwoWire& _wire;
int _intPin;

bool _gestureEnabled;
bool _proximityEnabled;
bool _colorEnabled;
bool _gestureIn;
int _gestureDirectionX;
int _gestureDirectionY;
int _gestureDirInX;
int _gestureDirInY;
int _gestureSensitivity;
int _detectedGesture;

bool write(uint8_t val);
bool write(uint8_t reg, uint8_t val);
bool read(uint8_t reg, uint8_t *val);
size_t readBlock(uint8_t reg, uint8_t *val, unsigned int len);

private:
#define REG(name, addr) \
bool get##name(uint8_t *val) { return read(addr, val); } \
bool set##name(uint8_t val) { return write(addr, val); } \
size_t read##name(uint8_t *val, uint8_t len) { return readBlock(addr, val, len); }
REG(ENABLE, 0x80)
REG(ATIME, 0x81)
REG(WTIME, 0x83)
REG(AILTL, 0x84)
REG(AILTH, 0x85)
REG(AIHTL, 0x86)
REG(AIHTH, 0x87)
REG(PILT, 0x89)
REG(PIHT, 0x8B)
REG(PERS, 0x8C)
REG(CONFIG1, 0x8D)
REG(PPULSE, 0x8E)
REG(CONTROL, 0x8F)
REG(CONFIG2, 0x90)
REG(ID, 0x92)
REG(STATUS, 0x93)
REG(CDATAL, 0x94)
REG(CDATAH, 0x95)
REG(RDATAL, 0x96)
REG(RDATAH, 0x97)
REG(GDATAL, 0x98)
REG(GDATAH, 0x99)
REG(BDATAL, 0x9A)
REG(BDATAH, 0x9B)
REG(PDATA, 0x9C)
REG(POFFSET_UR, 0x9D)
REG(POFFSET_DL, 0x9E)
REG(CONFIG3, 0x9F)
REG(GPENTH, 0xA0)
REG(GEXTH, 0xA1)
REG(GCONF1, 0xA2)
REG(GCONF2, 0xA3)
REG(GOFFSET_U, 0xA4)
REG(GOFFSET_D, 0xA5)
REG(GPULSE, 0xA6)
REG(GOFFSET_L, 0xA7)
REG(GOFFSET_R, 0xA9)
REG(GCONF3, 0xAA)
REG(GCONF4, 0xAB)
REG(GFLVL, 0xAE)
REG(GSTATUS, 0xAF)
REG(IFORCE, 0xE4)
REG(PICLEAR, 0xE5)
REG(CICLEAR, 0xE6)
REG(AICLEAR, 0xE7)
REG(GFIFO_U, 0xFC)
REG(GFIFO_D, 0xFD)
REG(GFIFO_L, 0xFE)
REG(GFIFO_R, 0xFF)
};

extern APDS9960 APDS;

#endif // ARDUINO_APDS9960
162 changes: 162 additions & 0 deletions ModuleTests/testSensorPack/infrared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#define IR_PIN 4
#include "src/IRremote.h"

//#include <IRremote.h>
//The included library is identical to the IRremote library by shirriff, version 2.6.1
//Source: https://github.com/Arduino-IRremote/Arduino-IRremote
//Here, we include the decoding functions in our folder only to make it more convenient for newbie users
//All rights belong to the original author, and we follow the MIT license.
//You no longer need to modify ~/Documents/Arduino/libraries/src/IRremote/IRremote.h as mentioned in our old manual.
bool makeSound = false;
bool printValue = false;
IRrecv irrecv(IR_PIN);
decode_results results;
//abbreviation //gait/posture/function names
#define K00 "0" //rest and shutdown all servos
#define K01 "1" //forward
#define K02 "2" //turn off gyro feedback to boost speed

#define K10 "3" //left
#define K11 "4" //neutral stand up posture
#define K12 "5" //right

#define K20 "p" //pause motion and shut off all servos
#define K21 "B" //backward
#define K22 "c" //calibration mode with IMU turned off

#define K30 "vt" //stepping
#define K31 "cr" //crawl
#define K32 "wk" //walk

#define K40 "tr" //trot
#define K41 "sit" //sit
#define K42 "str" //stretch

#define K50 "Old" //greeting
#define K51 "pu" //push up
#define K52 "pee" //standng with three legs

#define K60 "New" //"lu" //look up
#define K61 "p" //butt up
#define K62 "s" //call your customized Newbility saved to PROGMEM
#define KREPEAT "!"

#define SHORT_ENCODING // activating this line will use a shorter encoding of the HEX values
String translateIR() // takes action based on IR code received
// describing Remote IR codes.
{
#ifndef SHORT_ENCODING
switch (results.value) {
//IR signal key on IR remote //key mapping
case 0xFFA25D: /*PTLF(" CH-"); */ return (F(K00));
case 0xFF629D: /*PTLF(" CH"); */ return (F(K01));
case 0xFFE21D: /*PTLF(" CH+"); */ return (F(K02));

case 0xFF22DD: /*PTLF(" |<<"); */ return (F(K10));
case 0xFF02FD: /*PTLF(" >>|"); */ return (F(K11));
case 0xFFC23D: /*PTLF(" >||"); */ return (F(K12));

case 0xFFE01F: /*PTLF(" -"); */ return (F(K20));
case 0xFFA857: /*PTLF(" +"); */ return (F(K21));
case 0xFF906F: /*PTLF(" EQ"); */ return (F(K22));

case 0xFF6897: /*PTLF(" 0"); */ return (F(K30));
case 0xFF9867: /*PTLF(" 100+"); */ return (F(K31));
case 0xFFB04F: /*PTLF(" 200+"); */ return (F(K32));

case 0xFF30CF: /*PTLF(" 1"); */ return (F(K40));
case 0xFF18E7: /*PTLF(" 2"); */ return (F(K41));
case 0xFF7A85: /*PTLF(" 3"); */ return (F(K42));

case 0xFF10EF: /*PTLF(" 4"); */ return (F(K50));
case 0xFF38C7: /*PTLF(" 5"); */ return (F(K51));
case 0xFF5AA5: /*PTLF(" 6"); */ return (F(K52));

case 0xFF42BD: /*PTLF(" 7"); */ return (F(K60));
case 0xFF4AB5: /*PTLF(" 8"); */ return (F(K61));
case 0xFF52AD: /*PTLF(" 9"); */ return (F(K62));

case 0xFFFFFFFF: return (F(KREPEAT)); //Serial.println(" REPEAT");
#else
uint8_t trimmed = (results.value >> 8);
switch (trimmed) {
//IR signal key on IR remote //key mapping
case 0xA2: /*PTLF(" CH-"); */ return (F(K00));
case 0x62: /*PTLF(" CH"); */ return (F(K01));
case 0xE2: /*PTLF(" CH+"); */ return (F(K02));

case 0x22: /*PTLF(" |<<"); */ return (F(K10));
case 0x02: /*PTLF(" >>|"); */ return (F(K11));
case 0xC2: /*PTLF(" >||"); */ return (F(K12));

case 0xE0: /*PTLF(" -"); */ return (F(K20));
case 0xA8: /*PTLF(" +"); */ return (F(K21));
case 0x90: /*PTLF(" EQ"); */ return (F(K22));

case 0x68: /*PTLF(" 0"); */ return (F(K30));
case 0x98: /*PTLF(" 100+"); */ return (F(K31));
case 0xB0: /*PTLF(" 200+"); */ return (F(K32));

case 0x30: /*PTLF(" 1"); */ return (F(K40));
case 0x18: /*PTLF(" 2"); */ return (F(K41));
case 0x7A: /*PTLF(" 3"); */ return (F(K42));

case 0x10: /*PTLF(" 4"); */ return (F(K50));
case 0x38: /*PTLF(" 5"); */ return (F(K51));
case 0x5A: /*PTLF(" 6"); */ return (F(K52));

case 0x42: /*PTLF(" 7"); */ return (F(K60));
case 0x4A: /*PTLF(" 8"); */ return (F(K61));
case 0x52: /*PTLF(" 9"); */ return (F(K62));

case 0x12: return ("ts"); //for factory use

case 0xFF: return (F(KREPEAT)); //Serial.println(" REPEAT");
#endif
default:
{
//Serial.println(results.value, HEX);
}
return ""; //Serial.println("null");
} // End Case
//delay(100); // Do not get immediate repeat //no need because the main loop is slow

// The control could be organized in another way, such as:
// forward/backward to change the gaits corresponding to different speeds.
// left/right key for turning left and right
// number keys for different postures or behaviors
}

String testCase[] = { "testTouch", "testI2Cdevice", "testLight", "testIrDistance", "testPIR", "testNoise" };

void read_infrared() {
if (irrecv.decode(&results)) {
Serial.println(instruction);
String value = translateIR();
if (value == "s") {
makeSound = !makeSound;
if (makeSound)
playMelody(soundOn, sizeof(soundOn) / 2);
else
playMelody(mute, sizeof(mute) / 2);
} else if (value == "p") {
printValue = !printValue;
if (printValue)
Serial.println("Print enabled");
else
Serial.println("Print disabled");
} else if (value == "New") {
compatible_3V = true;
Serial.println("New 3.3V");
} else if (value == "Old") {
compatible_3V = false;
Serial.println("Old 5V");
} else
testID = value[0] - '0' >= 0 && value[0] - '0' < 6 ? value[0] - '0' : testID;

Serial.print("Change mode ");
Serial.println(testCase[testID]);
irrecv.resume(); // receive the next value
}
delay(50);
}
Loading

0 comments on commit b89a808

Please sign in to comment.