Transférer les fichiers vers 'offok'

Minimisation de l'empreinte mémoire de travail suite à des l'affichage de réceptions, sans émission infrarouge.
Réglage des temporisations d'affichage.
Correctif moche pour gérer la compilation avec ou sans sonorisation activée.
This commit is contained in:
JeArz 2021-10-08 07:07:10 +02:00
parent cc0516d52c
commit fdf5be3b2d
1 changed files with 48 additions and 28 deletions

View File

@ -5,12 +5,13 @@
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* /*
This gets IR codes send by a TvBeGone & displays results on OLED This gets IR codes send by a TvBeGone & displays results on OLED
02/14/21: First proof of IR sensor & Oled 02/14/21: First proof of IR sensor & Oled on UNO
02/17/21: Moved to new lib U8g2lib, works OK on UNO 02/17/21: Updated to new lib U8g2lib, works OK on UNO
04/05/21: OK on NANO 04/05/21: works OK on NANO
04/22/21: new logo, display hex code, test piezo OK 04/22/21: new logo, display hex code, test piezo OK
05/19/21: added offok_tunes.h for rtttl libraries & ringtones 05/19/21: added offok_tunes.h for rtttl libraries & ringtones
logo.h renamed to offok_logo.h logo.h renamed to offok_logo.h
10/08/21: enun t_tune for calls of play_r3tl for when SOUND is OFF
TODO: adjust parameters, use protothreads ? TODO: adjust parameters, use protothreads ?
*/ */
#include <Arduino.h> #include <Arduino.h>
@ -34,29 +35,46 @@ U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2\
/* the function tone() uses timer2 by default, so does IRremote lib. /* the function tone() uses timer2 by default, so does IRremote lib.
* File IRremoteBoardDefs.h, in lib IRremote define wich timer to use */ * File IRremoteBoardDefs.h, in lib IRremote define wich timer to use */
// #define IR_USE_TIMER1 // use Timer 1 instead of Timer 2 // #define IR_USE_TIMER1 // use Timer 1 instead of Timer 2
const int RECV_PIN = 2; #define NBCODES 120 // min number of codes to qualify a kit
#define ACQUINONE 3000 // no IR signal timeout in millisecond
const int RECV_PIN = 2; // IR receiver signal pin
IRrecv irrecv(RECV_PIN); IRrecv irrecv(RECV_PIN);
decode_results results; decode_results results;
/* /*
* Sound settings * Sound settings
*/ */
#define PIEZO 7 // Loudspeaker pin #define SOUND_ON // comment if you can't stand the noise !
enum t_tune {NoTone, Intro, CountOK, CountKO, GetIR };
#ifdef SOUND_ON
#define PIEZO 7 // Loudspeaker pin
#include "offok_tunes.h" // predefined ringtones juke-box :-) #include "offok_tunes.h" // predefined ringtones juke-box :-)
#endif
//#define DEBUG //#define DEBUG
#define SOUND_ON // comment if you can't stand
#define NBCODES 120 // min number of codes to qualify a kit
#define ACQUINONE 4000 // no IR signal timeout in millisecond
// ==================== Functions ==================== // ==================== Functions ====================
void showTrace(); // defined after main ifdef DEBUG void showTrace(); // defined after main ifdef DEBUG
void showCount(int val) ; // defined after main not used anymore void showCount(int val) ; // defined after main not used anymore
// play a rtttl ringtone definef in offok_tunes.h // play a rtttl ringtone defined in offok_tunes.h
void play_r3tl (const char * rtune){ void play_r3tl (t_tune itune){
char * rtune;
#ifdef SOUND_ON #ifdef SOUND_ON
switch (itune) { // ugly code to manage SOUND off
case NoTone : noTone(PIEZO);
return;
case Intro : rtune = _rIntro_ ;
break;
case CountOK : rtune = _rCountOK_ ;
break;
case CountKO : rtune = _rCountKO_ ;
break;
case GetIR : rtune = _rGetIR_ ;
break;
default : rtune = _rCountOK2_;
}
anyrtttl::blocking::play(PIEZO, rtune); anyrtttl::blocking::play(PIEZO, rtune);
#endif #endif // else: do nothing when ! SOUND_OFF
} }
void drawLogo(void) { // draw the logo screen void drawLogo(void) { // draw the logo screen
u8g2.firstPage(); u8g2.firstPage();
@ -65,18 +83,18 @@ void drawLogo(void) { // draw the logo screen
} while ( u8g2.nextPage() ); } while ( u8g2.nextPage() );
} }
// Oled brightness dimmer, slope up or down // Oled brightness dimmer, slope up or down
void constratSlope(int depart, int aim, int inc, int lag) { void contrastSlope(int depart, int aim, int inc, int lag) {
int i=depart; int i=depart;
// at first, if increasing then // at first, if increasing then
if (inc > 0) u8g2.setPowerSave(0); // disable oled if (inc > 0) u8g2.setPowerSave(0); // disable oled
do { do {
i=constrain(i,0,254); i=constrain(i,0,255);
u8g2.setContrast(i); // 0 (no contrast) to 255 u8g2.setContrast(i); // 0 (no contrast) to 255
delay (lag); delay (lag);
i=i+inc; i=i+inc;
} while (i != aim); } while (i != aim);
// at end, if decreasing then // at end, if decreasing then
if (inc < 0) u8g2.setPowerSave(0); // disable oled if (inc < 0) u8g2.clear(); // clear oled
} }
// & at the end ... the winner is // & at the end ... the winner is
void showResult(int val){ void showResult(int val){
@ -87,18 +105,18 @@ void showResult(int val){
u8g2.setFont(u8g2_font_profont17_tr); u8g2.setFont(u8g2_font_profont17_tr);
u8g2.drawStr(10,24, "Total recus :"); u8g2.drawStr(10,24, "Total recus :");
u8g2.setFont(u8g2_font_profont22_tr); u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(30,54, l1); u8g2.drawStr(35,55, l1);
} while ( u8g2.nextPage() ); } while ( u8g2.nextPage() );
if (val > NBCODES) if (val > NBCODES)
play_r3tl(_rCountOK_); play_r3tl(CountOK);
else else
play_r3tl(_rCountKO_); play_r3tl(CountKO);
noTone(PIEZO); play_r3tl(NoTone);
} }
// display incoming IR frame code // display incoming IR frame code
void showCode(unsigned long val) { void showCode(unsigned long val) {
char buf[16]; char buf[16];
play_r3tl(_rGetIR_); play_r3tl(GetIR);
u8g2.firstPage(); u8g2.firstPage();
do { do {
u8g2.setFont(u8g2_font_profont17_tr); u8g2.setFont(u8g2_font_profont17_tr);
@ -110,13 +128,15 @@ void showCode(unsigned long val) {
} }
void setup(void) { void setup(void) {
noTone(PIEZO); play_r3tl(NoTone);
u8g2.begin(); u8g2.begin();
drawLogo(); u8g2.clear();
#ifdef DEBUG #ifdef DEBUG
Serial.begin(9600); Serial.begin(9600);
#endif #endif
play_r3tl(_rIntro_); play_r3tl(Intro);
drawLogo();
contrastSlope(0, 255, 1, 15);
irrecv.enableIRIn(); // Start the receiver irrecv.enableIRIn(); // Start the receiver
delay(1000); delay(1000);
} }
@ -125,7 +145,7 @@ void setup(void) {
int cl=0; unsigned long lastReading=0, currentt=0; int cl=0; unsigned long lastReading=0, currentt=0;
void loop(void) { void loop(void) {
noTone(PIEZO); play_r3tl(NoTone);
if (irrecv.decode(&results)) { // if we keep getting signals, it is running if (irrecv.decode(&results)) { // if we keep getting signals, it is running
lastReading=millis(); lastReading=millis();
cl += 1; cl += 1;
@ -138,10 +158,10 @@ void loop(void) {
if ((lastReading + ACQUINONE < currentt) && ( cl > 0)) { // lastReading too old if ((lastReading + ACQUINONE < currentt) && ( cl > 0)) { // lastReading too old
showTrace(); showTrace();
showResult(cl); cl = 0; showResult(cl); cl = 0;
constratSlope(255, 0, -1, 50); contrastSlope(255, 0, -1, 35); // fades results in ~ 9 sec
delay(3000); delay(1000);
drawLogo(); drawLogo();
constratSlope(0, 255, 1, 20); contrastSlope(0, 255, 1, 15); // takes ~ 4 sec for logo to be full bright
} }
} }
} // loop } // loop