Skip to content

Commit

Permalink
bug fix + platformio migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Tack committed Feb 20, 2023
1 parent 590decb commit 9a72751
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 16 deletions.
10 changes: 10 additions & 0 deletions Firmware/platformio/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
39 changes: 39 additions & 0 deletions Firmware/platformio/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions Firmware/platformio/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
4 changes: 4 additions & 0 deletions Firmware/platformio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

; PlatformIO uses [framework-arduino-avr-attiny](https://github.com/SpenceKonde/ATTinyCore)
; More development info to be found on https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/extras/ATtiny_x5.md


[env:attiny45]
platform = atmelavr
board = attiny45
Expand Down
6 changes: 6 additions & 0 deletions Firmware/platformio/src/pins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "Arduino.h"

const int PIN_DTMF_OUT = 0; // ATtiny45.pin5
const int PIN_MODE_SELECT = 2; // ATtiny45.pin7
61 changes: 45 additions & 16 deletions Firmware/platformio/src/pulse-dtmf-converter.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
#include "dtmfgenerator.h"
#include "rotarydialer.h"
/*
pulse-dtmf-converter: application to converted pulse-dialing to DTMF-tones
Copyright (C) 2018 Christoph Tack
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* By pulling pin 7 of the ATtiny45, you can select to send a dtmf tone after each digit, or send them all at once after the last digit has been dialed.
* 0: (pin 7 = LOW) - tone after each digit
* 1: (pin 7 HIGH, default) gather all digits then send tones
*/

/*
2023-02-20 Christoph Tack :
* Correcting buffer size of pulseBuffer. It overflowed the amount of RAM
* Turn the amount of time between last dialed digit and start of DTMF-sequence into a configurable constant.
* Migrate toolchain to PlatformIO. (build succeeds, but not tested onto the target). The header files have been left in the src folder for ease of use for people using the Arduino IDE.
*/

#include <avr/power.h>
#include <avr/sleep.h>
#include "dtmfgenerator.h"
#include "rotarydialer.h"
#include "pins.h"

DtmfGenerator dtmf;
RotaryDialer rd(0); // pin5
RotaryDialer rd(PIN_DTMF_OUT);

const int modePin = 2; // pin7

int mode = 1; // 0: (modePin LOW) original - tone after each digit
// 1: (modePin HIGH) gather all digits then send tones
const bool REVERSE_DIAL_MODE = false; // set to true for reverse dial systems (e.g. in use on New-Zealand)
const bool REVERSE_DIAL_MODE = false; // set to true for reverse dial systems (e.g. in use on New-Zealand)
const int DTMF_DELAY_AFTER_LAST_DIALED_DIGIT_ms = 1200; //wait this after last dialed digit before sending DTMF sequence.
const int MAX_NR_OF_DIALED_DIGITS = 15; //your longest phone number should be shorter than this value.

unsigned long lastUpdate = 0;
byte pulsesCtr = 0;
byte pulsesBuffer[200];
byte pulsesBuffer[MAX_NR_OF_DIALED_DIGITS];
int mode = 0; // select when to send DTMF tones (see explanation above)


void setup()
{
pinMode(modePin, INPUT_PULLUP);
if (digitalRead(modePin) == LOW)
{
mode = 0;
}
pinMode(PIN_MODE_SELECT, INPUT_PULLUP);
mode = digitalRead(PIN_MODE_SELECT) == LOW ? 0 : 1;

reducePower();
dtmf.init();
Expand Down Expand Up @@ -61,10 +90,10 @@ void loop()
}
else
{
if (rd.available())
if (rd.available() && pulsesCtr < MAX_NR_OF_DIALED_DIGITS)
{
pulsesBuffer[pulsesCtr++] = rd.readPulses();
lastUpdate = millis() + 3000;
lastUpdate = millis() + DTMF_DELAY_AFTER_LAST_DIALED_DIGIT_ms;
}
if ((pulsesCtr > 0) && (millis() > lastUpdate))
{
Expand Down
11 changes: 11 additions & 0 deletions Firmware/platformio/test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

This directory is intended for PlatformIO Test Runner and project tests.

Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.

More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
Binary file added Hardware/Gerber_BRD170127R1.zip
Binary file not shown.
Binary file added Hardware/Schematic_BRD170127R1.pdf
Binary file not shown.

0 comments on commit 9a72751

Please sign in to comment.