Krolyxon
Commit a97b224

Branches

Tags

Refs →

orion-rffirmwarefirmware.ino

136 lines · 2.3 KB

1#include <Arduino.h>
2#include <USB.h>
3#include <USBHIDKeyboard.h>
4
5#include <BLEDevice.h>
6#include <BLEScan.h>
7#include <BleMouse.h>
8
9#include <RF24.h>
10#include <nRF24L01.h>
11
12#include "ELECHOUSE_CC1101_SRC_DRV.h"
13
14#include <WiFi.h>
15#include <esp_wifi.h>
16
17#include <esp_chip_info.h>
18#include <esp_heap_caps.h>
19#include <esp_system.h>
20#include <SPI.h>
21
22
23#include "display.h"
24#include "buttons.h"
25#include "menu.h"
26
27#include "config.h"
28#include "cc1101.h"
29
30// ================= USB HID =================
31USBHIDKeyboard Keyboard;
32
33// ===== BLE MOUSE =====
34BleMouse bleMouse("Orion-RF", "Orion-RF", 100);
35
36
37RF24 radio1(CE1_PIN, CSN1_PIN);
38RF24 radio2(CE2_PIN, CSN2_PIN);
39SPIClass *RADIO_SPI;
40
41
42
43
44// ================= BLE SCAN =================
45//BLEScan *pBLEScan;
46//
47//
48//void startBLEScan()
49//{
50// BLEDevice::init("");
51//
52// pBLEScan = BLEDevice::getScan();
53//
54// pBLEScan->setActiveScan(true);
55//
56// pBLEScan->start(5);
57//
58// Serial.println("BLE scan complete");
59//}
60
61// ================= SYSTEM INFO =================
62void printSystemUsage()
63{
64 esp_chip_info_t chip_info;
65
66 esp_chip_info(&chip_info);
67
68 Serial.printf("CPU cores: %d\n", chip_info.cores);
69
70 Serial.printf(
71 "Free heap: %d bytes\n",
72 heap_caps_get_free_size(MALLOC_CAP_DEFAULT)
73 );
74
75 Serial.printf(
76 "PSRAM free: %d bytes\n",
77 heap_caps_get_free_size(MALLOC_CAP_SPIRAM)
78 );
79}
80
81void showSplash()
82{
83 u8g2.clearBuffer();
84
85 u8g2.setFont(u8g2_font_logisoso20_tr); // big font
86 u8g2.drawStr(10, 40, "Orion-RF");
87
88 u8g2.setFont(u8g2_font_5x8_tr); // small subtitle
89 u8g2.drawStr(25, 58, "Initializing...");
90
91 u8g2.sendBuffer();
92
93 delay(1500); // 1.5 sec
94}
95
96
97// ================= SETUP =================
98void setup()
99{
100 Serial.begin(115200);
101
102 displayInit();
103 showSplash();
104
105 buttonsInit();
106 menuInit();
107
108 delay(1500);
109
110 USB.begin();
111 Keyboard.begin();
112
113 // Begin Ble mouse
114 bleMouse.begin();
115
116
117 // NRF SPI safety
118 pinMode(CSN1_PIN, OUTPUT);
119 digitalWrite(CSN1_PIN, HIGH);
120
121 pinMode(CSN2_PIN, OUTPUT);
122 digitalWrite(CSN2_PIN, HIGH);
123
124 RADIO_SPI = new SPIClass(FSPI);
125 RADIO_SPI->begin(NRF_SCK, NRF_MISO, NRF_MOSI);
126
127 printSystemUsage();
128
129 Serial.println("SYSTEM READY");
130}
131
132// ================= LOOP =================
133void loop()
134{
135 menuLoop();
136}