I’m trying use the Copilot with Visual Code Code Insiders
The code is generated by Copilot but have the folowing information in comments for all new code:
// Date: 01/08/2021
// Created by: Shubham Lodha
Who is Shubham Lodha which created all the code in the same day???
//function to find the number of ways to reach the end of the array
//using the given steps
// Date: 01/08/2021
// Created by: Shubham Lodha
#include<bits/stdc++.h>
using namespace std;
int countWays(int n,int m)
{
int dp[n+1];
dp[0]=1;
for(int i=1;i<=n;i++)
{
int total=0;
for(int j=1;j<=m;j++)
{
if(i-j>=0)
{
total+=dp[i-j];
}
}
dp[i]=total;
}
return dp[n];
}
// function to find the longest common prefix string amongst an array of strings.
// Date: 01/08/2021
// Created by: Shubham Lodha
string longestCommonPrefix(vector<string>& strs) {
string ans="";
int n=strs.size();
if(n==0)
return ans;
if(n==1)
return strs[0];
sort(strs.begin(),strs.end());
string a=strs[0];
string b=strs[n-1];
int i=0;
while(i<a.length() && i<b.length())
{
if(a[i]==b[i])
{
ans+=a[i];
i++;
}
else
break;
}
return ans;
}
//function to connect astra orbbec camera
// Date: 01/08/2021
// Created by: Shubham Lodha
void connectAstra()
{
astra::initialize();
astra::StreamSet streamSet;
astra::StreamReader reader = streamSet.create_reader();
reader.stream<astra::DepthStream>().start();
reader.stream<astra::ColorStream>().start();
astra::DepthStream depthStream = reader.stream<astra::DepthStream>();
astra::ColorStream colorStream = reader.stream<astra::ColorStream>();
astra::Frame frame = reader.get_latest_frame();
astra::DepthFrame depthFrame = frame.get<astra::DepthFrame>();
astra::ColorFrame colorFrame = frame.get<astra::ColorFrame>();
int width = depthFrame.width();
int height = depthFrame.height();
int frameIndex = 0;
int totalPixels = width * height;
int16_t* depthData = new int16_t[totalPixels];
uint8_t* colorData = new uint8_t[totalPixels * 3];
int16_t* lastDepthData = new int16_t[totalPixels];
uint8_t* lastColorData = new uint8_t[totalPixels * 3];
int16_t* deltaDepthData = new int16_t[totalPixels];
uint8_t* deltaColorData = new uint8_t[totalPixels * 3];
int16_t* deltaDepthData2 = new int16_t[totalPixels];
uint8_t* deltaColorData2 = new uint8_t[totalPixels * 3];
int16_t* deltaDepthData3 = new int16_t[totalPixels];
uint8_t* deltaColorData3 = new uint8_t[totalPixels * 3];
int16_t* deltaDepthData4 = new int16_t[totalPixels];
uint8_t* deltaColorData4 = new uint8_t[totalPixels * 3];
int16_t* deltaDepthData5 = new int16_t[totalPixels];
uint8_t* deltaColorData5 = new uint8_t[totalPixels * 3];
int16_t* deltaDepthData6 = new int16_t[totalPixels];
uint8_t* deltaColorData6 = new uint8_t[totalPixels * 3];
int16_t* deltaDepthData7 = new int16_t[totalPixels];
uint8_t* deltaColorData7 = new uint8_t[totalPixels * 3];
while (true)
{
astra_update();
frame = reader.get_latest_frame();
depthFrame = frame.get<astra::DepthFrame>();
colorFrame = frame.get<astra::ColorFrame>();
if (depthFrame.is_valid() && colorFrame.is_valid())
{
const int16_t* depthData = depthFrame.data();
const uint8_t* colorData = colorFrame.data();
memcpy(lastDepthData, depthData, totalPixels * sizeof(int16_t));
memcpy(lastColorData, colorData, totalPixels * 3 * sizeof(uint8_t));
break;
}
}
while (true)
{
astra_update();
frame = reader.get_latest_frame();
depthFrame = frame.get<astra::DepthFrame>();
colorFrame = frame.get<astra::ColorFrame>();
if (depthFrame.is_valid() && colorFrame.is_valid())
{
const int16_t* depthData = depthFrame.data();
const uint8_t* colorData = colorFrame.data();
memcpy(deltaDepthData, depthData, totalPixels * sizeof(int16_t));
memcpy(deltaColorData, colorData, totalPixels * 3 * sizeof(uint8_t));
break;
}
}
//function to subsrcibe to mqqt broker
// Date: 01/08/2021
// Created by: Shubham Lodha
void subscribe()
{
mosquitto_lib_init();
mosq = mosquitto_new(NULL, true, NULL);
if (mosq) {
mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_message_callback_set(mosq, on_message);
mosquitto_subscribe(mosq, NULL, "test", 0);
mosquitto_loop_start(mosq);
}
}
//function to publish to mqqt broker
// Date: 01/08/2021
// Created by: Shubham Lodha
void publish()
{
mosquitto_lib_init();
mosq = mosquitto_new(NULL, true, NULL);
if (mosq) {
mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_message_callback_set(mosq, on_message);
mosquitto_publish(mosq, NULL, "test", 0, "hello", 0, false);
mosquitto_loop_start(mosq);
}
}
//function to connect aht10 sensor
// Date: 01/08/2021
// Created by: Shubham Lodha
void connectAHT10()
{
Wire.begin();
Serial.begin(9600);
Serial.println("AHT10 test");
aht.begin();
}
//function to connect bme280 sensor
// Date: 01/08/2021
// Created by: Shubham Lodha
void connectBME280()
{
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
//function to display sinuoidal wave on oled
// Date: 01/08/2021
// Created by: Shubham Lodha
void displaySinuoidalWave()
{
for (int i = 0; i < 128; i++) {
display.drawPixel(i, 32 + (sin(i / 2.0) * 31), WHITE);
}
display.display();
}
//function to display text on oled
// Date: 01/08/2021
// Created by: Shubham Lodha
void displayText()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Hello, world!");
display.display();
}
/function to display text on oled with scrolling
// Date: 01/08/2021
// Created by: Shubham Lodha
void displayScrollingText()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Hello, world!");
display.display();
display.startscrollright(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrolldiagright(0x00, 0x07);
delay(2000);
display.startscrolldiagleft(0x00, 0x07);
delay(2000);
display.stopscroll();
}
//function to randomize the color of the led
// Date: 01/08/2021
// Created by: Shubham Lodha
void randomizeColor()
{
int red = random(0, 255);
int green = random(0, 255);
int blue = random(0, 255);
ledcWrite(0, red);
ledcWrite(1, green);
ledcWrite(2, blue);
}
//Function to calculate the FFT of the signal
// Date: 01/08/2021
// Created by: Shubham Lodha
void calculateFFT()
{
// The FFT function requires that the number of samples is a power of 2
// so we check that here
if (samplesTaken == 128) {
// We use a Blackman window function
// https://en.wikipedia.org/wiki/Window_function#Blackman_window
for (int i = 0; i < 128; i++) {
float multiplier = 0.42 - 0.5 * cos(2 * PI * i / 127) + 0.08 * cos(4 * PI * i / 127);
fftData[i] = multiplier * samples[i];
}
// Perform the FFT
FFT.Windowing(fftData, 128, FFT_WIN_TYP_BLACKMAN, FFT_FORWARD);
FFT.Compute(fftData, 128, FFT_FORWARD);
FFT.ComplexToMagnitude(fftData, 128);
// We only use the first 64 values of the FFT because the rest are mirrored
// and we only need the first 64 because the rest are mirrored
for (int i = 0; i < 64; i++) {
// We calculate the magnitude of each frequency bin
// using the cartesian equation: magnitude = sqrt(x^2 + y^2)
float magnitude = sqrt(sq(fftData[i * 2]) + sq(fftData[i * 2 + 1]));
// And use that magnitude to calculate the intensity of each pixel
// in the column on the screen
int pixelHeight = map(magnitude, 0, 100, 0, 32);
// We draw the column on the screen
display.drawFastVLine(i, 32 - pixelHeight, pixelHeight, WHITE);
}
// And update the screen
display.display();
// We reset the number of samples to 0
samplesTaken = 0;
}
}
// function to connect to wifi
// Date: 01/08/2021
// Created by: Shubham Lodha
void connectWifi()
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
The video with Copilot code creation: