Skip to content

Commit

Permalink
Add remote control support; etc. (v3.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
realA10001986 authored Sep 7, 2024
1 parent fbce020 commit a82b371
Show file tree
Hide file tree
Showing 15 changed files with 942 additions and 205 deletions.
4 changes: 2 additions & 2 deletions timecircuits-A10001986/gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ int16_t tcGPS::getSpeed()
if(_haveSpeed) {
#ifdef GPS_SPEED_SIMU
// Speed "simulator" for debugging
_speed = (79 + (rand() % 10));
if(_speed <= 80) _speed -= (79-8);
_speed = 66; //(79 + (rand() % 10));
//if(_speed <= 80) _speed -= (79-8);
#else
// Fake 1 and 2mph; GPS is not reliable at
// low speeds, need to ignore everything below
Expand Down
14 changes: 14 additions & 0 deletions timecircuits-A10001986/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,20 @@ void TCRotEnc::disabledPos()
fakeSpeed = -1;
}

// Init dec to speed position (speed only)
void TCRotEnc::speedPos(int16_t speed)
{
if(speed < 0) {
disabledPos();
return;
}

zeroEnc(speed);
rotEncPos = getEncPos();

fakeSpeed = targetSpeed = speed;
}

int16_t TCRotEnc::updateFakeSpeed(bool force)
{
bool timeout = (millis() - lastUpd > HWUPD_DELAY);
Expand Down
1 change: 1 addition & 0 deletions timecircuits-A10001986/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class TCRotEnc {
bool begin(bool forSpeed);
void zeroPos(int offs = 0);
void disabledPos();
void speedPos(int16_t speed);
int16_t updateFakeSpeed(bool force = false);
int updateVolume(int curVol, bool force = false);

Expand Down
19 changes: 18 additions & 1 deletion timecircuits-A10001986/rtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ void tcRTC::adjust(byte second, byte minute, byte hour, byte dayOfWeek, byte day
switch(_rtcType) {

case RTCT_PCF2129:
#ifdef HAVE_PCF2129
buffer[0] = PCF2129_TIME;
buffer[4] = bin2bcd(dayOfMonth);
buffer[5] = bin2bcd(dayOfWeek);
write_bytes(buffer, 8);

// OSF bit cleared by writing seconds
#endif
break;

case RTCT_DS3231:
Expand Down Expand Up @@ -190,13 +192,16 @@ void tcRTC::now(DateTime& dt)
switch(_rtcType) {

case RTCT_PCF2129:
#ifdef HAVE_PCF2129
read_bytes(PCF2129_TIME, buffer, 7);
dt.set(bcd2bin(buffer[6]) + 2000U,
bcd2bin(buffer[5] & 0x7F),
bcd2bin(buffer[3]),
bcd2bin(buffer[2]),
bcd2bin(buffer[1]),
bcd2bin(buffer[0] & 0x7F));
#endif
break;

case RTCT_DS3231:
default:
Expand All @@ -220,12 +225,14 @@ void tcRTC::clockOutEnable()
switch(_rtcType) {

case RTCT_PCF2129:
#ifdef HAVE_PCF2129
readValue = read_register(PCF2129_CLKCTRL);
// set squarewave to 1Hz
// Bits 2:0 - 110 sets 1Hz
readValue &= B11111000;
readValue |= B00000110;
write_register(PCF2129_CLKCTRL, readValue);
#endif
break;

case RTCT_DS3231:
Expand All @@ -245,12 +252,15 @@ void tcRTC::clockOutEnable()
*/
bool tcRTC::NeedOTPRefresh()
{
#ifdef HAVE_PCF2129
if(_rtcType == RTCT_PCF2129)
return true;

#endif

return false;
}

#ifdef HAVE_PCF2129
bool tcRTC::OTPRefresh(bool start)
{
uint8_t readValue = 0;
Expand All @@ -270,6 +280,7 @@ bool tcRTC::OTPRefresh(bool start)

return false;
}
#endif

/*
* Check if RTC is stopped due to power-loss
Expand All @@ -282,7 +293,11 @@ bool tcRTC::lostPower(void)
// Check Oscillator Stop Flag to see
// if RTC stopped due to power loss
// Only works before writing seconds
#ifdef HAVE_PCF2129
return read_register(PCF2129_TIME) >> 7;
#else
break;
#endif

case RTCT_DS3231:
default:
Expand All @@ -299,11 +314,13 @@ bool tcRTC::lostPower(void)
*/
bool tcRTC::battLow(void)
{
#ifdef HAVE_PCF2129
switch(_rtcType) {

case RTCT_PCF2129:
return (read_register(PCF2129_CTRL3) & 0x04) >> 2;
}
#endif

return false;
}
Expand Down
2 changes: 2 additions & 0 deletions timecircuits-A10001986/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ class tcRTC
void clockOutEnable();

bool NeedOTPRefresh();
#ifdef HAVE_PCF2129
bool OTPRefresh(bool start);
#endif

bool lostPower(void);
bool battLow(void);
Expand Down
5 changes: 5 additions & 0 deletions timecircuits-A10001986/speeddisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ void speedDisplay::off()
_onCache = 0;
}

bool speedDisplay::getOnOff()
{
return !!_onCache;
}

// Turn on all LEDs
#if 0
void speedDisplay::lampTest()
Expand Down
1 change: 1 addition & 0 deletions timecircuits-A10001986/speeddisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class speedDisplay {
bool begin(int dispType);
void on();
void off();
bool getOnOff();
#if 0
void lampTest();
#endif
Expand Down
15 changes: 8 additions & 7 deletions timecircuits-A10001986/tc_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ void audio_setup()
*
*/
void audio_loop()
{
{
float vol;

if(wav->isRunning()) {
if(!wav->loop()) {
wav->stop();
Expand Down Expand Up @@ -296,8 +296,9 @@ void play_file(const char *audio_file, uint16_t flags, float volumeFactor)
beepRunning = false;

#ifdef TC_HAVELINEOUT
playLineOut = (useLineOut && (flags & PA_LINEOUT)) ? true : false;
playLineOut = (haveLineOut && useLineOut && (flags & PA_LINEOUT)) ? true : false;
setLineOut(playLineOut);
if(playLineOut) flags &= ~PA_DYNVOL;
#else
playLineOut = false;
#endif
Expand Down Expand Up @@ -527,10 +528,10 @@ static float getVolume()
#ifdef TC_HAVELINEOUT
static void setLineOut(bool doLineOut)
{
if(useLineOut) {
// Mute/un-mute secondary DAC? No, for now.
//digitalWrite(MUTE_LINEOUT_PIN, doLineOut ? HIGH : LOW);
if(doLineOut) {
if(haveLineOut) {
if(useLineOut && doLineOut) {
// Mute/un-mute secondary DAC? No, for now.
//digitalWrite(MUTE_LINEOUT_PIN, doLineOut ? HIGH : LOW);
out->SetOutputModeMono(false);
// Switch off MAX98357, switch on PCM510x
digitalWrite(SWITCH_LINEOUT_PIN, HIGH);
Expand Down
26 changes: 17 additions & 9 deletions timecircuits-A10001986/tc_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

// These must not contain any characters other than
// '0'-'9', 'A'-'Z', '(', ')', '.', '_', '-' or space
#define TC_VERSION "V3.0.99" // 13 chars max
#define TC_VERSION "V3.1.0" // 13 chars max
#ifndef IS_ACAR_DISPLAY
#define TC_VERSION_EXTRA "JUN192024" // 13 chars max
#define TC_VERSION_EXTRA "SEP082024" // 13 chars max
#else // A-Car
#define TC_VERSION_EXTRA "06192024" // 12 chars max
#define TC_VERSION_EXTRA "09082024" // 12 chars max
#endif

//#define TC_DBG // debug output on Serial
Expand Down Expand Up @@ -82,6 +82,11 @@
// A secondary rotary encoder is used for audio volume.
#define TC_HAVE_RE

// Uncomment for Remote support
// "Remote" is a modified Futaba remote control with CS/A10001986 control board
// and the A10001986 "remote" firmware.
#define TC_HAVE_REMOTE

// Uncomment for support of a temperature/humidity sensor (MCP9808, BMx280,
// SI7021, SHT4x, TMP117, AHT20, HTU31D, MS8607) connected via i2c. Will be used
// for room condition mode and to display ambient temperature on speedometer
Expand Down Expand Up @@ -146,7 +151,7 @@
*** Miscellaneous ***
*************************************************************************/

// If this is uncommented, support for line-out audio (CB 1.4) is included.
// If this is uncommented, support for line-out audio (CB 1.4.5) is included.
// If enabled (350/351 on keypad), Time travel sounds as well as music from
// the Music Player will be played over line-out, and not the built-in speaker.
#define TC_HAVELINEOUT
Expand Down Expand Up @@ -179,6 +184,9 @@
// Use SPIFFS (if defined) or LittleFS (if undefined; esp32-arduino >= 2.x)
//#define USE_SPIFFS

// Uncomment for PCF2129 RTC chip support
//#define HAVE_PCF2129

// Custom stuff -----
#define TWSOUND // Use A10001986's sound files
//#define TWPRIVATE // A10001986's private customizations
Expand Down Expand Up @@ -216,7 +224,7 @@
*** GPIO pins ***
*************************************************************************/

#define STATUS_LED_PIN 2 // Status LED (on ESP) (TCD CB <V1.4)
#define STATUS_LED_PIN 2 // Status LED (on ESP) (unused on TCD CB <V1.4)
#define SECONDS_IN_PIN 15 // SQW Monitor 1Hz from the DS3231
#define ENTER_BUTTON_PIN 16 // enter key
#define WHITE_LED_PIN 17 // white led
Expand All @@ -234,11 +242,11 @@
#define SPI_SCK_PIN 18

#define VOLUME_PIN 32 // analog input pin (TCD CB <V1.4.5)
#define VOLUME_PIN_NEW 34 // analog input pin (TCD CB >=V1.4.5 preliminary)
#define VOLUME_PIN_NEW 34 // analog input pin (TCD CB >=V1.4.5)

#define MUTE_LINEOUT_PIN 2 // TCD CB >=1.4.5 (preliminary)
#define SWITCH_LINEOUT_PIN 32 // TCD CB >=1.4.5 (preliminary)
#define MLO_MIRROR 35 // TCD CB >=1.4.5 (preliminary)
#define MUTE_LINEOUT_PIN 2 // TCD CB >=1.4.5
#define SWITCH_LINEOUT_PIN 32 // TCD CB >=1.4.5
#define MLO_MIRROR 35 // TCD CB >=1.4.5

#define FAKE_POWER_BUTTON_PIN 13 // Fake "power" switch
#define EXTERNAL_TIMETRAVEL_IN_PIN 27 // Externally triggered TT (input)
Expand Down
17 changes: 16 additions & 1 deletion timecircuits-A10001986/tc_keypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ static void keypadEvent(char key, KeyState kstate)
case '6': // "6" held down -> play audio file "key6.mp3"
doKey = false;
keySnd[4] = key;
play_file(keySnd, PA_INTSPKR|PA_CHECKNM|PA_INTRMUS|PA_ALLOWSD|PA_DYNVOL);
play_file(keySnd, PA_LINEOUT|PA_CHECKNM|PA_INTRMUS|PA_ALLOWSD|PA_DYNVOL);
break;
case '7': // "7" held down -> re-enable/re-connect WiFi
doKey = false;
Expand Down Expand Up @@ -878,6 +878,17 @@ void keypad_loop()
}
validEntry = true;
break;
#ifdef TC_HAVE_REMOTE
case 992:
case 993:
rcModeState = remoteAllowed;
remoteAllowed = (code == 993);
if(rcModeState != remoteAllowed) {
saveRemoteAllowed();
}
validEntry = true;
break;
#endif
case 998:
if(timetravelPersistent) {
invalidEntry = true;
Expand Down Expand Up @@ -1039,6 +1050,7 @@ void keypad_loop()
(dateBuffer[0] == '3' ||
dateBuffer[0] == '5' ||
dateBuffer[0] == '6' ||
dateBuffer[0] == '7' ||
dateBuffer[0] == '8' ||
dateBuffer[0] == '9')) {

Expand All @@ -1057,6 +1069,9 @@ void keypad_loop()
case '6':
bttfnSendSIDCmd(cmd);
break;
case '7':
bttfnSendRemCmd(cmd);
break;
case '8':
bttfnSendVSRCmd(cmd);
break;
Expand Down
Loading

0 comments on commit a82b371

Please sign in to comment.