Skip to content

Commit

Permalink
Firmware V1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuallyaverage committed Aug 21, 2024
1 parent dc849a3 commit 54accc8
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 48 deletions.
3 changes: 0 additions & 3 deletions VRC-Haptics-Firmware-ESP/include/variables.h

This file was deleted.

13 changes: 0 additions & 13 deletions VRC-Haptics-Firmware-ESP/lib/PWM/PCA/library.json

This file was deleted.

13 changes: 0 additions & 13 deletions VRC-Haptics-Firmware-ESP/lib/wifi/OSC/library.json

This file was deleted.

5 changes: 5 additions & 0 deletions VRC-Haptics-Firmware-ESP/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ lib_deps =
platform = espressif8266
board = d1_mini
framework = arduino
monitor_filters =
esp8266_exception_decoder
monitor_speed = 115200
build_flags =
-I include
lib_deps =
${env.lib_deps}

upload_speed = 921600 ; Increase upload speed
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include <ArduinoOSCWiFi.h>

#include "config.h"
#include "variables.h"
#include "globals.h"

#include "osc.h"

void motorMessage_callback(const OscMessage&);
void serverPing_callback(const OscMessage&);
void printMessage(const OscMessage& message);

void MotorMessage_Callback(const OscMessage& message){
void motorMessage_callback(const OscMessage& message){

// create char array
String msg_str = message.arg<String>(0);
Expand Down
5 changes: 5 additions & 0 deletions VRC-Haptics-Firmware-ESP/src/OSC/callbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <ArduinoOSCWiFi.h>

void motorMessage_callback(const OscMessage&);
void serverPing_callback(const OscMessage&);
void printMessage(const OscMessage& message);
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <ArduinoOSCWiFi.h>

#include "config.h"
#include "globals.h"

#include "callbacks.cpp"
#include "OSC/callbacks.h"

const IPAddress ip(OSC_LOCAL_IP);
const IPAddress gateway(OSC_GATEWAY_IP);
Expand All @@ -15,14 +16,17 @@ void startOSCWifi() {
Serial.println("WIFI: Connecting");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {}
while (WiFi.status() != WL_CONNECTED) {
//Serial.println("");
delay(1);
}

// Print the IP address
Serial.print("WIFI: IP: ");
Serial.println(WiFi.localIP());

// Setup OSC
OscWiFi.subscribe(OSC_IN_PORT, OSC_MOTOR_ADDRESS, MotorMessage_Callback);
OscWiFi.subscribe(OSC_IN_PORT, OSC_MOTOR_ADDRESS, motorMessage_callback);
OscWiFi.subscribe(OSC_IN_PORT, "/ping/", serverPing_callback);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ void sendOSC(const String& oscAddress, const int16_t& value);
void sendOSC(const String& oscAddress, const int8_t& value);
void sendOSC(const String& oscAddress, const float_t& value);
void sendOSC(const String& oscAddress, char *value, uint16_t size);

Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#include <Arduino.h>

#include "config.h"
#include "variables.h"
#include "globals.h"

#include "pwmConfig.h"
#include "PWM/pwmConfig.h"
#include "pca.h"

#include "Adafruit_PWMServoDriver.h"
#include "Wire.h"

#ifdef PCA_1
Adafruit_PWMServoDriver pcaModule1 = Adafruit_PWMServoDriver(PCA_1);
#endif
Adafruit_PWMServoDriver pcaModule1 = Adafruit_PWMServoDriver(PCA_1, Wire);
Adafruit_PWMServoDriver pcaModule2 = Adafruit_PWMServoDriver(PCA_2, Wire);

#ifdef PCA_2
Adafruit_PWMServoDriver pcaModule2 = Adafruit_PWMServoDriver(PCA_2);
#endif

uint8_t motorMap[32] = {MOTOR_MAP};

Expand All @@ -27,13 +24,36 @@ void startPCA() {
//set frequencies
pcaModule1.setPWMFreq(PCA_FREQUENCY);
pcaModule2.setPWMFreq(PCA_FREQUENCY);

pcaModule1.begin();
pcaModule1.setOscillatorFrequency(27000000);
pcaModule1.setPWMFreq(1600); // This is the maximum PWM frequency

pcaModule2.begin();
pcaModule2.setOscillatorFrequency(27000000);
pcaModule2.setPWMFreq(1600); // This is the maximum PWM frequency

Wire.setClock(400000);

Serial.println(pcaModule1.getOscillatorFrequency());
Serial.println(pcaModule2.getOscillatorFrequency());
//chime
setToDuty(4095);
delay(100);
setToDuty(0);
}

/// @brief Sets all motors to the specified duty cycle, mapped to the MOTOR_MAP defined in config.h
/// @param dutyCycle The list of each motors duty cycle
void setAllDuty() {
for(uint8_t i = 0; i < 16; i++) {
pcaModule1.setPin(motorMap[i], motorDuty[i]);
pcaModule2.setPin(motorMap[i+16]-16, motorDuty[i+16]);// 3 HOURS JUST TO FIND THE -16..... I WANT TO DIE
}
}
void setToDuty(uint16_t duty) {
for(uint8_t i = 0; i < 32; i++) {
setMotorDuty(motorMap[i], motorDuty[i]);
setMotorDuty(motorMap[i], duty);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ void startPCA();

void setMotorDuty(uint8_t motorIndex, uint16_t dutyCycle);
void setAllDuty();
void setToDuty(uint16_t duty);


#define PCA_FREQUENCY 1600
11 changes: 11 additions & 0 deletions VRC-Haptics-Firmware-ESP/src/globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// globals.h
#ifndef GLOBALS_H
#define GLOBALS_H
#include "Arduino.h"


//be sure to init in main.cpp

extern uint16_t motorDuty[32];

#endif // GLOBALS_H
8 changes: 6 additions & 2 deletions VRC-Haptics-Firmware-ESP/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#include <Arduino.h>

//main config files
#include "variables.h"
#include "globals.h"
#include "config.h"
#include "main.h"

//import modules
#include "OSC/osc.h"
#include "PCA/pca.h"
#include "PWM/PCA/pca.h"

//setup scheduler
#include <TaskScheduler.h>

//init globals here
uint16_t motorDuty[32] = {0};

Scheduler TaskScheduler;

//Task task1(INTERVAL_OSC_TICK, TASK_FOREVER, &oscTick, &TaskScheduler, true);
Expand Down Expand Up @@ -62,6 +65,7 @@ void loop() {
if (millis()-start >= 1000) {
Serial.print("LoopRate: ");
Serial.println(ticks);
printMotorDuty();

start = millis();
ticks = 0;
Expand Down

0 comments on commit 54accc8

Please sign in to comment.