repo_name
stringlengths 5
122
| path
stringlengths 3
232
| text
stringlengths 6
1.05M
|
|---|---|---|
Joursoir/umt
|
UefiMonitorTest/MainMenu.h
|
#ifndef UMT_MAIN_MENU_H
#define UMT_MAIN_MENU_H
#include "UefiMonitorTest.h"
VOID
MainMenuInit (
IN UMT_CONTEXT *Ctx
);
VOID
MainMenuDoit (
IN UMT_CONTEXT *Ctx
);
VOID
MainMenuTip (
IN UMT_CONTEXT *Ctx
);
VOID
MainMenuChangeParam (
IN UMT_CONTEXT *Ctx,
IN INT8 ParamStep
);
VOID
MainMenuChangeValue (
IN UMT_CONTEXT *Ctx,
IN INT8 ValueStep
);
#endif /* UMT_MAIN_MENU_H */
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/ModelContext.h
|
<filename>deffem_postprocessor/headers/ModelContext.h
#pragma once
#ifndef MODEL_CONTEXT_H
#define MODEL_CONTEXT_H
#include <string>
#include "ModelInfo.h"
#include "CustomObject.h"
namespace deffem
{
class ModelContext
{
public:
CustomObject* model;
ModelInfo info;
std::string filename;
ModelContext(CustomObject* modelPtr, ModelInfo info, std::string filename)
{
this->model = modelPtr;
this->info = info;
this->filename = filename;
}
~ModelContext()
{
delete model;
}
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Camera.h
|
<reponame>mmaikel/DEFFEM_Postprocessor
#pragma once
#ifndef CEMERA_H
#define CAMERA_H
#include <glad/glad.h>
#include <glm/glm/glm.hpp>
namespace deffem
{
class Camera
{
public:
GLfloat theta;
GLfloat phi;
GLfloat radius;
GLfloat fov;
glm::fvec2 offset;
glm::fvec3 target;
Camera();
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Shader.h
|
#ifndef SHADER_H
#define SHADER_H
#include <glad/glad.h> // include glad to get all the required OpenGL headers
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <glm/glm/mat4x4.hpp>
namespace deffem
{
class Shader
{
public:
// the program ID
unsigned int ID;
// constructor reads and builds the shader
Shader(const GLchar* vertexPath, const GLchar* fragmentPath);
// use/activate the shader
void use() const;
// utility uniform functions
void setBool(const std::string& name, bool value) const;
void setInt(const std::string& name, int value) const;
void setFloat(const std::string& name, float value) const;
void setVec3(const GLchar* name, glm::vec3 value) const;
void setMat4(const GLchar* name, glm::mat4 value) const;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Line.h
|
#ifndef LINE_H
#define LINE_H
#include "Object.h"
#include "Color.h"
namespace deffem
{
class Line : Object
{
public:
Line(glm::vec3 p1, glm::vec3 p2, Color color);
void draw() override;
void draw(Shader* shader) override;
void draw(Shader* shader) const;
void destroy() override;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/ModelInfo.h
|
<reponame>mmaikel/DEFFEM_Postprocessor<filename>deffem_postprocessor/headers/ModelInfo.h
#pragma once
#ifndef MODELINFO_H
#define MODELINFO_H
#include "MinMax.h"
namespace deffem
{
class ModelInfo
{
public:
unsigned long nodeCount;
unsigned long elementCount;
MinMax minMaxValue;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Color.h
|
#pragma once
#ifndef COLOR_H
#define COLOR_H
#include <glad/glad.h>
#include <string>
#include <map>
namespace deffem
{
class Color
{
public:
Color();
Color(GLfloat red, GLfloat green, GLfloat blue);
Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
Color(GLfloat red, GLfloat green, GLfloat blue, std::string name);
Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha, std::string name);
static Color fromString(std::string colorName);
std::string colorName;
GLfloat red, green, blue, alpha;
};
class Colors
{
public:
static std::map<std::string, Color> colors;
static Color red;
static Color green;
static Color blue;
static Color lightBlue;
static Color yellow;
static Color magenta;
static Color purple;
static Color black;
static Color gray;
static Color lightGray;
static Color darkGray;
static Color white;
static Color orange;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/resources/ApplicationSettings.h
|
<reponame>mmaikel/DEFFEM_Postprocessor
#pragma once
#ifndef APPLICATION_SETTINGS_H
#define APPLICATION_SETTINGS_H
#include "../headers/Color.h"
#include <map>
#include <glm/glm/detail/type_vec2.hpp>
class
enum ThemeVariant
{
light = 0,
dark = 1
};
class ApplicationSettings
{
public:
glm::vec2 screenResolution;
ThemeVariant themeVariant;
Color backgroundColor;
bool showMeshPlane;
float initialModelScale;
long animationTickMillis;
Color textColor() const
{
switch (themeVariant)
{
case ThemeVariant::light:
return {0.0, 0.0, 0.0};
case ThemeVariant::dark:
return {1.0, 1.0, 1.0};
default:
return {0.5, 0.5, 0.5};
}
}
ApplicationSettings(std::map<std::string, std::string> config);
};
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Letter.h
|
#pragma once
#ifndef LETTER_H
#define LETTER_H
#include <glad/glad.h>
#include <glm/glm/vec2.hpp>
namespace deffem
{
struct Letter
{
GLuint TextureID; // ID handle of the glyph texture
glm::ivec2 Size; // Size of glyph
glm::ivec2 Bearing; // Offset from baseline to left/top of glyph
GLuint Advance; // Horizontal offset to advance to next glyph
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/MinMax.h
|
<filename>deffem_postprocessor/headers/MinMax.h
#pragma once
#ifndef MIN_MAX_H
#define MIN_MAX_H
namespace deffem
{
class MinMax
{
public:
float min;
float max;
MinMax(float min, float max)
{
this->min = min;
this->max = max;
}
MinMax()
{
this->min = -1;
this->max = -1;
}
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/GridPlane.h
|
#pragma once
#ifndef MESH_PLANE_H
#define MESH_PLANE_H
#include "Color.h"
#include "Shader.h"
#include <glm/glm/glm.hpp>
#include "Line.h"
#include <list>
namespace deffem
{
class GridPlane
{
public:
bool showGrid;
GridPlane();
GridPlane(glm::fvec2 size, int grids, const Color& meshColor);
~GridPlane();
void draw(Shader* shader, GLfloat gridLineWidth);
void draw();
private:
std::list<Line> gridLines;
Line* axisX;
Line* axisY;
Line* axisZ;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/ApplicationSettings.h
|
#pragma once
#ifndef APPLICATION_SETTINGS_H
#define APPLICATION_SETTINGS_H
#include "../headers/Color.h"
#include <map>
#include <glm/glm/glm.hpp>
namespace deffem
{
class ThemeVariant
{
public:
enum ThemeVariants
{
light = 0,
dark = 1
};
static ThemeVariants determine(const Color color)
{
const auto isLight = (0.3 * color.red + 0.59 * color.green + 0.11 * color.blue) >= 0.5;
if (isLight)
{
return light;
}
return dark;
}
};
class ApplicationSettings
{
public:
glm::vec2 screenResolution;
ThemeVariant::ThemeVariants themeVariant;
Color backgroundColor;
Color textColor;
Color gridPlaneColor;
glm::fvec2 heatmapSize;
bool showGridPlane;
GLfloat modelScale;
long animationTickMillis;
GLfloat lineWidth;
GLuint pointSize;
GLfloat cameraRadius;
glm::fvec3 modelIntersection;
std::map<std::string, std::string> config;
ApplicationSettings();
explicit ApplicationSettings(std::map<std::string, std::string> config);
void resetAll();
private:
Color textColorFn() const
{
switch (themeVariant)
{
case ThemeVariant::light:
return {0.0f, 0.0f, 0.0f};
case ThemeVariant::dark:
return {1.0f, 1.0f, 1.0f};
default:
return {0.5f, 0.5f, 0.5f};
}
}
Color meshPlaneColorFn() const
{
switch (themeVariant)
{
case ThemeVariant::light:
return {backgroundColor.red - 0.15f, backgroundColor.green - 0.15f, backgroundColor.blue - 0.15f };
case ThemeVariant::dark:
return { backgroundColor.red + 0.15f, backgroundColor.green + 0.15f, backgroundColor.blue + 0.15f };
default:
return {0.5f, 0.5f, 0.5f};
}
}
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Object.h
|
#ifndef OBJECT_H
#define OBJECT_H
#include "Shader.h"
#include <GL/GL.h>
namespace deffem
{
class Object
{
public:
virtual ~Object() = default;
virtual void draw() = 0;
virtual void draw(Shader* shader) = 0;
virtual void destroy() = 0;
protected:
GLuint VAO, VBO, EBO = 0;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/FileParser.h
|
#pragma once
#ifndef FILE_PARSER_H
#define FILE_PARSER_H
#include <vector>
#include "ModelInfo.h"
#include <map>
#include <list>
#include <glad/glad.h>
namespace deffem
{
class FileParser
{
public:
static ModelInfo readSections(const std::string& filename, std::vector<GLfloat>& verticesAndColors,
std::vector<GLuint>& indices);
static std::map<std::string, std::string> readConfig(std::string filename);
private:
static unsigned long processLine(const std::string& line, std::vector<GLfloat>& vertices,
std::list<GLfloat>& values,
char separator = ',');
static unsigned long processLine(const std::string& line, std::vector<GLuint>& indices, char separator = ',');
static bool checkSectionChanged(std::string test, std::string& section);
static void getHeatMapColor(float value, float* red, float* green, float* blue);
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/State.h
|
#pragma once
#ifndef STATE_H
#define STATE_H
#include <glad/glad.h>
#include <glm/glm/glm.hpp>
#include "Camera.h"
#include "Typer.h"
#include "Heatmap.h"
#include "ModelContext.h"
#include "ApplicationSettings.h"
#include "AnimationState.h"
#include "MouseState.h"
namespace deffem {
class State
{
public:
glm::fvec2 screenSize;
glm::fmat4 HUDprojection;
MouseState mouse;
Camera camera;
Heatmap* heatmap;
std::vector<ModelContext*> deffemModelContexts;
size_t currentModelIndex;
AnimationState animation;
GLfloat modelScale;
ApplicationSettings* settings;
State(ApplicationSettings* settings);
~State();
void clearModels();
void refresh();
bool animationTick();
void restartAnimation();
bool nextModel();
bool previousModel();
bool changeModel(size_t index);
ModelContext* currentModelContext();
void displayStateInfoText(Shader* textShader, Typer* typer);
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/MouseState.h
|
<filename>deffem_postprocessor/headers/MouseState.h
#pragma once
#ifndef MOUSE_STATE_H
#define MOUSE_STATE_H
#include <glm/glm/glm.hpp>
namespace deffem
{
class MouseState
{
public:
glm::fvec2 position;
bool isPressed;
bool isPressedWithShift;
bool isPressedWithControl;
MouseState();
void released();
void pressed();
void pressedWith(int mod);
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Heatmap.h
|
<filename>deffem_postprocessor/headers/Heatmap.h
#pragma once
#ifndef HEATMAP_H
#define HEATMAP_H
#include <glm/glm/detail/type_vec3.hpp>
#include "Typer.h"
#include "ModelInfo.h"
#include <list>
#include "CustomObject.h"
#include "Rectangle.h"
namespace deffem
{
class Heatmap
{
public:
Heatmap(glm::fvec2 pos, glm::fvec2 size, ModelInfo modelInfo, const Color& textColor);
~Heatmap();
void draw(Shader* shader, Shader* textShader, Typer* typer);
void getHeatMapColor(float value, float* red, float* green, float* blue) const;
void setProjection(glm::fmat4* projection);
void setPosition(glm::fvec2 pos);
private:
std::vector<float> valPoints;
glm::fmat4* projection;
glm::vec2 position;
CustomObject* heatmap;
std::list<std::pair<glm::fvec4, Rectangle>> heatMapRows;
ModelInfo modelInfo;
Color textColor;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Typer.h
|
#pragma once
#ifndef TYPER_H
#define TYPER_H
#include <glad/glad.h>
#include "Shader.h"
#include <string>
#include "Color.h"
#include <map>
#include "Letter.h"
namespace deffem
{
class Typer
{
public:
Typer();
~Typer();
void renderText(Shader* s, std::string text, glm::fvec2 pos, GLfloat size, Color color);
void bindTexture(char text);
private:
std::map<char, Letter> letters;
GLuint VAO{}, VBO{}, EBO = 0;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/deffem.h
|
<reponame>mmaikel/DEFFEM_Postprocessor<gh_stars>0
#pragma once
#ifndef
#include ""
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/CustomObject.h
|
<filename>deffem_postprocessor/headers/CustomObject.h
#pragma once
#ifndef CUSTOM_OBJECT_H
#define CUSTOM_OBJECT_H
#include "Object.h"
#include <vector>
namespace deffem
{
class CustomObject final : protected Object
{
public:
CustomObject(std::vector<GLfloat> vertices, std::vector<GLuint> indices,
std::vector<GLuint> attributes, int stride);
CustomObject(std::vector<GLfloat> vertices, std::vector<GLuint> attributes, int stride);
void draw(Shader* shader) override;
void draw() override;
void destroy() override;
~CustomObject();
private:
int indicesSize_;
int verticesSize_;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Rectangle.h
|
#pragma once
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include "Object.h"
#include "Color.h"
namespace deffem
{
class Rectangle : protected Object
{
public:
Rectangle(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
Rectangle(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height, Color color);
Rectangle(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height, Color color[4]);
void destroy() override;
void draw(Shader* shader) override;
void draw() override;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/Button.h
|
<gh_stars>0
#pragma once
#ifndef BUTTON_H
#define BUTTON_H
#include "Rectangle.h"
#include "Shader.h"
namespace deffem {
class Button : protected Rectangle
{
public:
Button(glm::fvec2 pos, glm::fvec2 size, std::string texturePath);
void draw(Shader *shader) override;
void draw() override;
void setProjection(glm::fmat4* projection);
void setPosition(glm::fvec2 pos);
bool isClicked(glm::fvec2 pos);
void changeTexture(const std::string& texturePath);
unsigned int texture;
~Button();
glm::fvec2 position;
glm::fvec2 size;
glm::fmat4* projection;
};
}
#endif
|
mmaikel/DEFFEM_Postprocessor
|
deffem_postprocessor/headers/AnimationState.h
|
<reponame>mmaikel/DEFFEM_Postprocessor
#pragma once
#ifndef ANIMATION_STATE_H
#define ANIMATION_STATE_H
#include <chrono>
namespace deffem
{
class AnimationState
{
public:
bool play;
bool isFinished;
bool repeat;
std::chrono::milliseconds nextDeadline;
std::chrono::milliseconds tickMillis;
void start();
void stop();
};
}
#endif
|
gaozm0509/ZMBadge
|
ZMBadge/UIView+ZMBadge.h
|
<reponame>gaozm0509/ZMBadge
//
// UIView+ZMBadge.h
// ZMBadge
//
// Created by gzm on 17/1/3.
// Copyright © 2017年 gzm. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger,ZMBadgeStyle) {
ZMBadgeStyleDot = 0,//很小的小红点
ZMBadgeStyleNumber,//包含数字的小红点
};
@interface UIView (ZMBadge)
/**
显示小红点 ZMBadgeStyleDot类型
*/
- (void)showBadge;
@property (nonatomic, copy) NSString *badge;
@end
|
gaozm0509/ZMBadge
|
ZMBadge/ViewController.h
|
//
// ViewController.h
// ZMBadge
//
// Created by gzm on 17/1/3.
// Copyright © 2017年 gzm. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
|
gaozm0509/ZMBadge
|
ZMBadge/AppDelegate.h
|
<reponame>gaozm0509/ZMBadge<gh_stars>0
//
// AppDelegate.h
// ZMBadge
//
// Created by gzm on 17/1/3.
// Copyright © 2017年 gzm. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
|
pascal-brand-st-dev/optee_client
|
libteec/src/tee_client_api.c
|
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <teec_trace.h>
#include <teec.h>
#include <tee_client_api.h>
#include <malloc.h>
#define TEE_TZ_DEVICE_NAME "opteearmtz00"
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
/*
* Maximum size of the device name
*/
#define TEEC_MAX_DEVNAME_SIZE 256
#ifdef _GNU_SOURCE
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
#else
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
#endif
static void teec_mutex_lock(pthread_mutex_t *mu)
{
int e = pthread_mutex_lock(mu);
if (e != 0)
EMSG("pthread_mutex_lock failed: %d\n", e);
}
static void teec_mutex_unlock(pthread_mutex_t *mu)
{
int e = pthread_mutex_unlock(mu);
if (e != 0)
EMSG("pthread_mutex_unlock failed: %d\n", e);
}
static void teec_resetTeeCmd(struct tee_cmd_io *cmd)
{
memset((void *)cmd, 0, sizeof(struct tee_cmd_io));
cmd->fd_sess = -1;
cmd->cmd = 0;
cmd->uuid = NULL;
cmd->origin = TEEC_ORIGIN_API;
cmd->err = TEEC_SUCCESS;
cmd->data = NULL;
cmd->data_size = 0;
cmd->op = NULL;
}
/*
* This function initializes a new TEE Context, connecting this Client
* application to the TEE identified by the name name.
*
* name == NULL will give the default TEE.
*/
TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context)
{
int name_size = 0;
const char* _name = name;
INMSG("%s", name);
if (context == NULL)
return TEEC_ERROR_BAD_PARAMETERS;
/*
* Specification says that when no name is provided it should fall back
* on a predefined TEE.
*/
if (name == NULL)
_name = TEE_TZ_DEVICE_NAME;
name_size = snprintf(context->devname, TEEC_MAX_DEVNAME_SIZE,
"/dev/%s", _name);
if (name_size >= TEEC_MAX_DEVNAME_SIZE)
return TEEC_ERROR_BAD_PARAMETERS; /* Device name truncated */
context->fd = open(context->devname, O_RDWR);
if (context->fd == -1)
return TEEC_ERROR_ITEM_NOT_FOUND;
pthread_mutex_init(&mutex, NULL);
OUTMSG("");
return TEEC_SUCCESS;
}
/*
* This function destroys an initialized TEE Context, closing the connection
* between the Client and the TEE.
* The function implementation MUST do nothing if context is NULL
*/
void TEEC_FinalizeContext(TEEC_Context *context)
{
if (context)
close(context->fd);
}
/*
* Allocates or registers shared memory.
*/
TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *shared_memory)
{
struct tee_shm_io shm;
size_t size;
uint32_t flags;
if (context == NULL || shared_memory == NULL)
return TEEC_ERROR_BAD_PARAMETERS;
size = shared_memory->size;
flags = shared_memory->flags;
memset(shared_memory, 0, sizeof(TEEC_SharedMemory));
shared_memory->size = size;
shared_memory->flags = flags;
memset((void *)&shm, 0, sizeof(shm));
shm.buffer = NULL;
shm.size = size;
shm.registered = 0;
shm.fd_shm = 0;
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (ioctl(context->fd, TEE_ALLOC_SHM_IOC, &shm) != 0) {
EMSG("ioctl(TEE_ALLOC_SHM_IOC) failed! (%s)\n",
strerror(errno));
return TEEC_ERROR_OUT_OF_MEMORY;
}
DMSG("fd %d size %d flags %08x", shared_memory->d.fd,
(int)shared_memory->size, shared_memory->flags);
shared_memory->size = size;
shared_memory->d.fd = shm.fd_shm;
/*
* Map memory to current user space process.
*
* Adjust the size in case it is 0 as, from the spec:
* The size is allowed to be zero. In this case memory is
* allocated and the pointer written in to the buffer field
* on return MUST not be NULL but MUST never be de-referenced
* by the Client Application. In this case however, the
* Shared Memory block can be used in Registered Memory References
*/
shared_memory->buffer = mmap(NULL,
(shared_memory->size ==
0) ? 8 : shared_memory->size,
PROT_READ | PROT_WRITE, MAP_SHARED,
shared_memory->d.fd, 0);
if (shared_memory->buffer == (void *)MAP_FAILED) {
EMSG("Mmap failed (%s)\n", strerror(errno));
shared_memory->buffer = NULL;
close(shared_memory->d.fd);
return TEEC_ERROR_OUT_OF_MEMORY;
}
shared_memory->registered = 0;
return TEEC_SUCCESS;
}
/*
* Releases shared memory.
*/
void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *shared_memory)
{
if (!shared_memory)
return;
if (shared_memory->registered)
return;
if (shared_memory->d.fd != 0) {
munmap(shared_memory->buffer, (shared_memory->size ==
0) ? 8 : shared_memory->size);
close(shared_memory->d.fd);
shared_memory->d.fd = 0;
}
shared_memory->buffer = NULL;
}
/*
* Register shared memory
*/
TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *shared_memory)
{
if (!context || !shared_memory)
return TEEC_ERROR_BAD_PARAMETERS;
shared_memory->registered = 1;
/* Use a default fd when not using the dma_buf framework */
if (!(shared_memory->flags & TEEC_MEM_DMABUF))
shared_memory->d.fd = 0;
return TEEC_SUCCESS;
}
/*
* This function opens a new Session between the Client application and the
* specified TEE application.
*
* Only connection_method == TEEC_LOGIN_PUBLIC is supported connection_data and
* operation shall be set to NULL.
*/
TEEC_Result TEEC_OpenSession(TEEC_Context *context,
TEEC_Session *session,
const TEEC_UUID *destination,
uint32_t connection_method,
const void *connection_data,
TEEC_Operation *operation, uint32_t *error_origin)
{
TEEC_Operation dummy_op;
uint32_t origin = TEEC_ORIGIN_API;
TEEC_Result res = TEEC_SUCCESS;
(void)connection_data;
struct tee_cmd_io cmd;
if (session != NULL)
session->fd = -1;
if ((context == NULL) || (session == NULL)) {
res = TEEC_ERROR_BAD_PARAMETERS;
goto error;
}
if (connection_method != TEEC_LOGIN_PUBLIC) {
res = TEEC_ERROR_NOT_SUPPORTED;
goto error;
}
teec_resetTeeCmd(&cmd);
cmd.uuid = (TEEC_UUID *)destination;
if (operation == NULL) {
/*
* The code here exist because Global Platform API states that
* it is allowed to give operation as a NULL pointer. In kernel
* and secure world we in most cases don't want this to be NULL,
* hence we use this dummy operation when a client doesn't
* provide any operation.
*/
memset(&dummy_op, 0, sizeof(TEEC_Operation));
operation = &dummy_op;
}
cmd.op = operation;
errno = 0;
if (ioctl(context->fd, TEE_OPEN_SESSION_IOC, &cmd) != 0) {
EMSG("ioctl(TEE_OPEN_SESSION_IOC) failed! (%s) err %08x ori %08x\n",
strerror(errno), cmd.err, cmd.origin);
if (cmd.origin)
origin = cmd.origin;
else
origin = TEEC_ORIGIN_COMMS;
if (cmd.err)
res = cmd.err;
else
res = TEEC_ERROR_COMMUNICATION;
goto error;
}
session->fd = cmd.fd_sess;
if (cmd.err != 0) {
EMSG("open session to TA UUID %x %x %x failed\n",
destination->timeLow,
destination->timeMid, destination->timeHiAndVersion);
}
origin = cmd.origin;
res = cmd.err;
error:
// printf("**** res=0x%08x, org=%d, seeid=%d ***\n", res, origin, cmd.fd_sess)
/*
* We do this check at the end instead of checking on every place where
* we set the error origin.
*/
if (res != TEEC_SUCCESS) {
if (session != NULL && session->fd != -1) {
close(session->fd);
session->fd = -1;
}
}
if (error_origin != NULL)
*error_origin = origin;
return res;
}
/*
* This function closes a session which has been opened with a TEE
* application.
*/
void TEEC_CloseSession(TEEC_Session *session)
{
if (session == NULL)
return;
close(session->fd);
}
/*
* Invokes a TEE command (secure service, sub-PA or whatever).
*/
TEEC_Result TEEC_InvokeCommand(TEEC_Session *session,
uint32_t cmd_id,
TEEC_Operation *operation,
uint32_t *error_origin)
{
INMSG("session: [%p], cmd_id: [%d]", session, cmd_id);
struct tee_cmd_io cmd;
TEEC_Operation dummy_op;
TEEC_Result result = TEEC_SUCCESS;
uint32_t origin = TEEC_ORIGIN_API;
if (session == NULL) {
origin = TEEC_ORIGIN_API;
result = TEEC_ERROR_BAD_PARAMETERS;
goto error;
}
if (operation == NULL) {
/*
* The code here exist because Global Platform API states that
* it is allowed to give operation as a NULL pointer. In kernel
* and secure world we in most cases don't want this to be NULL,
* hence we use this dummy operation when a client doesn't
* provide any operation.
*/
memset(&dummy_op, 0, sizeof(TEEC_Operation));
operation = &dummy_op;
}
teec_mutex_lock(&mutex);
operation->session = session;
teec_mutex_unlock(&mutex);
teec_resetTeeCmd(&cmd);
cmd.cmd = cmd_id;
cmd.op = operation;
if (ioctl(session->fd, TEE_INVOKE_COMMAND_IOC, &cmd) != 0)
EMSG("ioctl(TEE_INVOKE_COMMAND_IOC) failed! (%s)\n",
strerror(errno));
if (operation != NULL) {
teec_mutex_lock(&mutex);
operation->session = NULL;
teec_mutex_unlock(&mutex);
}
origin = cmd.origin;
result = cmd.err;
error:
if (error_origin != NULL)
*error_origin = origin;
OUTRMSG(result);
}
void TEEC_RequestCancellation(TEEC_Operation *operation)
{
struct tee_cmd_io cmd;
TEEC_Session *session;
if (operation == NULL)
return;
teec_mutex_lock(&mutex);
session = operation->session;
teec_mutex_unlock(&mutex);
if (session == NULL)
return;
teec_resetTeeCmd(&cmd);
cmd.op = operation;
if (ioctl(session->fd, TEE_REQUEST_CANCELLATION_IOC, &cmd) != 0)
EMSG("ioctl(TEE_REQUEST_CANCELLATION_IOC) failed! (%s)\n",
strerror(errno));
}
|
tobykurien/DroidOrb
|
Arduino/droid_orb/droid_orb.h
|
/*
* DroidOrb Android accessory
*
* This is free software. You can redistribute it and/or modify it under
* the terms of Creative Commons Attribution 3.0 United States License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
* See Github project http://github.com/tobykurien/DroidOrb for latest
*/
#ifndef DROIDORB_h
#define DROIDORB_h
#define ANDROID_CONNECTION_PORT "tcp:4567"
// TODO - some pins are used by USB host shield - find out which ones
// pins 13, 12, 11, 10, 9, 8, and 7 are used :-(
#define LED_RED 6
#define LED_GREEN 5
#define LED_BLUE 3
#define LED_WHITE 4
#define LIGHT_SENSOR A0
#define DELAY 1000
#define FADE_DELAY 5
#define DROID_ORB_ADDR 0
#define CMD_SET_LED 0
#define CMD_PULSE_LED 1
#define CMD_RESET 3
#define CMD_LIGHT_METER 4
#define CMD_LIGHTS_OFF 5
#define CMD_LIGHTS_ON 6
#define CMD_TEST 254
#define LIGHT_THRESHOLD_LOW 0x20
#define LIGHT_THRESHOLD_HIGH 0xA0
#endif
|
FKasy/cgv
|
cgv/render/placeable.h
|
<reponame>FKasy/cgv
#pragma once
#include <cgv/render/render_types_namespace.h>
using namespace cgv::render::render_types_ns;
#include "lib_begin.h"
namespace cgv {
namespace render {
class CGV_API placeable {
private:
vec3 position;
vec3 pitch_yaw_roll;
vec3 scale;
mat4 model_matrix;
void calculate_model_matrix();
public:
placeable();
placeable(const vec3 &position);
placeable(const vec3 &position, const vec3 &pitch_yaw_roll);
placeable(const vec3 &position, const vec3 &pitch_yaw_roll, const vec3 &scale);
vec3 get_position() const;
void set_position(const vec3 &position);
void set_position_x(const float x);
void set_position_y(const float y);
void set_position_z(const float z);
vec3 get_pitch_yaw_roll() const;
void set_pitch_yaw_roll(const vec3 &pyr);
void set_pitch(const float pitch);
void set_yaw(const float yaw);
void set_roll(const float roll);
vec3 get_scale();
void set_scale(const vec3 &scale);
void set_scale_x(const float x);
void set_scale_y(const float y);
void set_scale_z(const float z);
mat4 get_model_matrix() const;
void set_model_matrix(const mat4 &model_matrix);
};
} // namespace render
} // namespace cgv
#include <cgv/config/lib_end.h>
|
FKasy/cgv
|
cgv/type/info/type_access.h
|
#pragma once
#include <string>
#include <cgv/type/info/type_id.h>
#include <cgv/type/standard_types.h>
namespace cgv {
namespace type {
namespace info {
/// access value whos type is given by a TypeId
template <typename T>
struct type_access
{
/// return stored value converted into type T
static T get(const void* ptr, TypeId tid)
{
static T dummy = T();
switch (tid) {
case TI_BOOL : return(T)*static_cast<const bool*>(ptr);
case TI_INT8 : return(T)*static_cast<const int8_type*>(ptr);
case TI_INT16 : return(T)*static_cast<const int16_type*>(ptr);
case TI_INT32 : return(T)*static_cast<const int32_type*>(ptr);
case TI_INT64 : return(T)*static_cast<const int64_type*>(ptr);
case TI_UINT8 : return(T)*static_cast<const uint8_type*>(ptr);
case TI_UINT16 : return(T)*static_cast<const uint16_type*>(ptr);
case TI_UINT32 : return(T)*static_cast<const uint32_type*>(ptr);
case TI_UINT32_REV : return (T)*static_cast<const uint32_type*>(ptr);
case TI_UINT64 : return(T)*static_cast<const uint64_type*>(ptr);
case TI_FLT32 : return(T)*static_cast<const flt32_type*>(ptr);
case TI_FLT64 : return(T)*static_cast<const flt64_type*>(ptr);
default:
return dummy;
}
return dummy;
}
/// convert value from type T and store it
static bool set(void* ptr, TypeId tid, const T& v)
{
switch (tid) {
case TI_BOOL : *static_cast<bool*>(ptr) = (v != 0); break;
case TI_INT8 : *static_cast<int8_type*>(ptr) = (int8_type) v; break;
case TI_INT16 : *static_cast<int16_type*>(ptr) = (int16_type) v; break;
case TI_INT32 : *static_cast<int32_type*>(ptr) = (int32_type) v; break;
case TI_INT64 : *static_cast<int64_type*>(ptr) = (int64_type) v; break;
case TI_UINT8 : *static_cast<uint8_type*>(ptr) = (uint8_type) v; break;
case TI_UINT16 : *static_cast<uint16_type*>(ptr) = (uint16_type) v; break;
case TI_UINT32 : *static_cast<uint32_type*>(ptr) = (uint32_type) v; break;
case TI_UINT32_REV : *static_cast<uint32_type*>(ptr) = (uint32_type) v; break;
case TI_UINT64 : *static_cast<uint64_type*>(ptr) = (uint64_type) v; break;
case TI_FLT32 : *static_cast<flt32_type*>(ptr) = (flt32_type) v; break;
case TI_FLT64 : *static_cast<flt64_type*>(ptr) = (flt64_type) v; break;
default:
return false;
}
return true;
}
};
}
}
}
|
FKasy/cgv
|
plugins/openvr_driver/openvr_kit.h
|
#pragma once
#include <vr/gl_vr_display.h>
#include "openvr.h"
#include "openvr_camera.h"
#include <vector>
#include "lib_begin.h"
namespace vr {
/**@name vr device management */
//@{
/// information provided per vr device
class CGV_API openvr_kit : public gl_vr_display
{
protected:
vr::IVRSystem* get_hmd();
// convenience for not have to cast to proper type
openvr_camera* _openvr_camera;
public:
/// construct
openvr_kit(unsigned _width, unsigned _height, vr_driver* _driver, vr::IVRSystem* _hmd, const std::string& _name, bool _ffb_support, bool _wireless);
/// declare virtual destructor
~openvr_kit();
/// for each controller provide information on throttles and sticks and how they map to state axes
const std::vector<std::pair<int, int> >& get_controller_throttles_and_sticks(int controller_index) const;
/// for each controller provide information on throttles' and sticks' deadzone and precision values
const std::vector<std::pair<float, float> >& get_controller_throttles_and_sticks_deadzone_and_precision(int controller_index) const;
/// query current state of vr kit and return whether this was successful
bool query_state(vr_kit_state& state, int pose_query);
/// set the vibration strength between 0 and 1 of low and high frequency motors, return false if device is not connected anymore
bool set_vibration(unsigned controller_index, float low_frequency_strength, float high_frequency_strength);
/// access to 3x4 matrix in column major format for transformation from eye (0..left, 1..right) to head coordinates
void put_eye_to_head_matrix(int eye, float* pose_matrix);
/// access to 4x4 matrix in column major format for perspective transformation from eye (0..left, 1..right)
void put_projection_matrix(int eye, float z_near, float z_far, float* projection_matrix);
/// initialize render targets and framebuffer objects in current opengl context
bool init_fbos();
/// submit the rendered stereo frame to the hmd
void submit_frame();
};
}
#include <cgv/config/lib_end.h>
|
FKasy/cgv
|
cgv/render/drawable_and_placeable.h
|
#pragma once
#include <cgv/render/drawable.h>
#include <cgv/render/placeable.h>
#include "lib_begin.h"
namespace cgv {
namespace render {
// simple wrapper for drawable and placable in one
class CGV_API drawable_and_placeable : public drawable, public placeable {};
} // namespace render
} // namespace cgv
#include <cgv/config/lib_end.h>
|
FKasy/cgv
|
plugins/openvr_driver/openvr_camera.h
|
#pragma once
#include <memory>
#include <vector>
#include <chrono>
#include <vr/vr_camera.h>
#include "openvr.h"
#include "lib_begin.h"
///@ingroup VR
///@{
/**@file
defines camera class for camera provided by openvr_kit
*/
///
namespace vr {
class CGV_API openvr_camera : public vr_camera {
public:
openvr_camera(vr::IVRSystem *hmd);
virtual ~openvr_camera();
protected:
vr::IVRSystem *hmd;
private:
vr::IVRTrackedCamera *tracked_camera;
vr::TrackedCameraHandle_t tracked_camera_handle;
uint32_t last_frame_sequence;
uint32_t framebuffer_size;
vr::CameraVideoStreamFrameHeader_t current_frame_header;
vr::EVRTrackedCameraFrameType distortion_type;
bool initialize_impl() override;
bool start_impl() override;
bool stop_impl() override;
bool query_impl() override;
};
} // namespace vr
///@}
#include <cgv/config/lib_end.h>
|
FKasy/cgv
|
libs/vr/vr_camera.h
|
<reponame>FKasy/cgv
#pragma once
#include <vector>
#include <chrono>
#include "lib_begin.h"
///@ingroup VR
///@{
/**@file
defines camera class for camera provided by vr_kit
*/
///
namespace vr {
/// different status values for a camera
enum class camera_state : uint8_t {
UNINITIALIZED,
INITIALIZED,
STARTED,
ERROR
};
enum class camera_frame_format : uint8_t { RGBA = 0 };
enum class camera_frame_split : uint8_t { NONE = 0, LEFT_RIGHT, UP_DOWN };
class CGV_API vr_camera {
public:
vr_camera();
virtual ~vr_camera() = default;
bool initialize();
bool start();
bool stop();
/// query camera for next frame
/// implementations shall set new_frame_available & frame data
bool query();
bool is_new_frame_available() const;
float get_query_limit() const;
void set_query_limit(float fps);
/// get raw frame, format described by get_frame_format()
std::vector<unsigned char> get_frame() const;
std::vector<unsigned char> &get_frame_ref();
uint32_t get_frame_width() const;
uint32_t get_frame_height() const;
camera_frame_format get_frame_format() const;
camera_frame_split get_frame_split() const;
camera_state get_state() const;
uint8_t get_num_cameras() const;
protected:
uint8_t num_cameras;
std::vector<unsigned char> frame;
uint32_t frame_width;
uint32_t frame_height;
camera_frame_format frame_format;
camera_frame_split frame_split;
bool new_frame_available;
private:
camera_state state;
float query_limit;
std::chrono::high_resolution_clock::time_point last_query_timepoint;
virtual bool initialize_impl() = 0;
virtual bool start_impl() = 0;
virtual bool stop_impl() = 0;
virtual bool query_impl() = 0;
};
} // namespace vr
///@}
#include <cgv/config/lib_end.h>
|
FKasy/cgv
|
cgv/data/rectangle.h
|
<filename>cgv/data/rectangle.h
#pragma once
#include <array>
#include <cgv/math/fvec.h>
#include <cgv/render/render_types_namespace.h>
using namespace cgv::render::render_types_ns;
namespace cgv {
namespace data {
// no class for now, just typedef
// do not inherit from stl containers (no virtual destructors)
using rectangle = std::array<vec3, 4>;
static const rectangle null_rectangle = {
vec3{0.0f, 0.0f, 0.0f}, vec3{0.0f, 0.0f, 0.0f}, vec3{0.0f, 0.0f, 0.0f},
vec3{0.0f, 0.0f, 0.0f}};
} // namespace data
} // namespace cgv
|
FKasy/cgv
|
libs/cgv_gl/rectangle_renderer.h
|
#pragma once
#include <memory>
#include <cgv/data/rectangle.h>
#include <cgv/render/attribute_array_binding.h>
#include <cgv/render/drawable_and_placeable.h>
#include <cgv/render/render_types_namespace.h>
#include <cgv/render/shader_program.h>
#include <cgv/render/vertex_buffer.h>
#include <cgv_gl/gl/gl.h>
using namespace cgv::data;
using namespace cgv::math;
using namespace cgv::render;
using namespace cgv::render::render_types_ns;
#include "gl/lib_begin.h"
namespace cgv {
namespace render {
class CGV_API rectangle_renderer : public drawable_and_placeable {
public:
enum class draw_mode : uint8_t { NORMAL = 0, UPPER_HALF, LOWER_HALF, LEFT_HALF, RIGHT_HALF };
private:
rectangle rect;
draw_mode mode = draw_mode::NORMAL;
bool mode_changed = false;
bool flipped = false;
vec2 zoom = vec2(0.0f,0.0f);
vec2 offset = vec2(0.0f, 0.0f);
// does not own texture
std::shared_ptr<texture> tex;
attribute_array_binding vao;
vertex_buffer v_buf{ VertexBufferType::VBT_VERTICES,
VertexBufferUsage::VBU_DYNAMIC_DRAW };
shader_program prog;
public:
rectangle_renderer();
rectangle_renderer(const rectangle &rect);
rectangle_renderer(std::shared_ptr<texture> tex);
rectangle_renderer(const rectangle &rect, std::shared_ptr<texture> tex);
~rectangle_renderer();
bool init(context &ctx);
void init_frame(context &ctx);
// draw rectangle at position/orientation given by placeable
// draw with member texture
void draw(context &ctx);
// draw with given texture
void draw(context &ctx, const rectangle &rectangle, texture &texture);
// draw with given handle
void draw(context &ctx, const rectangle &rectangle, GLuint texture_handle);
// draw fullscreen, ignores placeable attributes
// draw with member texture
void draw_fullscreen(context &ctx);
// draw with given texture
void draw_fullscreen(context &ctx, texture &texture);
// draw with given handle
void draw_fullscreen(context &ctx, GLuint texture_handle);
void clear(context &ctx);
// mainly used for left/right eye
void set_draw_mode(draw_mode mode);
void set_flipped(bool flipped);
std::shared_ptr<texture> get_texture() const;
void set_texture(std::shared_ptr<texture> t);
rectangle get_rectangle() const;
void set_rectangle(const rectangle &rectangle);
vec2 get_zoom() const;
void set_zoom(const vec2 zoom);
vec2 get_offset() const;
void set_offset(const vec2 offset);
private:
void draw_impl(context &ctx, const rectangle &rectangle, texture &texture);
void draw_fullscreen_impl(context &ctx, texture &texture);
void set_draw_mode_uniforms(context & ctx);
};
} // namespace render
} // namespace cgv
#include <cgv/config/lib_end.h>
|
FKasy/cgv
|
plugins/crg_vr_view/lib_begin.h
|
<filename>plugins/crg_vr_view/lib_begin.h
#if defined(CRG_VR_VIEW_STATIC)
# define CGV_FORCE_STATIC_LIB
#endif
#ifdef CRG_VR_VIEW_EXPORTS
# define CGV_EXPORTS
#endif
#include <cgv/config/lib_begin.h>
|
Darksecond/libcore
|
include/core/containers/fixed_stack.h
|
#pragma once
#include <core/compiler.h>
#include <cassert>
namespace core
{
/**
* stack container (FILO) with a fixed (compile-time) size.
*/
template <typename T, size_t N>
class fixed_stack
{
//TODO Implement these as memcpy
CORE_NO_COPY(fixed_stack);
CORE_NO_MOVE(fixed_stack);
T _array[N];
T* _current;
public:
typedef T* iterator;
typedef const T* const_iterator;
inline fixed_stack() : _current(_array)
{
}
inline size_t size() const
{
return _current - _array;
}
inline size_t capacity() const
{
return N;
}
//TODO Add 'T&&' variant
inline void push(const T& value)
{
assert(size() < capacity());
*_current++ = value;
}
inline void pop()
{
assert(size() > 0);
--_current;
}
inline T& top()
{
assert(size() > 0);
return *(_current - 1);
}
inline const T& top() const
{
assert(size() > 0);
return *(_current - 1);
}
//TODO Rename to 'reset'
inline void clear()
{
_current = _array;
}
inline iterator begin()
{
return _array;
}
inline const_iterator begin() const
{
return _array;
}
inline iterator end()
{
return _current;
}
inline const_iterator end() const
{
return _current;
}
};
};
|
Darksecond/libcore
|
include/core/memory/stack_area.h
|
#pragma once
#include <core/compiler.h>
#include <core/types.h>
namespace core
{
template <int Size>
class stack_area
{
CORE_NO_COPY(stack_area);
CORE_NO_MOVE(stack_area);
uint8_t buffer[Size];
public:
inline void* start() const { return (void*)buffer; }
inline size_t size() const { return Size; }
inline void* end() const { return (uint8_t*)buffer + Size; }
};
};
|
Darksecond/libcore
|
include/core/hashing/fnv1a.h
|
#pragma once
#include <core/types.h>
#include <core/platform.h>
namespace core
{
#ifdef CORE_PLATFORM_WIN
//code from: http://seanmiddleditch.com/journal/2011/05/compile-time-string-hashing-in-c0x/
// FNV-1a constants
static const uint64_t fnv1a_basis = 14695981039346656037ULL;
static const uint64_t fnv1a_prime = 1099511628211ULL;
// compile-time hash helper function
inline uint64_t hash_one_fnv1a(char c, const char* remain, uint64_t value)
{
return c == 0 ? value : hash_one_fnv1a(remain[0], remain + 1, (value ^ c) * fnv1a_prime);
}
// compile-time hash
inline uint64_t hash_fnv1a(const char* str)
{
return hash_one_fnv1a(str[0], str + 1, fnv1a_basis);
}
#else
//code from: http://seanmiddleditch.com/journal/2011/05/compile-time-string-hashing-in-c0x/
// FNV-1a constants
static constexpr uint64_t fnv1a_basis = 14695981039346656037ULL;
static constexpr uint64_t fnv1a_prime = 1099511628211ULL;
// compile-time hash helper function
constexpr uint64_t hash_one_fnv1a(char c, const char* remain, uint64_t value)
{
return c == 0 ? value : hash_one_fnv1a(remain[0], remain + 1, (value ^ c) * fnv1a_prime);
}
// compile-time hash
constexpr uint64_t hash_fnv1a(const char* str)
{
return hash_one_fnv1a(str[0], str + 1, fnv1a_basis);
}
#endif
}
|
Darksecond/libcore
|
include/core/memory.h
|
#pragma once
#include <core/memory/new_delete.h>
#include <core/memory/arena.h>
#include <core/memory/heap_area.h>
#include <core/memory/linear_allocator.h>
//EXAMPLES:
//STL::FallbackAllocator& someArena = fallbackAllocator();
//int* a = CORE_NEW(someArena, int, 3);
//CORE_DELETE(someArena, a);
//int* b = CORE_NEW_ARRAY(someArena, int[3]);
//CORE_DELETE_ARRAY(someArena, b);
/*
struct alignas(128) bigalign
{
uint64_t i[2];
};
*/
|
Darksecond/libcore
|
include/core/time/hf_timer.h
|
#pragma once
#include <core/types.h>
#include <core/platform.h>
namespace core
{
/**
* High frequency timer.
* Usually has < millisecond resolution (depending on platform)
*/
class hf_timer
{
public:
/**
* (re)set the timer.
*/
void reset();
/**
* get the current delta in nanoseconds.
*/
double get_nanoseconds() const;
/**
* Get the current delta in seconds.
*/
double get_seconds() const;
/**
* Get teh current delta in milliseconds.
*/
double get_milliseconds() const;
private:
#ifdef CORE_PLATFORM_APPLE
uint64_t _start;
#endif
};
};
|
Darksecond/libcore
|
include/core/memory/arena.h
|
#pragma once
#include <core/types.h>
#include <core/logging/log.h> // For source_info
namespace core
{
class arena
{
public:
virtual ~arena() {}
virtual void* allocate(const size_t size, const size_t align, const size_t alignment_offset, const source_info& info) = 0;
virtual void free(void* object, const source_info& info) = 0;
};
//TODO Move to it's own file
/**
* This arena only works for allocators that have a constructor
* in the form of allocator(void* start, void* end).
* That's why it won't work for the system allocator.
*
* No access is provided to the allocator itself, for simplicity
* and to make clear this arena has limited usability.
*/
template <typename Allocator>
class possessive_arena : public arena
{
Allocator allocator;
public:
template <typename Area>
possessive_arena(const Area& area) : allocator(area.start(), area.end())
{
}
virtual void* allocate(const size_t size, const size_t align, const size_t alignment_offset, const source_info& info)
{
return allocator.allocate(size, align, alignment_offset);
}
virtual void free(void* object, const source_info& info)
{
allocator.free(object);
}
};
};
|
Darksecond/libcore
|
include/core/logging/console_logger.h
|
<reponame>Darksecond/libcore
#pragma once
#include <core/logging/log.h>
namespace core
{
class console_logger : public logger
{
public:
//replace format and args with fixed_string?
virtual void log(const core::source_info& source_info, int level, const char* channel, const char* format, va_list args);
};
};
|
Darksecond/libcore
|
include/core/string/string_hash.h
|
#pragma once
#include <core/types.h>
#include <core/hashing/fnv1a.h>
namespace core
{
class string_hash
{
public:
typedef uint64_t Type;
constexpr string_hash(const char* str) : hash(hash_fnv1a(str))
{
}
explicit constexpr string_hash(Type h) : hash(h)
{
}
constexpr inline operator Type() const
{
return hash;
}
private:
const Type hash;
};
};
|
Darksecond/libcore
|
include/core/memory/heap_area.h
|
<filename>include/core/memory/heap_area.h
#pragma once
#include <core/compiler.h>
#include <core/types.h>
namespace core
{
class heap_area
{
CORE_NO_COPY(heap_area);
void* _start;
size_t _size;
public:
explicit heap_area(size_t s);
~heap_area();
heap_area(heap_area&& other);
heap_area& operator=(heap_area&& other);
void reserve(size_t new_size);
void release();
inline void* start() const { return _start; }
/**
* \param end is start+size
*/
inline void* end() const { return (uint8_t*)_start + _size; }
inline size_t size() const { return _size; }
};
};
|
Darksecond/libcore
|
include/core/filesystem/fs_file.h
|
<filename>include/core/filesystem/fs_file.h<gh_stars>0
#pragma once
#include <core/filesystem/file.h>
#include <fstream>
namespace core
{
class fs_file : public file
{
std::fstream _stream;
public:
fs_file(const char* path, int mode, archive* owner);
virtual size_t read(void* buffer, size_t buf_size);
virtual void write(const void* buffer, size_t buf_size);
virtual void skip(size_t amount);
virtual void seek(size_t position);
virtual bool eof() const;
virtual size_t total_size();
};
};
|
Darksecond/libcore
|
include/core/filesystem/root.h
|
#pragma once
#include <core/types.h>
#include <core/containers/dynamic_array.h>
namespace core
{
class archive;
class arena;
class file;
class root
{
dynamic_array<archive*> _mounts;
public:
root(arena* arena, int capacity);
void mount(archive*);
void unmount(archive*);
//TODO: replace int mode with something better
/**
* Open a file with path and mode.
* Returns a nullptr if the file does not exist.
*/
file* open(const char* path, int mode);
/**
* Close a previously opened with 'open'.
*/
void close(file* file);
};
};
|
Darksecond/libcore
|
include/core/memory/linear_allocator.h
|
<reponame>Darksecond/libcore<filename>include/core/memory/linear_allocator.h
#pragma once
#include <core/types.h>
#include <core/logging/log.h>
namespace core
{
class linear_allocator
{
uint8_t* _start;
uint8_t* _end;
uint8_t* _current;
public:
linear_allocator(const void* start, const void* end);
/**
* \param size amount of data to allocate in bytes
* \param align data alignment
* \param alignment_offset alignment offset, how many bytes in should the alignment start. can be used for extra preamble data.
* \return pointer to allocated memory or nullptr if out of memory
* address+offset is aligned, NOT address itself
* So if you ask allocate(128, 16, 4) the the return value + 4 will be 16-byte aligned.
* The resulting memory block will be 128 bytes big (in total, offset doesn't get added to size)
* So the offset only influences where the alignemnt 'starts'.
*/
void* allocate(const size_t size, const size_t align, const size_t alignment_offset);
void free(void* object);
inline void reset() { _current = _start; }
};
};
|
Darksecond/libcore
|
include/core/filesystem/archive.h
|
<gh_stars>0
#pragma once
namespace core
{
class file;
class archive
{
public:
/**
* Open a file with path and mode if it exists.
* Returns nullptr if the file does not exist.
*/
virtual file* open(const char* path, int mode) = 0;
/**
* Close a file previously opened.
* This might also delete the file.
*/
virtual void close(file* file) = 0;
};
};
|
Darksecond/libcore
|
include/core/threading/condition_variable.h
|
#pragma once
#include <pthread.h>
namespace core
{
class mutex;
class condition_variable
{
public:
condition_variable();
~condition_variable();
/**
* Signal one waiting thread to resume.
*/
void signal_one();
/**
* Signal all waiting threads to resume.
*/
void signal_all();
/**
* Wait for a signal, will unlock mutex.
*/
void wait(mutex&);
private:
pthread_cond_t _condition;
};
};
|
Darksecond/libcore
|
include/core/containers/fixed_array.h
|
#pragma once
#include <core/compiler.h>
namespace core
{
template <typename T, size_t N>
class fixed_array
{
CORE_NO_MOVE(fixed_array);
CORE_NO_COPY(fixed_array);
T _array[N];
public:
typedef T* iterator;
typedef const T* const_iterator;
inline fixed_array()
{
for(size_t i = 0; i < N; ++i)
_array[i] = T();
}
inline explicit fixed_array(const T& initial_value)
{
for(size_t i = 0; i < N; ++i)
_array[i] = initial_value;
}
inline T& operator[](size_t i)
{
return _array[i];
}
inline const T& operator[](size_t i) const
{
return _array[i];
}
inline size_t capacity() const
{
return N;
}
inline size_t size() const
{
return N;
}
inline iterator begin()
{
return _array;
}
inline const_iterator begin() const
{
return _array;
}
inline iterator end()
{
return _array + N;
}
inline const_iterator end() const
{
return _array + N;
}
};
};
|
Darksecond/libcore
|
include/core/memory/simple_arena.h
|
#pragma once
#include <core/memory/arena.h>
#include <cassert>
namespace core
{
//TODO Rename this
template <typename Allocator>
class simple_arena : public arena
{
Allocator* allocator;
public:
simple_arena(Allocator* alloc) : allocator(alloc)
{
assert(alloc != nullptr);
}
virtual void* allocate(const size_t size, const size_t align, const size_t alignment_offset, const source_info& info)
{
return allocator->allocate(size, align, alignment_offset);
}
virtual void free(void* object, const source_info& info)
{
allocator->free(object);
}
};
};
|
Darksecond/libcore
|
include/core/filesystem/file.h
|
<filename>include/core/filesystem/file.h<gh_stars>0
#pragma once
#include <core/types.h>
namespace core
{
class archive;
class file
{
archive* _owner;
public:
file(archive* owner) : _owner(owner)
{
}
virtual ~file()
{
}
/**
* Read into buffer for a maximum of buf_size bytes.
* Returns the amount of bytes read.
*/
virtual size_t read(void* buffer, size_t buf_size) = 0;
/**
* Write from buffer into file for buf_size bytes.
*/
virtual void write(const void* buffer, size_t buf_size) = 0;
template <typename T>
inline size_t read(T& object)
{
return read(&object, sizeof(T));
}
template <typename T>
inline void write(const T& object)
{
write(&object, sizeof(T));
}
//async_read
//async_write
//streaming stuff?
/**
* skip amount of bytes.
*/
virtual void skip(size_t amount) = 0;
/**
* Seek to position in file.
*/
virtual void seek(size_t position) = 0;
virtual bool eof() const = 0; //or get_remaining_bytes
virtual size_t total_size() = 0;
archive* owner() const
{
return _owner;
}
};
};
|
Darksecond/libcore
|
include/core/compiler.h
|
<reponame>Darksecond/libcore<gh_stars>0
#pragma once
#include <core/platform.h>
#ifdef CORE_PLATFORM_WIN
#define CORE_ALIGNOF(type) __alignof(type)
#define CORE_NO_MOVE_CONSTRUCTOR(Class) Class(Class&&)
#define CORE_NO_MOVE_ASSIGNMENT(Class) Class& operator=(Class&&)
#define CORE_NO_COPY_CONSTRUCTOR(Class) Class(const Class&)
#define CORE_NO_COPY_ASSIGNMENT(Class) Class& operator=(const Class&)
#else //All other platforms (fallback)
#define CORE_ALIGNOF(type) alignof(type)
#define CORE_NO_MOVE_CONSTRUCTOR(Class) Class(Class&&) = delete;
#define CORE_NO_MOVE_ASSIGNMENT(Class) Class& operator=(Class&&) = delete;
#define CORE_NO_COPY_CONSTRUCTOR(Class) Class(const Class&) = delete;
#define CORE_NO_COPY_ASSIGNMENT(Class) Class& operator=(const Class&) = delete;
#endif
#define CORE_NO_MOVE(Class) \
CORE_NO_MOVE_CONSTRUCTOR(Class); \
CORE_NO_MOVE_ASSIGNMENT(Class)
#define CORE_NO_COPY(Class) \
CORE_NO_COPY_CONSTRUCTOR(Class); \
CORE_NO_COPY_ASSIGNMENT(Class)
|
Darksecond/libcore
|
include/core/string/fixed_string.h
|
#pragma once
#include <core/types.h>
#include <cassert>
#include <cstdio>
#include <string.h>
namespace core
{
//TODO add << operator stuff
template<size_t N>
class fixed_string
{
char _string[N];
size_t _length;
public:
inline fixed_string() : _length(0)
{
_string[0] = 0;
}
explicit fixed_string(const char* const str) : _length(strlen(str))
{
assert(_length < N);
memcpy(_string, str, _length+1); //copy null byte as well
}
/**
* Clear the fixed_string.
* This resets the length.
* This also makes the first/last byte a null byte.
*/
void clear()
{
_length = 0;
_string[0] = 0;
}
inline char& operator[](size_t i)
{
assert(i <= _length);
return _string[i];
}
inline const char& operator[](size_t i) const
{
assert(i <= _length);
return _string[i];
}
/**
* Returns a c_str compatible string for use with external code.
*/
inline const char* c_str() const
{
return _string;
}
inline size_t length() const
{
return _length;
}
inline size_t capacity() const
{
return N;
}
/**
* Append a count bytes of the string str to the fixed_string.
* The current length + the count cannot be greater than the capacity.
* An assert _will_ be raised if it does not fit.
* Append will make sure the fixed_string always ends with a null byte.
*/
inline void append(const char* str, size_t count)
{
assert(_length + count < N);
memcpy(_string + _length, str, count);
_length += count;
_string[_length] = 0;
}
/**
* Append a string to the fixed string.
* An assert _will_ be raised if it does not fit, so be careful.
*/
inline void append(const char* str)
{
append(str, strlen(str));
}
/**
* This will append a formatted string to the fixed_string.
* It will take in as many arguments as you supply in a printf style.
* If the end product formatted string does not fit it is clipped.
* When clipped, it will always end with a null byte so it is still a valid c_str.
*/
inline void append_fmt(const char* format, ...)
{
va_list formatters;
va_start(formatters, format);
append_fmt_v(format, formatters);
va_end(formatters);
}
/**
* This will append a formatted string to the fixed_string.
* It will take in as many arguments as you supply in a printf style.
* If the end product formatted string does not fit it is clipped.
* When clipped, it will always end with a null byte so it is still a valid c_str.
* This is the va_list version of append_fmt
*/
inline void append_fmt_v(const char* format, va_list formatters)
{
const int chars_written = vsnprintf(_string + _length, N - _length, format, formatters);
if(chars_written < 0)
{
_length = N-1;
_string[_length] = 0; //clip string, append null byte
}
else
{
_length += chars_written;
}
}
};
}
|
Darksecond/libcore
|
include/core/core.h
|
#pragma once
#define CORE_VERSION_MAJOR 0
#define CORE_VERSION_MINOR 1
|
Darksecond/libcore
|
include/core/util/pointer_align.h
|
<filename>include/core/util/pointer_align.h
#pragma once
#include <core/types.h>
namespace core
{
inline void* align_up(void* p, size_t align)
{
uintptr_t pi = uintptr_t(p);
const size_t mod = pi % align;
if (mod)
pi += (align - mod);
return (void*)pi;
}
inline void* align_down(void* p, size_t align)
{
uintptr_t pi = uintptr_t(p);
const size_t mod = pi % align;
if (mod)
pi -= mod;
return (void*)pi;
}
}
|
Darksecond/libcore
|
include/core/containers/dynamic_stack.h
|
<reponame>Darksecond/libcore<filename>include/core/containers/dynamic_stack.h<gh_stars>0
#pragma once
#include <core/compiler.h>
#include <core/memory/arena.h>
#include <core/memory/new_delete.h>
#include <cassert>
namespace core
{
template <typename T>
class dynamic_stack
{
//TODO Implement these
CORE_NO_COPY(dynamic_stack);
CORE_NO_MOVE(dynamic_stack);
arena* _arena;
T* _start; //Start of array
T* _end; //One after last element of array
T* _current; //Next empty element
public:
typedef T* iterator;
typedef const T* const_iterator;
dynamic_stack(arena* a, const size_t capacity) : _arena(a), _start(nullptr), _end(nullptr), _current(nullptr)
{
assert(a != nullptr);
reserve(capacity);
}
~dynamic_stack()
{
free();
}
void reserve(const size_t capacity)
{
assert(_start == nullptr);
_start = static_cast<T*>(_arena->allocate(sizeof(T)*capacity, CORE_ALIGNOF(T), 0, CORE_SOURCEINFO));
_current = _start;
_end = _start + capacity;
}
void free()
{
clear();
if(_start)
_arena->free(_start, CORE_SOURCEINFO);
_start = nullptr;
_end = nullptr;
_current = nullptr;
}
size_t size() const
{
return _current - _start;
}
size_t capacity() const
{
return _end - _start;
}
void push(const T& value)
{
assert(size() < capacity());
memory_internals::construct<T>(_current, value);
++_current;
}
void push(T&& value)
{
assert(size() < capacity());
memory_internals::construct<T>(_current, std::move(value));
++_current;
}
void pop()
{
assert(size() > 0);
--_current;
memory_internals::destruct(_current);
}
T& top()
{
assert(size() > 0);
return *(_current - 1);
}
const T& top() const
{
assert(size() > 0);
return *(_current - 1);
}
void clear()
{
for(size_t i = 0; i < size(); ++i)
memory_internals::destruct(_start + i);
_current = _start;
}
iterator begin()
{
return _start;
}
const_iterator begin() const
{
return _start;
}
iterator end()
{
return _current;
}
const_iterator end() const
{
return _current;
}
bool empty() const
{
return _start == _current;
}
};
};
|
Darksecond/libcore
|
include/core/threading/thread.h
|
<reponame>Darksecond/libcore
#pragma once
#include <core/compiler.h>
#include <pthread.h>
namespace core
{
/*
* This is a wrapper around native OS threads.
* The API is abstracted so it will work on multiple platforms.
*/
class thread
{
CORE_NO_MOVE(thread);
CORE_NO_COPY(thread);
enum class state_t
{
READY,
RUNNING,
SHOULD_STOP,
STOPPED,
};
public:
typedef void (*function)(const thread&);
/**
* This does not create an OS thread.
*/
thread();
/**
* This just calls destroy().
*/
~thread();
/**
* Create and start a new OS thread, with name and function to execute.
*/
void create(const char* name, function f);
/**
* Calls stop() followed by join().
*/
void destroy();
/**
* Join on thread.
*/
void join();
/**
* Tell thread to stop,
* there is no guarentee the thread _will_ actually stop,
* but it should.
*/
void stop();
/**
* This will be true if the thread should stop.
*/
bool should_stop() const;
/**
* This will be true if stop is not called.
*/
bool continue_running() const;
/**
This will be true if the thread has ended.
*/
bool is_stopped() const;
/**
* Yield back to the OS.
*/
void yield();
private:
static void* thread_main_function(void* thread);
function _function;
state_t _state;
pthread_t _thread;
const char* _name;
};
};
|
Darksecond/libcore
|
include/core/memory/system_allocator.h
|
<gh_stars>0
#pragma once
#include <core/types.h>
#include <core/logging/log.h>
namespace core
{
class system_allocator
{
public:
//address+offset should be aligned, NOT address itself
void* allocate(size_t size, size_t align, size_t offset);
void free(void* object);
};
};
|
Darksecond/libcore
|
include/core/logging/log.h
|
#pragma once
#include <cstdarg>
#define CORE_SOURCEINFO core::source_info(__FILE__, __FUNCTION__, __LINE__)
#define CORE_LOG(level, channel, format, ...) core::log::log(CORE_SOURCEINFO, level, channel, format, ##__VA_ARGS__)
#define CORE_LDEBUG(channel, format, ...) core::log::log(CORE_SOURCEINFO, 4, channel, format, ##__VA_ARGS__)
#define CORE_LINFO(channel, format, ...) core::log::log(CORE_SOURCEINFO, 3, channel, format, ##__VA_ARGS__)
#define CORE_LWARNING(channel, format, ...) core::log::log(CORE_SOURCEINFO, 2, channel, format, ##__VA_ARGS__)
#define CORE_LERROR(channel, format, ...) core::log::log(CORE_SOURCEINFO, 1, channel, format, ##__VA_ARGS__)
#define CORE_LFATAL(channel, format, ...) core::log::log(CORE_SOURCEINFO, 0, channel, format, ##__VA_ARGS__)
namespace core
{
struct source_info
{
inline source_info(const char* const file_, const char* const function_, const int line_) : file(file_), function(function_), line(line_)
{
}
const char* const file;
const char* const function;
const int line;
};
class logger
{
public:
virtual ~logger() {}
//replace format and args with fixed_string?
virtual void log(const core::source_info& source_info, int level, const char* channel, const char* format, va_list args) = 0;
};
//0 = fatal, 1 = error, 2 = warning, 3 = info, 4 = debug
namespace log
{
void set_logger(logger* logger, int i);
void log(const core::source_info& source_info, int level, const char* channel, const char* format, ...);
};
};
|
Darksecond/libcore
|
include/core/filesystem/modes.h
|
<reponame>Darksecond/libcore
#pragma once
namespace core
{
namespace fs_modes
{
static const int in = 1;
static const int out = 2;
static const int append = 4;
};
};
|
Darksecond/libcore
|
include/core/types.h
|
#pragma once
#include <cstddef>
#include <stdint.h>
namespace core
{
template<class T>
struct type_and_count
{
typedef T Type;
};
template<class T, size_t N>
struct type_and_count<T[N]>
{
typedef T Type;
static const size_t Count = N;
};
template<bool I>
struct bool_to_type
{
};
};
|
Darksecond/libcore
|
include/core/threading/thread_local_storage.h
|
#pragma once
#include <core/compiler.h>
#include <pthread.h>
#include <cassert>
namespace core
{
template <typename T>
class thread_specific_ptr
{
CORE_NO_COPY(thread_specific_ptr);
CORE_NO_MOVE(thread_specific_ptr);
pthread_key_t _key;
public:
thread_specific_ptr()
{
pthread_key_create(&_key, nullptr);
}
~thread_specific_ptr()
{
pthread_key_delete(_key);
}
thread_specific_ptr& operator=(T* p)
{
set(p);
return *this;
}
inline void set(T* p)
{
pthread_setspecific(_key, p);
}
inline T* get() const
{
return static_cast<T*>(pthread_getspecific(_key));
}
inline T* operator->() const
{
return get();
}
inline T& operator*() const
{
assert(get() != nullptr);
return *get();
}
};
};
|
Darksecond/libcore
|
include/core/memory/stack_allocator.h
|
<filename>include/core/memory/stack_allocator.h
#pragma once
#include <core/types.h>
#include <core/logging/log.h>
namespace core
{
class stack_allocator
{
uint8_t* _start;
uint8_t* _end;
uint8_t* _current;
public:
stack_allocator(const void* start, const void* end);
void* allocate(const size_t size, const size_t align, const size_t alignment_offset);
void free(void* object);
};
}
|
Darksecond/libcore
|
include/core/util/event.h
|
<gh_stars>0
#pragma once
#include <core/containers/dynamic_array.h>
namespace core
{
template<typename T>
class event;
template<typename R, typename... Args>
class event<R (Args...)> {
typedef R (*ptr)(void*, Args...);
struct stub
{
void* instance;
ptr function;
inline bool operator==(const stub& other)
{
return (instance == other.instance) && (function == other.function);
}
};
template<class T, R (T::*Function)(Args...)>
static R class_method_stub(void* instance, Args... args)
{
return (static_cast<T*>(instance)->*Function)(args...);
}
template<class T, R (T::*Function)(Args...) const>
static R const_class_method_stub(void* instance, Args... args)
{
return (static_cast<const T*>(instance)->*Function)(args...);
}
template<R (*Function)(Args...)>
static R function_stub(void* instance, Args... args)
{
return (Function)(args...);
}
public:
event() : _sink(nullptr)
{
}
class sink
{
core::dynamic_array<stub> stubs;
friend class event;
public:
sink(arena* a, const int max_listeners) : stubs(a, max_listeners)
{
}
//Non-const class member
template<class T, R (T::*Function)(Args...)>
void add_listener(T* o) {
stub stub;
stub.instance = o;
stub.function = &class_method_stub<T, Function>;
stubs.add(stub);
}
//const class member
template<class T, R (T::*Function)(Args...) const>
void add_listener(T* o) {
stub stub;
stub.instance = o;
stub.function = &const_class_method_stub<T, Function>;
stubs.add(stub);
}
//Freestanding function
template<R (*Function)(Args...)>
void add_listener() {
stub stub;
stub.instance = nullptr;
stub.function = &function_stub<Function>;
stubs.add(stub);
}
//Non-const class member
template<class T, R (T::*Function)(Args...)>
void remove_listener(T* o) {
stub stub;
stub.instance = o;
stub.function = &class_method_stub<T, Function>;
stubs.erase(stub);
}
//const class member
template<class T, R (T::*Function)(Args...) const>
void remove_listener(T* o) {
stub stub;
stub.instance = o;
stub.function = &const_class_method_stub<T, Function>;
stubs.erase(stub);
}
//Freestanding function
template<R (*Function)(Args...)>
void remove_listener() {
stub stub;
stub.instance = nullptr;
stub.function = &function_stub<Function>;
stubs.erase(stub);
}
};
void bind(sink* sink)
{
_sink = sink;
}
/**
* Signal all the listeners in the bound sink.
* This will assert if no sink is bound, use is_bound() to check.
*/
//TODO Do something with the return values perhaps?
void signal(Args... args) const
{
assert(is_bound());
for(int i=0;i<_sink->stubs.size();++i)
{
const stub& stub = _sink->stubs[i];
stub.function(stub.instance, args...);
}
}
bool is_bound() const
{
return _sink != nullptr;
}
private:
sink* _sink;
};
}
|
Darksecond/libcore
|
include/core/filesystem/fs_archive.h
|
<reponame>Darksecond/libcore
#pragma once
#include <core/filesystem/archive.h>
namespace core
{
class arena;
class fs_archive : public archive
{
arena* _arena;
const char* _directory;
public:
/**
* directory is the 'working directory' for this archive.
* arena is the memory arena used to create files in.
*/
fs_archive(const char* directory, arena* arena);
virtual file* open(const char* path, int mode) override;
virtual void close(file* file) override;
};
};
|
Darksecond/libcore
|
include/core/threading/mutex.h
|
#pragma once
#include <core/compiler.h>
#include <pthread.h>
namespace core
{
class mutex
{
public:
mutex();
~mutex();
/**
* Lock the mutex, or wait until it can be locked
*/
void lock();
/**
* Returns true when the lock was successfull
*/
bool try_lock();
/**
Unlock the mutex
*/
void unlock();
/**
* For internal use only.
*/
inline pthread_mutex_t& os_mutex()
{
return _mutex;
}
private:
pthread_mutex_t _mutex;
};
class scoped_lock
{
CORE_NO_COPY(scoped_lock);
CORE_NO_MOVE(scoped_lock);
mutex _mutex;
public:
inline scoped_lock()
{
_mutex.lock();
}
inline ~scoped_lock()
{
_mutex.unlock();
}
};
};
|
Darksecond/libcore
|
include/core/platform.h
|
#pragma once
/**
* Defines for platform detection.
* WIN64 needs to be before WIN32 as WIN32 is also on with 64-bit windows (backwards compatibility).
*/
#ifdef __APPLE__
#define CORE_PLATFORM apple
#define CORE_PLATFORM_APPLE
#elif __linux__
#define CORE_PLATFORM linux
#define CORE_PLATFORM_LINUX
#elif _WIN64
#define CORE_PLATFORM win
#define CORE_PLATFORM_SPECIFIC win64
#define CORE_PLATFORM_WIN
#define CORE_PLATFORM_WIN64
#elif _WIN32
#define CORE_PLATFORM win
#define CORE_PLATFORM_SPECIFIC win32
#define CORE_PLATFORM_WIN
#define CORE_PLATFORM_WIN32
#else
#error Unknown platform
#endif
|
Darksecond/libcore
|
include/core/containers/freelist.h
|
#pragma once
namespace core
{
class freelist
{
freelist* next;
public:
inline freelist();
inline freelist(void* start, void* end, size_t element_size);
inline void* pop();
inline void push(void* ptr);
};
inline freelist::freelist() : next(nullptr)
{
}
inline freelist::freelist(void* start, void* end, size_t element_size) : next(nullptr)
{
assert(element_size >= sizeof(freelist*));
union
{
void* as_void;
char* as_char;
freelist* as_freelist;
};
as_void = start;
next = as_freelist;
const size_t element_count = (static_cast<char*>(end) - as_char) / element_size;
as_char += element_size;
//initialize freelist chain
freelist* runner = next;
for(size_t i = 1; i < element_count; ++i)
{
runner->next = as_freelist;
runner = runner->next;
as_char += element_size;
}
}
inline void* freelist::pop()
{
if(next == nullptr)
return nullptr;
freelist* head = next;
next = head->next;
return head;
}
inline void freelist::push(void* ptr)
{
assert(ptr);
freelist* head = static_cast<freelist*>(ptr);
head->next = next;
next = head;
}
};
|
Darksecond/libcore
|
include/core/memory/new_delete.h
|
<filename>include/core/memory/new_delete.h<gh_stars>0
#pragma once
#include <core/types.h>
#include <core/compiler.h>
#include <core/logging/log.h>
#include <core/util/union_cast.h>
#include <cassert>
#include <type_traits>
#include <new>
#define CORE_NEW(arena, type, ...) (new ((arena).allocate(sizeof(type), CORE_ALIGNOF(type), 0, CORE_SOURCEINFO)) type(__VA_ARGS__))
#define CORE_NEW_ALIGNED(arena, type, alignment, ...) (new ((arena).allocate(sizeof(type), alignment, 0, CORE_SOURCEINFO)) type(__VA_ARGS__))
#define CORE_DELETE(arena, object) core::memory_internals::delete_mem(arena, object, CORE_SOURCEINFO)
#define CORE_NEW_ARRAY(arena, type) core::memory_internals::new_array_mem<core::type_and_count<type>::Type>(arena, CORE_ALIGNOF(core::type_and_count<type>::Type), core::type_and_count<type>::Count, CORE_SOURCEINFO)
#define CORE_NEW_ARRAY_ALIGNED(arena, type, alignment) core::memory_internals::new_array_mem<core::type_and_count<type>::Type>(arena, alignment, core::type_and_count<type>::Count, CORE_SOURCEINFO)
#define CORE_DELETE_ARRAY(arena, ptr) core::memory_internals::delete_array_mem(arena, ptr, CORE_SOURCEINFO);
namespace core
{
//TODO CORE_NEW_ARRAY_ALIGNED
//TODO Move to core::memory namespace instead of memory_internals
namespace memory_internals
{
typedef bool_to_type<false> NonPODType;
typedef bool_to_type<true> PODType;
template<typename T>
inline void destruct(T* object, NonPODType)
{
object->~T();
}
template<typename T>
inline void destruct(T* object, PODType)
{
//Do nothing
}
template<typename T>
inline void destruct(T* object)
{
assert(object);
destruct(object, bool_to_type<std::is_pod<T>::value>());
}
template<typename T>
inline void destruct_array(T* objects, const size_t N)
{
assert(objects);
for(size_t i=N; i>0; --i)
destruct(objects + i - 1);
}
template<typename T>
inline T* construct(void* where)
{
assert(where);
return new (where) T;
}
template<typename T>
inline T* construct(void* where, const T& what)
{
assert(where);
return new (where) T(what);
}
template<typename T>
inline T* construct(void* where, T&& what)
{
assert(where);
return new (where) T(what);
}
template<typename T>
inline T* construct_array(void* where, const size_t N)
{
assert(where);
T* as_T = union_cast<T*>(where);
for(size_t i=0; i<N; ++i)
construct<T>(as_T + i);
return as_T;
}
template<class A, typename T>
void delete_mem(A& arena, T* object, const source_info& info)
{
if(object)
{
destruct(object);
arena.free(object, info);
}
}
template<typename T, class A>
T* new_array_mem(A& arena, const size_t count, const size_t alignment, const source_info& info, PODType)
{
return static_cast<T*>(arena.allocate(sizeof(T) * count, alignment, 0, info));
}
template<typename T, class A>
T* new_array_mem(A& arena, const size_t count, const size_t alignment, const source_info& info, NonPODType)
{
union
{
void* as_void;
size_t* as_size_t;
};
as_void = arena.allocate( sizeof(T) * count + sizeof(size_t), alignment, sizeof(size_t), info );
*as_size_t++ = count;
return construct_array<T>(as_void, count);
}
template<typename T, class A>
T* new_array_mem(A& arena, size_t count, const size_t alignment, const source_info& info)
{
return new_array_mem<T>(arena, count, alignment, info, bool_to_type<std::is_pod<T>::value>());
}
template<typename T, class A>
void delete_array_mem(A& arena, T* ptr, const source_info& info, PODType)
{
arena.free(ptr, info);
}
template<typename T, class A>
void delete_array_mem(A& arena, T* ptr, const source_info& info, NonPODType)
{
union
{
size_t* as_size_t;
T* as_T;
};
as_T = ptr;
const size_t count = as_size_t[-1];
destruct_array(as_T, count);
arena.free(as_size_t-1, info);
}
template <typename T, class A>
void delete_array_mem(A& arena, T* ptr, const source_info& info)
{
if(ptr)
delete_array_mem(arena, ptr, info, bool_to_type<std::is_pod<T>::value>());
}
}
};
|
Darksecond/libcore
|
include/core/util/union_cast.h
|
<filename>include/core/util/union_cast.h
#pragma once
namespace core
{
template <typename TO, typename FROM>
inline TO union_cast(FROM from)
{
static_assert(sizeof(TO) == sizeof(FROM), "Can only cast from types of the same size.");
union
{
FROM cast_from;
TO cast_to;
};
cast_from = from;
return cast_to;
}
};
|
Darksecond/libcore
|
include/core/containers/dynamic_array.h
|
#pragma once
#include <core/compiler.h>
#include <core/memory/arena.h>
#include <core/memory/new_delete.h>
#include <cassert>
#include <utility>
namespace core
{
/**
* Dynamic array container, like std::vector.
* This will use an allocator to allocate memory and will not grow dynamically.
*/
template<typename T>
class dynamic_array
{
//TODO Implement with memcpy
CORE_NO_COPY(dynamic_array);
arena* _arena;
T* _start;
T* _end; //one after end of allocated memory
T* _used_end; //one after end of used items
public:
typedef T* iterator;
typedef const T* const_iterator;
explicit inline dynamic_array(arena* a) : _arena(a), _start(nullptr), _end(nullptr), _used_end(nullptr)
{
assert(a != nullptr);
}
inline dynamic_array(arena* a, const size_t initial_capacity) : _arena(a), _start(nullptr), _end(nullptr), _used_end(nullptr)
{
assert(a != nullptr);
reserve(initial_capacity);
}
dynamic_array(dynamic_array&& other) : _start(other._start), _end(other._end), _used_end(other._used_end)
{
other._start = nullptr;
other._end = nullptr;
other._used_end = nullptr;
}
dynamic_array& operator=(dynamic_array&& other)
{
free();
_start = other._start;
_end = other._end;
_used_end = other._used_end;
other._start = nullptr;
other._end = nullptr;
other._used_end = nullptr;
}
~dynamic_array()
{
free();
}
/**
* Allocate memory to store elements in. This will allocate memory for \p new_capacity elements.
*/
void reserve(size_t new_capacity)
{
assert(_start == nullptr); //dynamic_array has not been free-ed yet.
_start = static_cast<T*>(_arena->allocate(sizeof(T)*new_capacity, CORE_ALIGNOF(T), 0, CORE_SOURCEINFO));
_end = _start + new_capacity;
_used_end = _start;
}
/**
* \returns the current amount of elements in this array.
*/
size_t size()
{
return _used_end - _start;
}
/**
* The maximum amount of elements this array can contain.
*/
size_t capacity()
{
return _end - _start;
}
/**
* Clear all elements from the array.
* This will properly call the destructor on every element if required.
*/
void clear()
{
for(size_t i = 0; i < size(); ++i)
memory_internals::destruct(_start + i);
_used_end = _start;
}
/**
* Free the memory used by the array.
*/
void free()
{
clear();
if(_start)
_arena->free(_start, CORE_SOURCEINFO);
_start = nullptr;
_end = nullptr;
_used_end = nullptr;
}
/**
* Access elements of array.
* \param i element index. must be valid and in range.
*/
T& operator[](size_t i)
{
assert(_start + i < _used_end); //must be in range
return _start[i];
}
/**
* Access elements of array.
* \param i element index. must be valid and in range.
*/
const T& operator[](size_t i) const
{
assert(_start + i < _used_end); //must be in range
return _start[i];
}
/**
* Add element \p item to the end of the array by copying it.
* and increase size by one.
*/
void add(const T& item)
{
assert(_start != nullptr); //cannot be free-ed
assert(_end != _used_end); //cannot be full
memory_internals::construct<T>(_used_end, item);
++_used_end;
}
/**
* Add element \p item to the end of the array by moving it.
* and increase size by one.
*/
void add(T&& item)
{
assert(_start != nullptr); //cannot be free-ed
assert(_end != _used_end); //cannot be full
memory_internals::construct<T>(_used_end, std::move(item));
++_used_end;
}
/**
* Get direct access to the underlying array
*/
T* data()
{
return _start;
}
/**
* Get direct access to the underlying array
*/
const T* data() const
{
return _start;
}
/**
* Remove the last element from the array and decrease size()
*/
void pop_back()
{
assert(size() > 0);
--_used_end;
memory_internals::destruct(_used_end);
}
iterator begin()
{
return _start;
}
const_iterator begin() const
{
return _start;
}
iterator end()
{
return _used_end;
}
const_iterator end() const
{
return _used_end;
}
/**
* \returns true if the array is empty, false if not.
*/
bool empty() const
{
return _start == _used_end;
}
/**
* Erases element i by moving the last element into it's place.
* \warning This will _not_ keep the array order!
*/
inline void erase(size_t i)
{
assert(_start + i < _used_end); //cannot delete outside of used range
memory_internals::destruct(_start + i);
--_used_end;
const bool last = (_start +i == _used_end);
if(!empty() && !last)
{
memory_internals::construct<T>(_start + i, std::move(*_used_end));
memory_internals::destruct(_used_end);
}
}
/**
* Erases element pointed to by \p it by moving the last element into it's place.
* \warning This will _not_ keep the array order!
*/
void erase(iterator it)
{
erase(it - _start);
}
/**
* Erases element pointed to by \p it by moving the last element into it's place.
* \warning This will _not_ keep the array order!
*/
void erase(const_iterator it)
{
erase(it - _start);
}
/**
* This will erase the first element that matches \p element by moving the last element into it's place.
* \warning This will _not_ keep the array order!
*/
void erase(const T& element)
{
for(size_t i = 0; i < size(); ++i)
{
if(_start[i] == element)
{
erase(i);
return;
}
}
}
};
};
|
AlirezaKamyab/BankProjectCpp
|
Headers/date.h
|
<filename>Headers/date.h
#ifndef DATE_H
#define DATE_H
#include <iostream>
#include <stdexcept>
#include <string>
using namespace std;
class DateException : public exception {
public:
DateException() : message{""} {}
explicit DateException(const string& msg) : message{msg} {}
explicit DateException(const char* msg) : message{msg} {}
virtual ~DateException() {}
virtual const char* what(void) const noexcept { return message.c_str(); }
private:
string message;
};
class Date {
public:
Date();
Date(int d, int m, int y);
Date(const string&);
Date(const Date&);
Date(Date&&) noexcept;
~Date();
void set_date(int d, int m, int y);
void print_date() const;
bool equals(const Date& d) const;
int get_day() const { return day; }
int get_month() const { return month; }
int get_year() const { return year; }
void inc_one_day();
int compare(const Date&) const;
static bool is_leap_year(int year);
static int max_day_for_month(int m, int y);
static int days_between(const Date& d1, const Date& d2);
static Date str_to_date(string s);
Date& operator=(const Date&);
bool operator==(const Date&) const;
bool operator<(const Date&) const;
bool operator>(const Date&) const;
bool operator<=(const Date&) const;
bool operator>=(const Date&) const;
Date operator++(int);
Date& operator++(void);
private:
int day;
int month;
int year;
void reset();
};
// Non-member functions
ostream& operator<<(ostream& o, const Date& dte);
istream& operator>>(istream& in, Date& dte);
#endif // DATE_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/loan.h
|
#ifndef LOAN_H
#define LOAN_H
#include <string>
#include "date.h"
#include "vector"
using namespace std;
class Account;
class Bank;
class LoanException : public exception {
public:
LoanException() : message{""} {}
explicit LoanException(const string& msg) : message{msg} {}
explicit LoanException(const char* msg) : message{msg} {}
virtual ~LoanException() {}
virtual const char* what() const noexcept { return message.c_str(); }
private:
string message;
};
enum class LoanType {MONTH_12 = 4, MONTH_24 = 8, MONTH_36 = 12};
class Loan {
public:
Loan(const string&, const Account*, const Date&, const int64_t&, const LoanType& = LoanType::MONTH_24);
Loan(const string&, const Account*, const Date&, const int64_t&, const LoanType&, const int&, const int&);
Loan(const Loan&);
Loan(Loan&&) noexcept;
~Loan();
void setValue(const int64_t&);
void setRemainingPayments(const int&);
void setOverduePayments(const int&);
string getSerialNumber(void) const;
string getLinkedAccountNumber(void) const;
Date getLoanDate(void) const;
int64_t getValue(void) const;
LoanType getLoanType(void) const;
int getRemainingPayments(void) const;
int getPaidPayments(void) const;
int getOverduePayments(void) const;
void pay(Bank*);
int64_t getEachPayment(void) const;
static bool isValidSerial(const string&);
Loan& operator=(const Loan&);
operator string() const;
private:
string _serialNumber;
string _linkedAccountNumber;
Date _loanDate;
int64_t _value;
LoanType _loanType;
int _remaining_payments;
int _overdue_payments;
Loan();
void reset();
static vector<string> _loanSerials;
};
#endif // LOAN_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/user.h
|
<reponame>AlirezaKamyab/BankProjectCpp
#ifndef USER_H
#define USER_H
#include <string>
#include <vector>
using namespace std;
class UserException : public exception {
public:
UserException() : _message{""} {}
explicit UserException(const string& msg) : _message{msg} {}
explicit UserException(const char* msg) : _message{msg} {}
virtual ~UserException() {}
virtual const char* what() const noexcept { return _message.c_str(); }
private:
string _message;
};
class User {
public:
User(const string&, const string&);
User(const User&);
User(User&&) noexcept;
virtual ~User();
string getUsername() const;
string getPassword() const;
bool login(const User&) const;
bool login(const string&, const string&) const;
User& operator=(const User&);
bool operator==(const User&) const;
bool operator!=(const User&) const;
operator string() const;
protected:
string _username;
string _password;
User();
void reset();
private:
static vector<string> _usernames;
};
#endif // USER_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/employee.h
|
<reponame>AlirezaKamyab/BankProjectCpp
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include "person.h"
#include "client.h"
#include "user.h"
#include <string>
using namespace std;
class Bank;
class Account;
enum class EmployeeType {EMPLOYEE=0, FACILITIES=1, MANAGER=2};
class EmployeeException : public exception {
public:
EmployeeException() : message{""} {}
explicit EmployeeException(const string& msg) : message{msg} {}
explicit EmployeeException(const char* msg) : message{msg} {}
virtual ~EmployeeException() {}
virtual const char* what() const noexcept { return message.c_str(); }
private:
string message;
};
class Employee : public User, public Person {
public:
Employee(const string&, const string&, const string&, const int&, const Date&, const string&, const string&);
Employee(const string&, const string&, const string&, const int&, const Date&, const string&, const string&, const int64_t&,
const int&, const int&, Bank*);
Employee(const Employee&);
Employee(Employee&&) noexcept;
virtual ~Employee();
int getPersonnelId() const;
Bank* getBank() const;
int64_t getBaseIncome() const;
int64_t getIncome() const;
int64_t getPenalty() const;
int64_t getReward() const;
int getVacationHours() const;
int getExtraHours() const;
EmployeeType getEmployeeType() const;
static int getLastgGeneratedPersonnelId();
void setBaseIncome(const int64_t&);
void setPenalty(const int64_t&);
void setReward(const int64_t&);
void setVacationHours(const int&);
void setExtraHours(const int&);
void setBank(Bank*);
void setEmployeeType(const EmployeeType&);
static void setLastGeneratedPersonnelId(const int&);
void takeHoursOff(const int&);
void requestExtraHours(const int&);
Client* searchClient(const string& id) const;
void enableAccount(const string&) const;
void disableAccount(const string&) const;
void createAccount(Client*, const int64_t&) const;
void deleteAccount(const string&) const;
string showClientInfo(const string&) const;
static int generatePersonnelId();
Employee& operator=(const Employee&);
operator std::string() const;
protected:
int _personnelId;
int64_t _baseIncome;
int64_t _penalty = 0;
int64_t _reward = 0;
int _vacationHours;
int _extraHours;
EmployeeType _employeeType;
Bank* _bank;
static const int maxLeaveHours = 15;
static const int maxExtraHours = 12;
static const int64_t leavePenalty = 100000;
static const int64_t extraReward = 120000;
static int lastGeneratedPersonnelId;
Employee();
void reset();
};
#endif // EMPLOYEE_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/manager.h
|
#ifndef MANAGER_H
#define MANAGER_H
#include "facilities.h"
#include "exception"
using namespace std;
class ManagerException : public std::exception {
public:
ManagerException() : message{""} {}
explicit ManagerException(const string& msg) : message{msg} {}
explicit ManagerException(const char* msg) : message{msg} {}
virtual ~ManagerException() {}
virtual const char* what() const noexcept { return message.c_str(); }
private:
string message;
};
class Manager : public Employee {
public:
Manager(const string&, const string&, const string&, const int&, const Date&, const string&, const string&);
Manager(const string&, const string&, const string&, const int&, const Date&, const string&, const string&,
const int64_t&, const int&, const int&, Bank*);
Manager(const Manager&);
Manager(Manager&&) noexcept;
virtual ~Manager();
string employeeInfo(const int&) const;
void hireEmployee(Employee*) const;
void fireEmployee(const int&) const;
Manager& operator=(const Manager&);
private:
Manager();
void reset();
static int uniqueNumber;
};
#endif // MANAGER_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/person.h
|
#ifndef PERSON_H
#define PERSON_H
#include "date.h"
#include <vector>
using namespace std;
class PersonException : public exception {
public:
PersonException() : message{""} {}
explicit PersonException(const string& msg) : message{msg} {}
explicit PersonException(const char* msg) : message{msg} {}
virtual ~PersonException() {}
virtual const char* what(void) const noexcept { return message.c_str(); }
private:
string message;
};
class Person {
public:
Person(const string&, const string&, const string&, const Date&);
Person(const Person&);
Person(Person&&) noexcept;
virtual ~Person();
string getName() const;
string getLastName() const;
string getId() const;
Date getBirthday() const;
Person& operator=(const Person& rhs);
bool operator==(const Person& rhs) const;
bool operator!=(const Person& rhs) const;
operator string() const;
protected:
string _name;
string _lastname;
string _id;
Date _birthday;
Person();
void reset();
static void deleteFromPersonIds(const string&);
private:
static vector<string> _personIds;
};
#endif // PERSON_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/client.h
|
#ifndef CLIENT_H
#define CLIENT_H
#include "user.h"
#include "person.h"
#include "loan.h"
#include <vector>
using namespace std;
class Account;
class Facilities;
class Bank;
class ClientException : public exception {
public:
ClientException() : message{""} {}
explicit ClientException(const string& msg) : message{msg} {}
explicit ClientException(const char* msg) : message{msg} {}
virtual ~ClientException() {}
virtual const char* what(void) const noexcept { return message.c_str(); }
private:
string message;
};
class Client : public Person, public User {
public:
Client(const string&, const string&, const string&, const Date&, const string&, const string&);
Client(const string&, const string&, const string&, const Date&, const string&, const string&, const vector<Account*>&);
Client(const Client&);
Client(Client&&) noexcept;
~Client();
void createAccount(Account&);
Account* getAccount(const string&) const;
void deposit(const string&, const int64_t&) const;
void withdraw(const string&, const int64_t&) const;
void requestLoan(const string&, const LoanType&);
Loan* searchLoan(const string&) const;
string showLoans() const;
string showAccounts() const;
Client& operator=(const Client&);
operator string() const;
friend class Employee;
friend class Facilities;
friend class Bank;
private:
vector<Account*> _accounts;
Client();
void reset();
};
#endif // CLIENT_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/facilities.h
|
#ifndef FACILITIES_H
#define FACILITIES_H
#include <vector>
#include "employee.h"
#include "request.h"
using namespace std;
class FacilitiesException : public EmployeeException {
public:
FacilitiesException() : EmployeeException{""} {}
explicit FacilitiesException(const string& msg) : EmployeeException{msg} {}
explicit FacilitiesException(const char* msg) : EmployeeException{msg} {}
virtual ~FacilitiesException() {}
};
class Facilities : public Employee {
public:
Facilities(const string&, const string&, const string&, const int&, const Date&, const string&, const string&);
Facilities(const string&, const string&, const string&, const int&, const Date&, const string&, const string&,
const int64_t&, const int&, const int&, Bank*);
Facilities(const Facilities&);
Facilities(Facilities&&) noexcept;
virtual ~Facilities();
static void addLoanRequest(const Request&);
string acceptARequest();
void disableAccounts(Client*) const;
void disableAccounts(const string&) const;
string showAllrequests() const;
string loanInfo(const string&) const;
Facilities& operator=(const Facilities&);
friend class Bank;
private:
void reset();
Facilities();
static vector<Request> requests;
static bool _acceptedOneRequest;
};
#endif // FACILITIES_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/bank.h
|
<reponame>AlirezaKamyab/BankProjectCpp
#ifndef BANK_H
#define BANK_H
#include <vector>
#include <string>
#include "date.h"
using namespace std;
const string REPORT_FILE_NAME = "Report.txt";
class User;
class Client;
class Employee;
class Facilities;
class Manager;
class Loan;
class Account;
class BankException : public exception {
public:
BankException() : message{""} {}
explicit BankException(const string& msg) : message{msg} {}
explicit BankException(const char* msg) : message{msg} {}
virtual ~BankException() {}
virtual const char* what(void) const noexcept { return message.c_str(); }
private:
string message;
};
class Bank{
public:
Bank(Manager*, const string&, const int&);
Bank(Manager*, Facilities*, const string&, const int&);
Bank(const Bank&);
Bank(Bank&&) noexcept;
~Bank();
const Client* searchClient(const string&) const;
const Employee* searchEmployee(const int&) const;
const Employee* searchEmployee(const string&) const;
const Loan* searchLoans(const string&) const;
const Manager* getManager() const;
const Facilities* getFacility() const;
const Loan* searchLoan(const string&) const;
const Client* ownerOfTheAccount(const string&) const;
Date getStartDate() const;
Date getEndDate() const;
Account* searchAccount(const string&) const;
Employee* logAsEmployee(const string&, const string&) const;
Client* logAsClient(const string&, const string&) const;
User* searchUsername(const string&) const;
string withdrawLoan();
string endOfTheDay();
void readClientFromFile(const string&);
void readAccountFromFile(const string&);
void readLoanFromFile(const string&);
void readRequestFromFile(const string&);
void readEmployeeFromFile(const string&);
void readDateFromFile(const string&);
void writeClientToFile(const string&) const;
void writeAccountToFile(const string&) const;
void writeLoanToFile(const string&) const;
void writeRequestToFile(const string&) const;
void writeEmployeeToFile(const string&) const;
void writeDateToFile(const string&) const;
void writeToReport(const string&, const string&) const;
Bank& operator=(const Bank& other);
friend class Employee;
friend class Facilities;
friend class Manager;
friend class Account;
private:
string _name;
int _branch;
vector<Client*> _clients;
vector<Employee*> _employees;
Manager* _manager;
Facilities* _facilities;
Date _start;
Date _end;
Bank();
void reset();
void addEmployee(Employee*);
void addClient(Client*);
Client* _searchClient(const string&) const;
Employee* _searchEmployee(const int&) const;
Loan* _searchLoans(const string&) const;
Client* _ownerOfTheAccount(const string&) const;
};
#endif // BANK_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/request.h
|
<reponame>AlirezaKamyab/BankProjectCpp
#ifndef REQUEST_H
#define REQUEST_H
#include "loan.h"
#include "client.h"
#include "account.h"
#include <string>
using namespace std;
class Request{
public:
Request(Client*, Account*, const LoanType& = LoanType::MONTH_24);
Request(const Request&);
Request(Request&&) noexcept;
~Request();
LoanType getType() const;
Client* getClient() const;
Account* getAccount() const;
Request& operator=(const Request&);
operator std::string() const;
private:
LoanType _type;
Client* _client;
Account* _account;
Request();
void reset();
};
#endif // REQUEST_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/helperClass.h
|
#ifndef HELPERCLASS_H
#define HELPERCLASS_H
#include "date.h"
#include "time.h"
#include "ctime"
#include "random"
class Helper {
public:
static Time getCurrentTime();
static Date getCurrentDate();
static string generateRandom(const int&);
};
#endif // HELPERCLASS_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/time.h
|
<filename>Headers/time.h
#ifndef TIME_H
#define TIME_H
#include <exception>
#include <string>
using namespace std;
class TimeException : public exception {
public:
TimeException() : message{""} {}
explicit TimeException(const string& msg) : message{msg} {}
explicit TimeException(const char* msg) : message{msg} {}
virtual ~TimeException() {}
virtual const char* what(void) const noexcept { return message.c_str(); }
private:
string message;
};
class Time {
public:
Time(const int&, const int& = 0, const int& = 0);
Time(const Time&);
Time(Time&&) noexcept;
~Time();
int getHour() const;
int getMinute() const;
int getSecond() const;
void setHour(const int&);
void setMinute(const int&);
void setSecond(const int&);
Time& operator=(const Time&);
bool operator==(const Time&) const;
operator std::string() const;
private:
int _s;
int _m;
int _h;
Time();
void reset();
};
ostream& operator<<(ostream&, const Time&);
#endif // TIME_H
|
AlirezaKamyab/BankProjectCpp
|
Headers/account.h
|
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <string>
#include <vector>
#include "date.h"
using namespace std;
class Loan;
class AccountException : public exception {
public:
AccountException() : message{""} {}
explicit AccountException(const string& msg) : message{msg} {}
explicit AccountException(const char* msg) : message{msg} {}
virtual ~AccountException() {}
virtual const char* what() const noexcept { return message.c_str(); }
private:
string message;
};
class Bank;
class Account {
public:
Account(const string&, const string&, const Date&, Bank*);
Account(const string&, const string&, const Date&, const int64_t&, Bank*);
Account(const string&, const string&, const Date&, const int64_t&, const int&, const bool&, Bank*);
Account(const Account&);
Account(Account&&) noexcept;
~Account();
void changeStatus(const bool&);
void setBalance(const int64_t&);
void setValidationCount(const int&);
void setAccountNumber(const string&);
string getAccountNumber() const;
string getOwnersId() const;
bool getStatus() const;
int64_t getBalance() const;
int getValidationCount() const;
Bank* getBank() const;
Loan* getLoan() const;
void setLoan(Loan*);
Date getCreationDate() const;
Account& operator=(const Account&);
operator string() const;
private:
string _accountNumber;
string _ownersId;
Date _creationDate;
int64_t _balance;
int _validationCount;
bool _activated;
Bank* _bank;
Loan* _loan;
const static int64_t validAmount = 1e6;
Account();
void reset();
};
#endif // ACCOUNT_H
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Inc/common.h
|
<reponame>TDHolmes/OvenTemp<filename>STM32F446/OvenTemp/Inc/common.h
/*!
* @file common.h
* @author <NAME>
* @date 2-Sept-2017
* @brief Common functions and structures for all files.
*/
#pragma once
//! Common return type for the entire project
typedef enum {
RET_OK, //!< The return code if all goes well
RET_VAL_ERR, //!< If the values given cause an error
RET_NODATA_ERR, //!< If not enough data was given
RET_NOMEM_ERR, //!< If not enough memory is available
RET_LEN_ERR, //!< If there was some sort of length related error
RET_COM_ERR, //!< Some sort of communication error
RET_BUSY_ERR, //!< Some sort of busy resource / timeout
RET_GEN_ERR, //!< Lame catch all general error
RET_NORPT_ERR, //!< No available report
RET_INVALID_ARGS_ERR, //!< Incorrect arguments to the function called
RET_MAX_LEN_ERR, //!< Maximum length was violated
RET_WDG_SET, //!< Return code if the watchdog flag was set on reset
RET_CAL_ERR, //!< General error relating to calibration
RET_BAD_CHECKSUM, //!< General checksum related error (didn't match)
} ret_t;
void _Error_Handler(char *, int);
void _Error_Handler_withRetval(char * file, int line, int retval);
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
#define Error_Handler_withRetval(ret) _Error_Handler_withRetval(__FILE__, __LINE__, ret)
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Src/thermocouple.c
|
/*!
* @file thermocouple.c
* @author <NAME>
* @date 2-Sept-2017
* @brief Interface to the thermocouple temperature sensor
*/
#include <stdbool.h>
#include <stdint.h>
#include "common.h"
#include "hardware.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_adc.h"
// #include "stm32f4xx_hal_dma.h"
#define NUM_READINGS (8) // TODO: justify
#define THERM_GET_IDEX() (reading_index == (NUM_READINGS - 1) ? 0 : reading_index)
//! HAL ADC handle to get readings
extern ADC_HandleTypeDef hadc1;
static float vout_readings[NUM_READINGS]; //!< circular buffer of readings for averaging
static float vref_readings[NUM_READINGS]; //!< circular buffer of readings for averaging
//! Where the ADC stores the current reading, via either DMA or interrupt
static uint32_t pending_readings[3];
//! The current, most valid index from the ADC stored in `vout_readings` or `vref_readings`
static uint8_t reading_index;
static bool keep_converting; //!< tracks if we should continue triggering ADC conversions
static bool reading_ready; //!< True if there is a valid reading available
static bool ADC_running; //!< True if we are currently running the ADC peripheral
// Private function definitions
static void therm_ADC_done(void);
static void therm_startReading(bool single);
/*! Initializes all private variables for the thermocouple module to work.
* Does NOT start an ADC reading.
*/
void therm_init(void)
{
for (int8_t i = NUM_READINGS - 1; i > 0; i--) {
vout_readings[i] = 0;
vref_readings[i] = 0;
}
pending_readings[0] = 0;
pending_readings[1] = 0;
pending_readings[2] = 0;
reading_index = 0;
reading_ready = false;
ADC_running = false;
}
/*! Private function that either kicks off a single ADC reading or continuous
* readings. Called by the public functions `therm_startReading_single` and
* `therm_startReading_continuous`.
*/
static void therm_startReading(bool single_reading)
{
// Start an ADC conversions for both channels
if (HAL_ADC_Start_IT(&hadc1) != HAL_OK) {
Error_Handler();
}
if (single_reading) {
reading_ready = false;
}
if (keep_converting != !single_reading) {
// This is our first time getting called for continuous readings. reset
// the `reading_index` to make sure we get all new values when averaging.
reading_index = 0;
keep_converting = true;
}
ADC_running = true;
}
/*! starts a single ADC reading.
*/
void therm_startReading_single(void) {
therm_startReading(true);
}
/*! starts continuous ADC readings.
*/
void therm_startReading_continuous(void) {
therm_startReading(false);
}
/*! Private function that gets called after the ADC is done converting all thermocouple
* values and pulls them from the `pending_readings` array. Also triggers another
* reading if the `keep_converting` flag is set.
*/
static void therm_ADC_done(void)
{
reading_index += 1;
if (reading_index >= NUM_READINGS) {
reading_index = 0;
}
vout_readings[reading_index] = (float)pending_readings[0];
vref_readings[reading_index] = (float)pending_readings[1];
if (keep_converting) {
// setup another round of readings
// BUG: I think we're starting it twice. Here and in the ISR.
therm_startReading_continuous();
if (!reading_ready && reading_index == 0) {
// We've had enough readings to get a valid, averaged temperature
reading_ready = true;
}
} else {
// Only one reading. Ready to read
reading_ready = true;
ADC_running = false;
}
}
/*! Returns true if there is a valid reading ready, either single if not doing
* continuous readings, else enough to get an averaged result
*/
bool therm_valueReady(void) {
return reading_ready;
}
/*! Returns true if the ADC is currently reading data in. Not currently used.
*/
bool therm_ADCRunning(void) {
return ADC_running;
}
/*! Gets a reading from the thermocouple, returning
* the value in celsius with averaging over time.
*/
float therm_getValue_averaged(void)
{
float sensor, v1_25, vout = 0;
// Gather the readings and average them
for (int8_t i = NUM_READINGS - 1; i >= 0; i--) {
sensor += vout_readings[i];
v1_25 += vref_readings[i];
}
// Normalize and send out
sensor = sensor / NUM_READINGS;
v1_25 = v1_25 / NUM_READINGS;
vout = sensor * (1.25f / v1_25);
return (vout - 1.25f) / 0.005f;
}
/*! Gets a reading from the thermocouple, returning
* the value in celsius. No averaging!
*/
float therm_getValue_single(void)
{
float sensor = vout_readings[THERM_GET_IDEX()];
float v1_25 = vref_readings[THERM_GET_IDEX()];
// Normalize and send out
float vout = sensor * (1.25f / v1_25);
reading_ready = false;
return (vout - 1.25f) / 0.005f;
}
/****** ADC Callback functions *********/
/*! The calback from the ADC interrupt that fires each time it converts
* a channel, then stores it in `pending_readings`. Also keeps track if all channels
* are done converting and modifies the flags `ADC_running`.
*/
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
// Get the readings
static uint8_t pending_index = 0;
bool start_reading = false;
pending_readings[pending_index] = HAL_ADC_GetValue(hadc);
pending_index++;
if (pending_index == NUM_ADC_CHANNELS) {
if (keep_converting) {
// kick off another reading!
start_reading = true;
}
// update state
ADC_running = keep_converting;
pending_index = 0;
therm_ADC_done();
} else {
ADC_running = true;
start_reading = true;
}
// kick off another reading if requested
if (start_reading) {
HAL_StatusTypeDef ret;
ret = HAL_ADC_Start_IT(&hadc1);
if (ret != HAL_OK) {
Error_Handler_withRetval(ret);
}
}
}
/*! This function is called if the ADC peripheral runs into a critical error.
*/
void HAL_ADC_ErrorCallback(ADC_HandleTypeDef* hadc)
{
Error_Handler_withRetval(hadc->ErrorCode);
}
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Src/main.c
|
<filename>STM32F446/OvenTemp/Src/main.c<gh_stars>0
/*!
* @file main.c
* @author <NAME>
* @date 2-Sept-2017
* @brief Main file for the OvenTemp project.
*
* Stupid STM copyright notice at end.
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "common.h"
#include "hardware.h"
#include "display.h"
#include "thermocouple.h"
#include "stm32f4xx_hal.h"
#ifdef __APPLE__
#define SECTION(X) section("__DATA,__" X )
#define SECTION_START(X) __asm("section$start$__DATA$__" X)
#define SECTION_END(X) __asm("section$end$__DATA$__" X)
#else
#define SECTION(X) section(X)
#define SECTION_START(X)
#define SECTION_END(X)
#endif
//! How long we sleep between readings in idle mode, in seconds.
#define IDLE_MODE_SLEEPTIME (60)
//! How long we sleep between readings in active mode, in seconds.
#define ACTIVE_MODE_SLEEPTIME (1)
//! threshold to switch to active mode, in celsius
#define ACTIVE_TEMP_THRESHOLD (50.0f)
#define INSANE_TEMP_THRESHOLD (250.0f)
#define IDLE_SAMPLE_TIME_MS (60000UL) // TODO: change to 60 seconds
#define ACTIVE_SAMPLE_TIME_MS (1000)
#define IDLE_BLINK_PERIOD_MS (15000)
#define IDLE_BLINK_DURATION_MS (100)
//! Toggle heartbeat LED every 30 seconds
#define HB_TICK_TIME_MS (30000)
//! heartbeet LED is on for 0.1 seconds
#define HB_ON_TIME_MS (100)
ADC_HandleTypeDef hadc1; //!< HAL handle for ADC1
DMA_HandleTypeDef hdma_adc1; //!< HAL handle for DMA for ADC1. Currently not used.
I2C_HandleTypeDef hI2C3; //!< HAL handle for I2C3 (display)
RTC_HandleTypeDef hrtc; //!< HAL handle for our RTC. Used to awake us from deep sleep
UART_HandleTypeDef huart4; //!< HAL handle for UART4 for debug prints
extern __IO uint32_t uwTick; //!< HAL tick count
typedef enum {
kErrWriteReason,
kErrWriteErr
} err_mode_state_t;
//! Different modes the main loop can be in based on the oven temperature.
typedef enum {
kIdleMode,
kActiveMode,
kInsaneTempMode,
kInvalidMainMode
} e_main_modes;
static e_main_modes mode = kIdleMode; //!< global tracking main's state
static uint8_t str_buff[64]; //!< buffer for transmitting data over UART
/**** Private function definitions ****/
void blocking_delay(volatile uint32_t delay);
void blinkLED_withDelay(uint32_t delay);
void displayTemp(float temp, bool inFarenheit);
void sleep_enterSleep(void);
void sleep_enterStop(int timeToSleep_s);
static void SYSCLKConfig_STOP(void);
// Modes
void idleMode(void);
void activeMode(void);
void errMode(char * err_reason);
#ifdef DEBUG
void _print_string(char string[]);
#define print_string(x) _print_string(x)
#else
#define print_string(x) /* Don't do anything. */
#endif
/*! Main function. Initializes all peripherals needed, get's an initial thermocouple
* reading, then goes into either active or idle mode. We then continue, checking
* the battery voltage
*/
int main(void)
{
//! Reset of all peripherals, Initializes the Flash interface and the Systick.
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
hw_GPIO_Init();
#ifdef DEBUG
hw_UART4_Init();
#endif
print_string("Hello World!\n");
hw_ADC1_Init();
hw_I2C3_Init();
hw_RTC_Init();
/* Initialize interrupts */
hw_NVIC_Init();
// Initialize display and clear all digits
disp_init(DISP_I2C_ADDR);
disp_setBrightness(15);
disp_writeDigit_ascii(0, ' ', false);
disp_writeDigit_ascii(1, 'H', false);
disp_writeDigit_ascii(2, 'I', false);
disp_writeDigit_ascii(3, ' ', false);
disp_writeDisplay();
HAL_Delay(1000);
disp_writeDigit_raw(0, 0);
disp_writeDigit_raw(1, 0);
disp_writeDigit_raw(2, 0);
disp_writeDigit_raw(3, 0);
disp_writeDisplay();
therm_init();
// Main infinite loop
print_string("Entering Main\n");
therm_startReading_single();
while (1) {
switch (mode) {
case kIdleMode:
print_string("Main: in kIdleMode\n");
idleMode();
break;
case kActiveMode:
print_string("Main: in kActiveMode\n");
activeMode();
break;
case kInsaneTempMode:
print_string("Main: in kInsaneTempMode\n");
// Write the reason for the error
errMode("TEMP");
if ( therm_valueReady() ) {
if ( therm_getValue_single() < INSANE_TEMP_THRESHOLD ) {
mode = kActiveMode;
}
} else if ( !therm_ADCRunning() ) {
// Kick off a reading if there isn't one running
therm_startReading_single();
}
break;
case kInvalidMainMode:
print_string("Main: in kInvalidMainMode\n");
// Write the reason for the error
errMode("MAIN");
break;
default:
print_string("kDefaultMainMode\n");
errMode("UNKN");
break;
}
}
}
void activeMode(void)
{
float temperature = 0;
static uint32_t time_for_reading = 0;
if ( therm_valueReady() ) {
if (HAL_GetTick() >= time_for_reading) {
temperature = therm_getValue_averaged();
if (temperature < ACTIVE_TEMP_THRESHOLD) {
disp_clear();
disp_writeDisplay();
mode = kIdleMode;
time_for_reading = HAL_GetTick() + IDLE_SAMPLE_TIME_MS;
therm_startReading_single(); // Single thermocouple conversion
} else if (temperature > INSANE_TEMP_THRESHOLD) {
mode = kInsaneTempMode;
} else {
// temperature at needed value. Display temp
time_for_reading = HAL_GetTick() + ACTIVE_SAMPLE_TIME_MS;
displayTemp(temperature, true); // display temp in in farenheit
therm_startReading_single(); // Single thermocouple conversion
// deep sleep for a second to save power
// TODO: switch back to standby
sleep_enterSleep();
}
} else {
HAL_Delay(500);
}
} else if ( !therm_ADCRunning() ) {
// If we're not running temp readings, do that!
therm_startReading_single();
} else {
// Not done yet... Keep snoozin! ADC interrupt should wake us from SLEEP
sleep_enterSleep();
}
}
void idleMode(void)
{
float temperature;
static uint32_t time_for_blink = 0;
static bool blink_on = false;
if ( therm_valueReady() ) {
print_string("Therm value ready. Check it out.\n");
temperature = therm_getValue_single();
if ( temperature >= ACTIVE_TEMP_THRESHOLD ) {
mode = kActiveMode;
therm_startReading_single(); // Single thermocouple conversion
} else {
// Configure the RTC to wake us up in N miliseconds from standby
hw_RTC_setWakeup(IDLE_SAMPLE_TIME_MS);
sleep_enterStop(IDLE_SAMPLE_TIME_MS / 1000); // This divide should be optimized out by compiler
// Start a single thermocouple read after we wake back up
therm_startReading_single();
}
} else if ( !therm_ADCRunning() ) {
// If we're not running temp readings, do that!
print_string("Starting therm sample...\n");
therm_startReading_single();
} else {
// Not done yet... Keep snoozin! ADC interrupt should wake us from SLEEP
print_string("Sleep and wait for ADC...\n");
sleep_enterSleep();
}
disp_writeDigit_ascii(3, ' ', true); // Turn on the blink
disp_writeDisplay();
// // Check up on the blinker
// if ( HAL_GetTick() >= time_for_blink ) {
// if ( blink_on == true ) {
// disp_writeDigit_ascii(3, ' ', false); // Turn off the blink
// disp_writeDisplay();
// blink_on = false;
// time_for_blink = HAL_GetTick() + IDLE_BLINK_PERIOD_MS;
// } else {
// disp_writeDigit_ascii(3, ' ', true); // Turn on the blink
// disp_writeDisplay();
// blink_on = true;
// time_for_blink = HAL_GetTick() + IDLE_BLINK_DURATION_MS;
// }
// }
}
void errMode(char * err_reason)
{
static err_mode_state_t err_mode = kErrWriteReason;
static uint32_t time_for_err_display = 0;
if ( time_for_err_display < HAL_GetTick() ) {
if (err_mode == kErrWriteReason) {
for (uint8_t i = 0; i < 4; i++) {
disp_writeDigit_ascii(i, err_reason[i], false);
}
err_mode = kErrWriteErr;
} else {
disp_writeDigit_ascii(0, 'E', false);
disp_writeDigit_ascii(1, 'R', false);
disp_writeDigit_ascii(2, 'R', false);
disp_writeDigit_ascii(3, '!', false);
err_mode = kErrWriteReason;
}
disp_writeDisplay();
time_for_err_display = HAL_GetTick() + 1000;
}
sleep_enterSleep();
}
void sleep_enterSleep(void)
{
print_string("Entering sleep...\n");
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
print_string("Exiting sleep!\n");
}
void sleep_enterStop(int timeToSleep_s)
{
GPIO_InitTypeDef GPIO_InitStruct;
print_string("Entering STOP...\n");
HAL_Delay(250);
// Clear LEDs and display
hw_LED_setValue(0);
for (int i=0; i<4; i++) {
disp_writeDigit_ascii(i, ' ', false);
}
disp_writeDisplay();
/* Disable USB Clock */
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
/* Configure all GPIO as analog to reduce current consumption on non used IOs */
/* Enable GPIOs clock */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_All;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
/* Disable GPIOs clock */
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOE_CLK_DISABLE();
__HAL_RCC_GPIOF_CLK_DISABLE();
__HAL_RCC_GPIOG_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
/*## Configure the Wake up timer ###########################################*/
/* RTC Wakeup Interrupt Generation:
Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI))
Wakeup Time = Wakeup Time Base * WakeUpCounter
= (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI)) * WakeUpCounter
==> WakeUpCounter = Wakeup Time / Wakeup Time Base
To configure the wake up timer to 1s the WakeUpCounter is set to 0x0801:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16
Wakeup Time Base = 16 /(~32.768KHz) = ~0.488 ms
Wakeup Time = ~1s = 0.488ms * WakeUpCounter
==> WakeUpCounter = ~1s/0.488ms = 2049 = 0x0801 */
/* Disable Wake-up timer */
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
/* Enable Wake-up timer */
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x0801 * timeToSleep_s, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
/* FLASH Deep Power Down Mode enabled */
HAL_PWREx_EnableFlashPowerDown();
/*## Enter Stop Mode #######################################################*/
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
/* Configures system clock after wake-up from STOP: enable HSI, PLL and select
PLL as system clock source (HSI and PLL are disabled in STOP mode) */
SYSCLKConfig_STOP();
hw_GPIO_Init();
/* Disable Wake-up timer */
if(HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK) {
/* Initialization Error */
Error_Handler();
}
print_string("Exiting STOP!\n");
}
/*! This function takes in a positive, floating point value from [0, 1000) and
* displays it on the four digit display we have with the most percision possible.
*/
void displayTemp(float temp, bool inFarenheit)
{
uint8_t a,b,c,d = 0;
if (inFarenheit) {
temp = temp * 1.8f + 32.0f;
}
if (temp < 100) {
a = (uint8_t)(((uint32_t)temp % 100) / 10); // 10's place
b = (uint8_t)((uint32_t)temp % 10); // 1's place
c = (uint8_t)((uint32_t)(temp * 10.0f) % 10); // 10ths place
d = (uint8_t)((uint32_t)(temp * 100.0f) % 10); // 100ths place
// Write the dot out
disp_writeDigit_value(1, b, true);
disp_writeDigit_value(2, c, false);
} else {
a = (uint8_t)(((uint32_t)temp % 1000) / 100); // 100's place
b = (uint8_t)(((uint32_t)temp % 100) / 10); // 10's place
c = (uint8_t)((uint32_t)temp % 10); // 1's place
d = (uint8_t)((uint32_t)(temp * 10.0f) % 10); // 10ths place
// Write the dot out
disp_writeDigit_value(1, b, false);
disp_writeDigit_value(2, c, true);
}
//write out the rest
if (temp < 10) {
disp_writeDigit_raw(0, 0); // Clear this section
} else {
disp_writeDigit_value(0, a, false);
}
disp_writeDigit_value(3, d, false);
disp_writeDisplay();
}
/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
void _Error_Handler(char * file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
_Error_Handler_withRetval(file, line, 0);
}
#define SOS_O (300000)
#define SOS_S (150000)
/*! Helper function that blinks our LED with delays before and after using
* `blocking_delay`.
*/
void blinkLED_withDelay(uint32_t delay) {
hw_LED_setValue(0);
blocking_delay(delay);
hw_LED_setValue(1);
blocking_delay(delay);
}
/*! This function is called when there is a fatal error somewhere in the code.
* The current behavior is to blink rapidly and send a formatted string over
* UART.
* @param file (char *): Name of the file in which the error occurred.
* @param line (int): Line number on which the error occurred.
* @param retval (int): The error code for the failure.
*/
void _Error_Handler_withRetval(char * file, int line, int retval)
{
sprintf((char *)str_buff, "%s:%i -> %i\n", file, line, retval);
int cycle = 0;
typedef enum { kSave, kOur, kSouls, kPause} eSOS;
eSOS sos_state = kSave;
while(1)
{
cycle += 1;
switch (sos_state) {
case kSave:
if (cycle >= 3) {
sos_state = kOur;
cycle = 0;
}
blinkLED_withDelay(SOS_S);
break;
case kOur:
if (cycle >= 3) {
sos_state = kSouls;
cycle = 0;
}
blinkLED_withDelay(SOS_O);
break;
case kSouls:
if (cycle >= 3) {
sos_state = kPause;
cycle = 0;
}
blinkLED_withDelay(SOS_S);
break;
case kPause:
hw_LED_setValue(0);
blocking_delay(SOS_O * 3);
cycle = 0;
sos_state = kSave;
break;
}
// Print the error once a "cycle"
if (sos_state == kPause) {
print_string(str_buff);
}
}
}
#ifdef DEBUG
void _print_string(char string[]) {
HAL_UART_Transmit(&huart4, (uint8_t *)string,
strlen((const char *)string), 10);
}
#endif
/*! Simple, dumb delay function to be used when we can't necessarily rely on
* interrupts to do delay timing. Normally, you should use interrupt driven or
* HAL_Delay() to rely on the systick.
*/
inline void blocking_delay(volatile uint32_t delay) {
for (; delay != 0; delay--);
}
/**
* @brief Wake Up Timer callback
* @param hrtc : hrtc handle
* @retval None
*/
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
// TODO: finish.
}
/**
* @brief Configures system clock after wake-up from STOP: enable HSI, PLL
* and select PLL as system clock source.
* @param None
* @retval None
*/
static void SYSCLKConfig_STOP(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
uint32_t pFLatency = 0;
/* Get the Oscillators configuration according to the internal RCC registers */
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
/* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = (uint32_t)0x10; /* Default HSI calibration trimming value */
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
/* Initialization Error */
Error_Handler();
}
/* Get the Clocks configuration according to the internal RCC registers */
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK) {
Error_Handler();
}
}
// Index for doxygen
/*! \mainpage Documentation for OvenTemp project!
*
* \section intro_sec Introduction
*
* This project is a simple thermocouple with display to easily see the temperature
* of an old oven that doesn't have a digital display. It is designed to be battery
* powered and smart enough to only turn on when needed. It uses an STM32f446
* microcontroller because that was the easiest development board I had laying
* around to use. It is also quite nice to work with and has good low power
* performance.
*
*/
/********************** BEGIN STUPID COPYRIGHT NOTICE **************************
** This notice applies to any and all portions of this file
* that are not made by <NAME>. Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* COPYRIGHT(c) 2017 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Inc/hardware.h
|
/*!
* @file hardware.h
* @author <NAME>
* @date 2-Sept-2017
* @brief Hardware specific initialization and such.
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "stm32f4xx_hal.h"
#include "common.h"
#define NUM_ADC_CHANNELS (2) //!< Thermocouple vout and voltage ref
//! Enum of the timing pins we use.
typedef enum {
kTimingPin_D11 = GPIO_PIN_7,
kTimingPin_D01 = GPIO_PIN_2,
} timing_pin_t;
void SystemClock_Config(void);
void hw_GPIO_Init(void);
void hw_DMA_Init(void);
void hw_ADC1_Init(void);
void hw_I2C3_Init(void);
void hw_RTC_Init(void);
void hw_UART4_Init(void);
void hw_NVIC_Init(void);
void hw_RTC_setWakeup(uint32_t timeToWake_ms);
void hw_LED_setValue(uint8_t value);
void hw_LED_toggle(void);
void hw_TimingPin_setValue(timing_pin_t pin, uint8_t value);
void hw_TimingPin_toggle(timing_pin_t pin);
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Src/stm32f4xx_hal_msp.c
|
/*!
* @file stm32f4xx_hal_msp.c
* @author <NAME> & STMicroelectronics
* @date 2-Sept-2017
* @brief This file provides code for the MSP Initialization and
de-Initialization codes.
Copyright notice at bottom.
*/
#include "stm32f4xx_hal.h"
// Extern variables and functions
extern DMA_HandleTypeDef hdma_adc1;
extern void _Error_Handler(char *, int);
/*! Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
/* System interrupt init*/
/* MemoryManagement_IRQn interrupt configuration */
HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
/* BusFault_IRQn interrupt configuration */
HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
/* UsageFault_IRQn interrupt configuration */
HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
/* SVCall_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0);
/* DebugMonitor_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
/******** ADC FUNCTIONS ***********/
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance == ADC1)
{
/* Peripheral clock enable */
__HAL_RCC_ADC1_CLK_ENABLE();
/* ADC1 interrupt Init */
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
}
}
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance == ADC1)
{
/* Peripheral clock disable */
__HAL_RCC_ADC1_CLK_DISABLE();
/**ADC1 GPIO Configuration
PA4 ------> ADC1_IN4
PA6 ------> ADC1_IN6
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4 | GPIO_PIN_6);
/* ADC1 interrupt DeInit */
HAL_NVIC_DisableIRQ(ADC_IRQn);
}
}
/******** I2C FUNCTIONS ***********/
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
if(hi2c->Instance == I2C3)
{
/* Peripheral clock enable */
__HAL_RCC_I2C3_CLK_ENABLE();
}
}
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
{
if(hi2c->Instance == I2C3)
{
/* Peripheral clock disable */
__HAL_RCC_I2C3_CLK_DISABLE();
/* I2C3 interrupt DeInit */
HAL_NVIC_DisableIRQ(I2C3_EV_IRQn);
HAL_NVIC_DisableIRQ(I2C3_ER_IRQn);
}
}
/******** RTC FUNCTIONS ***********/
/**
* @brief RTC MSP Initialization
* This function configures the hardware resources used in this example
* @param hrtc: RTC handle pointer
*
* @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
* the RTC clock source; in this case the Backup domain will be reset in
* order to modify the RTC Clock source, as consequence RTC registers (including
* the backup registers) and RCC_BDCR register are set to their reset values.
*
* @retval None
*/
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/*##-1- Configue LSI as RTC clock soucre ###################################*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Enable RTC peripheral Clocks #######################################*/
/* Enable RTC Clock */
__HAL_RCC_RTC_ENABLE();
/*##-3- Configure the NVIC for RTC WakeUp Timer ############################*/
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0x0F, 0);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
}
/**
* @brief RTC MSP De-Initialization
* This function freeze the hardware resources used in this example:
* - Disable the Peripheral's clock
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc)
{
/*##-1- Reset peripherals ##################################################*/
__HAL_RCC_RTC_DISABLE();
}
/******** UART FUNCTIONS ***********/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
if(huart->Instance == UART4)
{
/* Peripheral clock enable */
__HAL_RCC_UART4_CLK_ENABLE();
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance == UART4)
{
/* Peripheral clock disable */
__HAL_RCC_UART4_CLK_DISABLE();
}
}
/**
* @}
*/
/**
* @}
*/
/*******************************************************************************
* This notice applies to any and all portions of this file
* that are not made or edited by <NAME>.
* Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* COPYRIGHT(c) 2017 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Src/stm32f4xx_it.c
|
/*!
* @file stm32f4xx_it.c
* @author <NAME> & STMicroelectronics
* @date 2-Sept-2017
* @brief Location where all system & peripheral interrupts are serviced.
Copyright notice at bottom.
*/
#include "stm32f4xx_hal.h"
#include "stm32f4xx.h"
#include "stm32f4xx_it.h"
#include "thermocouple.h"
#include "hardware.h"
// External variables
extern DMA_HandleTypeDef hdma_adc1;
extern ADC_HandleTypeDef hadc1;
extern I2C_HandleTypeDef hI2C3;
extern RTC_HandleTypeDef hrtc;
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
while (1); // We shouldn't hit an NMI AFAIK.
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
while (1);
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
while (1);
}
/**
* @brief This function handles Pre-fetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
while (1);
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
while (1);
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
while (1); // Non critical error, but still catch it for debugging.
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
while (1); // Non critical error, but still catch it for debugging.
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
while (1); // Non critical error, but still catch it for debugging.
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}
/******************************************************************************/
/* STM32F4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f4xx.s). */
/******************************************************************************/
/**
* @brief This function handles RTC Auto wake-up interrupt request.
* @param None
* @retval None
*/
void RTC_WKUP_IRQHandler(void)
{
HAL_RTCEx_WakeUpTimerIRQHandler(&hrtc);
}
/**
* @brief This function handles I2C3 event interrupt.
*/
void I2C3_EV_IRQHandler(void)
{
// hw_TimingPin_setValue(kTimingPin_D11, 1);
HAL_I2C_EV_IRQHandler(&hI2C3);
// hw_TimingPin_setValue(kTimingPin_D11, 0);
}
/**
* @brief This function handles I2C3 error interrupt.
*/
void I2C3_ER_IRQHandler(void)
{
hw_TimingPin_setValue(kTimingPin_D11, 1);
HAL_I2C_ER_IRQHandler(&hI2C3);
hw_TimingPin_setValue(kTimingPin_D11, 0);
}
/**
* @brief This function handles ADC1, ADC2 and ADC3 interrupts.
*/
void ADC_IRQHandler(void)
{
// hw_TimingPin_setValue(kTimingPin_D11, 1);
HAL_ADC_IRQHandler(&hadc1);
// hw_TimingPin_setValue(kTimingPin_D11, 0);
}
/**
* @brief This function handles DMA2 stream0 global interrupt.
*/
void DMA2_Stream0_IRQHandler(void)
{
HAL_DMA_IRQHandler(&hdma_adc1);
}
/*******************************************************************************
* COPYRIGHT(c) 2017 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Src/hardware.c
|
<reponame>TDHolmes/OvenTemp<filename>STM32F446/OvenTemp/Src/hardware.c
/*!
* @file hardware.c
* @author <NAME>
* @date 2-Sept-2017
* @brief Hardware specific initialization and such.
*/
#include <stdbool.h>
#include "hardware.h"
#include "common.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_iwdg.h"
#include "stm32f4xx_hal_rtc.h"
#include "stm32f4xx_hal_rtc_ex.h"
extern ADC_HandleTypeDef hadc1;
extern DMA_HandleTypeDef hdma_adc1;
extern I2C_HandleTypeDef hI2C3;
extern RTC_HandleTypeDef hrtc;
extern UART_HandleTypeDef huart4;
#define WDG_COUNT (410u) // TODO: recalculate
// Private functions
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/**Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
/** NVIC Configuration
*/
void hw_NVIC_Init(void)
{
/* ADC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(ADC_IRQn, 2, 2); // preempt, sub-priority
HAL_NVIC_EnableIRQ(ADC_IRQn);
/* I2C3_EV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(I2C3_EV_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(I2C3_EV_IRQn);
/* I2C3_ER_IRQn interrupt configuration */
HAL_NVIC_SetPriority(I2C3_ER_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(I2C3_ER_IRQn);
/* DMA2_Stream0_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 1, 1);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
// TODO: RTC interrupts?
}
/* ADC1 init function */
void hw_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ENABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = ENABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfDiscConversion = 1;
hadc1.Init.NbrOfConversion = NUM_ADC_CHANNELS;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_4;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_112CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_6;
sConfig.Rank = 2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
/* I2C3 init function */
void hw_I2C3_Init(void)
{
hI2C3.Instance = I2C3;
hI2C3.Init.ClockSpeed = 100000;
hI2C3.Init.DutyCycle = I2C_DUTYCYCLE_2;
hI2C3.Init.OwnAddress1 = 0;
hI2C3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hI2C3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hI2C3.Init.OwnAddress2 = 0;
hI2C3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hI2C3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hI2C3) != HAL_OK) {
Error_Handler();
}
}
/* RTC init function */
void hw_RTC_Init(void)
{
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
HAL_StatusTypeDef ret;
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
ret = HAL_RTC_Init(&hrtc);
if (ret != HAL_OK) {
Error_Handler_withRetval(ret);
}
/* Initialize RTC and set the Time and Date */
// TODO: Figure out magic value garbage
if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2) {
sTime.Hours = 0x0;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
ret = HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);
if (ret != HAL_OK) {
Error_Handler_withRetval(ret);
}
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 0x1;
sDate.Year = 0x0;
ret = HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);
if (ret != HAL_OK) {
Error_Handler_withRetval(ret);
}
HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);
}
}
void hw_RTC_setWakeup(uint32_t timeToWake_ms)
{
HAL_StatusTypeDef ret;
// 32,768 ticks/sec (2^15) / 16 (our divider) = 2048 ticks/sec
ret = HAL_RTCEx_SetWakeUpTimer(&hrtc, timeToWake_ms * 2, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
if (ret != HAL_OK) {
Error_Handler_withRetval(ret);
}
}
/* UART4 init function */
void hw_UART4_Init(void)
{
huart4.Instance = UART4;
huart4.Init.BaudRate = 115200;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart4) != HAL_OK) {
_Error_Handler(__FILE__, __LINE__);
}
}
/**
* Enable DMA controller clock
*/
void hw_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA2_Stream0_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
}
/** Pinout Configuration
*/
void hw_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
// PA5 is LD2 LED, PA7 and PA2 are timing pins
GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_5 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// GPIO_InitStruct.Alternate = 0;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/**ADC1 GPIO Configuration
PA4 ------> ADC1_IN4
PA6 ------> ADC1_IN6
*/
GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// PC13/PC14 are RTC input pins
GPIO_InitStruct.Pin = GPIO_PIN_13 | GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// GPIO_InitStruct.Alternate = 0;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/**I2C3 GPIO Configuration
PA8 ------> I2C3_SCL
PC9 ------> I2C3_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// Now SDA
GPIO_InitStruct.Pin = GPIO_PIN_9;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/**UART4 GPIO Configuration
PA0-WKUP ------> UART4_TX
PA1 ------> UART4_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void hw_LED_setValue(uint8_t value)
{
if (value == 0) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
} else {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
}
}
void hw_LED_toggle(void)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
void hw_TimingPin_setValue(timing_pin_t pin, uint8_t value)
{
if (value == 0) {
HAL_GPIO_WritePin(GPIOA, pin, GPIO_PIN_RESET);
} else {
HAL_GPIO_WritePin(GPIOA, pin, GPIO_PIN_SET);
}
}
void hw_TimingPin_toggle(timing_pin_t pin)
{
HAL_GPIO_TogglePin(GPIOA, pin);
}
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Inc/display.h
|
/*!
* @file display.h
* @author <NAME>
* @date 2-Sept-2017
* @brief C library adapted from the I2C LED Backpack adafruit code. More info at bottom.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#define DISP_I2C_ADDR (0x70 << 1)
#define LED_ON 1
#define LED_OFF 0
#define LED_RED 1
#define LED_YELLOW 2
#define LED_GREEN 3
#define HT16K33_BLINK_CMD 0x80
#define HT16K33_BLINK_DISPLAYON 0x01
#define HT16K33_BLINK_OFF 0
#define HT16K33_BLINK_2HZ 1
#define HT16K33_BLINK_1HZ 2
#define HT16K33_BLINK_HALFHZ 3
#define HT16K33_CMD_BRIGHTNESS 0xE0
#define SEVENSEG_DIGITS 5
#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
#define BYTE 0
void disp_init(uint8_t addr);
void disp_setBrightness(uint8_t b);
void disp_blinkRate(uint8_t b);
void disp_clear(void);
void disp_writeDigit_raw(uint8_t n, uint16_t bitmask);
void disp_writeDigit_value(uint8_t n, uint8_t number, bool point);
void disp_writeDigit_ascii(uint8_t n, uint8_t character, bool point);
void disp_writeDisplay(void);
/***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
----> http://www.adafruit.com/products/
----> http://www.adafruit.com/products/
These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by <NAME>/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Inc/thermocouple.h
|
/*!
* @file thermocouple.h
* @author <NAME>
* @date 2-Sept-2017
* @brief Interface to the thermocouple temperature sensor
*/
#pragma once
#include <stdbool.h>
void therm_init(void);
void therm_startReading_single(void);
void therm_startReading_continuous(void);
void therm_ADC_done(void);
float therm_getValue_averaged(void);
float therm_getValue_single(void);
// Utilities
inline float c2f(float celsius_data);
// Status functions
bool therm_ADCRunning(void);
bool therm_valueReady(void);
/*! Converts celsius to farenheight.
*/
inline float c2f(float celsius_data)
{
return celsius_data * (9.0 / 5.0) + 32.0;
}
|
TDHolmes/OvenTemp
|
STM32F446/OvenTemp/Src/display.c
|
<gh_stars>0
/*!
* @file display.c
* @author <NAME>
* @date 2-Sept-2017
* @brief C library adapted from the quad I2C LED Backpack adafruit code. More info at bottom.
*/
#include <stdint.h>
#include "display.h"
#include "common.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_i2c.h"
static const uint16_t alphafonttable[] = {
0b0000000000000001,
0b0000000000000010,
0b0000000000000100,
0b0000000000001000,
0b0000000000010000,
0b0000000000100000,
0b0000000001000000,
0b0000000010000000,
0b0000000100000000,
0b0000001000000000,
0b0000010000000000,
0b0000100000000000,
0b0001000000000000,
0b0010000000000000,
0b0100000000000000,
0b1000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0001001011001001,
0b0001010111000000,
0b0001001011111001,
0b0000000011100011,
0b0000010100110000,
0b0001001011001000,
0b0011101000000000,
0b0001011100000000,
0b0000000000000000, //
0b0000000000000110, // !
0b0000001000100000, // "
0b0001001011001110, // #
0b0001001011101101, // $
0b0000110000100100, // %
0b0010001101011101, // &
0b0000010000000000, // '
0b0010010000000000, // (
0b0000100100000000, // )
0b0011111111000000, // *
0b0001001011000000, // +
0b0000100000000000, // ,
0b0000000011000000, // -
0b0000000000000000, // .
0b0000110000000000, // /
0b0000110000111111, // 0
0b0000000000000110, // 1
0b0000000011011011, // 2
0b0000000010001111, // 3
0b0000000011100110, // 4
0b0010000001101001, // 5
0b0000000011111101, // 6
0b0000000000000111, // 7
0b0000000011111111, // 8
0b0000000011101111, // 9
0b0001001000000000, // :
0b0000101000000000, // ;
0b0010010000000000, // <
0b0000000011001000, // =
0b0000100100000000, // >
0b0001000010000011, // ?
0b0000001010111011, // @
0b0000000011110111, // A
0b0001001010001111, // B
0b0000000000111001, // C
0b0001001000001111, // D
0b0000000011111001, // E
0b0000000001110001, // F
0b0000000010111101, // G
0b0000000011110110, // H
0b0001001000000000, // I
0b0000000000011110, // J
0b0010010001110000, // K
0b0000000000111000, // L
0b0000010100110110, // M
0b0010000100110110, // N
0b0000000000111111, // O
0b0000000011110011, // P
0b0010000000111111, // Q
0b0010000011110011, // R
0b0000000011101101, // S
0b0001001000000001, // T
0b0000000000111110, // U
0b0000110000110000, // V
0b0010100000110110, // W
0b0010110100000000, // X
0b0001010100000000, // Y
0b0000110000001001, // Z
0b0000000000111001, // [
0b0010000100000000, //
0b0000000000001111, // ]
0b0000110000000011, // ^
0b0000000000001000, // _
0b0000000100000000, // `
0b0001000001011000, // a
0b0010000001111000, // b
0b0000000011011000, // c
0b0000100010001110, // d
0b0000100001011000, // e
0b0000000001110001, // f
0b0000010010001110, // g
0b0001000001110000, // h
0b0001000000000000, // i
0b0000000000001110, // j
0b0011011000000000, // k
0b0000000000110000, // l
0b0001000011010100, // m
0b0001000001010000, // n
0b0000000011011100, // o
0b0000000101110000, // p
0b0000010010000110, // q
0b0000000001010000, // r
0b0010000010001000, // s
0b0000000001111000, // t
0b0000000000011100, // u
0b0010000000000100, // v
0b0010100000010100, // w
0b0010100011000000, // x
0b0010000000001100, // y
0b0000100001001000, // z
0b0000100101001001, // {
0b0001001000000000, // |
0b0010010010001001, // }
0b0000010100100000, // ~
0b0011111111111111
};
static const uint16_t alpha_point_mask = (1<<14);
static uint8_t i2c_addr;
static uint16_t displaybuffer[8];
extern I2C_HandleTypeDef hI2C3;
void disp_init(uint8_t addr)
{
i2c_addr = addr;
// turn on oscillator
uint8_t data = 0x21;
HAL_StatusTypeDef retval = HAL_I2C_Master_Transmit(&hI2C3, (uint16_t)i2c_addr, &data, 1, 500);
if (retval != HAL_OK) {
Error_Handler_withRetval(retval);
}
disp_blinkRate(HT16K33_BLINK_OFF);
disp_setBrightness(15); // max brightness
}
void disp_setBrightness(uint8_t b)
{
if (b > 15) {
b = 15;
}
uint8_t data = HT16K33_CMD_BRIGHTNESS | b;
HAL_StatusTypeDef retval = HAL_I2C_Master_Transmit(&hI2C3, (uint16_t)i2c_addr, &data, 1, 5);
if (retval != HAL_OK) {
Error_Handler();
}
}
void disp_blinkRate(uint8_t b)
{
if (b > 3) {
b = 0; // turn off if not sure
}
uint8_t data = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1);
HAL_StatusTypeDef retval = HAL_I2C_Master_Transmit(&hI2C3, (uint16_t)i2c_addr, &data, 1, 5);
if (retval != HAL_OK) {
Error_Handler();
}
}
void disp_clear(void)
{
for (uint8_t i = 0; i < 8; i++) {
displaybuffer[i] = 0;
}
}
void disp_writeDigit_raw(uint8_t n, uint16_t bitmask)
{
displaybuffer[n] = bitmask;
}
void disp_writeDigit_value(uint8_t n, uint8_t number, bool point)
{
displaybuffer[n] = alphafonttable[number + 0x30];
if (point) {
displaybuffer[n] |= alpha_point_mask;
}
}
void disp_writeDigit_ascii(uint8_t n, uint8_t character, bool point)
{
displaybuffer[n] = alphafonttable[character];
if (point) {
displaybuffer[n] |= alpha_point_mask;
}
}
void disp_writeDisplay(void)
{
// Build up the payload. Start with 0
uint8_t data[17];
data[0] = 0;
for (uint8_t i = 0; i < 8; i++) {
data[2*i + 1] = displaybuffer[i] & 0xFF;
data[2*i + 2] = displaybuffer[i] >> 8;
}
HAL_StatusTypeDef retval = HAL_I2C_Master_Transmit(&hI2C3, (uint16_t)i2c_addr, data, 17, 5);
if (retval != HAL_OK) {
Error_Handler();
}
}
/***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
----> http://www.adafruit.com/products/
----> http://www.adafruit.com/products/
These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by <NAME>/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
|
hoani/OpenCat
|
WriteInstinct/InstinctNybble.h
|
#define NYBBLE
#define NUM_SKILLS 34
#define I2C_EEPROM
const char bd[] PROGMEM = {
30, 0, 0, 1,
39, 39, -80, -80, 20, 20, 47, 47,
30, 30, -73, -73, 24, 24, 48, 48,
26, 26, -64, -64, 25, 25, 46, 46,
23, 23, -55, -55, 24, 24, 43, 43,
21, 21, -48, -48, 20, 20, 39, 39,
21, 21, -41, -41, 15, 15, 32, 32,
22, 22, -36, -36, 8, 8, 26, 26,
24, 24, -31, -31, 0, 0, 19, 19,
26, 26, -28, -28, -8, -8, 12, 12,
29, 29, -25, -25, -15, -15, 4, 4,
33, 33, -24, -24, -23, -23, -4, -4,
38, 38, -23, -23, -30, -30, -10, -10,
44, 44, -24, -24, -36, -36, -15, -15,
51, 51, -26, -26, -41, -41, -17, -17,
60, 60, -30, -30, -45, -45, -18, -18,
68, 68, -36, -36, -47, -47, -21, -21,
77, 77, -40, -40, -47, -47, -25, -25,
84, 84, -43, -43, -46, -46, -25, -25,
87, 87, -48, -48, -42, -42, -22, -22,
89, 89, -53, -53, -37, -37, -18, -18,
88, 88, -59, -59, -30, -30, -13, -13,
85, 85, -66, -66, -24, -24, -5, -5,
81, 81, -72, -72, -16, -16, 3, 3,
77, 77, -78, -78, -9, -9, 11, 11,
71, 71, -82, -82, -1, -1, 18, 18,
64, 64, -86, -86, 5, 5, 25, 25,
58, 58, -88, -88, 11, 11, 32, 32,
53, 53, -89, -89, 16, 16, 38, 38,
48, 48, -87, -87, 18, 18, 43, 43,
42, 42, -82, -82, 19, 19, 46, 46,
};
const char bi[] PROGMEM = {
30, 0, 60, 1,
78, 87, -31, -34, 43, 26, -48, -44,
78, 86, -32, -32, 44, 25, -47, -50,
78, 85, -32, -30, 44, 26, -47, -54,
78, 83, -33, -29, 44, 29, -45, -56,
79, 79, -33, -29, 43, 34, -45, -56,
79, 77, -34, -28, 43, 38, -44, -58,
79, 75, -35, -28, 43, 43, -42, -57,
79, 75, -35, -28, 43, 45, -42, -57,
80, 76, -35, -28, 43, 45, -40, -57,
83, 76, -36, -29, 40, 45, -39, -54,
86, 77, -37, -29, 35, 44, -37, -54,
88, 77, -37, -30, 30, 44, -37, -52,
89, 77, -37, -30, 27, 44, -38, -52,
88, 78, -37, -31, 26, 43, -38, -51,
88, 78, -37, -31, 25, 43, -40, -48,
87, 78, -34, -31, 25, 44, -44, -48,
86, 78, -33, -32, 25, 44, -48, -47,
85, 78, -31, -32, 27, 44, -52, -47,
83, 78, -30, -33, 28, 44, -54, -45,
80, 79, -29, -34, 32, 43, -56, -44,
77, 79, -28, -34, 38, 43, -58, -44,
76, 79, -28, -35, 42, 43, -57, -42,
75, 79, -28, -35, 44, 43, -57, -42,
76, 81, -28, -36, 45, 42, -57, -39,
76, 84, -28, -36, 45, 39, -57, -39,
77, 87, -29, -37, 44, 33, -54, -37,
77, 88, -30, -37, 44, 29, -52, -37,
77, 88, -30, -37, 44, 27, -52, -38,
77, 88, -31, -37, 44, 26, -51, -40,
78, 88, -31, -36, 43, 25, -51, -41,
};
const char bk[] PROGMEM = {
45, 0, 0, 1,
31, 37, -56, -65, 6, -8, -6, 8,
28, 47, -58, -58, 7, -10, -7, 11,
26, 56, -59, -49, 8, -11, -8, 11,
23, 64, -60, -39, 10, -9, -10, 9,
20, 66, -61, -35, 12, -7, -12, 7,
18, 66, -62, -31, 13, -4, -13, 4,
15, 65, -63, -29, 15, 0, -15, 0,
12, 62, -63, -27, 17, 4, -17, -5,
9, 59, -64, -27, 20, 7, -19, -7,
6, 57, -64, -29, 22, 7, -22, -7,
3, 56, -64, -32, 25, 6, -25, -6,
0, 54, -64, -34, 28, 5, -28, -5,
-3, 52, -64, -37, 31, 4, -31, -4,
-6, 51, -64, -39, 34, 4, -34, -4,
-10, 49, -63, -41, 38, 3, -38, -3,
-10, 47, -66, -43, 36, 3, -36, -3,
-10, 45, -68, -46, 33, 3, -33, -3,
-6, 43, -72, -48, 26, 3, -26, -3,
-3, 40, -75, -49, 21, 3, -21, -4,
1, 38, -75, -51, 16, 4, -16, -4,
12, 36, -75, -53, 6, 5, -6, -5,
24, 33, -72, -55, -2, 5, 2, -5,
34, 31, -67, -56, -7, 6, 7, -6,
45, 28, -60, -58, -10, 7, 10, -7,
54, 26, -51, -59, -11, 8, 11, -8,
62, 23, -41, -60, -9, 10, 9, -10,
66, 20, -36, -61, -8, 12, 7, -12,
67, 18, -32, -62, -5, 13, 5, -13,
65, 15, -29, -63, -1, 15, 1, -15,
63, 12, -27, -63, 3, 17, -4, -17,
59, 9, -27, -64, 7, 20, -7, -19,
57, 6, -29, -64, 7, 22, -7, -22,
56, 3, -31, -64, 6, 25, -6, -25,
54, 0, -34, -64, 5, 28, -5, -28,
53, -3, -36, -64, 4, 31, -4, -31,
51, -6, -39, -64, 4, 34, -4, -34,
49, -10, -41, -63, 3, 38, -4, -38,
47, -10, -43, -66, 3, 36, -3, -36,
45, -10, -45, -68, 3, 33, -3, -33,
43, -6, -47, -72, 3, 26, -3, -26,
41, -3, -49, -75, 3, 21, -3, -21,
39, 1, -51, -75, 4, 16, -4, -16,
36, 12, -53, -75, 4, 6, -4, -6,
34, 24, -54, -72, 5, -2, -5, 2,
31, 34, -56, -67, 6, -7, -6, 7,
};
const char bkL[] PROGMEM = {
37, 0, 0, 1,
32, 37, -56, -62, 3, -8, -6, 2,
31, 49, -58, -59, 3, -11, -7, 3,
30, 59, -59, -57, 3, -10, -9, 4,
29, 66, -61, -54, 4, -8, -11, 5,
28, 67, -62, -53, 5, -5, -13, 4,
27, 65, -63, -51, 5, 0, -15, 3,
26, 61, -63, -51, 6, 5, -18, 2,
25, 58, -64, -51, 6, 7, -20, 0,
24, 56, -64, -51, 7, 6, -24, 0,
23, 54, -64, -52, 7, 5, -27, 0,
22, 52, -64, -53, 8, 4, -31, 0,
21, 50, -63, -53, 9, 4, -35, 0,
20, 48, -63, -54, 8, 3, -39, -1,
20, 46, -67, -55, 8, 3, -35, -1,
21, 43, -72, -56, 6, 3, -27, -1,
22, 40, -75, -56, 4, 3, -21, -2,
24, 38, -76, -57, 3, 4, -14, -2,
28, 35, -74, -58, 1, 5, -3, -2,
32, 32, -69, -58, -1, 6, 5, -3,
36, 29, -61, -59, -3, 7, 10, -3,
40, 26, -51, -59, -4, 8, 11, -3,
44, 23, -39, -60, -5, 10, 9, -4,
45, 19, -34, -60, -5, 12, 6, -4,
45, 16, -31, -61, -4, 14, 3, -5,
45, 13, -27, -61, -2, 17, -4, -5,
44, 9, -27, -62, -1, 20, -7, -6,
43, 6, -29, -62, 0, 22, -7, -6,
42, 2, -32, -63, 0, 26, -6, -7,
41, -2, -35, -63, 0, 30, -5, -8,
40, -5, -38, -64, 0, 34, -4, -8,
39, -10, -41, -64, 1, 38, -4, -9,
38, -10, -43, -66, 1, 36, -3, -8,
37, -8, -46, -66, 1, 30, -3, -7,
36, -4, -48, -67, 1, 23, -3, -5,
35, -1, -51, -67, 2, 18, -4, -3,
34, 12, -53, -66, 2, 6, -4, -1,
33, 26, -55, -64, 2, -3, -5, 1,
};
const char bkR[] PROGMEM = {
37, 0, 0, 1,
31, 34, -58, -65, 6, -2, -3, 8,
28, 38, -59, -56, 7, -4, -3, 11,
25, 42, -60, -46, 9, -4, -3, 10,
22, 44, -60, -36, 11, -5, -4, 8,
18, 46, -61, -32, 13, -4, -5, 5,
15, 45, -61, -29, 15, -3, -5, 0,
12, 45, -62, -27, 18, -2, -6, -5,
8, 43, -62, -28, 20, 0, -6, -7,
5, 42, -63, -31, 24, 0, -7, -6,
1, 42, -63, -34, 27, 0, -7, -5,
-3, 41, -64, -37, 31, 0, -8, -4,
-7, 40, -64, -40, 35, 1, -9, -4,
-10, 39, -65, -42, 39, 1, -8, -3,
-10, 38, -66, -45, 35, 1, -8, -3,
-7, 37, -67, -47, 27, 1, -6, -3,
-3, 36, -68, -49, 21, 1, -4, -4,
3, 35, -67, -52, 14, 2, -3, -4,
17, 34, -65, -54, 3, 2, 0, -5,
30, 33, -63, -56, -5, 2, 1, -6,
43, 32, -61, -57, -10, 3, 3, -7,
54, 31, -58, -59, -11, 3, 4, -8,
64, 30, -55, -60, -9, 4, 5, -10,
66, 29, -54, -61, -6, 4, 5, -12,
66, 28, -52, -62, -3, 5, 3, -14,
63, 27, -51, -63, 3, 5, 2, -17,
59, 26, -51, -64, 7, 6, 1, -19,
57, 24, -51, -64, 7, 6, 0, -22,
55, 23, -51, -64, 6, 7, 0, -26,
53, 22, -52, -64, 5, 8, 0, -30,
51, 21, -53, -64, 4, 8, 0, -34,
49, 20, -54, -63, 3, 9, 0, -38,
47, 20, -55, -66, 3, 8, -1, -36,
44, 20, -55, -71, 3, 7, -1, -29,
42, 21, -56, -74, 3, 5, -1, -23,
39, 22, -57, -75, 4, 4, -2, -18,
36, 26, -57, -75, 4, 1, -2, -6,
33, 31, -58, -71, 5, -1, -2, 3,
};
const char crF[] PROGMEM = {
34, 0, -5, 1,
35, 37, -46, -53, -23, -32, -3, 12,
39, 31, -43, -56, -24, -29, -3, 12,
42, 25, -40, -61, -25, -26, -4, 12,
47, 19, -37, -64, -26, -23, -5, 11,
51, 13, -34, -68, -26, -19, -7, 10,
54, 7, -31, -71, -27, -15, -8, 9,
58, 1, -28, -74, -26, -9, -10, 7,
61, -4, -25, -69, -26, 2, -11, -7,
64, 1, -21, -64, -26, -1, -14, -9,
67, 4, -18, -63, -25, -4, -16, -7,
75, 8, -16, -61, -29, -7, -12, -6,
73, 12, -24, -59, -35, -10, -1, -5,
68, 16, -29, -57, -36, -13, 3, -4,
62, 20, -34, -55, -36, -15, 5, -3,
56, 24, -39, -53, -36, -18, 7, -3,
50, 28, -43, -50, -35, -19, 9, -3,
44, 32, -48, -48, -34, -21, 11, -3,
37, 36, -53, -45, -32, -22, 12, -3,
31, 39, -56, -42, -29, -24, 12, -4,
25, 43, -61, -40, -26, -25, 12, -4,
19, 48, -64, -36, -23, -26, 11, -6,
13, 51, -68, -33, -19, -26, 10, -7,
7, 55, -71, -31, -15, -27, 9, -8,
1, 58, -74, -27, -9, -26, 7, -10,
-4, 62, -69, -24, 2, -26, -7, -11,
1, 65, -64, -21, -1, -26, -9, -14,
4, 68, -63, -17, -4, -25, -7, -16,
8, 76, -61, -17, -7, -31, -6, -8,
12, 72, -59, -25, -10, -35, -5, 0,
16, 67, -57, -30, -13, -36, -4, 3,
20, 61, -55, -35, -15, -36, -3, 5,
24, 55, -53, -39, -18, -36, -3, 7,
28, 49, -50, -44, -19, -35, -3, 9,
32, 42, -48, -49, -21, -33, -3, 11,
};
const char crL[] PROGMEM = {
26, 0, -5, 1,
35, 37, -46, -49, -25, -32, -3, 5,
37, 29, -42, -51, -26, -29, -4, 6,
39, 21, -38, -53, -26, -24, -5, 6,
41, 13, -34, -55, -26, -19, -7, 7,
43, 5, -30, -57, -27, -13, -9, 6,
45, -3, -26, -58, -28, -2, -10, 4,
47, 1, -21, -55, -28, -1, -14, 1,
48, 6, -17, -54, -28, -5, -17, 1,
50, 11, -23, -53, -32, -9, -2, 2,
48, 16, -29, -52, -32, -13, 3, 2,
45, 21, -36, -51, -31, -16, 6, 2,
42, 27, -42, -50, -30, -19, 9, 1,
39, 32, -48, -49, -30, -21, 11, 1,
37, 37, -54, -47, -28, -23, 12, 1,
34, 42, -59, -46, -27, -25, 12, 1,
31, 48, -64, -45, -26, -26, 11, 1,
29, 53, -69, -43, -25, -26, 10, 0,
26, 57, -73, -42, -23, -26, 8, 0,
22, 62, -69, -41, -19, -26, -7, 0,
24, 66, -64, -40, -19, -26, -8, -1,
26, 74, -61, -38, -20, -27, -7, 0,
27, 72, -59, -41, -21, -35, -5, 4,
29, 65, -56, -43, -22, -36, -4, 4,
31, 57, -54, -45, -23, -36, -2, 4,
33, 49, -50, -47, -24, -35, -3, 5,
35, 40, -47, -49, -24, -33, -3, 5,
};
const char crR[] PROGMEM = {
26, 0, -5, 1,
35, 37, -48, -53, -23, -29, 1, 12,
40, 35, -47, -58, -24, -27, 1, 12,
45, 32, -46, -63, -25, -27, 1, 12,
51, 29, -44, -68, -26, -25, 0, 10,
56, 26, -43, -72, -27, -24, 0, 8,
60, 23, -42, -73, -26, -21, 0, -1,
64, 24, -40, -64, -26, -19, 0, -9,
68, 25, -38, -62, -24, -20, -1, -6,
74, 27, -40, -60, -34, -21, 3, -5,
68, 29, -42, -57, -36, -22, 4, -4,
60, 31, -44, -54, -37, -23, 4, -3,
52, 32, -47, -51, -36, -23, 5, -3,
44, 34, -48, -48, -34, -24, 5, -3,
35, 36, -50, -44, -31, -25, 6, -3,
26, 38, -52, -40, -27, -26, 6, -4,
19, 40, -54, -36, -23, -26, 6, -6,
11, 41, -55, -33, -17, -27, 7, -7,
3, 43, -57, -28, -11, -27, 6, -9,
-4, 45, -57, -24, 2, -28, 2, -11,
2, 47, -55, -20, -2, -29, 1, -15,
7, 50, -54, -14, -6, -30, 1, -15,
12, 49, -53, -25, -10, -32, 2, 0,
17, 47, -52, -31, -13, -31, 2, 4,
22, 44, -51, -38, -16, -30, 2, 7,
28, 41, -50, -44, -19, -30, 1, 9,
33, 38, -48, -50, -22, -29, 1, 11,
};
const char ly[] PROGMEM = {
20, 0, -20, 1,
115, 117, -46, -51, 50, 49, -37, -25,
114, 117, -40, -57, 52, 49, -41, -23,
114, 117, -34, -62, 52, 49, -46, -21,
114, 117, -27, -66, 52, 49, -54, -21,
114, 116, -22, -66, 54, 48, -59, -24,
114, 116, -26, -65, 54, 48, -50, -29,
115, 115, -29, -61, 52, 50, -44, -34,
116, 115, -34, -59, 50, 50, -37, -32,
116, 115, -41, -55, 50, 50, -32, -33,
116, 115, -47, -50, 50, 50, -27, -35,
117, 114, -53, -44, 49, 52, -24, -38,
117, 114, -58, -38, 49, 52, -23, -43,
117, 114, -62, -32, 49, 52, -21, -49,
116, 114, -66, -24, 48, 54, -22, -58,
116, 114, -66, -23, 48, 54, -25, -56,
116, 115, -64, -26, 48, 52, -30, -48,
115, 116, -60, -31, 50, 50, -34, -41,
115, 116, -58, -37, 50, 50, -34, -35,
115, 116, -54, -43, 50, 50, -34, -30,
115, 116, -49, -49, 50, 50, -36, -26,
};
const char trF[] PROGMEM = {
24, 0, 0, 1,
43, 48, -51, -56, 7, -2, -8, 1,
48, 31, -47, -65, 7, 2, -7, -8,
52, 12, -42, -68, 8, 14, -7, -25,
55, -2, -37, -64, 11, 27, -7, -43,
58, -5, -31, -58, 14, 35, -9, -55,
60, 0, -25, -59, 18, 31, -11, -47,
61, 7, -19, -61, 24, 24, -15, -36,
61, 14, -12, -61, 30, 18, -20, -29,
62, 21, -8, -61, 35, 14, -22, -22,
67, 27, -11, -60, 27, 11, -15, -17,
68, 33, -22, -57, 15, 8, -6, -13,
61, 38, -41, -55, 2, 7, 1, -10,
48, 43, -56, -51, -2, 7, 1, -8,
31, 48, -65, -47, 2, 7, -8, -7,
12, 52, -68, -42, 14, 8, -25, -7,
-2, 55, -64, -37, 27, 11, -43, -7,
-5, 58, -58, -31, 35, 14, -55, -9,
0, 60, -59, -25, 31, 18, -47, -11,
7, 61, -61, -19, 24, 24, -36, -15,
14, 61, -61, -12, 18, 30, -29, -20,
21, 62, -61, -8, 14, 35, -22, -22,
27, 67, -60, -11, 11, 27, -17, -15,
33, 68, -57, -22, 8, 15, -13, -6,
38, 61, -55, -41, 7, 2, -10, 1,
};
const char trL[] PROGMEM = {
25, 0, 0, 1,
33, 39, -41, -45, 10, -2, -12, -3,
35, 24, -36, -49, 10, 4, -14, -3,
36, 8, -32, -52, 9, 15, -15, -4,
37, -6, -27, -55, 9, 30, -16, -5,
39, -15, -23, -53, 9, 48, -18, -9,
40, -11, -17, -51, 8, 47, -21, -10,
42, -3, -12, -50, 8, 38, -25, -10,
43, 3, -7, -49, 8, 32, -29, -10,
44, 9, 0, -48, 9, 27, -36, -9,
47, 14, -2, -47, 6, 23, -27, -9,
46, 19, -10, -46, 4, 19, -15, -9,
43, 24, -27, -44, 3, 16, -4, -9,
39, 29, -41, -43, 4, 14, 2, -9,
34, 33, -54, -42, 5, 14, 2, -9,
29, 37, -64, -40, 7, 13, -2, -9,
24, 41, -69, -39, 9, 13, -12, -9,
21, 45, -66, -38, 13, 14, -24, -9,
20, 48, -58, -36, 16, 15, -34, -9,
22, 51, -57, -35, 15, 17, -29, -9,
24, 53, -56, -33, 14, 20, -24, -10,
25, 54, -55, -31, 13, 23, -21, -10,
26, 59, -53, -30, 13, 22, -18, -10,
29, 65, -50, -33, 12, 10, -15, -6,
30, 60, -47, -37, 11, 2, -13, -4,
31, 50, -44, -41, 11, -2, -13, -3,
};
const char trR[] PROGMEM = {
25, 0, 0, 1,
31, 36, -43, -48, 14, 4, -9, 3,
35, 31, -41, -60, 14, 6, -9, 1,
39, 27, -40, -67, 13, 8, -9, -6,
43, 23, -39, -69, 13, 10, -9, -17,
46, 20, -37, -61, 14, 15, -9, -32,
49, 21, -36, -57, 16, 15, -9, -32,
52, 22, -34, -56, 18, 15, -10, -27,
54, 24, -32, -55, 21, 14, -10, -22,
54, 26, -31, -54, 26, 13, -12, -19,
62, 27, -31, -52, 16, 12, -8, -16,
65, 29, -33, -49, 6, 12, -6, -14,
57, 31, -39, -46, 0, 11, -4, -13,
46, 32, -43, -42, -3, 10, -3, -13,
31, 34, -47, -38, 1, 10, -3, -13,
16, 35, -50, -34, 9, 9, -4, -14,
-1, 37, -54, -29, 24, 9, -5, -15,
-11, 38, -54, -25, 39, 9, -7, -17,
-14, 40, -51, -20, 50, 8, -11, -20,
-7, 41, -51, -14, 42, 8, -10, -23,
-1, 42, -49, -9, 36, 8, -10, -28,
6, 44, -49, -3, 29, 8, -9, -33,
11, 46, -48, 0, 25, 8, -9, -33,
17, 47, -46, -6, 21, 4, -9, -19,
22, 44, -45, -20, 18, 3, -9, -8,
27, 40, -44, -36, 15, 3, -9, 0,
};
const char vt[] PROGMEM = {
17, 0, 0, 1,
51, 39, -57, -43, -18, 7, 19, -7,
42, 39, -47, -43, 1, 7, 0, -7,
39, 39, -43, -43, 7, 7, -7, -7,
39, 39, -43, -43, 7, 7, -7, -7,
39, 42, -43, -47, 7, 0, -7, 0,
39, 51, -43, -57, 7, -19, -7, 19,
39, 59, -43, -67, 7, -36, -7, 36,
39, 59, -43, -66, 7, -35, -7, 36,
39, 51, -43, -57, 7, -18, -7, 19,
39, 42, -43, -47, 7, 1, -7, 0,
39, 39, -43, -43, 7, 7, -7, -7,
39, 39, -43, -43, 7, 7, -7, -7,
40, 39, -45, -43, 3, 7, -3, -7,
50, 39, -56, -43, -16, 7, 16, -7,
58, 39, -65, -43, -33, 7, 33, -7,
60, 39, -68, -43, -38, 7, 38, -7,
52, 39, -59, -43, -21, 7, 22, -7,
};
const char wkF[] PROGMEM = {
43, 0, 0, 1,
12, 59, -55, -49, 23, 24, -2, -12,
15, 59, -63, -47, 22, 27, -8, -11,
18, 59, -67, -45, 20, 30, -20, -11,
21, 59, -66, -43, 18, 34, -33, -10,
24, 59, -64, -40, 16, 38, -37, -10,
27, 58, -62, -37, 15, 43, -41, -11,
30, 57, -60, -35, 13, 47, -45, -12,
32, 58, -57, -32, 13, 47, -48, -13,
35, 60, -57, -29, 12, 45, -47, -14,
38, 62, -58, -26, 12, 41, -42, -15,
40, 65, -59, -23, 11, 36, -37, -16,
43, 66, -59, -20, 11, 32, -33, -18,
45, 67, -59, -17, 11, 18, -30, -20,
47, 62, -59, -14, 11, 7, -26, -22,
49, 53, -59, -12, 12, 1, -24, -24,
51, 40, -58, -12, 13, 2, -21, -22,
52, 26, -57, -12, 14, 7, -19, -20,
54, 17, -55, -14, 15, 13, -18, -16,
55, 15, -54, -16, 17, 16, -16, -15,
57, 13, -53, -23, 18, 19, -15, -9,
58, 12, -51, -38, 21, 22, -13, -2,
58, 12, -49, -51, 23, 24, -12, -1,
59, 13, -47, -60, 26, 23, -11, -6,
59, 17, -45, -66, 29, 20, -11, -15,
59, 20, -43, -66, 32, 18, -10, -33,
59, 23, -41, -65, 37, 17, -10, -35,
58, 26, -38, -63, 41, 15, -11, -40,
57, 29, -35, -61, 46, 14, -12, -44,
58, 32, -33, -58, 47, 13, -13, -47,
59, 34, -30, -57, 47, 12, -14, -48,
61, 37, -27, -58, 43, 12, -15, -43,
64, 40, -24, -59, 38, 11, -16, -38,
65, 42, -21, -59, 34, 11, -17, -34,
67, 44, -18, -59, 23, 11, -19, -31,
64, 46, -15, -59, 10, 11, -21, -27,
56, 48, -12, -59, 3, 12, -23, -24,
45, 50, -12, -58, 1, 13, -23, -22,
31, 52, -12, -57, 5, 14, -20, -19,
18, 53, -14, -56, 13, 15, -17, -17,
16, 55, -16, -55, 15, 17, -15, -16,
14, 57, -18, -53, 17, 17, -13, -15,
12, 57, -33, -52, 21, 20, -4, -14,
12, 58, -47, -50, 23, 22, 0, -13,
};
const char wkL[] PROGMEM = {
43, 0, 0, 1,
40, 59, -55, -51, 8, 24, -2, -9,
41, 59, -63, -50, 8, 27, -8, -9,
42, 59, -67, -49, 7, 30, -20, -8,
42, 59, -66, -48, 7, 34, -33, -8,
43, 59, -64, -48, 7, 38, -37, -8,
44, 58, -62, -47, 7, 43, -41, -8,
45, 57, -60, -46, 8, 47, -45, -8,
46, 58, -57, -46, 8, 47, -48, -8,
46, 60, -57, -45, 8, 45, -47, -8,
47, 62, -58, -44, 8, 41, -42, -8,
48, 65, -59, -43, 8, 36, -37, -8,
48, 66, -59, -42, 8, 32, -33, -8,
49, 67, -59, -41, 8, 18, -30, -8,
50, 62, -59, -41, 9, 7, -26, -8,
50, 53, -59, -40, 9, 1, -24, -9,
51, 40, -58, -40, 9, 2, -21, -8,
52, 26, -57, -40, 10, 7, -19, -7,
52, 17, -55, -41, 10, 13, -18, -6,
53, 15, -54, -41, 10, 16, -16, -6,
53, 13, -53, -44, 11, 19, -15, -4,
54, 12, -51, -48, 11, 22, -13, -4,
54, 12, -49, -51, 12, 24, -12, -5,
55, 13, -47, -54, 12, 23, -11, -6,
55, 17, -45, -57, 13, 20, -11, -8,
56, 20, -43, -60, 13, 18, -10, -11,
56, 23, -41, -59, 14, 17, -10, -13,
57, 26, -38, -59, 14, 15, -11, -13,
57, 29, -35, -59, 15, 14, -12, -14,
58, 32, -33, -58, 15, 13, -13, -15,
58, 34, -30, -57, 14, 12, -14, -15,
59, 37, -27, -57, 14, 12, -15, -15,
59, 40, -24, -57, 12, 11, -16, -14,
59, 42, -21, -56, 12, 11, -17, -14,
59, 44, -18, -56, 10, 11, -19, -13,
56, 46, -15, -56, 7, 11, -21, -12,
53, 48, -12, -55, 6, 12, -23, -12,
50, 50, -12, -54, 5, 13, -23, -12,
46, 52, -12, -54, 4, 14, -20, -11,
42, 53, -14, -53, 5, 15, -17, -11,
41, 55, -16, -53, 6, 17, -15, -10,
41, 57, -18, -52, 6, 17, -13, -10,
40, 57, -33, -52, 7, 20, -4, -10,
40, 58, -47, -51, 8, 22, 0, -9,
};
const char wkR[] PROGMEM = {
43, 0, 0, 1,
12, 55, -53, -49, 23, 12, -5, -12,
15, 55, -55, -47, 22, 12, -7, -11,
18, 56, -58, -45, 20, 13, -9, -11,
21, 56, -60, -43, 18, 13, -11, -10,
24, 57, -59, -40, 16, 14, -13, -10,
27, 57, -59, -37, 15, 15, -14, -11,
30, 58, -58, -35, 13, 15, -15, -12,
32, 58, -58, -32, 13, 15, -15, -13,
35, 58, -57, -29, 12, 14, -15, -14,
38, 59, -57, -26, 12, 14, -15, -15,
40, 59, -56, -23, 11, 12, -14, -16,
43, 60, -56, -20, 11, 11, -13, -18,
45, 58, -56, -17, 11, 9, -13, -20,
47, 55, -55, -14, 11, 7, -13, -22,
49, 52, -55, -12, 12, 5, -12, -24,
51, 49, -54, -12, 13, 4, -11, -22,
52, 45, -54, -12, 14, 4, -11, -20,
54, 42, -53, -14, 15, 5, -10, -16,
55, 41, -53, -16, 17, 6, -10, -15,
57, 40, -52, -23, 18, 7, -10, -9,
58, 40, -51, -38, 21, 7, -9, -2,
58, 40, -51, -51, 23, 8, -9, -1,
59, 40, -50, -60, 26, 8, -9, -6,
59, 41, -49, -66, 29, 8, -9, -15,
59, 42, -49, -66, 32, 7, -8, -33,
59, 43, -48, -65, 37, 7, -8, -35,
58, 44, -47, -63, 41, 7, -8, -40,
57, 44, -47, -61, 46, 8, -8, -44,
58, 45, -46, -58, 47, 8, -8, -47,
59, 46, -45, -57, 47, 8, -8, -48,
61, 47, -44, -58, 43, 8, -8, -43,
64, 47, -43, -59, 38, 8, -8, -38,
65, 48, -43, -59, 34, 8, -8, -34,
67, 49, -42, -59, 23, 8, -8, -31,
64, 49, -41, -59, 10, 8, -8, -27,
56, 50, -40, -59, 3, 9, -9, -24,
45, 51, -40, -58, 1, 9, -8, -22,
31, 51, -40, -57, 5, 10, -7, -19,
18, 52, -40, -56, 13, 10, -7, -17,
16, 53, -41, -55, 15, 10, -6, -16,
14, 53, -42, -53, 17, 11, -5, -15,
12, 54, -46, -52, 21, 11, -4, -14,
12, 54, -50, -50, 23, 11, -5, -13,
};
const char balance[] PROGMEM = {
1, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 30, 30, -30, -30, 30, 30, -30, -30,
};
const char buttUp[] PROGMEM = {
1, 0, 15, 1,
20, 40, 0, 0, 5, 5, 3, 3, 90, 90, -45, -45, -60, -60, -5, -5,
};
const char calib[] PROGMEM = {
1, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const char dropped[] PROGMEM = {
1, 0, 75, 1,
0, 30, 0, 0, -5, -5, 15, 15, -75, -75, -60, -60, 60, 60, 30, 30,
};
const char hs[] PROGMEM = {
1, 0, -30, 1,
0, -20, -60, 0, -5, -5, 20, 20, 30, 30, -75, -75, 60, 60, 45, 45,
};
const char hs1[] PROGMEM = {
1, 0, 0, 1,
0, -20, -60, 0, -5, -5, 20, 20, 50, 50, -10, -10, 70, 70, -45, -45,
};
const char hs2[] PROGMEM = {
1, 0, 75, 1,
0, -20, -60, 0, -5, -5, 20, 20, 0, 0, 75, 75, 60, 60, -75, -75,
};
const char lifted[] PROGMEM = {
1, 0, -75, 1,
0, -70, 0, 0, 0, 0, 0, 0, 55, 55, 20, 20, 45, 45, 0, 0,
};
const char lu[] PROGMEM = {
1, -30, 15, 1,
-45, 60, -60, 0, 5, 5, 3, 3, -60, 70, -45, -35, 15, -60, 10, -65,
};
const char rest[] PROGMEM = {
1, 0, 0, 1,
-30, -80, -45, 0, -3, -3, 3, 3, 60, 60, -60, -60, -45, -45, 45, 45,
};
const char sit[] PROGMEM = {
1, 0, -20, 1,
0, -20, -60, 0, -5, -5, 20, 20, 30, 30, -90, -90, 60, 60, 45, 45,
};
const char sleep[] PROGMEM = {
1, 0, 0, 1,
-10, -100, 0, 0, -5, -5, 3, 3, 80, 80, -80, -80, -55, -55, 55, 55,
};
const char str[] PROGMEM = {
1, 0, 15, 1,
0, 30, 0, 0, -5, -5, 0, 0, -75, -75, -45, -45, 60, 60, -45, -45,
};
const char zero[] PROGMEM = {
1, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const char hi[] PROGMEM = {
-3, 0, -30, 1,
1, 2, 3,
0, -20, -60, 0, 0, 0, 0, 0, 30, 30, -90, -90, 60, 60, 45, 45, 5, 1, 0, 0,
35, -15, -60, 0, -3, -3, 3, 3, -75, 30, -85, -70, 40, 65, 60, 0, 6, 0, 0, 0,
40, -10, -35, 0, -3, -3, 3, 3, -60, 30, -80, -70, 60, 65, 60, 0, 6, 0, 0, 0,
};
const char pee[] PROGMEM = {
-4, 0, 10, 1,
2, 3, 2,
30, 20, 0, 0, 15, -10, 60, -10, 40, 40, 85, -45, 10, 60, 15, -45, 6, 0, 0, 0,
45, 20, -45, 0, 15, -10, 60, -10, 60, 53, 75, -60, -30, 40, 0, -21, 2, 10, 0, 0,
30, 20, -30, 0, 15, -10, 60, -10, 40, 40, 85, -45, 10, 50, 0, -45, 8, 0, 0, 0,
40, 25, 0, 0, 15, -10, 60, -10, 40, 40, 70, -45, 10, 50, -30, -45, 8, 0, 0, 0,
};
const char pu[] PROGMEM = {
-5, 0, -15, 1,
1, 2, 3,
30, 30, 0, 0, 0, 0, 0, 0, 60, 60, 70, 70, 15, 15, -70, -70, 6, 0, 0, 0,
0, -40, 0, 0, 0, 0, 0, 0, 30, 30, 95, 95, 60, 60, -70, -70, 6, 1, 0, 0,
5, 5, 0, 0, 0, 0, 0, 0, 75, 75, 55, 55, -50, -50, -75, -75, 8, 0, 0, 0,
5, 5, 0, 0, 0, 0, 0, 0, 75, -70, 55, 55, -50, 70, -75, -75, 8, 0, 0, 0,
60, -30, -45, 0, 0, 0, 0, 0, 70, -70, 55, 0, -30, -45, -75, -45, 8, 1, 0, 0,
};
const char rc[] PROGMEM = {
-3, 0, 0, 2,
0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -88, -43, 67, 87, 42, -35, 42, 42, 8, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -83, -88, 87, 42, 42, 42, 42, -40, 8, 0, 0, 0,
-8, -20, -11, 0, -1, -1, 0, 0, 18, 18, 18, 18, -14, -14, -14, -14, 5, 0, 0, 0,
};
#if !defined(MAIN_SKETCH) || !defined(I2C_EEPROM)
//if it's not the main sketch to save data or there's no external EEPROM,
//the list should always contain all information.
const char* skillNameWithType[] = {"bdI", "biI", "bkI", "bkLI", "bkRI", "crFI", "crLI", "crRI", "lyI", "trFI", "trLI", "trRI", "vtI", "wkFI", "wkLI", "wkRI", "balanceI", "buttUpI", "calibI", "droppedI", "hsN", "hs1N", "hs2N", "liftedI", "luI", "restI", "sitI", "sleepI", "strI", "zeroN", "hiI", "peeI", "puI", "rcI",};
const char* progmemPointer[] = {bd, bi, bk, bkL, bkR, crF, crL, crR, ly, trF, trL, trR, vt, wkF, wkL, wkR, balance, buttUp, calib, dropped, hs, hs1, hs2, lifted, lu, rest, sit, sleep, str, zero, hi, pee, pu, rc, };
#else //only need to know the pointers to newbilities, because the intuitions have been saved onto external EEPROM,
//while the newbilities on progmem are assigned to new addresses
const char* progmemPointer[] = {hs, hs1, hs2, zero, };
#endif
//the total byte of instincts is 4712
//the maximal array size is 365 bytes of bk.
//Make sure to leave enough memory for SRAM to work properly. Any single skill should be smaller than 400 bytes for safety.
|
Siege36/LED_clock
|
Clock/config_sample.h
|
#define SSID "#######"
#define PASSWORD "#######"
#define HOSTNAME "#######"
|
renaudbedard/littlebits-arduino
|
Sketches/LFO/Pins.h
|
#include "Arduino.h"
#ifndef PINS_H
#define PINS_H
class In
{
public:
class Digital
{
public:
};
class Analog
{
public:
static const byte Speed = 0;
};
};
class Out
{
public:
class Digital
{
public:
};
class Analog
{
public:
static const byte Lfo = 5;
};
};
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.