Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api muse integration #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

var museData struct {
Alpha float32
Beta float32
Delta float32
Theta float32
Gamma float32
Mellow float32
Blink bool
JawClench bool
Alpha float32
Beta float32
Delta float32
Theta float32
Gamma float32
Mellow float32
Blink bool
JawClench bool
}

func alphaHandler(msg *osc.Message) {
Expand Down Expand Up @@ -55,19 +55,19 @@ func jawClenchHandler(msg *osc.Message) {

func getDataHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"alpha": museData.Alpha,
"beta": museData.Beta,
"delta": museData.Delta,
"theta": museData.Theta,
"gamma": museData.Gamma,
"mellow": museData.Mellow,
"blink": museData.Blink,
"jawClench": museData.JawClench,
"alpha": museData.Alpha,
"beta": museData.Beta,
"delta": museData.Delta,
"theta": museData.Theta,
"gamma": museData.Gamma,
"mellow": museData.Mellow,
"blink": museData.Blink,
"jawClench": museData.JawClench,
})
}

func main() {
ip := "192.168.18.146"
ip := "192.168.18.59"
port := 5000

dispatcher := osc.NewStandardDispatcher()
Expand Down
34 changes: 32 additions & 2 deletions src/app/components/environment/Classroom.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { Canvas, useThree } from "@react-three/fiber";
import React, { useState, useEffect, useRef } from "react";

import axios from "axios";
import {
OrbitControls,
PerspectiveCamera,
Expand All @@ -24,6 +24,16 @@ type cameraAngle = {
z: number;
};

interface Data {
alpha: number;
beta: number;
delta: number;
theta: number;
gamma: number;
mellow: number;
concentration: number;
}

export const Classroom = () => {
console.log("Classroom component rendered");
const [rainSound, setRainSound] = useState("/lowRain.mp3");
Expand Down Expand Up @@ -76,13 +86,33 @@ export const Classroom = () => {
};

useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get<Data>(
"http://localhost:8080/api/data"
);
const concentration =
response.data.beta +
response.data.alpha -
(response.data.theta + response.data.delta + 0.1);
response.data.concentration = concentration;
setFocus(concentration);
handleIntensityChange(concentration);
console.log(concentration);
} catch (error) {
console.error("Error fetching data:", error);
}
};

const fetchDataInterval = setInterval(fetchData, 1000);
audioRef.current!.src = rainSound;
audioRef.current!.play();
window.addEventListener("keydown", handleArrowKeyPress);
return () => {
clearInterval(fetchDataInterval);
window.removeEventListener("keydown", handleArrowKeyPress);
};
}, [rainSound]);
}, [rainSound, Focus]);

const CameraLookAt = ({ x, y, z }: cameraAngle) => {
const { camera } = useThree();
Expand Down
40 changes: 35 additions & 5 deletions src/app/components/environment/Dorm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { Canvas, useThree } from "@react-three/fiber";
import React, { useState, useEffect, useRef } from "react";

import axios from "axios";
import {
OrbitControls,
PerspectiveCamera,
Expand All @@ -24,19 +24,29 @@ type cameraAngle = {
z: number;
};

interface Data {
alpha: number;
beta: number;
delta: number;
theta: number;
gamma: number;
mellow: number;
concentration: number;
}

export const Dorm = () => {
console.log("Kos component rendered");

const [rainSound, setRainSound] = useState("/lowRain.mp3");
const [Focus, setFocus] = useState(0.5);
const [rainKey, setRainKey] = useState(0);
const [ cameraLookAt, setCameraLookAt] = useState<cameraAngle>({
const [cameraLookAt, setCameraLookAt] = useState<cameraAngle>({
x: 0,
y: 0.75,
z: 0,
});

const audioRef = useRef<HTMLAudioElement>(null);

const handleIntensityChange = (newIntensity: number) => {
setFocus(newIntensity);
if (newIntensity > 0.5) {
Expand Down Expand Up @@ -77,13 +87,33 @@ export const Dorm = () => {
};

useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get<Data>(
"http://localhost:8080/api/data"
);
const concentration =
response.data.beta +
response.data.alpha -
(response.data.theta + response.data.delta + 0.1);
response.data.concentration = concentration;
setFocus(concentration);
handleIntensityChange(concentration);
console.log(concentration);
} catch (error) {
console.error("Error fetching data:", error);
}
};

const fetchDataInterval = setInterval(fetchData, 1000);
audioRef.current!.src = rainSound;
audioRef.current!.play();
window.addEventListener("keydown", handleArrowKeyPress);
return () => {
clearInterval(fetchDataInterval);
window.removeEventListener("keydown", handleArrowKeyPress);
};
}, [rainSound]);
}, [rainSound, Focus]);

const CameraLookAt = ({ x, y, z }: cameraAngle) => {
const { camera } = useThree();
Expand Down Expand Up @@ -155,7 +185,7 @@ export const Dorm = () => {
<ambientLight intensity={Focus + 0.15} />
<PerspectiveCamera
makeDefault
position={[2, 0.75,3]}
position={[2, 0.75, 3]}
fov={65}
near={0.1}
far={100}
Expand Down
35 changes: 32 additions & 3 deletions src/app/components/environment/Lake.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { Canvas, useThree } from "@react-three/fiber";
import React, { useState, useEffect, useRef } from "react";

import axios from "axios";
import {
OrbitControls,
PerspectiveCamera,
Expand All @@ -24,9 +24,18 @@ type cameraAngle = {
z: number;
};

interface Data {
alpha: number;
beta: number;
delta: number;
theta: number;
gamma: number;
mellow: number;
concentration: number;
}

export const Lake = () => {
console.log("Lake component rendered");

const [rainSound, setRainSound] = useState("/lowRain.mp3");
const [Focus, setFocus] = useState(0.5);
const [rainKey, setRainKey] = useState(0);
Expand Down Expand Up @@ -77,13 +86,33 @@ export const Lake = () => {
};

useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get<Data>(
"http://localhost:8080/api/data"
);
const concentration =
response.data.beta +
response.data.alpha -
(response.data.theta + response.data.delta + 0.1);
response.data.concentration = concentration;
setFocus(concentration);
handleIntensityChange(concentration);
console.log(concentration);
} catch (error) {
console.error("Error fetching data:", error);
}
};

const fetchDataInterval = setInterval(fetchData, 1000);
audioRef.current!.src = rainSound;
audioRef.current!.play();
window.addEventListener("keydown", handleArrowKeyPress);
return () => {
clearInterval(fetchDataInterval);
window.removeEventListener("keydown", handleArrowKeyPress);
};
}, [rainSound]);
}, [rainSound, Focus]);

const CameraLookAt = ({ x, y, z }: cameraAngle) => {
const { camera } = useThree();
Expand Down
16 changes: 12 additions & 4 deletions src/app/datatesting/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ const DataStream = () => {
const response = await axios.get<Data>(
"http://localhost:8080/api/data"
);
// Calculate the concentration
const concentration =
response.data.beta +
response.data.alpha -
(response.data.theta + response.data.delta);
response.data.concentration = concentration;
setData(response.data);
console.log(concentration);
} catch (error) {
console.error("Error fetching data:", error);
}
};

const fetchDataInterval = setInterval(fetchData, 200);
const fetchDataInterval = setInterval(fetchData, 1000);

return () => clearInterval(fetchDataInterval);
}, []);
Expand All @@ -40,9 +47,10 @@ const DataStream = () => {
<p>Alpha: {data.alpha}</p>
<p>Beta: {data.beta}</p>
<p>Delta: {data.delta}</p>
<p>theta: {data.theta}</p>
<p>gamma: {data.gamma}</p>
<p>concen: {data.alpha - data.beta}</p>
<p>Theta: {data.theta}</p>
<p>Gamma: {data.gamma}</p>
<p>Mellow: {data.mellow}</p>
<p>Concentration: {data.concentration}</p>
</div>
)}
</div>
Expand Down