Skip to content

Instantly share code, notes, and snippets.

@fagci
Created October 22, 2023 09:39
Show Gist options
  • Save fagci/e548a3732016c81258aa0a93777a1217 to your computer and use it in GitHub Desktop.
Save fagci/e548a3732016c81258aa0a93777a1217 to your computer and use it in GitHub Desktop.
si5351 esp32 web ui
#include "si5351.h"
#include "Wire.h"
#include <DNSServer.h>
#include <ESPUI.h>
#include <WiFi.h>
#define INITIAL_F 27000000
#define CORRECTION 120000
#define AP_NAME "F-GEN"
Si5351 si5351;
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 4, 1);
DNSServer dnsServer;
const char* hostname = "espui";
int fInputId;
void UpdateF() {
unsigned long freq = ESPUI.getControl(fInputId)->value.toInt();
si5351.set_freq(freq * SI5351_FREQ_MULT, SI5351_CLK0);
}
void numberCall(Control* sender, int type) {
UpdateF();
}
void switchCall(Control* sender, int value)
{
switch (value)
{
case S_ACTIVE:
UpdateF();
break;
case S_INACTIVE:
si5351.reset();
break;
}
}
void SetupUI() {
ESPUI.captivePortal = false;
fInputId = ESPUI.number("F 8000..225000000", &numberCall, ControlColor::Alizarin, INITIAL_F, 8000, 225000000);
ESPUI.switcher("Power", &switchCall, ControlColor::None, false);
ESPUI.begin("Gen control", "fagci", "fagcip4ss");
}
void SetupGen() {
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
si5351.set_correction(CORRECTION, SI5351_PLL_INPUT_XO);
}
void CreateHotspot() {
WiFi.setHostname(hostname);
WiFi.mode(WIFI_AP);
delay(100);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(AP_NAME);
delay(500);
dnsServer.start(DNS_PORT, "*", apIP);
}
void setup() {
CreateHotspot();
SetupUI();
SetupGen();
}
void loop() {
dnsServer.processNextRequest();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment