Skip to content

Commit

Permalink
v2.1.99.9 - update configuration file, new command for sub-system board.
Browse files Browse the repository at this point in the history
  • Loading branch information
Super169 committed Dec 19, 2018
1 parent 7ca1221 commit 25b4cb3
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 109 deletions.
Binary file modified info/Info.xlsx
Binary file not shown.
27 changes: 18 additions & 9 deletions lib/EventHandler/drivers/EdsPsxButton/EdsPsxButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ void EdsPsxButton::Initialize(EventData *data) {
}
*/

void EdsPsxButton::Setup(SSBoard *ssb) {
void EdsPsxButton::Setup(SSBoard *ssb, uint8_t normalCheckMs, uint8_t noEventMs, uint16_t ignoreRepeatMs) {
if (_dbg->require(110)) _dbg->log(110, 0, "EdsPsxButton::Setup(*ssb)");
_ssb = ssb;
_normalCheckMs = normalCheckMs;
_noEventMs = noEventMs;
_ignoreRepeatMs = ignoreRepeatMs;

// Check if device available

byte cmd[] = {0xA8, 0x8A, 0x02, 0x01, 0x03, 0xED};
Expand All @@ -35,7 +39,10 @@ bool EdsPsxButton::GetData() {
bool _prevDataRady = _lastDataReady;
_lastDataReady = false;

byte cmd[] = {0xA8, 0x8A, 0x02, 0x01, 0x03, 0xED};

// byte cmd[] = {0xA8, 0x8A, 0x02, 0x01, 0x03, 0xED};
byte cmd[] = { 0xA8, 0x8A, 0x07, 0x01, 0x00, 0x03, 0x2E, 0x01, 0x01, 0x3C, 0xED };

unsigned long startMs = millis();
if (!_ssb->SendCommand((byte *) cmd, true)) return false;

Expand All @@ -44,14 +51,15 @@ bool EdsPsxButton::GetData() {

Buffer *result = _ssb->ReturnBuffer();
// Data returned: A8 8A 0B 01 ?? ?? ?? {1} {2} ....
// New return: A8 8A 08 01 00 02 28 02 [ EF 00 ] 24 ED
uint16_t data;
byte *button = (byte *) &data;
button[0] = result->peek(8);
button[1] = result->peek(7);
button[0] = result->peek(9);
button[1] = result->peek(8);

// Due to the behavious of PSX control board, it will repeat the value within 1s
// Need to skip repeated value if handled
if (_prevDataRady && (_lastReportValue == data) && (_lastValueHandled) && ((millis() - _lastReportMS) < EPB_IGNORE_REPEAT_TIME)) {
if (_prevDataRady && (_lastReportValue == data) && (_lastValueHandled) && ((millis() - _lastReportMS) < _ignoreRepeatMs)) {
// ignore this value as it has just been handled
// _dbg->msg("PSX Button already handled: %d, %04X : %04X, %d, %ld", _prevDataRady, _lastReportValue, data, _lastValueHandled, millis() - _lastReportMS);
_lastDataReady = true;
Expand Down Expand Up @@ -81,14 +89,15 @@ void EdsPsxButton::PostHandler(bool eventMatched, bool isRelated, bool pending)
// wait longer if
// - button pressed, and no event required or handled: i.e. !eventMatched
if ((_lastDataReady) && (_lastReportValue != 0xFFFF) && ((!eventMatched) || (isRelated))) {
_nextReportMs = millis() + 100;
_nextReportMs = millis() + _noEventMs;
} else {
_nextReportMs = millis() + EDS_CONTINUE_CHECK_MS;
_nextReportMs = millis() + _normalCheckMs;
}
}

void EdsPsxButton::Shock() {
if (!IsAvailable()) return;
byte cmd[] = {0xA8, 0x8A, 0x02, 0x02, 0x04, 0xED};
_ssb->SendCommand((byte *) cmd, false);
// byte cmd[] = {0xA8, 0x8A, 0x02, 0x02, 0x04, 0xED};
byte cmd[] = {0xA8, 0x8A, 0x07, 0x01, 0x00, 0x03, 0x2E, 0x01, 0x01, 0x3C, 0xED};
_ssb->SendCommand((byte *) cmd, true);
}
25 changes: 22 additions & 3 deletions lib/EventHandler/drivers/EdsPsxButton/EdsPsxButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,49 @@
#include "SSBoard.h"

#define EPB_NO_BUTTON 0xFFFF
#define EPB_CONTINUE_CHECK_MS 20
#define EPB_IGNORE_REPEAT_TIME 200
// #define EPB_CONTINUE_CHECK_MS 20
// #define EPB_NO_EVENT_MS 100
// #define EPB_IGNORE_REPEAT_TIME 200

/*
* Event Data Source for PSX Button
*
* Get Data: send "A8 8A 02 01 03 ED" to bus
* wait for return "A8 8A 0B 01 -- -- -- ?? ?? -- -- -- -- -- ED"
*/
/*
* New sub-system board command:
*
* Get Data: A8 8A 06 01 00 02 28 02 33 ED
* Return: A8 8A 08 01 00 02 28 02 [ EF 00 ] 24 ED
* 0 1 2 3 4 5 6 7 8 9
*
*
* Shock: A8 8A 07 01 00 03 2E 01 01 3C ED
*
*
*/


class EdsPsxButton : public EventDataSource {
public:
EdsPsxButton(EventData *data, MyDebugger *dbg, byte devId = 0);
~EdsPsxButton();

// void Initialize(EventData *data) override;
void Setup(SSBoard *ssb);
void Setup(SSBoard *ssb, uint8_t normalCheckMs, uint8_t noEventMs, uint16_t ignoreRepeatMs);
bool GetData() override;
void PostHandler(bool eventMatched, bool isRelated, bool pending) override;
void Shock();

private:
SSBoard *_ssb;

uint8_t _normalCheckMs = 0;
uint8_t _noEventMs = 0;
uint16_t _ignoreRepeatMs = 0;


uint16_t _lastReportValue = 0;
};

Expand Down
109 changes: 29 additions & 80 deletions src/RobotConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void RobotConfig::initConfig() {
setTouch(DEFAULT_TOUCH_ENABLED, DEFAULT_TOUCH_DETECT_PERIOD, DEFAULT_TOUCH_RELEASE_PERIOD);
setMp3(DEFAULT_MP3_ENABLED, DEFAULT_MP3_VOLUME, DEFAULT_MP3_STARTUP);
setMpu(DEFAULT_MPU_ENABLED, DEFAULT_MPU_CHECK_FREQ, DEFAULT_MPU_POSITION_CHECK_FREQ);
setPsx(DEFAULT_PSX_ENABLED, DEFAULT_PSX_CHECK_MS, DEFAULT_PSX_IGNORE_REPEAT_MS);
setPsx(DEFAULT_PSX_ENABLED, DEFAULT_PSX_CHECK_MS, DEFAULT_PSX_NO_EVENT_MS, DEFAULT_PSX_IGNORE_REPEAT_MS, DEFAULT_PSX_SHOCK);

}

Expand Down Expand Up @@ -102,6 +102,13 @@ void RobotConfig::checkConversion() {

_data[RC_MPU_CHECK_FREQ] = _data[V0_MPU_CHECK_FREQ];
_data[RC_MPU_POSITION_CHECK_FREQ] = _data[V0_POSITION_CHECK_FREQ];

_data[RC_PSX_ENABLED] = DEFAULT_PSX_ENABLED;
_data[RC_PSX_CHECK_MS] = DEFAULT_PSX_CHECK_MS;
_data[RC_PSX_NO_EVENT_MS] = DEFAULT_PSX_NO_EVENT_MS;
setUint16_t(RC_PSX_IGNORE_REPEAT_MS, DEFAULT_PSX_IGNORE_REPEAT_MS);
_data[RC_PSX_SHOCK] = DEFAULT_PSX_SHOCK;

_data[RC_VERSION] = CURRENT_VERSION;
}
}
Expand All @@ -113,16 +120,17 @@ void RobotConfig::checkConfig() {
if (touchDetectPeriod() < MIN_TOUCH_PERIOD) setTouchDetectPeriod(DEFAULT_TOUCH_DETECT_PERIOD);
if (touchReleasePeriod() < MIN_TOUCH_PERIOD) setTouchReleasePeriod(DEFAULT_TOUCH_RELEASE_PERIOD);


// if (voltageAlarmInterval() < 10) setVoltageAlarmInterval(DEFAULT_ALARM_INTERVAL);

if ((mpuCheckFreq() < MIN_BATTERY_CHECK_FREQ) || (mpuCheckFreq() > MAX_BATTERY_CHECK_FREQ)) {
setMpuCheckFreq(DEFAULT_MPU_CHECK_FREQ);
}

if ((positionCheckFreq() < MIN_BATTERY_CHECK_FREQ) || (positionCheckFreq() > MAX_BATTERY_CHECK_FREQ)) {
if ((mpuPositionCheckFreq() < MIN_BATTERY_CHECK_FREQ) || (mpuPositionCheckFreq() > MAX_BATTERY_CHECK_FREQ)) {
setMpuPositionCheckFreq(DEFAULT_MPU_POSITION_CHECK_FREQ);
}

if (psxCheckMs() < MIN_PSX_MS) setPsxCheckMs(DEFAULT_PSX_CHECK_MS);
if (psxNoEventMs() < MIN_PSX_MS) setPsxNoEventMs(DEFAULT_PSX_NO_EVENT_MS);
if (psxIgnoreRepeatMs() < MIN_PSX_IGNORE_REPEAT_MS) setPsxIgnoreRepeatMs(DEFAULT_PSX_IGNORE_REPEAT_MS);

}

byte RobotConfig::writeConfig() {
Expand All @@ -149,7 +157,7 @@ byte RobotConfig::writeConfig() {

void RobotConfig::dumpConfig() {
if (_dbg == NULL) return;
_dbg->printf("\n\nRobot Config V%d:\n", _data[RC_VERSION]);
_dbg->printf("\n\nRobot Config v%d:\n", _data[RC_VERSION]);
_dbg->printf("Debug: %s\n", (enableDebug() ? "Enabled" : "Disabled"));
_dbg->printf("Maximum Servo: %d, Detection Retry: %d\n", maxServo(), maxDetectRetry());
_dbg->printf("Default command wait(ms): %d, Maximum Retry: %d\n", maxCommandWaitMs(), maxCommandRetry());
Expand All @@ -162,13 +170,13 @@ void RobotConfig::dumpConfig() {
_dbg->printf("Router: %s\n", (connectRouter() ? "Enabled" : "Disabled"));
_dbg->printf("OLED: %s\n", (enableOLED() ? "Enabled" : "Disabled"));
_dbg->printf("Touch Sensor: %s, Detect Period: %d, Release Period: %d\n",
(enableTouch() ? "Enabled" : "Disabled"), touchDetectPeriod(), touchReleasePeriod());
(touchEnabled() ? "Enabled" : "Disabled"), touchDetectPeriod(), touchReleasePeriod());

_dbg->printf("MPU6050: %s, Check Freq: %d, Position Confirm Freq: %d\n",
(enableMpu() ? "Enabled" : "Disabled"), mpuCheckFreq(), positionCheckFreq());
(mpuEnabled() ? "Enabled" : "Disabled"), mpuCheckFreq(), mpuPositionCheckFreq());

_dbg->printf("PSX Button: %s, Check Interval: %d, Ignore Repeat Interval: %d\n",
(enablePsxButton() ? "Enabled" : "Disabled"), psxCheckMs(), psxIgnoreRepeatMs());
_dbg->printf("PSX Button: %s, Check Interval: %d, No Event: %d, Ignore Repeat Interval: %d, shock: %s\n",
(psxEnabled() ? "Enabled" : "Disabled"), psxCheckMs(), psxNoEventMs(), psxIgnoreRepeatMs(),(psxShock() ? "Enabled" : "Disabled"));

_dbg->println();
}
Expand All @@ -191,34 +199,8 @@ bool RobotConfig::setOLED(bool value) {

bool RobotConfig::setTouchEnabled(bool value) {
_data[RC_TOUCH_ENABLED] = value;
return enableTouch();
}

/*
void RobotConfig::setTouchAction(uint8_t id, uint8_t value) {
if (id >= RC_TOUCH_ACTION_CNT) return;
_data[RC_TOUCH_ACTION + id] = value;
return touchEnabled();
}
*/

bool RobotConfig::enableTouch() {
if (!_data[RC_TOUCH_ENABLED]) return false;
return true; // For new event handler, touch enabled if events required.
/*
bool enabled = false;
for (uint8_t id = 0; id < RC_TOUCH_ACTION_CNT; id++) {
enabled |= _data[RC_TOUCH_ACTION + id];
}
return enabled;
*/
}

/*
uint8_t RobotConfig::touchAction(uint8_t id) {
if (id >= RC_TOUCH_ACTION_CNT) return DEFAULT_TOUCH_NO_ACTION;
return (_data[RC_TOUCH_ACTION + id]);
}
*/

void RobotConfig::setTouchDetectPeriod(uint16_t detectPeriod) {
setUint16_t(RC_TOUCH_DETECT_PERIOD, detectPeriod);
Expand Down Expand Up @@ -256,30 +238,6 @@ void RobotConfig::setBattery(uint16_t refVoltage, uint16_t minVoltage, uint16_t
setBatteryAlarmSec(alarmSec);
}


/*
void RobotConfig::setAlarmVoltage(uint16_t alarmVoltage) {
setUint16_t(RC_ALARM_VOLTAGE, alarmVoltage);
}
void RobotConfig::setVoltageAlarmMp3(uint8_t mp3) {
setUint16_t(RC_ALARM_MP3, mp3);
}
void RobotConfig::setVoltageAlarmInterval(uint8_t interval) {
setUint16_t(RC_ALARM_MP3, interval);
}
void RobotConfig::setVoltage(uint16_t refVoltage, uint16_t minVoltage, uint16_t maxVoltage, uint16_t alarmVoltage, uint8_t mp3, uint8_t interval) {
setBatteryRefVoltage(refVoltage);
setBatteryMinValue(minVoltage);
setBatteryMaxValue(maxVoltage);
setAlarmVoltage(alarmVoltage);
setVoltageAlarmMp3(mp3);
setVoltageAlarmInterval(interval);
};
*/

void RobotConfig::setMaxServo(uint8_t maxServo) {
_data[RC_MAX_SERVO] = maxServo;
}
Expand Down Expand Up @@ -312,20 +270,6 @@ void RobotConfig::setMpuEnabled(bool enabled) {
_data[RC_MPU_ENABLED] = enabled;
}

/*
void RobotConfig::setAutoStand(bool autoStand) {
_data[RC_AUTO_STAND] = autoStand;
}
void RobotConfig::setAutoFaceUp(uint8_t faceUp) {
_data[RC_AUTO_FACE_UP] = faceUp;
}
void RobotConfig::setAutoFaceDown(uint8_t faceDown) {
_data[RC_AUTO_FACE_DOWN] = faceDown;
}
*/

void RobotConfig::setMpuCheckFreq(uint8_t checkFreq) {
_data[RC_MPU_CHECK_FREQ] = checkFreq;
}
Expand All @@ -339,13 +283,18 @@ void RobotConfig::setPsxEnabled(bool enabled) {
_data[RC_PSX_ENABLED] = enabled;
}

void RobotConfig::setPsxCheckMs(uint16_t value) {
setUint16_t(RC_PSX_CHECK_MS, value);
void RobotConfig::setPsxCheckMs(uint8_t value) {
_data[RC_PSX_CHECK_MS] = value;
}

void RobotConfig::setPsxNoEventMs(uint8_t value) {
_data[RC_PSX_NO_EVENT_MS] = value;
}

void RobotConfig::setPsxIgnoreRepeatMs(uint16_t value) {
setUint16_t(RC_PSX_IGNORE_REPEAT_MS, value);
}



void RobotConfig::setPsxShock(bool enabled) {
_data[RC_PSX_SHOCK] = enabled;
}
27 changes: 19 additions & 8 deletions src/RobotConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@

#define DEFAULT_PSX_ENABLED false
#define DEFAULT_PSX_CHECK_MS 20
#define DEFAULT_PSX_NO_EVENT_MS 100
#define DEFAULT_PSX_IGNORE_REPEAT_MS 200

#define DEFAULT_PSX_SHOCK false
#define MIN_PSX_MS 10
#define MIN_PSX_IGNORE_REPEAT_MS 50

#define RC_RECORD_SIZE 60
#define RC_CONFIG_DATA_SIZE 56
Expand All @@ -77,7 +80,9 @@

#define RC_PSX_ENABLED 35 // V1: New
#define RC_PSX_CHECK_MS 36
#define RC_PSX_NO_EVENT_MS 37
#define RC_PSX_IGNORE_REPEAT_MS 38
#define RC_PSX_SHOCK 40

#define RC_MPU_ENABLED 41 // V1: Rename
#define RC_MPU_CHECK_FREQ 42 // V1: Moved from 52
Expand Down Expand Up @@ -159,19 +164,22 @@ class RobotConfig {
}

void setPsxEnabled(bool enabled);
void setPsxCheckMs(uint16_t value);
void setPsxCheckMs(uint8_t value);
void setPsxNoEventMs(uint8_t value);
void setPsxIgnoreRepeatMs(uint16_t value);
inline void setPsx(bool enablePsxButton, uint16_t psxCheckMs, uint16_t psxIgnoreRepeatMs) {
void setPsxShock(bool enabled);
inline void setPsx(bool enablePsxButton, uint8_t psxCheckMs, uint8_t psxNoEventMs, uint16_t psxIgnoreRepeatMs, bool psxShock) {
setPsxEnabled(enablePsxButton);
setPsxCheckMs(psxCheckMs);
setPsxNoEventMs(psxNoEventMs);
setPsxIgnoreRepeatMs(psxIgnoreRepeatMs);
setPsxShock(psxShock);
}


bool enableDebug() { return _data[RC_ENABLE_DEBUG]; }
bool connectRouter() { return _data[RC_CONNECT_ROUTER]; }
bool enableOLED() { return _data[RC_ENABLE_OLED]; }
bool enableTouch();
uint16_t batteryRefVoltage() { return getUint16_t(RC_BATTERY_REF_VOLTAGE); }
uint16_t batteryMinValue() { return getUint16_t(RC_BATTERY_MIN_VALUE); }
uint16_t batteryMaxValue() { return getUint16_t(RC_BATTERY_MAX_VALUE); }
Expand All @@ -187,16 +195,19 @@ class RobotConfig {
uint8_t mp3Volume() { return _data[RC_MP3_VOLUME]; }
uint8_t mp3Startup() { return _data[RC_MP3_STARTUP]; }

bool enableMpu() { return _data[RC_MPU_ENABLED]; }
bool mpuEnabled() { return _data[RC_MPU_ENABLED]; }
uint8_t mpuCheckFreq() { return _data[RC_MPU_CHECK_FREQ]; }
uint8_t positionCheckFreq() { return _data[RC_MPU_POSITION_CHECK_FREQ]; }
uint8_t mpuPositionCheckFreq() { return _data[RC_MPU_POSITION_CHECK_FREQ]; }

bool touchEnabled() { return _data[RC_TOUCH_ENABLED]; }
uint16_t touchDetectPeriod() { return getUint16_t(RC_TOUCH_DETECT_PERIOD); }
uint16_t touchReleasePeriod() { return getUint16_t(RC_TOUCH_RELEASE_PERIOD); }

bool enablePsxButton() { return _data[RC_PSX_ENABLED]; }
uint16_t psxCheckMs() { return getUint16_t(RC_PSX_CHECK_MS); }
bool psxEnabled() { return _data[RC_PSX_ENABLED]; }
uint8_t psxCheckMs() { return _data[RC_PSX_CHECK_MS]; }
uint8_t psxNoEventMs() { return _data[RC_PSX_NO_EVENT_MS]; }
uint16_t psxIgnoreRepeatMs() { return getUint16_t(RC_PSX_IGNORE_REPEAT_MS); }
bool psxShock() { return _data[RC_PSX_SHOCK]; }

private:
void initObject(HardwareSerial *hsDebug);
Expand Down
Loading

0 comments on commit 25b4cb3

Please sign in to comment.