Browse Source

fix rotary sharing its pins

main
Hendrik Langer 7 years ago
parent
commit
764fd08528
  1. BIN
      alarm.mp3
  2. BIN
      alarm.wav
  3. 3
      platformio.ini
  4. 12
      src/hardware.h
  5. 9
      src/main.cpp
  6. 1
      src/main.h
  7. 10
      src/rotary.cpp
  8. 3
      src/screen.cpp

BIN
alarm.mp3

Binary file not shown.

BIN
alarm.wav

Binary file not shown.

3
platformio.ini

@ -15,7 +15,8 @@ board = heltec_wifi_lora_32
board_f_cpu = 240000000L
board_f_flash = 80000000L
framework = arduino
build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DDEBUG_INT_ALLOC_DECISIONS=1 -DCONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=y
build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DDEBUG_INT_ALLOC_DECISIONS=1
; -DCONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=y
lib_deps =
; Basecamp

12
src/hardware.h

@ -6,8 +6,8 @@
// KEY_BUILTIN = 0
static constexpr uint8_t buttonPin = 0;
static constexpr uint8_t sensorPin = 0;
static constexpr uint8_t rotaryPinA = 39;
static constexpr uint8_t rotaryPinB = 38;
static constexpr uint8_t rotaryPinA = 35;
static constexpr uint8_t rotaryPinB = 34;
static constexpr uint8_t rotaryPinButton = 2;
static constexpr uint8_t PROGMEM LED_PIN = 21;
static constexpr uint8_t PROGMEM NUM_LEDS = 10;
@ -34,10 +34,10 @@ static constexpr int batteryLimit = 2800;
* 3V3 O O 3V3
* GND O < 36 only input, no pullups
* RX * (3) < 37 only input, no pullups
* TX * (1) < 38 ROTARY_A only input, no pullups
* RST * BUTTON < 39 ROTARY_B only input, no pullups
* 0 * KEY_BUILTIN < 34 only input, no pullups
* 22 * ? < 35 only input, no pullups
* TX * (1) < 38 only input, no pullups
* RST * BUTTON hall < 39 only input, no pullups
* 0 * KEY_BUILTIN < 34 ROTARY_B only input, no pullups
* 22 * ? < 35 ROTARY_A only input, no pullups
* BME280_SDO 19 * LoRa_MISO ? * 32
* BME280_CS 23 * ? * 33
* 18 x LoRa_CS * 25 MAX98_DIN

9
src/main.cpp

@ -321,6 +321,14 @@ struct tm getAlarmTime() {
return alarmTime;
}
bool isAlarmActive(){
time_t now;
time(&now);
double seconds = difftime(now, mktime(&alarmTime));
if (seconds > -24*60*60 && seconds <=0) return true;
else return false;
}
void obtain_time(void) {
sntp_setoperatingmode(SNTP_OPMODE_POLL);
@ -348,6 +356,7 @@ void rotation(int i, int direction, int buttonPressed) {
}
if (direction == 1) screen->next();
else if (direction == -1) screen->previous();
Serial.println("rotation call returned");
}

1
src/main.h

@ -7,6 +7,7 @@ void suspend(uint32_t secondsToSleep);
void suspend();
void setAlarmTime(struct tm time);
struct tm getAlarmTime();
bool isAlarmActive();
void loop();
void rotation(int i, int direction, int buttonPressed);
void obtain_time(void);

10
src/rotary.cpp

@ -28,7 +28,7 @@ bool Rotary::begin(uint8_t pinA, uint8_t pinB, uint8_t pinButton) {
"encoderTask", /* String with name of task. */
2048, /* Stack size in words. */
this, /* Parameter passed as input of the task */
tskIDLE_PRIORITY+2, /* Priority of the task. */
tskIDLE_PRIORITY+1, /* Priority of the task. */
&taskHandle); /* Task handle. */
attachInterrupt(digitalPinToInterrupt(pinA), doEncoder, CHANGE);
@ -47,7 +47,8 @@ void Rotary::task(void *pvParameters) {
uint32_t ulNotificationValue;
while(true) {
ulNotificationValue = ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
delay(2); // wait until bounce settled
Serial.println("rotation task");
delay(1); // wait until bounce settled (1 or 2 is fine)
if (digitalRead(pinButton) == HIGH) {
buttonPressed = true;
@ -75,8 +76,9 @@ void Rotary::task(void *pvParameters) {
ulNotificationValue = ulTaskNotifyTake( pdTRUE, 0 ); // clear pending notifications
debouncePulses++;
if (debouncePulses > 3) { // update every 4 pulses
// debouncePulses++;
// if (debouncePulses > 3) { // update every 4 pulses
if (digitalRead(pinB) == HIGH && digitalRead(pinA) == HIGH) { // update everytime inbetween positions
debouncePulses = 0;
if (encoderPos > encoderPosOld+1) {
value++; // if the value has at least changed for 2

3
src/screen.cpp

@ -255,6 +255,9 @@ void MainScreen::draw() {
u8g2.drawStr(0, 20, timeStr);
u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font
u8g2.drawUTF8(0, 30, weatherStr);
if (isAlarmActive()) u8g2.drawUTF8(110,42, "A");
u8g2.setFont(u8g2_font_prospero_bold_nbp_tf); // choose a suitable font
u8g2_uint_t width = u8g2.getUTF8Width(titleStr); // calculate the pixel width of the text

Loading…
Cancel
Save