Skip to content

Instantly share code, notes, and snippets.

@cms-codes
Last active October 4, 2023 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cms-codes/108c4d555101a1854105692d09d31727 to your computer and use it in GitHub Desktop.
Save cms-codes/108c4d555101a1854105692d09d31727 to your computer and use it in GitHub Desktop.
WiFi-Arrgh!
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
const uint16_t ir_pin = 32;
const uint8_t buttonPinLen = 6;
const uint8_t buttonPins[buttonPinLen] =
{
33, 26, 27, 25, 14, 12
};
enum ButtonNames_e
{
POWER,
UP,
DOWN,
SELECT,
LEFT,
RIGHT
};
struct PinMap_s
{
uint8_t buttonPin;
ButtonNames_e* name;
};
struct IrCommandMap_s
{
void(*irCommandFunction)(void);
};
uint8_t tvPowerState = 0;
uint8_t bdTrayState = 0;
PinMap_s pinMap[buttonPinLen];
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
IRsend irsend(ir_pin);
uint16_t tvPowerOffSeq[77] =
{
0x0000, 0x006D, 0x0022, 0x0002, 0x0157, 0x00AC, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0016, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0041,
0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041,
0x0015, 0x0016, 0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0041, 0x0015, 0x0016,
0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0689, 0x0157, 0x0056, 0x0015, 0x0E94
};
uint16_t tvPowerOnSeq[77] =
{
0x0000, 0x006D, 0x0022, 0x0002, 0x0157, 0x00AC, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0016, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0041,
0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0016,
0x0015, 0x0016, 0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0016,
0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0041, 0x0015, 0x0016, 0x0015, 0x0016,
0x0015, 0x0689, 0x0157, 0x0056, 0x0015, 0x0E94
};
uint16_t bdOpenSeq[83] =
{
0x0000, 0x006D, 0x0027, 0x0000, 0x00AB, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x00BF,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x05C9
};
uint16_t bdSelectSeq[83] =
{
0x0000, 0x006D, 0x0027, 0x0000, 0x00AB, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x00BF,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x05C9
};
uint16_t bdDownSeq[83] =
{
0x0000, 0x006D, 0x0027, 0x0000, 0x00AB, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x00BF,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x05C9
};
uint16_t bdLeftSeq[83] =
{
0x0000, 0x006D, 0x0027, 0x0000, 0x00AB, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x00BF,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0040,
0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x05C9
};
uint16_t bdRightSeq[83] =
{
0x0000, 0x006D, 0x0027, 0x0000, 0x00AB, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x00BF,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x05C9
};
uint16_t bdPowerSeq[83] =
{
0x0000, 0x006D, 0x0027, 0x0000, 0x00AB, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x00BF,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x05C9
};
uint16_t bdUpSeq[83] =
{
0x0000, 0x006D, 0x0027, 0x0000, 0x00AB, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x00BF,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x05C9
};
void printStatusMsg(const char *s)
{
const char *clear = " ";
u8g2.drawStr(0, 26, clear);
//u8g2.sendBuffer();
u8g2.drawStr(0, 26, s);
u8g2.sendBuffer();
}
void tvPowerOn(void)
{
printStatusMsg("TV: power on ");
irsend.sendPronto(tvPowerOnSeq, 77, 3);
}
void bdPowerOn(void)
{
printStatusMsg("BD: power on ");
irsend.sendPronto(bdPowerSeq, 83, 3);
}
void bdTrayOpen(void)
{
printStatusMsg("BD: tray open");
irsend.sendPronto(bdOpenSeq, 83, 3);
}
void bdTrayClose(void)
{
printStatusMsg("BD: tray close");
irsend.sendPronto(bdOpenSeq, 83, 3);
}
void bdUp(void)
{
printStatusMsg("BD: up");
irsend.sendPronto(bdUpSeq, 83, 3);
}
void bdDown(void)
{
printStatusMsg("BD: down");
irsend.sendPronto(bdDownSeq, 83, 3);
}
void bdSelect(void)
{
printStatusMsg("BD: select");
irsend.sendPronto(bdSelectSeq, 83, 3);
}
void bdLeft(void)
{
printStatusMsg("BD: left");
irsend.sendPronto(bdLeftSeq, 83, 3);
}
void bdRight(void)
{
printStatusMsg("BD: right");
irsend.sendPronto(bdRightSeq, 83, 3);
}
void powerToggle(void)
{
bdPowerOn();
delay(3000);
tvPowerOn();
}
IrCommandMap_s irCommandMap[buttonPinLen] =
{
// POWER, UP, DOWN, SELECT, LEFT, RIGHT
{&powerToggle},
{&bdUp},
{&bdDown},
{&bdSelect},
{&bdLeft},
{&bdRight}
};
int readPin(uint16_t pinNumber)
{
int pinValue = -1;
pinValue = digitalRead((uint8_t)pinNumber);
return pinValue;
}
void initPinMap(PinMap_s* pinMap)
{
for (int i=0; i < buttonPinLen; i++)
{
pinMap[i].buttonPin = buttonPins[i];
pinMode(buttonPins[i], INPUT_PULLUP);
pinMap[i].name = reinterpret_cast<ButtonNames_e*>(i);
}
}
void callCommand(uint8_t index)
{
auto fn = irCommandMap[index].irCommandFunction;
fn();
}
void setup() {
u8g2.begin();
u8g2.setDisplayRotation(U8G2_R2);
irsend.begin();
initPinMap(pinMap);
}
void loop()
{
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_pxplusibmvga8_mf); // choose a suitable font
u8g2.drawStr(0,10,"WiFi-Arrgh!"); // write something to the internal memory
// u8g2.setDrawColor(1);
// u8g2.setFontMode(0);
u8g2.sendBuffer(); // transfer internal memory to the display
uint8_t buttonValue = -1;
while (1)
{
for (int i=0; i < buttonPinLen; i++)
{
buttonValue = readPin(buttonPins[i]);
if (buttonValue == 0)
{
callCommand(i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment