void sendChannel1()
{
    sendHeader(1);
    //analog inputs
    for(uint8_t i=0;i < sizeOfArray(channel1);i++) {
        AnalogInputs::Name name = pgm::read(&channel1[i]);
        uint16_t v = AnalogInputs::getRealValue(name);
        printUInt(v);
        printD();
    }

    for(uint8_t i=0;i<MAX_BANANCE_CELLS;i++) {
        printUInt(TheveninMethod::getReadableRthCell(i));
        printD();
    }

    printUInt(TheveninMethod::getReadableBattRth());
    printD();

    printUInt(TheveninMethod::getReadableWiresRth());
    printD();

    printUInt(Monitor::getChargeProcent());
    printD();
    printUInt(Monitor::getETATime());
    printD();

    sendEnd();
}
Exemple #2
0
CubeMesh::CubeMesh(const Vector& size) : Mesh(GL_TRIANGLES, false)
{
    // -0.5 .. 0.5
    static const float vertices[][3] = {
        /* 0 */ { -0.5, -0.5, -0.5 },
        /* 1 */ {  0.5, -0.5, -0.5 },
        /* 2 */ {  0.5, -0.5,  0.5 },
        /* 3 */ { -0.5, -0.5,  0.5 },

        /* 4 */ { -0.5,  0.5, -0.5 },
        /* 5 */ {  0.5,  0.5, -0.5 },
        /* 6 */ {  0.5,  0.5,  0.5 },
        /* 7 */ { -0.5,  0.5,  0.5 },
    };

    static const int faces[][6] = {
        { 0, 1, 2, 3, 0, 2 }, // bottom
        { 4, 7, 6, 5, 4, 6 }, // up
        { 4, 5, 1, 0, 4, 1 }, // front
        { 6, 7, 3, 2, 6, 3 }, // back
        { 7, 4, 0, 3, 7, 0 }, // left
        { 5, 6, 2, 1, 5, 2 }, // right
    };
    
    static const float normals[][3] = {
        {  0.0, -1.0,  0.0 }, // bottom
        {  0.0,  1.0,  0.0 }, // up
        {  0.0,  0.0, -1.0 }, // front
        {  0.0,  0.0,  1.0 }, // back
        { -1.0,  0.0,  0.0 }, // left
        {  1.0,  0.0,  0.0 }, // right
    };

    static const float uv[][2] = {
        { 1.0, 0.0 },
        { 0.0, 0.0 },
        { 0.0, 1.0 },
        { 1.0, 1.0 },
        { 1.0, 0.0 },
        { 0.0, 1.0 },
    };

    for (size_t i = 0; i < sizeOfArray(faces); i++)
    {
        for (int k=0; k<6; k++)
        {
            m_faces.push_back(Face(UV(uv[k][0], uv[k][1]),
                                   Vector(normals[i][0], normals[i][1], normals[i][2]),
                                   size * Vector(vertices[faces[i][k]][0], vertices[faces[i][k]][1], vertices[faces[i][k]][2]))
                             );
        }
    }

    init();
}
bool SettingsMenu::run() {
    int8_t index;
    do {
        index = runSimple();

        if(index < 0) return false;
        switch(index) {
        case sizeOfArray(SettingsStaticMenu) - 2:  //reset
            p_.setDefault();
            buzzer.soundSelect();
            break;
        case sizeOfArray(SettingsStaticMenu) - 1:  //save
            return true;
        default:
            Settings undo(p_);
            if(!runEdit(index))
                p_ = undo;
            p_.check();
            p_.apply();
            break;
        }
    } while(true);
}
Exemple #4
0
/**
	Procedure: cmpP2S

	Purpose: Compares User Input to String (1 True, 0 False)

	Parameters: Buffer(input from keyboard)
				Word(the string being compared to)

	Return value: Comparison Code; Zero If Not Same

	Calls: sizeOfPointer, sizeOfArray

	Globals: None

	Errors: None
**/
int cmpP2S(char *Buffer, char Word[]){
	int WordSize, BufferSize;
	int Temp;
	int flag= 0;
	int i = 0;
	BufferSize = sizeOfPointer(Buffer);
	WordSize = sizeOfArray(Word);
	//printf("\n\n%d",WordSize);
	if(WordSize <1){
		//error word to short
		printf("error 1");
		return -1;
	}
	else{
		if(BufferSize>WordSize){
			//printf(">");
			return 0;
		}
		else if(BufferSize<WordSize){
			//printf("<");
			return 0;
		}
		else{
			while(i< WordSize){
				//printf("\nWord:%c Buff:%c",Word[i],Buffer[i]);
				if(Word[i] != Buffer[i]){
					flag = 1;
					break;
				}
				i++;
			}
			
			//printf("%d",flag);
			if(flag == 0){
				//printf("\nzero!");
				//sys_req(READ,TERMINAL,Buffer,&bufSize);
				return 1;
			}
			else{
				//printf("\nnot 0");
				//sys_req(READ,TERMINAL,Buffer,&bufSize);
				return 0;
			}
		}
	}
}	
jint ImagePHash::registerNative(JNIEnv* env) {
	if (!env) {
		return JNI_ERR;
	}

	jclass ImagePHash = env->FindClass(CLASS_NAME);

	if (ImagePHash == NULL) {
		return JNI_ERR; // Exception
	}

	jint result = env->RegisterNatives(
			ImagePHash,
			NATIVE_METHOD,
			sizeOfArray(NATIVE_METHOD)
		);

	env->DeleteLocalRef(ImagePHash);

	return result;
} // ImagePHash::registerNative
uint8_t Keyboard::getPressedWithDelay()
{
    uint8_t key, i = 0;

    do {
        Time::delayDoIdle(BUTTON_DELAY);
        key = hardware::getKeyPressed();
        if(last_key_count_ == 0) {
            last_key_ = key;
            state_ = 0;
            delay_ = 0;
        }
        last_key_count_ += (last_key_ == key)? 1: -1;

        if(last_key_count_ > BUTTON_DEBOUNCE_COUNT) {
            // button pressed
            last_key_count_ = BUTTON_DEBOUNCE_COUNT;
            i++;
        } else {
            //button changed
            i = 0;
        }
    } while (i <= pgm::read(&stateDelay[state_]));

    if(state_ < sizeOfArray(stateDelay) - 1) {
        delay_++;
        if(delay_ >= pgm::read(&stayInState[state_])) {
            if(last_key_ == BUTTON_NONE) {
                state_ = 0; //we stay at state == 1 while last_key_ == BUTTON_NONE
            } else if(state_ == 0) {
                    Buzzer::soundKeyboard();
            }

            state_ ++;
            delay_ = 0;
        }
    }

    return last_key_;
}
static void test_utility_StringPrinter()
{
    String name = "1.txt";

    StringPrinter("abc\n").printToFile(name);
    StringPrinter().format("abc").format("%s\n", "def").printToFile(name);
    StringPrinter().pushFormat("abc").pushFormat("%s\n", "def").printToFile(name);
    {
        StringPrinter p;
        p.stream() << "ab" << "c";
        p.stream() << "de" << "f\n";
        p.printToFile(name);
    }
    {
        StringPrinter p;
        p.pushStream() << "ab" << "c";
        p.pushStream() << "de" << "f\n";
        p.printToFile(name);
    }

    {
        CachedOutputFileManager::getSingletonPtr()->getFile(name).flush();

        std::ifstream fi(name.c_str());
        const char *strs[] = 
        {
            "abc", "def", "abcdef", "def", "abcdef",
        };

        for (size_t i = 0; i < sizeOfArray(strs); ++i)
        {
            String l;
            ASSERT(getline(fi, l) && l == strs[i]);
        }
    }
}
void SettingsMenu::run() {
    int8_t index;
    do {
        index = runSimple();

        if(index < 0) return;
        switch(index) {
        case sizeOfArray(SettingsStaticMenu) - 1:  //reset
            p_.setDefault();
            Buzzer::soundSelect();
            break;
        default:
            Settings undo(p_);
            if(!runEdit(index)) {
                p_ = undo;
            } else {
                Buzzer::soundSelect();
                p_.check();
            }
            p_.apply();
            break;
        }
    } while(true);
}
static void test_utility_arraySize()
{
    struct A{};
    A a[5];
    ASSERT(sizeOfArray(a) == 5);
}
uint16_t ProgramData::getDefaultVoltagePerCell(VoltageType type)
{
    STATIC_ASSERT(sizeOfArray(voltsPerCell) == ProgramData::LAST_BATTERY_TYPE);
    uint16_t result = pgm::read(&voltsPerCell[battery.type][type]);
    return result;
}
ProgramData::BatteryClass ProgramData::getBatteryClass() {
    STATIC_ASSERT(sizeOfArray(ProgramData::batteryClassMap) == ProgramData::LAST_BATTERY_TYPE);
    return pgm::read(&ProgramData::batteryClassMap[battery.type]);
}
const char * const  ProgramData::batteryString[] PROGMEM = {
        string_battery_None,
        string_battery_NiCd,
        string_battery_NiMH,
        string_battery_Pb,
        string_battery_Life,
        string_battery_Lilo,
        string_battery_Lipo,
        string_battery_Li430,
        string_battery_Li435,
        string_battery_NiZn,
        string_battery_Unknown,
        string_battery_LED,
};

STATIC_ASSERT(sizeOfArray(ProgramData::batteryString) == ProgramData::LAST_BATTERY_TYPE);

const ProgramData::BatteryClass ProgramData::batteryClassMap[] PROGMEM = {
/*None*/    ClassUnknown,
/*NiCd*/    ClassNiXX,
/*NiMH*/    ClassNiXX,
/*Pb*/      ClassPb,
/*Life*/    ClassLiXX,
/*Lilo*/    ClassLiXX,
/*Lipo*/    ClassLiXX,
/*Li430*/   ClassLiXX,
/*Li435*/   ClassLiXX,
/*NiZn*/    ClassNiZn,
/*Unknown*/ ClassUnknown,
/*LED*/     ClassLED
};
#include "AnalogInputsPrivate.h"
#include "memory.h"
#include "Utils.h"

const AnalogInputs::DefaultValues AnalogInputs::inputsP_[] PROGMEM = {

    {{0,  50},         {12913,  11895}},   //Vout_plus_pin
    {{0,  50},         {12913,  11895}},   //Vout_minus_pin
    {{348,  100},         {5491,  1000}},   //Ismps
    {{1230,  100},         {3947,  300}},   //Idischarge

    {{0,  0},         {1,  1}},   //VoutMux
    {{8000,  5940},         {8642,  3479}},   //Tintern
    {{0,  0},         {23492,  14052}},   //Vin
    {{4701,  3660},         {0,  0}},   //Textern

    {{0,  0},         {25219,  3946}},   //Vb0_pin
    {{0,  0},         {26178,  3975}},   //Vb1_pin
    {{0,  0},         {26077,  3957}},   //Vb2_pin
    {{0,  0},         {26171,  3963}},   //Vb3_pin
    {{0,  0},         {25184,  3912}},   //Vb4_pin
    {{0,  0},         {25169,  3916}},   //Vb5_pin
    {{0,  0},         {25405,  3933}},   //Vb6_pin


    {{347,  100},         {5487,  1000}},   //IsmpsSet
    {{1915,  100},         {6210,  300}},   //IdischargeSet
};

STATIC_ASSERT(sizeOfArray(AnalogInputs::inputsP_) == AnalogInputs::PHYSICAL_INPUTS);
inline uint8_t nextInput(uint8_t i) {
    i++;
    if(i >= sizeOfArray(order_analogInputs_on)) i=0;
    return i;
}
Exemple #15
0
void main(void)
{
	WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

	BCSCTL1 = CALBC1_1MHZ;                    // Set DCO (MPU to 1MHz)
	DCOCTL = CALDCO_1MHZ;

	P1SEL = BIT1 + BIT2;                     // P1.1 = RXD, P1.2=TXD
	P1SEL2 = BIT1 + BIT2;                     // P1.1 = RXD, P1.2=TXD

	//P1DIR |= BIT0 + BIT6;					// BIT0 and BIT6 as outputs (LEDS)
	P1OUT = 0;
	P2OUT = 0;

	UCA0CTL1 |= UCSSEL_2;                     // SMCLK
	UCA0BR0 = 104;                            // 1MHz 9600
	UCA0BR1 = 0;                              // 1MHz 9600
	UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1
	UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
	IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt
	__bis_SR_register(GIE);       //interrupts enabled



	char text[32];
	unsigned int text_lenth = 32;
	flushArray(text,text_lenth);

	char command[10];
	unsigned int command_lenth = 10;
	flushArray(command,10);

	//*INIT*//
	text[0] = 'H';
	text[1] = 'E';
	text[2] = 'J';

	text_lenth = sizeOfArray(text);


	//char intext[20];
	//flushArray(intext,20);


	flushArray(interarray,8);

	//char set_name[] = {"AT+NAMEkretsn5"};
	//send_at_command(set_name, 14);

	//char ret_true[] = {"SUCCESS"};
	//char ret_false[] = {"LAME"};


	TACCR0 = 20000;
	TACCTL0 |= CCIE;      // Enable interrupts for CCR0.
	TACTL |= MC_1 + TASSEL1 + ID_0 + TACLR;

	P1DIR |= red_L + red_R  + blue_R + green_R;  // LED pins to outputs, BTN is
	P2DIR |= blue_L + green_L;
	__enable_interrupt();

	//boot_seq(); //Awesome boot sequence!


	for(;;)
	{
		on();
		PWM();
		if(P1IN & button_L && hold_L == 0)
		{
			dim_all();
			mode--;
			hold_L = 1;
			buttonDelay(250);
		}
		if(P1IN & button_R && hold_R == 0)
		{
			dim_all();
			mode++;
			hold_R = 1;
			buttonDelay(250);
		}
		if((P1IN & ~button_L) && (hold_L == 1))
		{
			hold_L = 0;
		}
		if((P1IN & ~button_R) && (hold_R == 1))
		{
			hold_R = 0;
		}



		if(f_read == 1)
		{
			IE2 &= ~UCA0RXIE;
			//send_text(interarray,in_lenth);
			command_lenth = read_buffer(command);

			//*DEBUG*
			//send_text(command, command_lenth);

			f_read = 0;
			IE2 |= UCA0RXIE;
		}


		if(f_command == 1)
		{
			IE2 &= ~UCA0RXIE;

			if ( strcmp(command, "forwards") == 0 )
			{
				mode++;
			}
			else if ( strcmp(command, "backward") == 0 )
			{
				mode--;
			}
			else if ( strcmp(command, "mode0000") == 0 )
			{
				mode = 0;
			}
			else if ( strcmp(command, "mode0001") == 0 )
			{
				mode = 1;
			}
			else if ( strcmp(command, "mode0002") == 0 )
			{
				mode = 2;
			}
			else if ( strcmp(command, "mode0003") == 0 )
			{
				mode = 3;
			}
			else if ( strcmp(command, "mode0004") == 0 )
			{
				mode = 4;
			}
			else if ( strcmp(command, "mode0005") == 0 )
			{
				mode = 5;
			}
			else if ( strcmp(command, "mode0006") == 0 )
			{
				mode = 6;
			}
			else if ( strcmp(command, "mode0007") == 0 )
			{
				mode = 7;
				chaosTime = 0;
			}
			else if ( strcmp(command, "mode0008") == 0 )
			{
				mode = 8;
			}
			else if ( strcmp(command, "mode0009") == 0 )
			{
				mode = 9;
			}
			else if ( strcmp(command, "mode0010") == 0 )
			{
				mode = 10;
			}
			else if (command[0] == 'c' && command[1] == 'u' )
			{
				for(special_iter = 0; special_iter < 6; special_iter++)
				{
					special[special_iter] = command[special_iter+2];
				}
				mode = 8;
			}

			f_command = 0;
			flushArray(command,command_lenth);

			IE2 |= UCA0RXIE;
		}



	}

}
SettingsMenu::SettingsMenu(const Settings &p):
        EditMenu(SettingsStaticMenu, sizeOfArray(SettingsStaticMenu)), p_(p){};